aboutsummaryrefslogtreecommitdiffstats
path: root/ui/source/ui.slider.js
diff options
context:
space:
mode:
authorRichard Worth <rdworth@gmail.com>2008-05-25 04:04:57 +0000
committerRichard Worth <rdworth@gmail.com>2008-05-25 04:04:57 +0000
commitc0f0e4d2ccd3cc317d25baa446bd4af150a41d01 (patch)
treea5721c5f096384d174510840c0face3d5f073a6c /ui/source/ui.slider.js
parent0f2369e8d8975d9128fb45192502a7e4206909d2 (diff)
downloadjquery-ui-c0f0e4d2ccd3cc317d25baa446bd4af150a41d01.tar.gz
jquery-ui-c0f0e4d2ccd3cc317d25baa446bd4af150a41d01.zip
merged experimental mouse branch
Diffstat (limited to 'ui/source/ui.slider.js')
-rw-r--r--ui/source/ui.slider.js73
1 files changed, 34 insertions, 39 deletions
diff --git a/ui/source/ui.slider.js b/ui/source/ui.slider.js
index 15cba687a..a15c917dd 100644
--- a/ui/source/ui.slider.js
+++ b/ui/source/ui.slider.js
@@ -20,11 +20,10 @@
});
};
- $.widget("ui.slider", {
+ $.widget("ui.slider", $.extend($.ui.mouse, {
plugins: {},
ui: function(e) {
return {
- instance: this,
options: this.options,
handle: this.currentHandle,
value: this.options.axis != "both" || !this.options.axis ? Math.round(this.value(null,this.options.axis == "vertical" ? "y" : "x")) : {
@@ -44,8 +43,8 @@
.removeData("slider")
.unbind(".slider");
this.handle
- .unwrap("a")
- .mouse("destroy");
+ .unwrap("a");
+ this.mouseDestroy();
this.generated && this.generated.remove();
},
enable: function() {
@@ -74,40 +73,29 @@
if (!this.handle.length) {
self.handle = self.generated = $(self.options.handles || [0]).map(function() {
var handle = $("<div/>").addClass("ui-slider-handle").appendTo(self.element);
+ handle.data("mouse", {});
if (this.id)
handle.attr("id", this.id);
return handle[0];
});
}
+ this.mouseInit();
+
$(this.handle)
- .mouse({
- executor: this,
- delay: this.options.delay,
- distance: this.options.distance,
- dragPrevention: this.options.prevention ? this.options.prevention.toLowerCase().split(',') : ['input','textarea','button','select','option'],
- start: this.start,
- stop: this.stop,
- drag: this.drag,
- condition: function(e, handle) {
- if(!this.disabled) {
- if(this.currentHandle) this.blur(this.currentHandle);
- this.focus(handle,1);
- return !this.disabled;
- }
- }
- })
+ .data("mouse", {})
.wrap('<a href="javascript:void(0)" style="cursor:default;"></a>')
.parent()
.bind('focus', function(e) { self.focus(this.firstChild); })
.bind('blur', function(e) { self.blur(this.firstChild); })
.bind('keydown', function(e) { self.keydown(e.keyCode, this.firstChild); })
;
-
+
// Bind the click to the slider itself
this.element.bind('mousedown.slider', function(e) {
self.click.apply(self, [e]);
- self.currentHandle.data("mouse").trigger(e);
+ //TODO - fix this. Broken since experimental mouse
+ //self.currentHandle.data("mouse").trigger(e);
self.firstValue = self.firstValue + 1; //This is for always triggering the change event
});
@@ -190,8 +178,6 @@
}, null, !this.options.distance);
},
-
-
createRange: function() {
this.rangeElement = $('<div></div>')
.addClass('ui-slider-range')
@@ -224,6 +210,7 @@
return parseInt(((parseInt(curHandle.css(axis == "x" ? "left" : "top"),10) / (this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(handle,axis))) * this.options.realMax[axis]) + this.options.min[axis],10);
}
+
},
convertValue: function(value,axis) {
return this.options.min[axis] + (value / (this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(null,axis))) * this.options.realMax[axis];
@@ -264,9 +251,10 @@
},
- start: function(e, handle) {
+ mouseStart: function(e) {
var o = this.options;
+ var handle = e.target;
// Prepare the outer size
this.actualSize = { width: this.element.outerWidth() , height: this.element.outerHeight() };
@@ -281,20 +269,17 @@
this.firstValue = this.value();
this.propagate('start', e);
- return false;
-
- },
- stop: function(e) {
- this.propagate('stop', e);
- if (this.firstValue != this.value())
- this.propagate('change', e);
- // This is a especially ugly fix for strange blur events happening on mousemove events
- this.focus(this.currentHandle, true);
- return false;
+
+ if(!this.disabled) {
+ if(this.currentHandle) this.blur(this.currentHandle);
+ this.focus(handle,1);
+ return !this.disabled;
+ }
},
- drag: function(e, handle) {
+ mouseDrag: function(e) {
var o = this.options;
+
var position = { top: e.pageY - this.offset.top - this.clickOffset.top, left: e.pageX - this.offset.left - this.clickOffset.left};
if(!this.currentHandle) this.focus(this.previousHandle, true); //This is a especially ugly fix for strange blur events happening on mousemove events
@@ -323,12 +308,20 @@
x: this.convertValue(position.left, "x"),
y: this.convertValue(position.top, "y")
};
-
+
if (this.rangeElement)
this.updateRange();
this.propagate('slide', e);
return false;
},
+ mouseStop: function(e) {
+ this.propagate('stop', e);
+ if (this.firstValue != this.value())
+ this.propagate('change', e);
+ // This is a especially ugly fix for strange blur events happening on mousemove events
+ this.focus(this.currentHandle, true);
+ return false;
+ },
moveTo: function(value, handle, noPropagation) {
@@ -405,13 +398,15 @@
this.propagate("slide", null);
}
}
- });
+ }));
$.ui.slider.getter = "value";
$.ui.slider.defaults = {
+ distance: 0,
+ delay: 0,
+ cancel: ":input,button",
handle: ".ui-slider-handle",
- distance: 1
};
})(jQuery);