merged experimental mouse branch

This commit is contained in:
Richard Worth 2008-05-25 04:04:57 +00:00
parent 0f2369e8d8
commit c0f0e4d2cc
6 changed files with 420 additions and 405 deletions

View File

@ -1,4 +1,4 @@
/*
/*
* jQuery UI @VERSION
*
* Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
@ -7,7 +7,7 @@
*
* http://docs.jquery.com/UI
*
* $Id: ui.core.js 5634 2008-05-19 20:53:51Z joern.zaefferer $
* $Id: ui.core.js 5587 2008-05-13 19:56:42Z scott.gonzalez $
*/
;(function($) {
@ -26,7 +26,7 @@
for (var i = 0; i < set.length; i++) {
if (instance.options[set[i][0]]) {
set[i][1].apply(instance.element, args);
set[i][1].apply(instance, args);
}
}
}
@ -156,86 +156,123 @@
/** Mouse Interaction Plugin **/
$.widget("ui.mouse", {
init: function() {
$.ui.mouse = {
mouseInit: function() {
var self = this;
this.element
.bind('mousedown.mouse', function() { return self.click.apply(self, arguments); })
.bind('mouseup.mouse', function() { (self.timer && clearTimeout(self.timer)); })
.bind('click.mouse', function() { if(self.initialized) { self.initialized = false; return false; } });
//Prevent text selection in IE
this.element.bind('mousedown.mouse', function(e) {
return self.mouseDown(e);
});
// Prevent text selection in IE
if ($.browser.msie) {
this.unselectable = this.element.attr('unselectable');
this._mouseUnselectable = this.element.attr('unselectable');
this.element.attr('unselectable', 'on');
}
this.started = false;
},
destroy: function() {
this.element.unbind('.mouse').removeData("mouse");
($.browser.msie && this.element.attr('unselectable', this.unselectable));
mouseDestroy: function() {
this.element.unbind('.mouse');
// Restore text selection in IE
($.browser.msie
&& this.element.attr('unselectable', this._mouseUnselectable));
},
trigger: function() { return this.click.apply(this, arguments); },
click: function(e) {
if( e.which != 1 //only left click starts dragging
|| $.inArray(e.target.nodeName.toLowerCase(), this.options.dragPrevention || []) != -1 // Prevent execution on defined elements
|| (this.options.condition && !this.options.condition.apply(this.options.executor || this, [e, this.element])) //Prevent execution on condition
) { return true; }
mouseDown: function(e) {
var self = this;
this.initialized = false;
var initialize = function() {
self._MP = { left: e.pageX, top: e.pageY }; // Store the click mouse position
$(document).bind('mouseup.mouse', function() { return self.stop.apply(self, arguments); });
$(document).bind('mousemove.mouse', function() { return self.drag.apply(self, arguments); });
// we may have missed mouseup (out of window)
(this._mouseStarted
&& this.mouseUp(e));
if(!self.initalized && Math.abs(self._MP.left-e.pageX) >= self.options.distance || Math.abs(self._MP.top-e.pageY) >= self.options.distance) {
(self.options.start && self.options.start.call(self.options.executor || self, e, self.element));
(self.options.drag && self.options.drag.call(self.options.executor || self, e, this.element)); //This is actually not correct, but expected
self.initialized = true;
}
};
this._mouseDownEvent = e;
if(this.options.delay) {
if(this.timer) { clearTimeout(this.timer); }
this.timer = setTimeout(initialize, this.options.delay);
} else {
initialize();
var self = this,
btnIsLeft = (e.which == 1),
elIsCancel = ($(e.target).is(this.options.cancel));
if (!btnIsLeft || elIsCancel) {
return true;
}
return false;
},
stop: function(e) {
if(!this.initialized) {
return $(document).unbind('mouseup.mouse').unbind('mousemove.mouse');
this._mouseDelayMet = (this.options.delay == 0);
if (!this._mouseDelayMet) {
this._mouseDelayTimer = setTimeout(function() {
self._mouseDelayMet = true;
}, this.options.delay);
}
(this.options.stop && this.options.stop.call(this.options.executor || this, e, this.element));
// these delegates are required to keep context
this._mouseMoveDelegate = function(e) {
return self.mouseMove(e);
}
this._mouseUpDelegate = function(e) {
return self.mouseUp(e);
}
$(document)
.bind('mousemove.mouse', this._mouseMoveDelegate)
.bind('mouseup.mouse', this._mouseUpDelegate);
$(document).unbind('mouseup.mouse').unbind('mousemove.mouse');
return false;
},
drag: function(e) {
var o = this.options;
mouseMove: function(e) {
// IE mouseup check - mouseup happened when mouse was out of window
if ($.browser.msie && !e.button) {
return this.stop.call(this, e); // IE mouseup check
return this.mouseUp(e);
}
if(!this.initialized && (Math.abs(this._MP.left-e.pageX) >= o.distance || Math.abs(this._MP.top-e.pageY) >= o.distance)) {
(o.start && o.start.call(o.executor || this, e, this.element));
this.initialized = true;
} else {
if(!this.initialized) { return false; }
if (this._mouseStarted) {
this.mouseDrag(e);
return false;
}
if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
this._mouseStarted =
(this.mouseStart(this._mouseDownEvent, e) !== false);
(this._mouseStarted || this.mouseUp(e));
}
return !this._mouseStarted;
},
mouseUp: function(e) {
$(document)
.unbind('mousemove.mouse', this._mouseMoveDelegate)
.unbind('mouseup.mouse', this._mouseUpDelegate);
if (this._mouseStarted) {
this._mouseStarted = false;
this.mouseStop(e);
}
(o.drag && o.drag.call(this.options.executor || this, e, this.element));
return false;
},
}
});
mouseDistanceMet: function(e) {
return (Math.max(
Math.abs(this._mouseDownEvent.pageX - e.pageX),
Math.abs(this._mouseDownEvent.pageY - e.pageY)
) >= this.options.distance
);
},
mouseDelayMet: function(e) {
return this._mouseDelayMet;
},
// These are placeholder methods, to be overriden by extending plugin
mouseStart: function(e) {},
mouseDrag: function(e) {},
mouseStop: function(e) {}
};
$.ui.mouse.defaults = {
cancel: null,
distance: 0,
delay: 0
};
})(jQuery);

View File

@ -10,41 +10,35 @@
* Depends:
* ui.core.js
*
* Revision: $Id: ui.draggable.js 5618 2008-05-16 16:28:05Z scott.gonzalez $
* Revision: $Id: ui.draggable.js 5672 2008-05-23 04:11:30Z braeker $
*/
;(function($) {
$.widget("ui.draggable", {
$.widget("ui.draggable", $.extend($.ui.mouse, {
init: function() {
//Initialize needed constants
var o = this.options;
//Initialize mouse events for interaction
this.element.mouse({
executor: this,
delay: o.delay,
distance: o.distance,
dragPrevention: o.cancel,
start: this.start,
stop: this.stop,
drag: this.drag,
condition: function(e) {
var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
if(!handle) $(this.options.handle, this.element).each(function() { if(this == e.target) handle = true; });
return !(e.target.className.indexOf("ui-resizable-handle") != -1 || this.options.disabled) && handle;
}
});
this.mouseInit();
//Position the node
if(o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position')))
this.element.css('position', 'relative');
},
start: function(e) {
mouseStart: function(e) {
var o = this.options;
if (o.disabled || $(e.target).is('.ui-resizable-handle')) return false;
var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
if(!handle) $(this.options.handle, this.element).each(function() {
if(this == e.target) handle = true;
});
if (!handle) return false;
if($.ui.ddmanager) $.ui.ddmanager.current = this;
//Create and append the visible helper
@ -118,15 +112,13 @@
}
}
//Call plugins and callbacks
this.propagate("start", e);
this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size
if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
return false;
return true;
},
convertPositionTo: function(d, pos) {
if(!pos) pos = this.position;
@ -170,7 +162,6 @@
if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options
/*
* - Position constraining -
* Constrain the position to a mix of grid, containment.
@ -192,7 +183,7 @@
return position;
},
drag: function(e) {
mouseDrag: function(e) {
//Compute the helpers position
this.position = this.generatePosition(e);
@ -204,10 +195,10 @@
if(!this.options.axis || this.options.axis == "x") this.helper[0].style.left = this.position.left+'px';
if(!this.options.axis || this.options.axis == "y") this.helper[0].style.top = this.position.top+'px';
if($.ui.ddmanager) $.ui.ddmanager.drag(this, e);
return false;
return false;
},
stop: function(e) {
mouseStop: function(e) {
//If we are using droppables, inform the manager about the drop
if ($.ui.ddmanager && !this.options.dropBehaviour)
@ -225,7 +216,6 @@
}
return false;
},
clear: function() {
if(this.options.helper != 'original' && !this.cancelHelperRemoval) this.helper.remove();
@ -236,7 +226,7 @@
// From now on bulk stuff - mainly helpers
plugins: {},
ui: function(e) {
uiHash: function(e) {
return {
helper: this.helper,
position: this.position,
@ -245,24 +235,26 @@
};
},
propagate: function(n,e) {
$.ui.plugin.call(this, n, [e, this.ui()]);
return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.ui()], this.options[n]);
$.ui.plugin.call(this, n, [e, this.uiHash()]);
return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.uiHash()], this.options[n]);
},
destroy: function() {
if(!this.element.data('draggable')) return;
this.element.removeData("draggable").unbind(".draggable").mouse("destroy");
this.element.removeData("draggable").unbind(".draggable");
this.mouseDestroy();
}
}));
$.extend($.ui.draggable, {
defaults: {
distance: 0,
delay: 0,
cancel: ":input,button",
helper: "original",
appendTo: "parent"
}
});
$.ui.draggable.defaults = {
helper: "original",
appendTo: "parent",
cancel: ['input','textarea','button','select','option'],
distance: 1,
delay: 0
};
$.ui.plugin.add("draggable", "cursor", {
start: function(e, ui) {
var t = $('body');

View File

@ -10,11 +10,11 @@
* Depends:
* ui.core.js
*
* Revision: $Id: ui.resizable.js 5653 2008-05-21 04:09:48Z braeker $
* Revision: $Id: ui.resizable.js 5668 2008-05-22 18:17:30Z rdworth $
*/
;(function($) {
$.widget("ui.resizable", {
$.widget("ui.resizable", $.extend($.ui.mouse, {
init: function() {
var self = this, o = this.options;
@ -209,24 +209,7 @@
});
}
//Initialize mouse events for interaction
this.element.mouse({
executor: this,
delay: 0,
distance: 0,
dragPrevention: ['input','textarea','button','select','option'],
start: this.start,
stop: this.stop,
drag: this.drag,
condition: function(e) {
if(this.disabled) return false;
for(var i in this.options.handles) {
if($(this.options.handles[i])[0] == e.target) return true;
}
return false;
}
});
this.mouseInit();
},
plugins: {},
ui: function() {
@ -241,11 +224,13 @@
this.element.triggerHandler(n == "resize" ? n : ["resize", n].join(""), [e, this.ui()], this.options[n]);
},
destroy: function() {
var el = this.element, wrapped = el.children(".ui-resizable").get(0),
var el = this.element, wrapped = el.children(".ui-resizable").get(0);
_destroy = function(exp) {
this.mouseDestroy();
var _destroy = function(exp) {
$(exp).removeClass("ui-resizable ui-resizable-disabled")
.mouse("destroy").removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
.removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
};
_destroy(el);
@ -272,7 +257,15 @@
this.element.addClass("ui-resizable-disabled");
this.disabled = true;
},
start: function(e) {
mouseStart: function(e) {
if(this.disabled) return false;
var handle = false;
for(var i in this.options.handles) {
if($(this.options.handles[i])[0] == e.target) handle = true;
}
if (!handle) return false;
var o = this.options, iniPos = this.element.position(), el = this.element,
num = function(v) { return parseInt(v, 10) || 0; }, ie6 = $.browser.msie && $.browser.version < 7;
o.resizing = true;
@ -312,35 +305,10 @@
$('body').css('cursor', this.axis + '-resize');
this.propagate("start", e);
return false;
return true;
},
stop: function(e) {
this.options.resizing = false;
var o = this.options, num = function(v) { return parseInt(v, 10) || 0; }, self = this;
mouseDrag: function(e) {
if(o.proxy) {
var pr = o.proportionallyResize, ista = pr && (/textarea/i).test(pr.get(0).nodeName),
soffseth = ista && $.ui.hasScroll(pr.get(0), 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
soffsetw = ista ? 0 : self.sizeDiff.width;
var s = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) },
left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
if (!o.animate)
this.element.css($.extend(s, { top: top, left: left }));
if (o.proxy && !o.animate) this._proportionallyResize();
this.helper.remove();
}
if (o.preserveCursor)
$('body').css('cursor', 'auto');
this.propagate("stop", e);
return false;
},
drag: function(e) {
//Increase performance, avoid regex
var el = this.helper, o = this.options, props = {},
self = this, smp = this.originalMousePosition, a = this.axis;
@ -371,6 +339,33 @@
return false;
},
mouseStop: function(e) {
this.options.resizing = false;
var o = this.options, num = function(v) { return parseInt(v, 10) || 0; }, self = this;
if(o.proxy) {
var pr = o.proportionallyResize, ista = pr && (/textarea/i).test(pr.get(0).nodeName),
soffseth = ista && $.ui.hasScroll(pr.get(0), 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
soffsetw = ista ? 0 : self.sizeDiff.width;
var s = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) },
left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
if (!o.animate)
this.element.css($.extend(s, { top: top, left: left }));
if (o.proxy && !o.animate) this._proportionallyResize();
this.helper.remove();
}
if (o.preserveCursor)
$('body').css('cursor', 'auto');
this.propagate("stop", e);
return false;
},
_updateCache: function(data) {
var o = this.options;
this.offset = this.helper.offset();
@ -498,10 +493,13 @@
return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [e, dx, dy]));
}
}
});
}));
$.extend($.ui.resizable, {
defaults: {
cancel: ":input,button",
distance: 0,
delay: 0,
preventDefault: true,
transparent: false,
minWidth: 10,

View File

@ -14,9 +14,9 @@
*/
;(function($) {
$.widget("ui.selectable", {
$.widget("ui.selectable", $.extend($.ui.mouse, {
init: function() {
var instance = this;
var self = this;
this.element.addClass("ui-selectable");
@ -25,7 +25,7 @@
// cache selectee children based on filter
var selectees;
this.refresh = function() {
selectees = $(instance.options.filter, instance.element[0]);
selectees = $(self.options.filter, self.element[0]);
selectees.each(function() {
var $this = $(this);
var pos = $this.offset();
@ -47,24 +47,7 @@
this.selectees = selectees.addClass("ui-selectee");
//Initialize mouse interaction
this.element.mouse({
executor: this,
appendTo: 'body',
delay: 0,
distance: 0,
dragPrevention: ['input','textarea','button','select','option'],
start: this.start,
stop: this.stop,
drag: this.drag,
condition: function(e) {
var isSelectee = false;
$(e.target).parents().andSelf().each(function() {
if($.data(this, "selectable-item")) isSelectee = true;
});
return this.options.keyboard ? !isSelectee : true;
}
});
this.mouseInit();
this.helper = $(document.createElement('div')).css({border:'1px dotted black'});
},
@ -79,8 +62,8 @@
this.element
.removeClass("ui-selectable ui-selectable-disabled")
.removeData("selectable")
.unbind(".selectable")
.mouse("destroy");
.unbind(".selectable");
this.mouseDestroy();
},
enable: function() {
this.element.removeClass("ui-selectable-disabled");
@ -90,20 +73,21 @@
this.element.addClass("ui-selectable-disabled");
this.disabled = true;
},
start: function(ev, element) {
mouseStart: function(e) {
var self = this;
this.opos = [ev.pageX, ev.pageY];
this.opos = [e.pageX, e.pageY];
if (this.disabled)
return;
var options = this.options;
this.selectees = $(options.filter, element);
this.selectees = $(options.filter, this.element[0]);
// selectable START callback
this.element.triggerHandler("selectablestart", [ev, {
"selectable": element,
this.element.triggerHandler("selectablestart", [e, {
"selectable": this.element[0],
"options": options
}], options.start);
@ -112,8 +96,8 @@
this.helper.css({
"z-index": 100,
"position": "absolute",
"left": ev.clientX,
"top": ev.clientY,
"left": e.clientX,
"top": e.clientY,
"width": 0,
"height": 0
});
@ -125,21 +109,28 @@
this.selectees.filter('.ui-selected').each(function() {
var selectee = $.data(this, "selectable-item");
selectee.startselected = true;
if (!ev.ctrlKey) {
if (!e.ctrlKey) {
selectee.$element.removeClass('ui-selected');
selectee.selected = false;
selectee.$element.addClass('ui-unselecting');
selectee.unselecting = true;
// selectable UNSELECTING callback
$(this.element).triggerHandler("selectableunselecting", [ev, {
selectable: element,
self.element.triggerHandler("selectableunselecting", [e, {
selectable: self.element[0],
unselecting: selectee.element,
options: options
}], options.unselecting);
}
});
var isSelectee = false;
$(e.target).parents().andSelf().each(function() {
if($.data(this, "selectable-item")) isSelectee = true;
});
return this.options.keyboard ? !isSelectee : true;
},
drag: function(ev, element) {
mouseDrag: function(e) {
var self = this;
this.dragged = true;
if (this.disabled)
@ -147,7 +138,7 @@
var options = this.options;
var x1 = this.opos[0], y1 = this.opos[1], x2 = ev.pageX, y2 = ev.pageY;
var x1 = this.opos[0], y1 = this.opos[1], x2 = e.pageX, y2 = e.pageY;
if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
@ -155,7 +146,7 @@
this.selectees.each(function() {
var selectee = $.data(this, "selectable-item");
//prevent helper from being selected if appendTo: selectable
if (!selectee || selectee.element == element)
if (!selectee || selectee.element == self.element[0])
return;
var hit = false;
if (options.tolerance == 'touch') {
@ -178,8 +169,8 @@
selectee.$element.addClass('ui-selecting');
selectee.selecting = true;
// selectable SELECTING callback
$(this.element).triggerHandler("selectableselecting", [ev, {
selectable: element,
self.element.triggerHandler("selectableselecting", [e, {
selectable: self.element[0],
selecting: selectee.element,
options: options
}], options.selecting);
@ -187,7 +178,7 @@
} else {
// UNSELECT
if (selectee.selecting) {
if (ev.ctrlKey && selectee.startselected) {
if (e.ctrlKey && selectee.startselected) {
selectee.$element.removeClass('ui-selecting');
selectee.selecting = false;
selectee.$element.addClass('ui-selected');
@ -200,23 +191,23 @@
selectee.unselecting = true;
}
// selectable UNSELECTING callback
$(this.element).triggerHandler("selectableunselecting", [ev, {
selectable: element,
self.element.triggerHandler("selectableunselecting", [e, {
selectable: self.element[0],
unselecting: selectee.element,
options: options
}], options.unselecting);
}
}
if (selectee.selected) {
if (!ev.ctrlKey && !selectee.startselected) {
if (!e.ctrlKey && !selectee.startselected) {
selectee.$element.removeClass('ui-selected');
selectee.selected = false;
selectee.$element.addClass('ui-unselecting');
selectee.unselecting = true;
// selectable UNSELECTING callback
$(this.element).triggerHandler("selectableunselecting", [ev, {
selectable: element,
self.element.triggerHandler("selectableunselecting", [e, {
selectable: self.element[0],
unselecting: selectee.element,
options: options
}], options.unselecting);
@ -224,49 +215,60 @@
}
}
});
return false;
},
stop: function(ev, element) {
mouseStop: function(e) {
var self = this;
this.dragged = false;
var options = this.options;
$('.ui-unselecting', this.element).each(function() {
$('.ui-unselecting', this.element[0]).each(function() {
var selectee = $.data(this, "selectable-item");
selectee.$element.removeClass('ui-unselecting');
selectee.unselecting = false;
selectee.startselected = false;
$(this.element).triggerHandler("selectableunselected", [ev, {
selectable: element,
self.element.triggerHandler("selectableunselected", [e, {
selectable: self.element[0],
unselected: selectee.element,
options: options
}], options.unselected);
});
$('.ui-selecting', this.element).each(function() {
$('.ui-selecting', this.element[0]).each(function() {
var selectee = $.data(this, "selectable-item");
selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
selectee.selecting = false;
selectee.selected = true;
selectee.startselected = true;
$(this.element).triggerHandler("selectableselected", [ev, {
selectable: element,
self.element.triggerHandler("selectableselected", [e, {
selectable: self.element[0],
selected: selectee.element,
options: options
}], options.selected);
});
$(this.element).triggerHandler("selectablestop", [ev, {
selectable: element,
this.element.triggerHandler("selectablestop", [e, {
selectable: self.element[0],
options: this.options
}], this.options.stop);
this.helper.remove();
return false;
}
}));
$.extend($.ui.selectable, {
defaults: {
distance: 0,
delay: 0,
cancel: ":input,button",
appendTo: 'body',
autoRefresh: true,
filter: '*',
tolerance: 'touch'
}
});
$.ui.selectable.defaults = {
appendTo: 'body',
autoRefresh: true,
filter: '*',
tolerance: 'touch'
};
})(jQuery);

View File

@ -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,29 +73,17 @@
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); })
@ -107,7 +94,8 @@
// 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;
if(!this.disabled) {
if(this.currentHandle) this.blur(this.currentHandle);
this.focus(handle,1);
return !this.disabled;
}
},
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;
},
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
@ -329,6 +314,14 @@
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);

View File

@ -26,7 +26,7 @@
return false;
};
$.widget("ui.sortable", {
$.widget("ui.sortable", $.extend($.ui.mouse, {
init: function() {
var o = this.options;
@ -44,39 +44,7 @@
this.offset = this.element.offset();
//Initialize mouse events for interaction
this.element.mouse({
executor: this,
delay: o.delay,
distance: o.distance || 1,
dragPrevention: o.prevention ? o.prevention.toLowerCase().split(',') : ['input','textarea','button','select','option'],
start: this.start,
stop: this.stop,
drag: this.drag,
condition: function(e) {
if(this.options.disabled || this.options.type == 'static') return false;
//Find out if the clicked node (or one of its parents) is a actual item in this.items
var currentItem = null, nodes = $(e.target).parents().each(function() {
if($.data(this, 'sortable-item')) {
currentItem = $(this);
return false;
}
});
if($.data(e.target, 'sortable-item')) currentItem = $(e.target);
if(!currentItem) return false;
if(this.options.handle) {
var validHandle = false;
$(this.options.handle, currentItem).each(function() { if(this == e.target) validHandle = true; });
if(!validHandle) return false;
}
this.currentItem = currentItem;
return true;
}
});
this.mouseInit();
},
plugins: {},
@ -86,7 +54,6 @@
placeholder: (inst || this)["placeholder"] || $([]),
position: (inst || this)["position"].current,
absolutePosition: (inst || this)["position"].absolute,
instance: this,
options: this.options,
element: this.element,
item: (inst || this)["currentItem"],
@ -251,8 +218,8 @@
this.element
.removeClass("ui-sortable ui-sortable-disabled")
.removeData("sortable")
.unbind(".sortable")
.mouse("destroy");
.unbind(".sortable");
this.mouseDestroy();
for ( var i = this.items.length - 1; i >= 0; i-- )
this.items[i].item.removeData("sortable-item");
@ -264,8 +231,7 @@
.appendTo('body')
.css({ position: 'absolute' })
.css((that || this).placeholderElement.offset())
.css({ width: (that || this).placeholderElement.outerWidth(), height: (that || this).placeholderElement.outerHeight() })
;
.css({ width: (that || this).placeholderElement.outerWidth(), height: (that || this).placeholderElement.outerHeight() });
},
contactContainers: function(e) {
for (var i = this.containers.length - 1; i >= 0; i--){
@ -314,10 +280,31 @@
};
},
start: function(e,el) {
mouseStart: function(e) {
var o = this.options;
this.currentContainer = this;
if(this.options.disabled || this.options.type == 'static') return false;
//Find out if the clicked node (or one of its parents) is a actual item in this.items
var currentItem = null, nodes = $(e.target).parents().each(function() {
if($.data(this, 'sortable-item')) {
currentItem = $(this);
return false;
}
});
if($.data(e.target, 'sortable-item')) currentItem = $(e.target);
if(!currentItem) return false;
if(this.options.handle) {
var validHandle = false;
$(this.options.handle, currentItem).each(function() { if(this == e.target) validHandle = true; });
if(!validHandle) return false;
}
this.currentItem = currentItem;
this.refresh();
//Create and append the visible helper
@ -391,45 +378,11 @@
if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
this.dragging = true;
return false;
return true;
},
stop: function(e) {
this.propagate("stop", e); //Call plugins and trigger callbacks
if(this.position.dom != this.currentItem.prev()[0]) this.propagate("update", e); //Trigger update callback if the DOM position has changed
if(!contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
this.propagate("remove", e);
for (var i = this.containers.length - 1; i >= 0; i--){
if(contains(this.containers[i].element[0], this.currentItem[0])) {
this.containers[i].propagate("update", e, this);
this.containers[i].propagate("receive", e, this);
}
};
};
//Post events to containers
for (var i = this.containers.length - 1; i >= 0; i--){
this.containers[i].propagate("deactivate", e, this);
if(this.containers[i].containerCache.over) {
this.containers[i].propagate("out", e, this);
this.containers[i].containerCache.over = 0;
}
}
//If we are using droppables, inform the manager about the drop
if ($.ui.ddmanager && !this.options.dropBehaviour) $.ui.ddmanager.drop(this, e);
this.dragging = false;
if(this.cancelHelperRemoval) return false;
$(this.currentItem).css('visibility', '');
if(this.placeholder) this.placeholder.remove();
this.helper.remove();
return false;
},
drag: function(e) {
mouseDrag: function(e) {
//Compute the helpers position
this.position.current = { top: e.pageY - this.offset.top, left: e.pageX - this.offset.left };
@ -463,6 +416,41 @@
this.helper.css({ left: this.position.current.left+'px', top: this.position.current.top+'px' }); // Stick the helper to the cursor
return false;
},
mouseStop: function(e) {
this.propagate("stop", e); //Call plugins and trigger callbacks
if(this.position.dom != this.currentItem.prev()[0]) this.propagate("update", e); //Trigger update callback if the DOM position has changed
if(!contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
this.propagate("remove", e);
for (var i = this.containers.length - 1; i >= 0; i--){
if(contains(this.containers[i].element[0], this.currentItem[0])) {
this.containers[i].propagate("update", e, this);
this.containers[i].propagate("receive", e, this);
}
};
};
//Post events to containers
for (var i = this.containers.length - 1; i >= 0; i--){
this.containers[i].propagate("deactivate", e, this);
if(this.containers[i].containerCache.over) {
this.containers[i].propagate("out", e, this);
this.containers[i].containerCache.over = 0;
}
}
//If we are using droppables, inform the manager about the drop
if ($.ui.ddmanager && !this.options.dropBehaviour) $.ui.ddmanager.drop(this, e);
this.dragging = false;
if(this.cancelHelperRemoval) return false;
$(this.currentItem).css('visibility', '');
if(this.placeholder) this.placeholder.remove();
this.helper.remove();
return false;
},
rearrange: function(e, i, a) {
a ? a.append(this.currentItem) : i.item[this.direction == 'down' ? 'before' : 'after'](this.currentItem);
@ -470,11 +458,14 @@
if(this.placeholderElement) this.placeholder.css(this.placeholderElement.offset());
if(this.placeholderElement && this.placeholderElement.is(":visible")) this.placeholder.css({ width: this.placeholderElement.outerWidth(), height: this.placeholderElement.outerHeight() });
}
});
}));
$.extend($.ui.sortable, {
getter: "serialize toArray",
defaults: {
distance: 0,
delay: 0,
cancel: ":input,button",
items: '> *',
zIndex: 1000
}
@ -553,8 +544,8 @@
if((o.containment.left != undefined || o.containment.constructor == Array) && !o._containment) return;
if(!o._containment) o._containment = o.containment;
if(o._containment == 'parent') o._containment = this[0].parentNode;
if(o._containment == 'sortable') o._containment = this[0];
if(o._containment == 'parent') o._containment = this.element[0].parentNode;
if(o._containment == 'sortable') o._containment = this.element[0];
if(o._containment == 'document') {
o.containment = [
0,
@ -581,7 +572,7 @@
var o = ui.options;
var h = ui.helper;
var c = o.containment;
var self = ui.instance;
var self = this;
var borderLeft = (parseInt(self.offsetParent.css("borderLeftWidth"), 10) || 0);
var borderRight = (parseInt(self.offsetParent.css("borderRightWidth"), 10) || 0);
var borderTop = (parseInt(self.offsetParent.css("borderTopWidth"), 10) || 0);