Skip to content

Commit c982e5c

Browse files
Michael DobekidisMichael Dobekidis
Michael Dobekidis
authored and
Michael Dobekidis
committed
Fix for showHandles not working on "false"
1 parent 0c74548 commit c982e5c

File tree

3 files changed

+75
-12
lines changed

3 files changed

+75
-12
lines changed

examples/phase-slide.js

+63-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ phaseSlider = function (game) {
5353
_this.tweenObj.onComplete.add(function () {
5454
this.locked = false;
5555
this.slideIndex += 1;
56-
5756
if (_this.options.autoAnimate === false && this.slideIndex >= _this.options._objects.length - 1) {
5857
if (_this.options._showHandles === true) {
5958
this.sliderControlsGroup.children[0].alpha = 0;
@@ -280,17 +279,35 @@ phaseSlider = function (game) {
280279
sliderBGAlpha: options.sliderBGAlpha || 1,
281280
_customHandleNext: options.customHandleNext || "",
282281
_customHandlePrev: options.customHandlePrev || "",
283-
_showHandles: options.showHandles || true,
282+
_showHandles: options.showHandles == undefined ? true : options.showHandles,
284283
_onNextCallback: options.onNextCallback || false,
285-
_onPrevCallback: options.onPrevCallback || false
284+
_onPrevCallback: options.onPrevCallback || false,
285+
_addModal: options.modal || false,
286+
_modalAlpha: options.modalAlpha || 0.7,
287+
_staticElements: options.staticElements || []
286288
};
287289

288290
//////////////////////////////////////////////////////////////////////////////////////////////
289291

290292
var bgRect;
293+
_this._modal = {};
294+
if(_this.options._addModal === true) {
295+
_this._modal = game.add.graphics(game.width, game.height);
296+
_this._modal.beginFill(0x000000, _this.options._modalAlpha);
297+
_this._modal.x = 0;
298+
_this._modal.y = 0;
299+
_this._modal.inputEnabled = true;
300+
_this._modal.drawRect(0, 0, _this.game.width, _this.game.height);
301+
}
302+
else {
303+
_this._modal = false;
304+
}
291305

292306
//////// OBJECTS GROUP
307+
///
308+
_this.sliderBGGroup = _this.game.add.group();
293309
_this.sliderMainGroup = _this.game.add.group();
310+
_this.sliderBGGroup.width = _this.options._width;
294311
_this.sliderMainGroup.width = _this.options._width;
295312
if (_this.options._mode === "horizontal") {
296313
_this.sliderMainGroup.width = _this.options._width * _this.options._objects.length;
@@ -310,6 +327,10 @@ phaseSlider = function (game) {
310327
_this.sliderMainGroup.height = _this.options._height;
311328
_this.sliderMainGroup.x = _this.options._x;
312329
_this.sliderMainGroup.y = _this.options._y;
330+
//
331+
_this.sliderBGGroup.height = _this.options._height;
332+
_this.sliderBGGroup.x = _this.options._x;
333+
_this.sliderBGGroup.y = _this.options._y;
313334

314335
/// DRAG for horizontal
315336
/*var draggableSprite = _this.game.add.sprite(_this.options._x, _this.options._y);
@@ -352,7 +373,7 @@ phaseSlider = function (game) {
352373
bgRect.drawRect(0, 0, _this.options._width, _this.options._height);
353374
_this.sliderMainGroup.add(bgRect);
354375
} else {
355-
_this.sliderMainGroup.add(_this.options.customSliderBG);
376+
_this.sliderBGGroup.add(_this.options.customSliderBG);
356377
}
357378
// add controls
358379
if (_this.options._showHandles === true) {
@@ -410,26 +431,43 @@ phaseSlider = function (game) {
410431
chevronLeft.alpha = 0;
411432
}
412433
}
434+
else {
435+
436+
}
413437

414438

415439
// ADDING THE BLOCKS
416440
if (_this.options._objects.length > 0) {
417-
for (var i = 0; i < _this.options._objects.length; i++) {
441+
var objArr = _this.options._objects.slice(0);
442+
var length = Number(objArr.length);
443+
for (var i = 0; i < length; i++) {
418444
var x;
419445
var y;
420446
// mode
421447
if (_this.options._mode === "horizontal") {
422-
_this.options._objects[i].x = (_this.options._width * i);
448+
objArr[i].x = (_this.options._width * i);
423449
} else if (_this.options._mode === "vertical-from-top") {
424-
_this.options._objects[i].y = (_this.options._height * i) * -1;
450+
objArr[i].y = (_this.options._height * i) * -1;
425451

426452
} else if (_this.options._mode === "vertical-from-bottom") {
427-
_this.options._objects[i].y = (_this.options._height * i);
453+
objArr[i].y = (_this.options._height * i);
428454
}
429-
_this.sliderMainGroup.add(_this.options._objects[i]);
455+
_this.sliderMainGroup.add(objArr[i]);
430456
}
457+
_this.options._objects = _this.sliderMainGroup.children;
458+
//window.console.log(_this.options._objects.length, _this.options._objects, _this.sliderMainGroup.children.length);
431459
}
432460

461+
462+
// ADDING STATIC ELEMENTS
463+
if(_this.options._staticElements.length > 0) {
464+
for (var i = 0;i<_this.options._staticElements.length;i++ ) {
465+
game.world.bringToTop(_this.options._staticElements[i]);
466+
_this.sliderBGGroup.add(_this.options._staticElements[i]);
467+
}
468+
}
469+
470+
433471
// move the chevrons to top
434472
if (_this.options._showHandles === true) {
435473
_this.sliderControlsGroup.add(chevronRight);
@@ -461,13 +499,28 @@ phaseSlider = function (game) {
461499
getCurrentIndex: function () {
462500
return _this.slideIndex;
463501
},
502+
refreshSlider: function() {
503+
504+
},
505+
removeItemAt: function(index) {
506+
_this.sliderMainGroup.removeChildAt(index);
507+
_this.options._objects = _this.sliderMainGroup.children;
508+
},
464509
hideSlider: function() {
465510
_this.sliderMainGroup.visible = false;
466511
_this.sliderControlsGroup.visible = false;
512+
_this.sliderBGGroup.visible = false;
513+
if(_this._modal) {
514+
_this._modal.visible = false;
515+
}
467516
},
468517
showSlider: function() {
469518
_this.sliderMainGroup.visible = true;
470519
_this.sliderControlsGroup.visible = true;
520+
_this.sliderBGGroup.visible = true;
521+
if(_this._modal) {
522+
_this._modal.visible = true;
523+
}
471524
}
472525
};
473-
};
526+
};

phase-slide.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ phaseSlider = function (game) {
279279
sliderBGAlpha: options.sliderBGAlpha || 1,
280280
_customHandleNext: options.customHandleNext || "",
281281
_customHandlePrev: options.customHandlePrev || "",
282-
_showHandles: options.showHandles || true,
282+
_showHandles: options.showHandles == undefined ? true : options.showHandles,
283283
_onNextCallback: options.onNextCallback || false,
284284
_onPrevCallback: options.onPrevCallback || false,
285285
_addModal: options.modal || false,
@@ -431,6 +431,9 @@ phaseSlider = function (game) {
431431
chevronLeft.alpha = 0;
432432
}
433433
}
434+
else {
435+
436+
}
434437

435438

436439
// ADDING THE BLOCKS
@@ -496,6 +499,13 @@ phaseSlider = function (game) {
496499
getCurrentIndex: function () {
497500
return _this.slideIndex;
498501
},
502+
refreshSlider: function() {
503+
504+
},
505+
removeItemAt: function(index) {
506+
_this.sliderMainGroup.removeChildAt(index);
507+
_this.options._objects = _this.sliderMainGroup.children;
508+
},
499509
hideSlider: function() {
500510
_this.sliderMainGroup.visible = false;
501511
_this.sliderControlsGroup.visible = false;

0 commit comments

Comments
 (0)