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 * jQuery UI @VERSION
* *
* Copyright (c) 2008 Paul Bakaus (ui.jquery.com) * Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
@ -7,7 +7,7 @@
* *
* http://docs.jquery.com/UI * 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($) { ;(function($) {
@ -26,7 +26,7 @@
for (var i = 0; i < set.length; i++) { for (var i = 0; i < set.length; i++) {
if (instance.options[set[i][0]]) { 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 **/ /** Mouse Interaction Plugin **/
$.widget("ui.mouse", { $.ui.mouse = {
init: function() { mouseInit: function() {
var self = this; var self = this;
this.element this.element.bind('mousedown.mouse', function(e) {
.bind('mousedown.mouse', function() { return self.click.apply(self, arguments); }) return self.mouseDown(e);
.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
if ($.browser.msie) {
this.unselectable = this.element.attr('unselectable');
this.element.attr('unselectable', 'on');
}
},
destroy: function() {
this.element.unbind('.mouse').removeData("mouse");
($.browser.msie && this.element.attr('unselectable', this.unselectable));
},
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; }
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); });
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;
}
};
if(this.options.delay) {
if(this.timer) { clearTimeout(this.timer); }
this.timer = setTimeout(initialize, this.options.delay);
} else {
initialize();
}
return false;
},
stop: function(e) {
if(!this.initialized) {
return $(document).unbind('mouseup.mouse').unbind('mousemove.mouse');
}
(this.options.stop && this.options.stop.call(this.options.executor || this, e, this.element));
$(document).unbind('mouseup.mouse').unbind('mousemove.mouse');
return false;
},
drag: function(e) {
var o = this.options;
if ($.browser.msie && !e.button) {
return this.stop.call(this, e); // IE mouseup check
}
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; }
}
(o.drag && o.drag.call(this.options.executor || this, e, this.element));
return false;
}
}); });
// Prevent text selection in IE
if ($.browser.msie) {
this._mouseUnselectable = this.element.attr('unselectable');
this.element.attr('unselectable', 'on');
}
this.started = false;
},
mouseDestroy: function() {
this.element.unbind('.mouse');
// Restore text selection in IE
($.browser.msie
&& this.element.attr('unselectable', this._mouseUnselectable));
},
mouseDown: function(e) {
// we may have missed mouseup (out of window)
(this._mouseStarted
&& this.mouseUp(e));
this._mouseDownEvent = e;
var self = this,
btnIsLeft = (e.which == 1),
elIsCancel = ($(e.target).is(this.options.cancel));
if (!btnIsLeft || elIsCancel) {
return true;
}
this._mouseDelayMet = (this.options.delay == 0);
if (!this._mouseDelayMet) {
this._mouseDelayTimer = setTimeout(function() {
self._mouseDelayMet = true;
}, this.options.delay);
}
// 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);
return false;
},
mouseMove: function(e) {
// IE mouseup check - mouseup happened when mouse was out of window
if ($.browser.msie && !e.button) {
return this.mouseUp(e);
}
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);
}
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); })(jQuery);

View File

@ -10,41 +10,35 @@
* Depends: * Depends:
* ui.core.js * 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($) { ;(function($) {
$.widget("ui.draggable", { $.widget("ui.draggable", $.extend($.ui.mouse, {
init: function() { init: function() {
//Initialize needed constants //Initialize needed constants
var o = this.options; var o = this.options;
//Initialize mouse events for interaction this.mouseInit();
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;
}
});
//Position the node //Position the node
if(o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position'))) if(o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position')))
this.element.css('position', 'relative'); this.element.css('position', 'relative');
}, },
start: function(e) { mouseStart: function(e) {
var o = this.options; 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; if($.ui.ddmanager) $.ui.ddmanager.current = this;
//Create and append the visible helper //Create and append the visible helper
@ -118,15 +112,13 @@
} }
} }
//Call plugins and callbacks //Call plugins and callbacks
this.propagate("start", e); this.propagate("start", e);
this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size
if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
return false; return true;
}, },
convertPositionTo: function(d, pos) { convertPositionTo: function(d, pos) {
if(!pos) pos = this.position; 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 if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options
/* /*
* - Position constraining - * - Position constraining -
* Constrain the position to a mix of grid, containment. * Constrain the position to a mix of grid, containment.
@ -192,7 +183,7 @@
return position; return position;
}, },
drag: function(e) { mouseDrag: function(e) {
//Compute the helpers position //Compute the helpers position
this.position = this.generatePosition(e); 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 == "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(!this.options.axis || this.options.axis == "y") this.helper[0].style.top = this.position.top+'px';
if($.ui.ddmanager) $.ui.ddmanager.drag(this, e); 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 we are using droppables, inform the manager about the drop
if ($.ui.ddmanager && !this.options.dropBehaviour) if ($.ui.ddmanager && !this.options.dropBehaviour)
@ -225,7 +216,6 @@
} }
return false; return false;
}, },
clear: function() { clear: function() {
if(this.options.helper != 'original' && !this.cancelHelperRemoval) this.helper.remove(); if(this.options.helper != 'original' && !this.cancelHelperRemoval) this.helper.remove();
@ -236,7 +226,7 @@
// From now on bulk stuff - mainly helpers // From now on bulk stuff - mainly helpers
plugins: {}, plugins: {},
ui: function(e) { uiHash: function(e) {
return { return {
helper: this.helper, helper: this.helper,
position: this.position, position: this.position,
@ -245,24 +235,26 @@
}; };
}, },
propagate: function(n,e) { propagate: function(n,e) {
$.ui.plugin.call(this, n, [e, this.ui()]); $.ui.plugin.call(this, n, [e, this.uiHash()]);
return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.ui()], this.options[n]); return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.uiHash()], this.options[n]);
}, },
destroy: function() { destroy: function() {
if(!this.element.data('draggable')) return; 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", { $.ui.plugin.add("draggable", "cursor", {
start: function(e, ui) { start: function(e, ui) {
var t = $('body'); var t = $('body');

View File

@ -10,11 +10,11 @@
* Depends: * Depends:
* ui.core.js * 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($) { ;(function($) {
$.widget("ui.resizable", { $.widget("ui.resizable", $.extend($.ui.mouse, {
init: function() { init: function() {
var self = this, o = this.options; var self = this, o = this.options;
@ -209,24 +209,7 @@
}); });
} }
//Initialize mouse events for interaction this.mouseInit();
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;
}
});
}, },
plugins: {}, plugins: {},
ui: function() { ui: function() {
@ -241,11 +224,13 @@
this.element.triggerHandler(n == "resize" ? n : ["resize", n].join(""), [e, this.ui()], this.options[n]); this.element.triggerHandler(n == "resize" ? n : ["resize", n].join(""), [e, this.ui()], this.options[n]);
}, },
destroy: function() { 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") $(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); _destroy(el);
@ -272,7 +257,15 @@
this.element.addClass("ui-resizable-disabled"); this.element.addClass("ui-resizable-disabled");
this.disabled = true; 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, 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; num = function(v) { return parseInt(v, 10) || 0; }, ie6 = $.browser.msie && $.browser.version < 7;
o.resizing = true; o.resizing = true;
@ -312,35 +305,10 @@
$('body').css('cursor', this.axis + '-resize'); $('body').css('cursor', this.axis + '-resize');
this.propagate("start", e); this.propagate("start", e);
return false; return true;
}, },
stop: function(e) { mouseDrag: 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;
},
drag: function(e) {
//Increase performance, avoid regex //Increase performance, avoid regex
var el = this.helper, o = this.options, props = {}, var el = this.helper, o = this.options, props = {},
self = this, smp = this.originalMousePosition, a = this.axis; self = this, smp = this.originalMousePosition, a = this.axis;
@ -371,6 +339,33 @@
return false; 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) { _updateCache: function(data) {
var o = this.options; var o = this.options;
this.offset = this.helper.offset(); 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])); return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [e, dx, dy]));
} }
} }
}); }));
$.extend($.ui.resizable, { $.extend($.ui.resizable, {
defaults: { defaults: {
cancel: ":input,button",
distance: 0,
delay: 0,
preventDefault: true, preventDefault: true,
transparent: false, transparent: false,
minWidth: 10, minWidth: 10,

View File

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

View File

@ -20,11 +20,10 @@
}); });
}; };
$.widget("ui.slider", { $.widget("ui.slider", $.extend($.ui.mouse, {
plugins: {}, plugins: {},
ui: function(e) { ui: function(e) {
return { return {
instance: this,
options: this.options, options: this.options,
handle: this.currentHandle, handle: this.currentHandle,
value: this.options.axis != "both" || !this.options.axis ? Math.round(this.value(null,this.options.axis == "vertical" ? "y" : "x")) : { 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") .removeData("slider")
.unbind(".slider"); .unbind(".slider");
this.handle this.handle
.unwrap("a") .unwrap("a");
.mouse("destroy"); this.mouseDestroy();
this.generated && this.generated.remove(); this.generated && this.generated.remove();
}, },
enable: function() { enable: function() {
@ -74,29 +73,17 @@
if (!this.handle.length) { if (!this.handle.length) {
self.handle = self.generated = $(self.options.handles || [0]).map(function() { self.handle = self.generated = $(self.options.handles || [0]).map(function() {
var handle = $("<div/>").addClass("ui-slider-handle").appendTo(self.element); var handle = $("<div/>").addClass("ui-slider-handle").appendTo(self.element);
handle.data("mouse", {});
if (this.id) if (this.id)
handle.attr("id", this.id); handle.attr("id", this.id);
return handle[0]; return handle[0];
}); });
} }
this.mouseInit();
$(this.handle) $(this.handle)
.mouse({ .data("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;
}
}
})
.wrap('<a href="javascript:void(0)" style="cursor:default;"></a>') .wrap('<a href="javascript:void(0)" style="cursor:default;"></a>')
.parent() .parent()
.bind('focus', function(e) { self.focus(this.firstChild); }) .bind('focus', function(e) { self.focus(this.firstChild); })
@ -107,7 +94,8 @@
// Bind the click to the slider itself // Bind the click to the slider itself
this.element.bind('mousedown.slider', function(e) { this.element.bind('mousedown.slider', function(e) {
self.click.apply(self, [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 self.firstValue = self.firstValue + 1; //This is for always triggering the change event
}); });
@ -190,8 +178,6 @@
}, null, !this.options.distance); }, null, !this.options.distance);
}, },
createRange: function() { createRange: function() {
this.rangeElement = $('<div></div>') this.rangeElement = $('<div></div>')
.addClass('ui-slider-range') .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); 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) { convertValue: function(value,axis) {
return this.options.min[axis] + (value / (this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(null,axis))) * this.options.realMax[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 o = this.options;
var handle = e.target;
// Prepare the outer size // Prepare the outer size
this.actualSize = { width: this.element.outerWidth() , height: this.element.outerHeight() }; this.actualSize = { width: this.element.outerWidth() , height: this.element.outerHeight() };
@ -281,20 +269,17 @@
this.firstValue = this.value(); this.firstValue = this.value();
this.propagate('start', e); 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) { mouseDrag: 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) {
var o = this.options; var o = this.options;
var position = { top: e.pageY - this.offset.top - this.clickOffset.top, left: e.pageX - this.offset.left - this.clickOffset.left}; 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 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); this.propagate('slide', e);
return false; 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) { moveTo: function(value, handle, noPropagation) {
@ -405,13 +398,15 @@
this.propagate("slide", null); this.propagate("slide", null);
} }
} }
}); }));
$.ui.slider.getter = "value"; $.ui.slider.getter = "value";
$.ui.slider.defaults = { $.ui.slider.defaults = {
distance: 0,
delay: 0,
cancel: ":input,button",
handle: ".ui-slider-handle", handle: ".ui-slider-handle",
distance: 1
}; };
})(jQuery); })(jQuery);

View File

@ -26,7 +26,7 @@
return false; return false;
}; };
$.widget("ui.sortable", { $.widget("ui.sortable", $.extend($.ui.mouse, {
init: function() { init: function() {
var o = this.options; var o = this.options;
@ -44,39 +44,7 @@
this.offset = this.element.offset(); this.offset = this.element.offset();
//Initialize mouse events for interaction //Initialize mouse events for interaction
this.element.mouse({ this.mouseInit();
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;
}
});
}, },
plugins: {}, plugins: {},
@ -86,7 +54,6 @@
placeholder: (inst || this)["placeholder"] || $([]), placeholder: (inst || this)["placeholder"] || $([]),
position: (inst || this)["position"].current, position: (inst || this)["position"].current,
absolutePosition: (inst || this)["position"].absolute, absolutePosition: (inst || this)["position"].absolute,
instance: this,
options: this.options, options: this.options,
element: this.element, element: this.element,
item: (inst || this)["currentItem"], item: (inst || this)["currentItem"],
@ -251,8 +218,8 @@
this.element this.element
.removeClass("ui-sortable ui-sortable-disabled") .removeClass("ui-sortable ui-sortable-disabled")
.removeData("sortable") .removeData("sortable")
.unbind(".sortable") .unbind(".sortable");
.mouse("destroy"); this.mouseDestroy();
for ( var i = this.items.length - 1; i >= 0; i-- ) for ( var i = this.items.length - 1; i >= 0; i-- )
this.items[i].item.removeData("sortable-item"); this.items[i].item.removeData("sortable-item");
@ -264,8 +231,7 @@
.appendTo('body') .appendTo('body')
.css({ position: 'absolute' }) .css({ position: 'absolute' })
.css((that || this).placeholderElement.offset()) .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) { contactContainers: function(e) {
for (var i = this.containers.length - 1; i >= 0; i--){ 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; var o = this.options;
this.currentContainer = this; 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(); this.refresh();
//Create and append the visible helper //Create and append the visible helper
@ -391,45 +378,11 @@
if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
this.dragging = true; this.dragging = true;
return false;
return true;
}, },
stop: function(e) { mouseDrag: 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) {
//Compute the helpers position //Compute the helpers position
this.position.current = { top: e.pageY - this.offset.top, left: e.pageX - this.offset.left }; 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 this.helper.css({ left: this.position.current.left+'px', top: this.position.current.top+'px' }); // Stick the helper to the cursor
return false; 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) { rearrange: function(e, i, a) {
a ? a.append(this.currentItem) : i.item[this.direction == 'down' ? 'before' : 'after'](this.currentItem); 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.placeholder.css(this.placeholderElement.offset());
if(this.placeholderElement && this.placeholderElement.is(":visible")) this.placeholder.css({ width: this.placeholderElement.outerWidth(), height: this.placeholderElement.outerHeight() }); if(this.placeholderElement && this.placeholderElement.is(":visible")) this.placeholder.css({ width: this.placeholderElement.outerWidth(), height: this.placeholderElement.outerHeight() });
} }
}); }));
$.extend($.ui.sortable, { $.extend($.ui.sortable, {
getter: "serialize toArray", getter: "serialize toArray",
defaults: { defaults: {
distance: 0,
delay: 0,
cancel: ":input,button",
items: '> *', items: '> *',
zIndex: 1000 zIndex: 1000
} }
@ -553,8 +544,8 @@
if((o.containment.left != undefined || o.containment.constructor == Array) && !o._containment) return; if((o.containment.left != undefined || o.containment.constructor == Array) && !o._containment) return;
if(!o._containment) o._containment = o.containment; if(!o._containment) o._containment = o.containment;
if(o._containment == 'parent') o._containment = this[0].parentNode; if(o._containment == 'parent') o._containment = this.element[0].parentNode;
if(o._containment == 'sortable') o._containment = this[0]; if(o._containment == 'sortable') o._containment = this.element[0];
if(o._containment == 'document') { if(o._containment == 'document') {
o.containment = [ o.containment = [
0, 0,
@ -581,7 +572,7 @@
var o = ui.options; var o = ui.options;
var h = ui.helper; var h = ui.helper;
var c = o.containment; var c = o.containment;
var self = ui.instance; var self = this;
var borderLeft = (parseInt(self.offsetParent.css("borderLeftWidth"), 10) || 0); var borderLeft = (parseInt(self.offsetParent.css("borderLeftWidth"), 10) || 0);
var borderRight = (parseInt(self.offsetParent.css("borderRightWidth"), 10) || 0); var borderRight = (parseInt(self.offsetParent.css("borderRightWidth"), 10) || 0);
var borderTop = (parseInt(self.offsetParent.css("borderTopWidth"), 10) || 0); var borderTop = (parseInt(self.offsetParent.css("borderTopWidth"), 10) || 0);