Skip to content

Commit

Permalink
fix(flicking): Fix getting target panel for adaptiveHeight
Browse files Browse the repository at this point in the history
When adpativeHeight option is set and moved by .moveTo(),
correct getting target panel element

Fix #445
Close #446
  • Loading branch information
netil authored Feb 3, 2017
1 parent 725200b commit bcca1a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/flicking.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,21 @@ eg.module("flicking", ["jQuery", eg, window, document, eg.MovableCoord], functio
var height;
var dataName = "data-height";

$panel = this[ "get" + (
var conf = this._conf;
var indexToMove = conf.indexToMove;

$panel = indexToMove === 0 ?

// panel moved by 1
this[ "get" + (
direction === MC.DIRECTION_LEFT && "Next" ||
direction === MC.DIRECTION_RIGHT && "Prev" || ""
) + "Element" ]();
) + "Element" ]() :

// panel moved by .moveTo()
conf.panel.$list.eq(
conf.panel.currIndex + indexToMove
);

$first = $panel.find(":first");
height = $first.attr(dataName);
Expand Down
11 changes: 8 additions & 3 deletions test/unit/js/flicking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,22 @@ QUnit.test("hwAccelerable", function(assert) {
QUnit.test("adaptiveHeight", function(assert) {
// Given
var inst = this.create("#mflick4", {
adaptiveHeight: true,
circular: true
adaptiveHeight: true
});

// Then
for (var i = 0; i < inst._conf.panel.count; i++) {
for (var i = 0; i < inst._conf.panel.count-1; i++) {
var panelHeight = inst.getElement().outerHeight(true);
assert.ok(panelHeight === inst.$container.height(), "Should update container's height according to each panel's height");
inst.next(0);
assert.ok(panelHeight === Number(inst.getPrevElement().children(':first').attr('data-height')), "Should cache each panel's height to first element");
}

// When
inst.moveTo(0,0);

// Then
assert.ok(inst.$container.height() === Number(inst.getElement().children(':first').attr('data-height')), "The container's height should be updated");
});

QUnit.test("thresholdAngle", function(assert) {
Expand Down

0 comments on commit bcca1a2

Please # to comment.