Skip to content

Commit

Permalink
fix(flicking): Corrected direction param on .moveTo()
Browse files Browse the repository at this point in the history
Fixed param value on evaluating direction

Fix naver#436 
Close naver#437
  • Loading branch information
netil authored Jan 5, 2017
1 parent 62f456e commit 6c4f961
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/flicking.js
Original file line number Diff line number Diff line change
Expand Up @@ -1337,22 +1337,18 @@ eg.module("flicking", ["jQuery", eg, window, document, eg.MovableCoord], functio
return this;
}

if (circular) {
indexToMove = no - panel.no;
indexToMove = no - (circular ? panel.no : currentIndex);
isPositive = indexToMove > 0;

// check for real panel count which can be moved on each sides in circular mode
if (circular &&
Math.abs(indexToMove) >
(isPositive ? panel.count - (currentIndex + 1) : currentIndex)) {
indexToMove = indexToMove + (isPositive ? -1 : 1) * panel.count;
isPositive = indexToMove > 0;

// check for real panel count which can be moved on each sides
if (Math.abs(indexToMove) > (isPositive ?
panel.count - (currentIndex + 1) : currentIndex)) {
indexToMove = indexToMove + (isPositive ? -1 : 1) * panel.count;
}

this._setPanelNo({ no: no });
} else {
indexToMove = no - currentIndex;
this._setPanelNo({ index: no, no: no });
}

this._setPanelNo(circular ? { no: no } : { no: no, index: no });
this._conf.indexToMove = indexToMove;
this._setValueToMove(isPositive);

Expand Down
42 changes: 42 additions & 0 deletions test/unit/js/flicking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,48 @@ QUnit.test("Check for functionality", function(assert) {
runTest(1,value);
});

QUnit.test("Check for the direction", function(assert) {
var el;
var inst;
var MC = eg.MovableCoord;

var setCondition = function(no) {
el = inst.$wrapper[0];

el.eventDirection = [];
inst.moveTo(no, 0);
};

var runTest = function(direction) {
var eventDirection = $.unique(el.eventDirection);
var strDirection = direction === MC.DIRECTION_LEFT ? "LEFT" : "RIGHT";

assert.equal(direction, eventDirection.length === 1 && eventDirection[0], "Panel moved to "+ strDirection +"?");
};

// non-circular
inst = this.create("#mflick1");
setCondition(1);
runTest(MC.DIRECTION_LEFT);

setCondition(0);
runTest(MC.DIRECTION_RIGHT);

// circular
inst = this.create("#mflick2", {
circular : true
});

setCondition(2);
runTest(MC.DIRECTION_RIGHT);

setCondition(0);
runTest(MC.DIRECTION_LEFT);

setCondition(1);
runTest(MC.DIRECTION_LEFT);
});

QUnit.test("Animation #1 - Default duration value", function(assert) {
var done = assert.async();

Expand Down

0 comments on commit 6c4f961

Please sign in to comment.