Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/dateSliderDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@

_returnValues: function(data){
try{
return "min:" + this._format(data.values.min) + " max:" + this._format(data.values.max);
return "min:" + this._format(data.values.min) + " max:" + this._format(data.values.max) + " lastHandle:" + data.lastHandle;
} catch (e){
return e;
}
Expand Down
2 changes: 1 addition & 1 deletion demo/sliderDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
},

_returnValues: function(data){
return "min:" + data.values.min + " max:" + data.values.max;
return "min:" + data.values.min + " max:" + data.values.max + " lastHandle:" + data.lastHandle;
}

});
Expand Down
24 changes: 23 additions & 1 deletion jQRangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@
setTimeout(function(){
that.element.trigger(eventName, {
label: that.element,
values: that.values()
values: that.values(),
lastHandle: that._lastHandle ? that._lastHandle : null
});
}, 1);
},
Expand Down Expand Up @@ -402,9 +403,30 @@
this._values.min = this._min(left, right);
this._values.max = this._max(left, right);

this._updateLastValues();

return changing;
},

_updateLastValues: function() {
var left = this._leftHandle("value"),
right = this._rightHandle("value");

if (this._lastValues) {
if (this._lastValues.min !== left && this._lastValues.max === right) {
this._lastHandle = 'left';
}
if (this._lastValues.min !== left && this._lastValues.max !== right) {
this._lastHandle = 'middle';
}
if (this._lastValues.min === left && this._lastValues.max !== right) {
this._lastHandle = 'right';
}
}

this._lastValues = {min: this._values.min, max: this._values.max};
},

_min: function(value1, value2){
return Math.min(value1, value2);
},
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,44 @@ var scrollRightTest = new TestCase(
}
);

var handleLeftTest = new TestCase(
"Handle left",
function(){
var self = this;
$(el).on('valuesChanging', function(e,data) {
self.leftResult = data.lastHandle;
})
var leftHandle = el.find(".ui-rangeSlider-leftHandle");
leftHandle.simulate("drag", {
dx: el.find(".ui-rangeSlider-container").innerWidth() - leftHandle.position().left,
dy: 0
});
},
function(){
QUnit.equal(this.leftResult,'left', "Last Handle should be left");
}
);


var handleRightTest = new TestCase(
"Handle right",
function(){
var self = this;
$(el).on('valuesChanging', function(e,data) {
self.rightResult = data.lastHandle;
})
var rightHandle = el.find(".ui-rangeSlider-rightHandle");

rightHandle.simulate("drag", {
dx: el.find(".ui-rangeSlider-container").innerWidth() - rightHandle.position().left - rightHandle.outerWidth(true),
dy: 0
});
},
function(){
QUnit.equal(this.rightResult,'right', "Last Handle should be right");
}
);

var issue12 = new TestCase(
"Issue 12",
function(){
Expand Down Expand Up @@ -605,6 +643,7 @@ testRunner.add("jQRangeSlider", [setUp,
defaultCtorTest,
valuesSetter, changeValuesTest, minMaxSetter, boundsSetter,
zoomInTest, zoomOutTest, scrollLeftTest, scrollRightTest,
handleLeftTest, handleRightTest,
issue12,
rangeLimitMax, rangeLimitMaxWithMinAndMax, rangeLimitMin, rangeLimitMinWithMinAndMax,
destroyTest,
Expand Down