internal methods: mouse*

This commit is contained in:
Chi Cheng 2008-08-17 08:15:49 +00:00
parent 6e8832d440
commit d5bbbd2a07
5 changed files with 56 additions and 56 deletions

View File

@ -202,11 +202,11 @@ $.ui = {
/** Mouse Interaction Plugin **/ /** Mouse Interaction Plugin **/
$.ui.mouse = { $.ui.mouse = {
mouseInit: function() { _mouseInit: function() {
var self = this; var self = this;
this.element.bind('mousedown.'+this.widgetName, function(e) { this.element.bind('mousedown.'+this.widgetName, function(e) {
return self.mouseDown(e); return self._mouseDown(e);
}); });
// Prevent text selection in IE // Prevent text selection in IE
@ -220,7 +220,7 @@ $.ui.mouse = {
// TODO: make sure destroying one instance of mouse doesn't mess with // TODO: make sure destroying one instance of mouse doesn't mess with
// other instances of mouse // other instances of mouse
mouseDestroy: function() { _mouseDestroy: function() {
this.element.unbind('.'+this.widgetName); this.element.unbind('.'+this.widgetName);
// Restore text selection in IE // Restore text selection in IE
@ -228,28 +228,28 @@ $.ui.mouse = {
&& this.element.attr('unselectable', this._mouseUnselectable)); && this.element.attr('unselectable', this._mouseUnselectable));
}, },
mouseDown: function(e) { _mouseDown: function(e) {
// we may have missed mouseup (out of window) // we may have missed mouseup (out of window)
(this._mouseStarted && this.mouseUp(e)); (this._mouseStarted && this._mouseUp(e));
this._mouseDownEvent = e; this._mouseDownEvent = e;
var self = this, var self = this,
btnIsLeft = (e.which == 1), btnIsLeft = (e.which == 1),
elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).parents().add(e.target).filter(this.options.cancel).length : false); elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).parents().add(e.target).filter(this.options.cancel).length : false);
if (!btnIsLeft || elIsCancel || !this.mouseCapture(e)) { if (!btnIsLeft || elIsCancel || !this._mouseCapture(e)) {
return true; return true;
} }
this._mouseDelayMet = !this.options.delay; this.mouseDelayMet = !this.options.delay;
if (!this._mouseDelayMet) { if (!this.mouseDelayMet) {
this._mouseDelayTimer = setTimeout(function() { this._mouseDelayTimer = setTimeout(function() {
self._mouseDelayMet = true; self.mouseDelayMet = true;
}, this.options.delay); }, this.options.delay);
} }
if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) { if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
this._mouseStarted = (this.mouseStart(e) !== false); this._mouseStarted = (this._mouseStart(e) !== false);
if (!this._mouseStarted) { if (!this._mouseStarted) {
e.preventDefault(); e.preventDefault();
return true; return true;
@ -258,10 +258,10 @@ $.ui.mouse = {
// these delegates are required to keep context // these delegates are required to keep context
this._mouseMoveDelegate = function(e) { this._mouseMoveDelegate = function(e) {
return self.mouseMove(e); return self._mouseMove(e);
}; };
this._mouseUpDelegate = function(e) { this._mouseUpDelegate = function(e) {
return self.mouseUp(e); return self._mouseUp(e);
}; };
$(document) $(document)
.bind('mousemove.'+this.widgetName, this._mouseMoveDelegate) .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
@ -270,40 +270,40 @@ $.ui.mouse = {
return false; return false;
}, },
mouseMove: function(e) { _mouseMove: function(e) {
// IE mouseup check - mouseup happened when mouse was out of window // IE mouseup check - mouseup happened when mouse was out of window
if ($.browser.msie && !e.button) { if ($.browser.msie && !e.button) {
return this.mouseUp(e); return this._mouseUp(e);
} }
if (this._mouseStarted) { if (this._mouseStarted) {
this.mouseDrag(e); this._mouseDrag(e);
return false; return false;
} }
if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) { if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
this._mouseStarted = this._mouseStarted =
(this.mouseStart(this._mouseDownEvent, e) !== false); (this._mouseStart(this._mouseDownEvent, e) !== false);
(this._mouseStarted ? this.mouseDrag(e) : this.mouseUp(e)); (this._mouseStarted ? this._mouseDrag(e) : this._mouseUp(e));
} }
return !this._mouseStarted; return !this._mouseStarted;
}, },
mouseUp: function(e) { _mouseUp: function(e) {
$(document) $(document)
.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate) .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate); .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
if (this._mouseStarted) { if (this._mouseStarted) {
this._mouseStarted = false; this._mouseStarted = false;
this.mouseStop(e); this._mouseStop(e);
} }
return false; return false;
}, },
mouseDistanceMet: function(e) { _mouseDistanceMet: function(e) {
return (Math.max( return (Math.max(
Math.abs(this._mouseDownEvent.pageX - e.pageX), Math.abs(this._mouseDownEvent.pageX - e.pageX),
Math.abs(this._mouseDownEvent.pageY - e.pageY) Math.abs(this._mouseDownEvent.pageY - e.pageY)
@ -311,15 +311,15 @@ $.ui.mouse = {
); );
}, },
mouseDelayMet: function(e) { _mouseDelayMet: function(e) {
return this._mouseDelayMet; return this.mouseDelayMet;
}, },
// These are placeholder methods, to be overriden by extending plugin // These are placeholder methods, to be overriden by extending plugin
mouseStart: function(e) {}, _mouseStart: function(e) {},
mouseDrag: function(e) {}, _mouseDrag: function(e) {},
mouseStop: function(e) {}, _mouseStop: function(e) {},
mouseCapture: function(e) { return true; } _mouseCapture: function(e) { return true; }
}; };
$.ui.mouse.defaults = { $.ui.mouse.defaults = {

View File

@ -21,10 +21,10 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
(this.options.cssNamespace && this.element.addClass(this.options.cssNamespace+"-draggable")); (this.options.cssNamespace && this.element.addClass(this.options.cssNamespace+"-draggable"));
(this.options.disabled && this.element.addClass('ui-draggable-disabled')); (this.options.disabled && this.element.addClass('ui-draggable-disabled'));
this.mouseInit(); this._mouseInit();
}, },
mouseStart: function(e) { _mouseStart: function(e) {
var o = this.options; var o = this.options;
@ -135,7 +135,7 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
this.helper.addClass("ui-draggable-dragging"); this.helper.addClass("ui-draggable-dragging");
this.mouseDrag(e); //Execute the drag once - this causes the helper not to be visible before getting its correct position this._mouseDrag(e); //Execute the drag once - this causes the helper not to be visible before getting its correct position
return true; return true;
}, },
_convertPositionTo: function(d, pos) { _convertPositionTo: function(d, pos) {
@ -207,7 +207,7 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
return position; return position;
}, },
mouseDrag: function(e) { _mouseDrag: function(e) {
//Compute the helpers position //Compute the helpers position
this.position = this._generatePosition(e); this.position = this._generatePosition(e);
@ -222,7 +222,7 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
return false; return false;
}, },
mouseStop: 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
var dropped = false; var dropped = false;
@ -268,7 +268,7 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
destroy: function() { destroy: function() {
if(!this.element.data('draggable')) return; if(!this.element.data('draggable')) return;
this.element.removeData("draggable").unbind(".draggable").removeClass('ui-draggable-dragging ui-draggable-disabled'); this.element.removeData("draggable").unbind(".draggable").removeClass('ui-draggable-dragging ui-draggable-disabled');
this.mouseDestroy(); this._mouseDestroy();
} }
})); }));
@ -492,7 +492,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work) this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
if(this.shouldRevert) this.instance.options.revert = true; //revert here if(this.shouldRevert) this.instance.options.revert = true; //revert here
this.instance.mouseStop(e); this.instance._mouseStop(e);
//Also propagate receive event, since the sortable is actually receiving a element //Also propagate receive event, since the sortable is actually receiving a element
this.instance.element.triggerHandler("sortreceive", [e, $.extend(this.instance.ui(), { sender: inst.element })], this.instance.options["receive"]); this.instance.element.triggerHandler("sortreceive", [e, $.extend(this.instance.ui(), { sender: inst.element })], this.instance.options["receive"]);
@ -534,8 +534,8 @@ $.ui.plugin.add("draggable", "connectToSortable", {
this.instance.options.helper = function() { return ui.helper[0]; }; this.instance.options.helper = function() { return ui.helper[0]; };
e.target = this.instance.currentItem[0]; e.target = this.instance.currentItem[0];
this.instance.mouseCapture(e, true); this.instance._mouseCapture(e, true);
this.instance.mouseStart(e, true, true); this.instance._mouseStart(e, true, true);
//Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
this.instance.offset.click.top = inst.offset.click.top; this.instance.offset.click.top = inst.offset.click.top;
@ -548,7 +548,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
} }
//Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
if(this.instance.currentItem) this.instance.mouseDrag(e); if(this.instance.currentItem) this.instance._mouseDrag(e);
} else { } else {
@ -558,7 +558,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
this.instance.isOver = 0; this.instance.isOver = 0;
this.instance.cancelHelperRemoval = true; this.instance.cancelHelperRemoval = true;
this.instance.options.revert = false; //No revert here this.instance.options.revert = false; //No revert here
this.instance.mouseStop(e, true); this.instance._mouseStop(e, true);
this.instance.options.helper = this.instance.options._helper; this.instance.options.helper = this.instance.options._helper;
//Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size

View File

@ -212,7 +212,7 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
}); });
} }
this.mouseInit(); this._mouseInit();
}, },
plugins: {}, plugins: {},
ui: function() { ui: function() {
@ -234,7 +234,7 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
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);
this.mouseDestroy(); this._mouseDestroy();
var _destroy = function(exp) { var _destroy = function(exp) {
$(exp).removeClass("ui-resizable ui-resizable-disabled") $(exp).removeClass("ui-resizable ui-resizable-disabled")
@ -257,7 +257,7 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
_destroy(wrapped); _destroy(wrapped);
} }
}, },
mouseStart: function(e) { _mouseStart: function(e) {
if(this.options.disabled) return false; if(this.options.disabled) return false;
var handle = false; var handle = false;
@ -312,7 +312,7 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
this._propagate("start", e); this._propagate("start", e);
return true; return true;
}, },
mouseDrag: function(e) { _mouseDrag: 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 = {},
@ -348,7 +348,7 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
return false; return false;
}, },
mouseStop: function(e) { _mouseStop: function(e) {
this.options.resizing = false; this.options.resizing = false;
var o = this.options, num = function(v) { return parseInt(v, 10) || 0; }, self = this; var o = this.options, num = function(v) { return parseInt(v, 10) || 0; }, self = this;

View File

@ -45,7 +45,7 @@ $.widget("ui.selectable", $.extend({}, $.ui.mouse, {
this.selectees = selectees.addClass("ui-selectee"); this.selectees = selectees.addClass("ui-selectee");
this.mouseInit(); this._mouseInit();
this.helper = $(document.createElement('div')) this.helper = $(document.createElement('div'))
.css({border:'1px dotted black'}) .css({border:'1px dotted black'})
@ -63,9 +63,9 @@ $.widget("ui.selectable", $.extend({}, $.ui.mouse, {
.removeClass("ui-selectable ui-selectable-disabled") .removeClass("ui-selectable ui-selectable-disabled")
.removeData("selectable") .removeData("selectable")
.unbind(".selectable"); .unbind(".selectable");
this.mouseDestroy(); this._mouseDestroy();
}, },
mouseStart: function(e) { _mouseStart: function(e) {
var self = this; var self = this;
this.opos = [e.pageX, e.pageY]; this.opos = [e.pageX, e.pageY];
@ -121,7 +121,7 @@ $.widget("ui.selectable", $.extend({}, $.ui.mouse, {
}); });
return this.options.keyboard ? !isSelectee : true; return this.options.keyboard ? !isSelectee : true;
}, },
mouseDrag: function(e) { _mouseDrag: function(e) {
var self = this; var self = this;
this.dragged = true; this.dragged = true;
@ -210,7 +210,7 @@ $.widget("ui.selectable", $.extend({}, $.ui.mouse, {
return false; return false;
}, },
mouseStop: function(e) { _mouseStop: function(e) {
var self = this; var self = this;
this.dragged = false; this.dragged = false;

View File

@ -41,7 +41,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
this.offset = this.element.offset(); this.offset = this.element.offset();
//Initialize mouse events for interaction //Initialize mouse events for interaction
this.mouseInit(); this._mouseInit();
}, },
plugins: {}, plugins: {},
@ -283,7 +283,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
.removeClass("ui-sortable ui-sortable-disabled") .removeClass("ui-sortable ui-sortable-disabled")
.removeData("sortable") .removeData("sortable")
.unbind(".sortable"); .unbind(".sortable");
this.mouseDestroy(); 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");
@ -360,7 +360,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
}; };
}, },
mouseCapture: function(e, overrideHandle) { _mouseCapture: function(e, overrideHandle) {
if(this.options.disabled || this.options.type == 'static') return false; if(this.options.disabled || this.options.type == 'static') return false;
@ -390,7 +390,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
}, },
mouseStart: function(e, overrideHandle, noActivation) { _mouseStart: function(e, overrideHandle, noActivation) {
var o = this.options; var o = this.options;
this.currentContainer = this; this.currentContainer = this;
@ -499,7 +499,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
this.dragging = true; this.dragging = true;
this.mouseDrag(e); //Execute the drag once - this causes the helper not to be visible before getting its correct position this._mouseDrag(e); //Execute the drag once - this causes the helper not to be visible before getting its correct position
return true; return true;
@ -566,7 +566,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
return position; return position;
}, },
mouseDrag: function(e) { _mouseDrag: function(e) {
//Compute the helpers position //Compute the helpers position
this.position = this._generatePosition(e); this.position = this._generatePosition(e);
@ -633,7 +633,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
}, },
mouseStop: function(e, noPropagation) { _mouseStop: function(e, noPropagation) {
//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)