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
27 changes: 19 additions & 8 deletions jQDateRangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Expand Down Expand Up @@ -42,8 +42,19 @@
});
},

_setLimits: function(min, max)
{
if (((min instanceof Date) || (min === false)) || ((max instanceof Date) || (max === false)))
{
if ((min instanceof Date) && (max instanceof Date) && (min < max))
return;

$.ui.rangeSlider.prototype._setLimits.apply(this, [min.valueOf(), max.valueOf()]);
}
},

_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));
Expand All @@ -55,7 +66,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)};
Expand All @@ -81,13 +92,13 @@
return (function(formatter){
return function(value){
return formatter(new Date(value));
}
};
}(formatter));
},

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()]);
Expand All @@ -113,16 +124,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)};
},

Expand Down
115 changes: 78 additions & 37 deletions jQRangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,7 +86,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);
Expand All @@ -94,6 +95,7 @@
this._setRangeOption(key, value);
this._setStepOption(key, value);
this._setScalesOption(key, value);
this._setLimitsOption(key, value);
},

_validProperty: function(object, name, defaultValue){
Expand Down Expand Up @@ -167,7 +169,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();
Expand Down Expand Up @@ -213,6 +215,28 @@
}
},

_setLimits: function(min, max){
if (!this.options.limits)
this.options.limits = {};

if ((typeof(min) === "number") || (min === false))
this.options.limits.min = min;

if ((typeof(max) === "number") || (max === 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");
Expand All @@ -223,7 +247,7 @@
this.container = $("<div class='ui-rangeSlider-container' />")
.css("position", "absolute")
.appendTo(this.element);

this.innerBar = $("<div class='ui-rangeSlider-innerBar' />")
.css("position", "absolute")
.css("top", 0)
Expand Down Expand Up @@ -251,36 +275,48 @@
},

_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
};

var rightHandleParams = {
isLeft: false,
bounds: this.options.bounds,
value: this._values.max,
step: this.options.step
}).appendTo(this.container);
};

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);
},

_createBar: function(){
this.bar = $("<div />")
.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
};

this._bar(barParams);

this.options.range = this._bar("option", "range");
this.options.wheelMode = this._bar("option", "wheelMode");
Expand Down Expand Up @@ -359,10 +395,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;
},

Expand All @@ -389,7 +425,7 @@
this._trigger("valuesChanged");

if (isAutomatic !== true){
this._trigger("userValuesChanged");
this._trigger("userValuesChanged");
}

this._valuesChanged = false;
Expand All @@ -403,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;
},
Expand Down Expand Up @@ -520,11 +556,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;
}

Expand Down Expand Up @@ -589,7 +625,7 @@
}

this._createRuler();
this._setRulerParameters();
this._setRulerParameters();
},

/*
Expand All @@ -616,18 +652,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;
},
Expand All @@ -640,7 +681,7 @@
},

zoomIn: function(quantity){
this._bar("zoomIn", quantity)
this._bar("zoomIn", quantity);
},

zoomOut: function(quantity){
Expand All @@ -658,7 +699,7 @@
this._bar("scrollRight", quantity);
this._bar("stopScroll");
},

/**
* Resize
*/
Expand All @@ -675,7 +716,7 @@

this._destroyWidgets();
this._destroyElements();

this.element.removeClass("ui-rangeSlider");
this.options = null;

Expand Down
13 changes: 9 additions & 4 deletions jQRangeSliderBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,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;
},
Expand Down
Loading