From 7b9bd0132a4248787b1ed1ad4c3234e3db72446d Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Thu, 25 Apr 2013 15:16:44 +0200 Subject: [PATCH 01/10] Implemented limits --- jQDateRangeSlider.js | 43 +++++++++++++--- jQRangeSlider.js | 110 ++++++++++++++++++++++++++++------------- jQRangeSliderBar.js | 63 +++++++++++++++++++++++ jQRangeSliderHandle.js | 24 ++++++--- 4 files changed, 193 insertions(+), 47 deletions(-) diff --git a/jQDateRangeSlider.js b/jQDateRangeSlider.js index 57acdae1..67f1f52f 100644 --- a/jQDateRangeSlider.js +++ b/jQDateRangeSlider.js @@ -9,7 +9,7 @@ (function ($, undefined) { "use strict"; - + $.widget("ui.dateRangeSlider", $.ui.rangeSlider, { options: { bounds: {min: new Date(2010,0,1).valueOf(), max: new Date(2012,0,1).valueOf()}, @@ -17,6 +17,16 @@ }, _create: function(){ + var limits = this.options.limits; + if (limits) + { + if (limits.min instanceof Date) + limits.min = limits.min.getTime(); + + if (limits.max instanceof Date) + limits.max = limits.max.getTime(); + } + $.ui.rangeSlider.prototype._create.apply(this); this.element.addClass("ui-dateRangeSlider"); @@ -42,8 +52,27 @@ }); }, + _setLimits: function(min, max) + { + if (((min instanceof Date) || (min === null) || (min === false)) + && ((max instanceof Date) || (max === null) || (max === false)) + ) + { + if (min instanceof Date) + min = min.getTime(); + + if (max instanceof Date) + max = max.getTime(); + + if (min && max && (min > max)) + return; + + $.ui.rangeSlider.prototype._setLimits.apply(this, [min, max]); + } + }, + _setOption: function(key, value){ - if ((key === "defaultValues" || key === "bounds") && typeof value !== "undefined" && value !== null && this._isValidDate(value.min) && this._isValidDate(value.max)){ + if ((key === "defaultValues" || key === "bounds" || key === "limits") && typeof value !== "undefined" && value !== null && this._isValidDate(value.min) && this._isValidDate(value.max)){ $.ui.rangeSlider.prototype._setOption.apply(this, [key, {min:value.min.valueOf(), max:value.max.valueOf()}]); }else{ $.ui.rangeSlider.prototype._setOption.apply(this, this._toArray(arguments)); @@ -55,7 +84,7 @@ }, option: function(key){ - if (key === "bounds" || key === "defaultValues"){ + if (key === "bounds" || key === "defaultValues" || key === "limits"){ var result = $.ui.rangeSlider.prototype.option.apply(this, arguments); return {min:new Date(result.min), max:new Date(result.max)}; @@ -87,7 +116,7 @@ values: function(min, max){ var values = null; - + if (this._isValidDate(min) && this._isValidDate(max)) { values = $.ui.rangeSlider.prototype.values.apply(this, [min.valueOf(), max.valueOf()]); @@ -113,16 +142,16 @@ return new Date($.ui.rangeSlider.prototype.max.apply(this)); }, - + bounds: function(min, max){ var result; - + if (this._isValidDate(min) && this._isValidDate(max)) { result = $.ui.rangeSlider.prototype.bounds.apply(this, [min.valueOf(), max.valueOf()]); } else { result = $.ui.rangeSlider.prototype.bounds.apply(this, this._toArray(arguments)); } - + return {min: new Date(result.min), max: new Date(result.max)}; }, diff --git a/jQRangeSlider.js b/jQRangeSlider.js index 149e0578..61d175bf 100644 --- a/jQRangeSlider.js +++ b/jQRangeSlider.js @@ -85,7 +85,7 @@ }, _setOption: function(key, value) { - this._setWheelOption(key, value); + this._setWheelOption(key, value); this._setArrowsOption(key, value); this._setLabelsOption(key, value); this._setLabelsDurations(key, value); @@ -94,6 +94,7 @@ this._setRangeOption(key, value); this._setStepOption(key, value); this._setScalesOption(key, value); + this._setLimitsOption(key, value); }, _validProperty: function(object, name, defaultValue){ @@ -167,7 +168,7 @@ _setFormatterOption: function(key, value){ if (key === "formatter" && value !== null && typeof value === "function"){ this.options.formatter = value; - + if (this.options.valueLabels !== "hide"){ this._destroyLabels(); this._createLabels(); @@ -213,6 +214,28 @@ } }, + _setLimits: function(min, max){ + if (!this.options.limits) + this.options.limits = {}; + + if ((typeof(min) === "number") || null || false) + this.options.limits.min = min; + + if ((typeof(max) === "number") || null || false) + this.options.limits.max = max; + + this._leftHandle("option", "limits", this.options.limits); + this._rightHandle("option", "limits", this.options.limits); + this._bar("option", "limits", this.options.limits); + }, + + _setLimitsOption: function(key, value){ + if (key === "limits" && typeof value.min !== "undefined" && typeof value.max !== "undefined") + { + this._setLimits(value.min, value.max); + } + }, + _createElements: function(){ if (this.element.css("position") !== "absolute"){ this.element.css("position", "relative"); @@ -223,7 +246,7 @@ this.container = $("
") .css("position", "absolute") .appendTo(this.element); - + this.innerBar = $("
") .css("position", "absolute") .css("top", 0) @@ -251,36 +274,50 @@ }, _createHandles: function(){ - this.leftHandle = this._createHandle({ - isLeft: true, - bounds: this.options.bounds, - value: this._values.min, - step: this.options.step - }).appendTo(this.container); - - this.rightHandle = this._createHandle({ + var leftHandleParams = { + isLeft: true, + bounds: this.options.bounds, + value: this._values.min, + step: this.options.step + }; + + if (this.options.limits) + leftHandleParams.limits = this.options.limits; + + var rightHandleParams = { isLeft: false, bounds: this.options.bounds, value: this._values.max, step: this.options.step - }).appendTo(this.container); + }; + + if (this.options.limits) + rightHandleParams.limits = this.options.limits; + + this.leftHandle = this._createHandle(leftHandleParams).appendTo(this.container); + this.rightHandle = this._createHandle(rightHandleParams).appendTo(this.container); }, - + _createBar: function(){ this.bar = $("
") .prependTo(this.container) .bind("sliderDrag scroll zoom", $.proxy(this._changing, this)) .bind("stop", $.proxy(this._changed, this)); - - this._bar({ - leftHandle: this.leftHandle, - rightHandle: this.rightHandle, - values: {min: this._values.min, max: this._values.max}, - type: this._handleType(), - range: this.options.range, - wheelMode: this.options.wheelMode, - wheelSpeed: this.options.wheelSpeed - }); + + var barParams = { + leftHandle: this.leftHandle, + rightHandle: this.rightHandle, + values: {min: this._values.min, max: this._values.max}, + type: this._handleType(), + range: this.options.range, + wheelMode: this.options.wheelMode, + wheelSpeed: this.options.wheelSpeed + }; + + if (this.options.limits) + barParams.limits = this.options.limits; + + this._bar(barParams); this.options.range = this._bar("option", "range"); this.options.wheelMode = this._bar("option", "wheelMode"); @@ -359,10 +396,10 @@ }, _getValue: function(position, handle){ - if (handle === this.rightHandle){ + if (handle === this.rightHandle){ position = position - handle.outerWidth(); } - + return position * (this.options.bounds.max - this.options.bounds.min) / (this.container.innerWidth() - handle.outerWidth(true)) + this.options.bounds.min; }, @@ -389,7 +426,7 @@ this._trigger("valuesChanged"); if (isAutomatic !== true){ - this._trigger("userValuesChanged"); + this._trigger("userValuesChanged"); } this._valuesChanged = false; @@ -520,11 +557,11 @@ this._scrollTimeout = setTimeout(function(){ if (timesBeforeSpeedingUp === 0){ if (timeout > minTimeout){ - timeout = Math.max(minTimeout, timeout / 1.5); + timeout = Math.max(minTimeout, timeout / 1.5); } else { quantity = Math.min(maxQuantity, quantity * 2); } - + timesBeforeSpeedingUp = 5; } @@ -589,7 +626,7 @@ } this._createRuler(); - this._setRulerParameters(); + this._setRulerParameters(); }, /* @@ -616,18 +653,23 @@ return this._values.max; }, - + bounds: function(min, max){ if (this._isValidValue(min) && this._isValidValue(max) && min < max){ - + this._setBounds(min, max); this._updateRuler(); this._changed(true); } - + return this.options.bounds; }, + limits: function(min, max){ + this._setLimits(min, max); + return this.options.limits; + }, + _isValidValue: function(value){ return typeof value !== "undefined" && parseFloat(value) === value; }, @@ -658,7 +700,7 @@ this._bar("scrollRight", quantity); this._bar("stopScroll"); }, - + /** * Resize */ @@ -675,7 +717,7 @@ this._destroyWidgets(); this._destroyElements(); - + this.element.removeClass("ui-rangeSlider"); this.options = null; diff --git a/jQRangeSliderBar.js b/jQRangeSliderBar.js index 5d21e407..e9ac3e51 100644 --- a/jQRangeSliderBar.js +++ b/jQRangeSliderBar.js @@ -67,6 +67,8 @@ this._setWheelSpeedOption(value); } else if (key === "wheelMode"){ this._setWheelModeOption(value); + } else if (key === "limits"){ + this._setLimitsOption(value); } }, @@ -112,6 +114,40 @@ } }, + _setLimits: function(min, max) + { + if (((min instanceof Date) || (typeof(min) === "number") || (min === null) || (min === false)) + && ((max instanceof Date) || (typeof(max) === "number") || (max === null) || (max === false)) + ) + { + if (min instanceof Date) + min = min.getTime(); + + if (max instanceof Date) + max = max.getTime(); + + if (min && max && (min > max)) + return; + + if (!this.options.limits) + this.options.limits = {}; + + if (min) + this.options.limits.min = min; + + if (min) + this.options.limits.max = max; + } + }, + + _setLimitsOption: function(value) + { + if (typeof value.min !== "undefined" && typeof value.max !== "undefined") + { + this._setLimits(value.min, value.max); + } + }, + _bindMouseWheel: function(mode){ if (mode === "zoom"){ this.element.parent().bind("mousewheel.bar", $.proxy(this._mouseWheelZoom, this)); @@ -233,6 +269,33 @@ this._deactivateRange(); }, + _mouseDrag: function(event) + { + var position = event.pageX - this.cache.click.left; + + if (!position) + return false; + + var limits = this.options.limits; + if (limits) + { + var max = limits.max; + var min = limits.min; + if ((position > 0) && max && (this._values.max >= max)) + return false; + else if ((position < 0) && min && (this._values.min <= min)) + return false; + } + + position = this._constraintPosition(position + this.cache.initialOffset.left); + + this._applyPosition(position); + + this._triggerMouseEvent("sliderDrag"); + + return false; + }, + _mouseStop: function(event){ $.ui.rangeSliderDraggable.prototype._mouseStop.apply(this, [event]); diff --git a/jQRangeSliderHandle.js b/jQRangeSliderHandle.js index 02449d2a..a3cdd719 100644 --- a/jQRangeSliderHandle.js +++ b/jQRangeSliderHandle.js @@ -43,9 +43,9 @@ }, destroy: function(){ - this.element.empty(); + this.element.empty(); - $.ui.rangeSliderDraggable.prototype.destroy.apply(this); + $.ui.rangeSliderDraggable.prototype.destroy.apply(this); }, _setOption: function(key, value){ @@ -68,6 +68,9 @@ }else if (key === "range" && this._checkRange(value)){ this.options.range = value; this.update(); + }else if (key === "limits"){ + this.options.limits = value; + this.update(); } $.ui.rangeSliderDraggable.prototype._setOption.apply(this, [key, value]); @@ -87,7 +90,7 @@ _initElement: function(){ $.ui.rangeSliderDraggable.prototype._initElement.apply(this); - + if (this.cache.parent.width === 0 || this.cache.parent.width === null){ setTimeout($.proxy(this._initElementIfNotDestroyed, this), 500); }else{ @@ -163,7 +166,7 @@ _constraintValue: function(value){ value = Math.min(value, this._bounds().max); value = Math.max(value, this._bounds().min); - + value = this._round(value); if (this.options.range !== false){ @@ -182,6 +185,15 @@ value = Math.max(value, this._bounds().min); } + var limits = this.options.limits; + if (limits) + { + if (this.options.isLeft && (typeof(limits.min) === "number")) + value = Math.max(value, limits.min); + else if (typeof(limits.max) === "number") + value = Math.min(value, limits.max); + } + return value; }, @@ -257,7 +269,7 @@ position: function(position){ if (typeof position !== "undefined"){ this._cache(); - + position = this._constraintPosition(position); this._applyPosition(position); } @@ -294,7 +306,7 @@ return this._left - previous; } - + previous = this._value; this.value(this.add(previous, this.multiplyStep(this.options.step, quantity))); From a6c53ae3a465a3297c38ce31d037a40f6749e5b3 Mon Sep 17 00:00:00 2001 From: Guillaume Gautreau Date: Fri, 26 Apr 2013 14:19:33 +0200 Subject: [PATCH 02/10] Letting the handles constraining values --- jQRangeSliderBar.js | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/jQRangeSliderBar.js b/jQRangeSliderBar.js index e9ac3e51..ddd05441 100644 --- a/jQRangeSliderBar.js +++ b/jQRangeSliderBar.js @@ -269,33 +269,6 @@ this._deactivateRange(); }, - _mouseDrag: function(event) - { - var position = event.pageX - this.cache.click.left; - - if (!position) - return false; - - var limits = this.options.limits; - if (limits) - { - var max = limits.max; - var min = limits.min; - if ((position > 0) && max && (this._values.max >= max)) - return false; - else if ((position < 0) && min && (this._values.min <= min)) - return false; - } - - position = this._constraintPosition(position + this.cache.initialOffset.left); - - this._applyPosition(position); - - this._triggerMouseEvent("sliderDrag"); - - return false; - }, - _mouseStop: function(event){ $.ui.rangeSliderDraggable.prototype._mouseStop.apply(this, [event]); @@ -395,14 +368,19 @@ _constraintPosition: function(left){ var position = {}, - right; + right, constrainedRight; position.left = $.ui.rangeSliderDraggable.prototype._constraintPosition.apply(this, [left]); - position.left = this._leftHandle("position", position.left); - right = this._rightHandle("position", position.left + this.cache.width.outer - this.cache.rightHandle.width); - position.width = right - position.left + this.cache.rightHandle.width; + right = position.left + this.cache.width.outer - this.cache.rightHandle.width; + constrainedRight = this._rightHandle("position", right); + + if (constrainedRight !== right){ + position.left = this._leftHandle("position", position.left + constrainedRight - right); + } + + position.width = constrainedRight - position.left + this.cache.rightHandle.width; return position; }, From febb42c6514f09693f704a0031c1b5c0ae6b2cd3 Mon Sep 17 00:00:00 2001 From: Guillaume Gautreau Date: Fri, 26 Apr 2013 14:22:58 +0200 Subject: [PATCH 03/10] No need to create an option in the bar, since handles are constraining values --- jQRangeSlider.js | 3 --- jQRangeSliderBar.js | 36 ------------------------------------ 2 files changed, 39 deletions(-) diff --git a/jQRangeSlider.js b/jQRangeSlider.js index 61d175bf..5ad82009 100644 --- a/jQRangeSlider.js +++ b/jQRangeSlider.js @@ -314,9 +314,6 @@ wheelSpeed: this.options.wheelSpeed }; - if (this.options.limits) - barParams.limits = this.options.limits; - this._bar(barParams); this.options.range = this._bar("option", "range"); diff --git a/jQRangeSliderBar.js b/jQRangeSliderBar.js index ddd05441..437e0f33 100644 --- a/jQRangeSliderBar.js +++ b/jQRangeSliderBar.js @@ -67,8 +67,6 @@ this._setWheelSpeedOption(value); } else if (key === "wheelMode"){ this._setWheelModeOption(value); - } else if (key === "limits"){ - this._setLimitsOption(value); } }, @@ -114,40 +112,6 @@ } }, - _setLimits: function(min, max) - { - if (((min instanceof Date) || (typeof(min) === "number") || (min === null) || (min === false)) - && ((max instanceof Date) || (typeof(max) === "number") || (max === null) || (max === false)) - ) - { - if (min instanceof Date) - min = min.getTime(); - - if (max instanceof Date) - max = max.getTime(); - - if (min && max && (min > max)) - return; - - if (!this.options.limits) - this.options.limits = {}; - - if (min) - this.options.limits.min = min; - - if (min) - this.options.limits.max = max; - } - }, - - _setLimitsOption: function(value) - { - if (typeof value.min !== "undefined" && typeof value.max !== "undefined") - { - this._setLimits(value.min, value.max); - } - }, - _bindMouseWheel: function(mode){ if (mode === "zoom"){ this.element.parent().bind("mousewheel.bar", $.proxy(this._mouseWheelZoom, this)); From 92b52e89aa753edd64e734447177e839a48f59db Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Fri, 26 Apr 2013 14:37:39 +0200 Subject: [PATCH 04/10] Somes fixes. --- jQDateRangeSlider.js | 24 ++++++++++++++---------- jQRangeSlider.js | 13 +++++++------ jQRangeSliderBar.js | 6 ++---- jQRangeSliderDraggable.js | 7 +++++-- jQRangeSliderHandle.js | 2 +- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/jQDateRangeSlider.js b/jQDateRangeSlider.js index 67f1f52f..0d91f0de 100644 --- a/jQDateRangeSlider.js +++ b/jQDateRangeSlider.js @@ -17,17 +17,8 @@ }, _create: function(){ - var limits = this.options.limits; - if (limits) - { - if (limits.min instanceof Date) - limits.min = limits.min.getTime(); - - if (limits.max instanceof Date) - limits.max = limits.max.getTime(); - } - $.ui.rangeSlider.prototype._create.apply(this); + this._normalizeLimits(); this.element.addClass("ui-dateRangeSlider"); }, @@ -52,6 +43,19 @@ }); }, + _normalizeLimits: function() + { + var limits = this.options.limits; + if (limits) + { + if (limits.min instanceof Date) + limits.min = limits.min.getTime(); + + if (limits.max instanceof Date) + limits.max = limits.max.getTime(); + } + }, + _setLimits: function(min, max) { if (((min instanceof Date) || (min === null) || (min === false)) diff --git a/jQRangeSlider.js b/jQRangeSlider.js index 61d175bf..f3517a69 100644 --- a/jQRangeSlider.js +++ b/jQRangeSlider.js @@ -230,7 +230,7 @@ }, _setLimitsOption: function(key, value){ - if (key === "limits" && typeof value.min !== "undefined" && typeof value.max !== "undefined") + if (key === "limits" && ((typeof(value.min) !== "undefined") || (typeof value.max !== "undefined"))) { this._setLimits(value.min, value.max); } @@ -281,9 +281,6 @@ step: this.options.step }; - if (this.options.limits) - leftHandleParams.limits = this.options.limits; - var rightHandleParams = { isLeft: false, bounds: this.options.bounds, @@ -291,8 +288,12 @@ step: this.options.step }; - if (this.options.limits) - rightHandleParams.limits = this.options.limits; + var limits = this.options.limits; + if (limits) + { + leftHandleParams.limits = limits; + rightHandleParams.limits = limits; + } this.leftHandle = this._createHandle(leftHandleParams).appendTo(this.container); this.rightHandle = this._createHandle(rightHandleParams).appendTo(this.container); diff --git a/jQRangeSliderBar.js b/jQRangeSliderBar.js index e9ac3e51..647af28c 100644 --- a/jQRangeSliderBar.js +++ b/jQRangeSliderBar.js @@ -114,8 +114,7 @@ } }, - _setLimits: function(min, max) - { + _setLimits: function(min, max){ if (((min instanceof Date) || (typeof(min) === "number") || (min === null) || (min === false)) && ((max instanceof Date) || (typeof(max) === "number") || (max === null) || (max === false)) ) @@ -140,8 +139,7 @@ } }, - _setLimitsOption: function(value) - { + _setLimitsOption: function(value){ if (typeof value.min !== "undefined" && typeof value.max !== "undefined") { this._setLimits(value.min, value.max); diff --git a/jQRangeSliderDraggable.js b/jQRangeSliderDraggable.js index 44962640..7f458765 100644 --- a/jQRangeSliderDraggable.js +++ b/jQRangeSliderDraggable.js @@ -24,7 +24,7 @@ destroy: function(){ this.cache = null; - + $.ui.rangeSliderMouseTouch.prototype.destroy.apply(this); }, @@ -70,6 +70,9 @@ _mouseDrag: function(event){ var position = event.pageX - this.cache.click.left; + if (!position) + return false; + position = this._constraintPosition(position + this.cache.initialOffset.left); this._applyPosition(position); @@ -89,7 +92,7 @@ _constraintPosition: function(position){ if (this.element.parent().length !== 0 && this.cache.parent.offset !== null){ - position = Math.min(position, + position = Math.min(position, this.cache.parent.offset.left + this.cache.parent.width - this.cache.width.outer); position = Math.max(position, this.cache.parent.offset.left); } diff --git a/jQRangeSliderHandle.js b/jQRangeSliderHandle.js index a3cdd719..ee4235bc 100644 --- a/jQRangeSliderHandle.js +++ b/jQRangeSliderHandle.js @@ -123,7 +123,7 @@ left: this._parsePixels(parent, "paddingLeft") }, width: parent.width() - } + }; }, _position: function(value){ From e8ebd45c589900dcfd3c8d442c90fb92fbc068a8 Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Mon, 29 Apr 2013 09:47:40 +0200 Subject: [PATCH 05/10] Call _normalizeLimits before parent constructor so that the handles have the correct types. --- jQDateRangeSlider.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/jQDateRangeSlider.js b/jQDateRangeSlider.js index 0d91f0de..93b90597 100644 --- a/jQDateRangeSlider.js +++ b/jQDateRangeSlider.js @@ -17,8 +17,8 @@ }, _create: function(){ - $.ui.rangeSlider.prototype._create.apply(this); this._normalizeLimits(); + $.ui.rangeSlider.prototype._create.apply(this); this.element.addClass("ui-dateRangeSlider"); }, @@ -60,18 +60,11 @@ { if (((min instanceof Date) || (min === null) || (min === false)) && ((max instanceof Date) || (max === null) || (max === false)) + && (min > max) ) { - if (min instanceof Date) - min = min.getTime(); - - if (max instanceof Date) - max = max.getTime(); - - if (min && max && (min > max)) - return; - $.ui.rangeSlider.prototype._setLimits.apply(this, [min, max]); + this._normalizeLimits(); } }, @@ -114,7 +107,7 @@ return (function(formatter){ return function(value){ return formatter(new Date(value)); - } + }; }(formatter)); }, From 7b1b12870dabaa9fdb552c15ccad39eaad7969ea Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Mon, 29 Apr 2013 09:53:36 +0200 Subject: [PATCH 06/10] Fixes _setLimits limits types --- jQDateRangeSlider.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jQDateRangeSlider.js b/jQDateRangeSlider.js index 93b90597..935e7b54 100644 --- a/jQDateRangeSlider.js +++ b/jQDateRangeSlider.js @@ -63,8 +63,13 @@ && (min > max) ) { + if (min instanceof Date) + min = min.getTime(); + + if (max instanceof Date) + max = max.getTime(); + $.ui.rangeSlider.prototype._setLimits.apply(this, [min, max]); - this._normalizeLimits(); } }, From 494d3e37bc71a13326703a321044fc07906d49c3 Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Mon, 29 Apr 2013 10:25:11 +0200 Subject: [PATCH 07/10] Check if limits not undefined whether of number type in handles --- jQDateRangeSlider.js | 7 ------- jQRangeSliderHandle.js | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/jQDateRangeSlider.js b/jQDateRangeSlider.js index 935e7b54..c1548cac 100644 --- a/jQDateRangeSlider.js +++ b/jQDateRangeSlider.js @@ -17,7 +17,6 @@ }, _create: function(){ - this._normalizeLimits(); $.ui.rangeSlider.prototype._create.apply(this); this.element.addClass("ui-dateRangeSlider"); @@ -63,12 +62,6 @@ && (min > max) ) { - if (min instanceof Date) - min = min.getTime(); - - if (max instanceof Date) - max = max.getTime(); - $.ui.rangeSlider.prototype._setLimits.apply(this, [min, max]); } }, diff --git a/jQRangeSliderHandle.js b/jQRangeSliderHandle.js index ee4235bc..1d861c65 100644 --- a/jQRangeSliderHandle.js +++ b/jQRangeSliderHandle.js @@ -188,9 +188,9 @@ var limits = this.options.limits; if (limits) { - if (this.options.isLeft && (typeof(limits.min) === "number")) + if (this.options.isLeft && (typeof(limits.min) !== "undefined")) value = Math.max(value, limits.min); - else if (typeof(limits.max) === "number") + else if (typeof(limits.max) !== "undefined") value = Math.min(value, limits.max); } From 9d3f635105d033f073c5fc6c058eae3ca135c60d Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Mon, 13 May 2013 15:19:05 +0200 Subject: [PATCH 08/10] Bug fix (bouncing handles) --- jQDateRangeSlider.js | 23 +++++--------------- jQRangeSlider.js | 11 ++++++---- jQRangeSliderBar.js | 35 +++++++++++++++++++++++++++++-- jQRangeSliderDraggable.js | 44 ++++++++++++++++++++++++++++++++------- jQRangeSliderHandle.js | 22 ++++++++++++++++---- 5 files changed, 99 insertions(+), 36 deletions(-) diff --git a/jQDateRangeSlider.js b/jQDateRangeSlider.js index c1548cac..59f19926 100644 --- a/jQDateRangeSlider.js +++ b/jQDateRangeSlider.js @@ -42,27 +42,14 @@ }); }, - _normalizeLimits: function() - { - var limits = this.options.limits; - if (limits) - { - if (limits.min instanceof Date) - limits.min = limits.min.getTime(); - - if (limits.max instanceof Date) - limits.max = limits.max.getTime(); - } - }, - _setLimits: function(min, max) { - if (((min instanceof Date) || (min === null) || (min === false)) - && ((max instanceof Date) || (max === null) || (max === false)) - && (min > max) - ) + if (((min instanceof Date) || (min === false)) || ((max instanceof Date) || (max === false))) { - $.ui.rangeSlider.prototype._setLimits.apply(this, [min, max]); + if ((min instanceof Date) && (max instanceof Date) && (min < max)) + return; + + $.ui.rangeSlider.prototype._setLimits.apply(this, [min.valueOf(), max.valueOf()]); } }, diff --git a/jQRangeSlider.js b/jQRangeSlider.js index 9ecdd240..b4a0a3fb 100644 --- a/jQRangeSlider.js +++ b/jQRangeSlider.js @@ -14,6 +14,7 @@ options: { bounds: {min:0, max:100}, defaultValues: {min:20, max:50}, + limits: {min: false, max: false}, wheelMode: null, wheelSpeed: 4, arrows: true, @@ -218,10 +219,10 @@ if (!this.options.limits) this.options.limits = {}; - if ((typeof(min) === "number") || null || false) + if ((typeof(min) === "number") || (min === false)) this.options.limits.min = min; - if ((typeof(max) === "number") || null || false) + if ((typeof(max) === "number") || (max === false)) this.options.limits.max = max; this._leftHandle("option", "limits", this.options.limits); @@ -398,7 +399,9 @@ position = position - handle.outerWidth(); } - return position * (this.options.bounds.max - this.options.bounds.min) / (this.container.innerWidth() - handle.outerWidth(true)) + this.options.bounds.min; + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + return Math.round(position * (this.options.bounds.max - this.options.bounds.min) / (this.container.innerWidth() - handle.outerWidth(true)) + this.options.bounds.min); }, _trigger: function(eventName){ @@ -680,7 +683,7 @@ }, zoomIn: function(quantity){ - this._bar("zoomIn", quantity) + this._bar("zoomIn", quantity); }, zoomOut: function(quantity){ diff --git a/jQRangeSliderBar.js b/jQRangeSliderBar.js index 437e0f33..84386e5c 100644 --- a/jQRangeSliderBar.js +++ b/jQRangeSliderBar.js @@ -187,6 +187,10 @@ var left = this._leftHandle("position"), right = this._rightHandle("position") + this.options.rightHandle.width(); + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + right = Math.round(right); + this.element.offset({ left: left }); @@ -225,6 +229,13 @@ this.cache.leftHandle = {}; this.cache.leftHandle.offset = this.options.leftHandle.offset(); + + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + this.cache.rightHandle.offset.left = Math.round(this.cache.rightHandle.offset.left); + this.cache.rightHandle.offset.top = Math.round(this.cache.rightHandle.offset.top); + this.cache.leftHandle.offset.left = Math.round(this.cache.leftHandle.offset.left); + this.cache.leftHandle.offset.top = Math.round(this.cache.leftHandle.offset.top); }, _mouseStart: function(event){ @@ -263,6 +274,12 @@ this.cache.offset.left = ui.offset.left; this.cache.leftHandle.offset = ui.offset; + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + this.cache.offset.left = Math.round(this.cache.offset.left); + this.cache.leftHandle.offset.left = Math.round(this.cache.leftHandle.offset.left); + this.cache.leftHandle.offset.top = Math.round(this.cache.leftHandle.offset.top); + this._positionBar(); }, @@ -278,6 +295,12 @@ this._values.max = ui.value; this.cache.rightHandle.offset = ui.offset; + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + this.cache.offset.left = Math.round(this.cache.offset.left); + this.cache.leftHandle.offset.left = Math.round(this.cache.leftHandle.offset.left); + this.cache.leftHandle.offset.top = Math.round(this.cache.leftHandle.offset.top); + this._positionBar(); }, @@ -341,11 +364,19 @@ constrainedRight = this._rightHandle("position", right); if (constrainedRight !== right){ - position.left = this._leftHandle("position", position.left + constrainedRight - right); + position.left = this._leftHandle("position", position.left + constrainedRight - right); } - + + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + position.left = Math.round(position.left); + position.width = constrainedRight - position.left + this.cache.rightHandle.width; + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + position.width = Math.round(position.width); + return position; }, diff --git a/jQRangeSliderDraggable.js b/jQRangeSliderDraggable.js index 7f458765..b618b7cb 100644 --- a/jQRangeSliderDraggable.js +++ b/jQRangeSliderDraggable.js @@ -42,7 +42,7 @@ _setOption: function(key, value){ if (key === "containment"){ if (value === null || $(value).length === 0){ - this.options.containment = null + this.options.containment = null; }else{ this.options.containment = $(value); } @@ -56,12 +56,19 @@ _mouseStart: function(event){ this._cache(); this.cache.click = { - left: event.pageX, - top: event.pageY + left: event.pageX, + top: event.pageY }; this.cache.initialOffset = this.element.offset(); + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + this.cache.click.left = Math.round(this.cache.click.left); + this.cache.click.top = Math.round(this.cache.click.top); + this.cache.initialOffset.left = Math.round(this.cache.initialOffset.left); + this.cache.initialOffset.top = Math.round(this.cache.initialOffset.top); + this._triggerMouseEvent("mousestart"); return true; @@ -70,6 +77,10 @@ _mouseDrag: function(event){ var position = event.pageX - this.cache.click.left; + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + position = Math.round(position); + if (!position) return false; @@ -97,6 +108,10 @@ position = Math.max(position, this.cache.parent.offset.left); } + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + position = Math.round(position); + return position; }, @@ -104,7 +119,7 @@ var offset = { top: this.cache.offset.top, left: position - } + }; this.element.offset({left:position}); @@ -129,6 +144,11 @@ this._cacheDimensions(); this.cache.offset = this.element.offset(); + + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + this.cache.offset.left = Math.round(this.cache.offset.left); + this.cache.offset.top = Math.round(this.cache.offset.top); }, _cacheMargins: function(){ @@ -144,20 +164,28 @@ if (this.options.parent !== null){ var container = this.element.parent(); + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX this.cache.parent = { offset: container.offset(), width: container.width() - } + }; + + this.cache.parent.width = Math.round(this.cache.parent.width); + this.cache.parent.offset.left = Math.round(this.cache.parent.offset.left); + this.cache.parent.offset.top = Math.round(this.cache.parent.offset.top); }else{ this.cache.parent = null; } }, _cacheDimensions: function(){ + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX this.cache.width = { - outer: this.element.outerWidth(), - inner: this.element.width() - } + outer: Math.round(this.element.outerWidth()), + inner: Math.round(this.element.width()) + }; }, _parsePixels: function(element, string){ diff --git a/jQRangeSliderHandle.js b/jQRangeSliderHandle.js index 1d861c65..0d4f4316 100644 --- a/jQRangeSliderHandle.js +++ b/jQRangeSliderHandle.js @@ -19,6 +19,7 @@ options: { isLeft: true, bounds: {min:0, max:100}, + limits: {min: false, max: false}, range: false, value: 0, step: false @@ -122,8 +123,11 @@ padding: { left: this._parsePixels(parent, "paddingLeft") }, - width: parent.width() + width: parent.width() >> 0 }; + + this.cache.parent.offset.left = this.cache.parent.offset.left >> 0; + this.cache.parent.offset.top = this.cache.parent.offset.top >> 0; }, _position: function(value){ @@ -188,9 +192,9 @@ var limits = this.options.limits; if (limits) { - if (this.options.isLeft && (typeof(limits.min) !== "undefined")) + if (this.options.isLeft && (limits.min || (limits.min === 0))) value = Math.max(value, limits.min); - else if (typeof(limits.max) !== "undefined") + else if (limits.max || (limits.max === 0)) value = Math.min(value, limits.max); } @@ -216,17 +220,27 @@ availableWidth = this.cache.parent.width - this.cache.width.outer, parentPosition = this.cache.parent.offset.left; - + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + return Math.round(ratio * availableWidth + parentPosition); return ratio * availableWidth + parentPosition; }, _getValueForPosition: function(position){ + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + position = Math.round(position); + var raw = this._getRawValueForPositionAndBounds(position, this.options.bounds.min, this.options.bounds.max); return this._constraintValue(raw); }, _getRawValueForPositionAndBounds: function(position, min, max){ + //Round the position to avoid differences between the offset returned + //by the browsers and the ones based on event.pageX + position = Math.round(position); + var parentPosition = this.cache.parent.offset === null ? 0 : this.cache.parent.offset.left, availableWidth = this.cache.parent.width - this.cache.width.outer, ratio = (position - parentPosition) / availableWidth; From c743324b76038486bf5b60095890fe6e819163f9 Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Mon, 13 May 2013 15:46:17 +0200 Subject: [PATCH 09/10] Bug fix --- jQRangeSliderHandle.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jQRangeSliderHandle.js b/jQRangeSliderHandle.js index 0d4f4316..4355e6cd 100644 --- a/jQRangeSliderHandle.js +++ b/jQRangeSliderHandle.js @@ -123,11 +123,12 @@ padding: { left: this._parsePixels(parent, "paddingLeft") }, - width: parent.width() >> 0 + width: parent.width() }; - this.cache.parent.offset.left = this.cache.parent.offset.left >> 0; - this.cache.parent.offset.top = this.cache.parent.offset.top >> 0; + this.cache.parent.offset.left = Math.round(this.cache.parent.offset.left); + this.cache.parent.offset.top = Math.round(this.cache.parent.offset.top); + this.cache.parent.width = Math.round(this.cache.parent.width); }, _position: function(value){ @@ -223,7 +224,6 @@ //Round the position to avoid differences between the offset returned //by the browsers and the ones based on event.pageX return Math.round(ratio * availableWidth + parentPosition); - return ratio * availableWidth + parentPosition; }, _getValueForPosition: function(position){ From 5983237db86ecdc2f75f0dcc385658def1e8bfce Mon Sep 17 00:00:00 2001 From: Nicolas Frandeboeuf Date: Tue, 14 May 2013 17:16:45 +0200 Subject: [PATCH 10/10] Fix the bouncing handles (really this time) --- jQRangeSlider.js | 8 ++--- jQRangeSliderBar.js | 31 ------------------- jQRangeSliderDraggable.js | 34 ++------------------- jQRangeSliderHandle.js | 23 +++++--------- jQRangeSliderLabel.js | 64 +++++++++++++++++++-------------------- 5 files changed, 46 insertions(+), 114 deletions(-) diff --git a/jQRangeSlider.js b/jQRangeSlider.js index b4a0a3fb..6bcd3221 100644 --- a/jQRangeSlider.js +++ b/jQRangeSlider.js @@ -399,9 +399,7 @@ position = position - handle.outerWidth(); } - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - return Math.round(position * (this.options.bounds.max - this.options.bounds.min) / (this.container.innerWidth() - handle.outerWidth(true)) + this.options.bounds.min); + return position * (this.options.bounds.max - this.options.bounds.min) / (this.container.innerWidth() - handle.outerWidth(true)) + this.options.bounds.min; }, _trigger: function(eventName){ @@ -441,8 +439,8 @@ max = this._max(left, right), changing = (min !== this._values.min || max !== this._values.max); - this._values.min = this._min(left, right); - this._values.max = this._max(left, right); + this._values.min = min; + this._values.max = max; return changing; }, diff --git a/jQRangeSliderBar.js b/jQRangeSliderBar.js index 84386e5c..2443abec 100644 --- a/jQRangeSliderBar.js +++ b/jQRangeSliderBar.js @@ -187,10 +187,6 @@ var left = this._leftHandle("position"), right = this._rightHandle("position") + this.options.rightHandle.width(); - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - right = Math.round(right); - this.element.offset({ left: left }); @@ -229,13 +225,6 @@ this.cache.leftHandle = {}; this.cache.leftHandle.offset = this.options.leftHandle.offset(); - - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - this.cache.rightHandle.offset.left = Math.round(this.cache.rightHandle.offset.left); - this.cache.rightHandle.offset.top = Math.round(this.cache.rightHandle.offset.top); - this.cache.leftHandle.offset.left = Math.round(this.cache.leftHandle.offset.left); - this.cache.leftHandle.offset.top = Math.round(this.cache.leftHandle.offset.top); }, _mouseStart: function(event){ @@ -274,12 +263,6 @@ this.cache.offset.left = ui.offset.left; this.cache.leftHandle.offset = ui.offset; - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - this.cache.offset.left = Math.round(this.cache.offset.left); - this.cache.leftHandle.offset.left = Math.round(this.cache.leftHandle.offset.left); - this.cache.leftHandle.offset.top = Math.round(this.cache.leftHandle.offset.top); - this._positionBar(); }, @@ -295,12 +278,6 @@ this._values.max = ui.value; this.cache.rightHandle.offset = ui.offset; - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - this.cache.offset.left = Math.round(this.cache.offset.left); - this.cache.leftHandle.offset.left = Math.round(this.cache.leftHandle.offset.left); - this.cache.leftHandle.offset.top = Math.round(this.cache.leftHandle.offset.top); - this._positionBar(); }, @@ -367,16 +344,8 @@ position.left = this._leftHandle("position", position.left + constrainedRight - right); } - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - position.left = Math.round(position.left); - position.width = constrainedRight - position.left + this.cache.rightHandle.width; - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - position.width = Math.round(position.width); - return position; }, diff --git a/jQRangeSliderDraggable.js b/jQRangeSliderDraggable.js index b618b7cb..1ee8d345 100644 --- a/jQRangeSliderDraggable.js +++ b/jQRangeSliderDraggable.js @@ -62,13 +62,6 @@ this.cache.initialOffset = this.element.offset(); - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - this.cache.click.left = Math.round(this.cache.click.left); - this.cache.click.top = Math.round(this.cache.click.top); - this.cache.initialOffset.left = Math.round(this.cache.initialOffset.left); - this.cache.initialOffset.top = Math.round(this.cache.initialOffset.top); - this._triggerMouseEvent("mousestart"); return true; @@ -77,10 +70,6 @@ _mouseDrag: function(event){ var position = event.pageX - this.cache.click.left; - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - position = Math.round(position); - if (!position) return false; @@ -108,10 +97,6 @@ position = Math.max(position, this.cache.parent.offset.left); } - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - position = Math.round(position); - return position; }, @@ -144,11 +129,6 @@ this._cacheDimensions(); this.cache.offset = this.element.offset(); - - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - this.cache.offset.left = Math.round(this.cache.offset.left); - this.cache.offset.top = Math.round(this.cache.offset.top); }, _cacheMargins: function(){ @@ -164,32 +144,24 @@ if (this.options.parent !== null){ var container = this.element.parent(); - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX this.cache.parent = { offset: container.offset(), width: container.width() }; - - this.cache.parent.width = Math.round(this.cache.parent.width); - this.cache.parent.offset.left = Math.round(this.cache.parent.offset.left); - this.cache.parent.offset.top = Math.round(this.cache.parent.offset.top); }else{ this.cache.parent = null; } }, _cacheDimensions: function(){ - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX this.cache.width = { - outer: Math.round(this.element.outerWidth()), - inner: Math.round(this.element.width()) + outer: this.element.outerWidth(), + inner: this.element.width() }; }, _parsePixels: function(element, string){ - return parseInt(element.css(string), 10) || 0; + return parseFloat(element.css(string), 10) || 0; }, _triggerMouseEvent: function(event){ diff --git a/jQRangeSliderHandle.js b/jQRangeSliderHandle.js index 4355e6cd..cdc24011 100644 --- a/jQRangeSliderHandle.js +++ b/jQRangeSliderHandle.js @@ -125,10 +125,6 @@ }, width: parent.width() }; - - this.cache.parent.offset.left = Math.round(this.cache.parent.offset.left); - this.cache.parent.offset.top = Math.round(this.cache.parent.offset.top); - this.cache.parent.width = Math.round(this.cache.parent.width); }, _position: function(value){ @@ -221,26 +217,16 @@ availableWidth = this.cache.parent.width - this.cache.width.outer, parentPosition = this.cache.parent.offset.left; - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - return Math.round(ratio * availableWidth + parentPosition); + return ratio * availableWidth + parentPosition; }, _getValueForPosition: function(position){ - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - position = Math.round(position); - var raw = this._getRawValueForPositionAndBounds(position, this.options.bounds.min, this.options.bounds.max); return this._constraintValue(raw); }, _getRawValueForPositionAndBounds: function(position, min, max){ - //Round the position to avoid differences between the offset returned - //by the browsers and the ones based on event.pageX - position = Math.round(position); - var parentPosition = this.cache.parent.offset === null ? 0 : this.cache.parent.offset.left, availableWidth = this.cache.parent.width - this.cache.width.outer, ratio = (position - parentPosition) / availableWidth; @@ -284,7 +270,14 @@ if (typeof position !== "undefined"){ this._cache(); + //There might be a slight difference between the positions, + //so if this difference is lower than 0.005 we consider it null. + var oldPos = position; position = this._constraintPosition(position); + var diff = Math.abs(position - oldPos); + if (diff < 0.005) + return this._left; + this._applyPosition(position); } diff --git a/jQRangeSliderLabel.js b/jQRangeSliderLabel.js index 5fb02fe0..94ef2bd0 100644 --- a/jQRangeSliderLabel.js +++ b/jQRangeSliderLabel.js @@ -8,7 +8,7 @@ */ (function($, undefined){ - + "use strict"; $.widget("ui.rangeSliderLabel", $.ui.rangeSliderMouseTouch, { @@ -100,7 +100,7 @@ this._display(this.options.handle[this.options.handleType]("value")); this._positionner.PositionLabels(); } - + this._positionner.options.show = this.options.show; }, @@ -158,7 +158,7 @@ _onSwitch: function(event, isLeft){ this.options.isLeft = isLeft; - + this._toggleClass(); this._positionner.PositionLabels(); }, @@ -228,7 +228,7 @@ this._resizeProxy = $.proxy(this.onWindowResize, this); $(window).resize(this._resizeProxy); - } + }; this.Destroy = function(){ if (this._resizeProxy){ @@ -246,13 +246,13 @@ this.left = null; this.right = null; } - - this.cache = null; - } + + this.cache = null; + }; this.AfterInit = function () { this.initialized = true; - } + }; this.Cache = function(){ if (this.label1.css("display") === "none"){ @@ -271,7 +271,7 @@ this.CacheElement(this.handle1, this.cache.handle1); this.CacheElement(this.handle2, this.cache.handle2); this.CacheElement(this.label1.offsetParent(), this.cache.offsetParent); - } + }; this.CacheIfNecessary = function(){ if (this.cache === null){ @@ -283,7 +283,7 @@ this.CacheHeight(this.label2, this.cache.label2); this.CacheWidth(this.label1.offsetParent(), this.cache.offsetParent); } - } + }; this.CacheElement = function(label, cache){ this.CacheWidth(label, cache); @@ -299,27 +299,27 @@ left: this.ParsePixels("borderLeftWidth", label), right: this.ParsePixels("borderRightWidth", label) }; - } + }; this.CacheWidth = function(label, cache){ cache.width = label.width(); cache.outerWidth = label.outerWidth(); - } + }; this.CacheHeight = function(label, cache){ cache.outerHeightMargin = label.outerHeight(true); - } + }; this.ParsePixels = function(name, element){ return parseInt(element.css(name), 10) || 0; - } + }; this.BindHandle = function(handle){ handle.bind("updating.positionner", $.proxy(this.onHandleUpdating, this)); handle.bind("update.positionner", $.proxy(this.onHandleUpdated, this)); handle.bind("moving.positionner", $.proxy(this.onHandleMoving, this)); handle.bind("stop.positionner", $.proxy(this.onHandleStop, this)); - } + }; this.PositionLabels = function(){ this.CacheIfNecessary(); @@ -335,7 +335,7 @@ this.PositionLabel(this.label1, label1Pos.left, this.cache.label1); this.PositionLabel(this.label2, label2Pos.left, this.cache.label2); - } + }; this.PositionLabel = function(label, leftOffset, cache){ var parentShift = this.cache.offsetParent.offset.left + this.cache.offsetParent.border.left, @@ -354,7 +354,7 @@ label.css("left", ""); label.css("right", rightPosition); } - } + }; this.ConstraintPositions = function(pos1, pos2){ if (pos1.center < pos2.center && pos1.outerRight > pos2.outerLeft){ @@ -364,7 +364,7 @@ pos2 = this.getLeftPosition(pos2, pos1); pos1 = this.getRightPosition(pos2, pos1); } - } + }; this.getLeftPosition = function(left, right){ var center = (right.center + left.center) / 2, @@ -373,7 +373,7 @@ left.left = leftPos; return left; - } + }; this.getRightPosition = function(left, right){ var center = (right.center + left.center) / 2; @@ -381,7 +381,7 @@ right.left = center + right.cache.margin.left + right.cache.border.left; return right; - } + }; this.ShowIfNecessary = function(){ if (this.options.show === "show" || this.moving || !this.initialized || this.updating) return; @@ -389,7 +389,7 @@ this.label1.stop(true, true).fadeIn(this.options.durationIn || 0); this.label2.stop(true, true).fadeIn(this.options.durationIn || 0); this.moving = true; - } + }; this.HideIfNeeded = function(){ if (this.moving === true){ @@ -397,7 +397,7 @@ this.label2.stop(true, true).delay(this.options.delayOut || 0).fadeOut(this.options.durationOut || 0); this.moving = false; } - } + }; this.onHandleMoving = function(event, ui){ this.ShowIfNecessary(); @@ -405,38 +405,38 @@ this.UpdateHandlePosition(ui); this.PositionLabels(); - } + }; this.onHandleUpdating = function(){ this.updating = true; - } + }; this.onHandleUpdated = function(){ this.updating = false; this.cache = null; - } + }; this.onHandleStop = function(){ this.HideIfNeeded(); - } + }; this.onWindowResize = function(){ this.cache = null; - } + }; this.UpdateHandlePosition = function(ui){ if (this.cache === null) return; - + if (ui.element[0] === this.handle1[0]){ this.UpdatePosition(ui, this.cache.handle1); }else{ this.UpdatePosition(ui, this.cache.handle2); } - } + }; this.UpdatePosition = function(element, cache){ cache.offset = element.offset; - } + }; this.GetRawPosition = function(labelCache, handleCache){ var handleCenter = handleCache.offset.left + handleCache.outerWidth / 2, @@ -453,8 +453,8 @@ outerRight: outerLeft + labelCache.outerWidth + labelCache.margin.left + labelCache.margin.right, cache: labelCache, center: handleCenter - } - } + }; + }; this.Init(); }