Skip to content

Commit

Permalink
fix(MovableCoord): add support Hammer 2.0.4, 2.0.5 (#432)
Browse files Browse the repository at this point in the history
ref #431
  • Loading branch information
sculove authored Dec 16, 2016
1 parent d00ab0e commit 76fc44a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/movableCoord.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ eg.module("movableCoord", [eg, window, "Hammer"], function(ns, global, HM) {
"use strict";

var SUPPORT_TOUCH = "ontouchstart" in global;
var assignFn = HM.assign || HM.merge;

// jscs:enable maximumLineLength
/**
Expand Down Expand Up @@ -59,7 +60,7 @@ eg.module("movableCoord", [eg, window, "Hammer"], function(ns, global, HM) {
*/
var MC = ns.MovableCoord = ns.Class.extend(ns.Component, {
construct: function(options) {
HM.assign(this.options = {
assignFn(this.options = {
min: [0, 0],
max: [100, 100],
bounce: [10, 10, 10, 10],
Expand Down Expand Up @@ -115,7 +116,7 @@ eg.module("movableCoord", [eg, window, "Hammer"], function(ns, global, HM) {
inputType: [ "touch", "mouse" ]
};

HM.assign(subOptions, options);
assignFn(subOptions, options);

var inputClass = this._convertInputType(subOptions.inputType);
if (!inputClass) {
Expand Down Expand Up @@ -880,6 +881,7 @@ eg.module("movableCoord", [eg, window, "Hammer"], function(ns, global, HM) {
MC.DIRECTION_ALL = MC.DIRECTION_HORIZONTAL | MC.DIRECTION_VERTICAL;

return {
"MovableCoord": ns.MovableCoord
"MovableCoord": ns.MovableCoord,
"assignFn": assignFn
};
});
24 changes: 24 additions & 0 deletions test/unit/js/movableCoord.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,3 +1345,27 @@ QUnit.test("_convertInputType (not support touch)", function(assert) {
// Then
assert.equal(inst._convertInputType(inputType), null, "type is null(not supporting touch)");
});

QUnit.test("assignFn (using Hammer)", function(assert) {
// Given
var mockHammer = {
merge: $.noop
};

// When
var method = eg.invoke("movableCoord", [eg, null, mockHammer]);

// Then
assert.equal(!!method.assignFn, true, "using merge function");

// Given
mockHammer = {
assign: $.noop
};

// When
method = eg.invoke("movableCoord", [eg, null, mockHammer]);

// Then
assert.equal(!!method.assignFn, true, "using assign function");
});

0 comments on commit 76fc44a

Please sign in to comment.