diff options
author | Scott González <scott.gonzalez@gmail.com> | 2009-12-22 19:51:24 +0000 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2009-12-22 19:51:24 +0000 |
commit | 06e29401b880b5e8fc64be00b2be9df5cc8f0f88 (patch) | |
tree | cec761b0a3f921f7f0192238ef3cc47f4dc8d439 /ui | |
parent | b6d17b24d4d2302d490c2f83552c7fbc16e96ba4 (diff) | |
download | jquery-ui-06e29401b880b5e8fc64be00b2be9df5cc8f0f88.tar.gz jquery-ui-06e29401b880b5e8fc64be00b2be9df5cc8f0f88.zip |
Split mouse into its own file and udpdated dependency lists.
Fixes #5023 - Split mouse code into its own file.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.accordion.js | 1 | ||||
-rw-r--r-- | ui/jquery.ui.core.js | 149 | ||||
-rw-r--r-- | ui/jquery.ui.datepicker.js | 1 | ||||
-rw-r--r-- | ui/jquery.ui.dialog.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.draggable.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.droppable.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.mouse.js | 163 | ||||
-rw-r--r-- | ui/jquery.ui.progressbar.js | 1 | ||||
-rw-r--r-- | ui/jquery.ui.resizable.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.selectable.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.slider.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.sortable.js | 2 | ||||
-rw-r--r-- | ui/jquery.ui.tabs.js | 1 | ||||
-rw-r--r-- | ui/jquery.ui.widget.js | 12 |
14 files changed, 187 insertions, 155 deletions
diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index 31c2badb0..8340c0f1f 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -9,6 +9,7 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.core.js b/ui/jquery.ui.core.js index d11cf91fe..d5f2de74e 100644 --- a/ui/jquery.ui.core.js +++ b/ui/jquery.ui.core.js @@ -223,153 +223,4 @@ $.extend($.expr[':'], { } }); -/** Mouse Interaction Plugin **/ - -$.ui.mouse = { - _mouseInit: function() { - var self = this; - - this.element - .bind('mousedown.'+this.widgetName, function(event) { - return self._mouseDown(event); - }) - .bind('click.'+this.widgetName, function(event) { - if(self._preventClickEvent) { - self._preventClickEvent = false; - event.stopImmediatePropagation(); - return false; - } - }); - - // Prevent text selection in IE - if ($.browser.msie) { - this._mouseUnselectable = this.element.attr('unselectable'); - this.element.attr('unselectable', 'on'); - } - - this.started = false; - }, - - // TODO: make sure destroying one instance of mouse doesn't mess with - // other instances of mouse - _mouseDestroy: function() { - this.element.unbind('.'+this.widgetName); - - // Restore text selection in IE - ($.browser.msie - && this.element.attr('unselectable', this._mouseUnselectable)); - }, - - _mouseDown: function(event) { - // don't let more than one widget handle mouseStart - // TODO: figure out why we have to use originalEvent - event.originalEvent = event.originalEvent || {}; - if (event.originalEvent.mouseHandled) { return; } - - // we may have missed mouseup (out of window) - (this._mouseStarted && this._mouseUp(event)); - - this._mouseDownEvent = event; - - var self = this, - btnIsLeft = (event.which == 1), - elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false); - if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) { - return true; - } - - this.mouseDelayMet = !this.options.delay; - if (!this.mouseDelayMet) { - this._mouseDelayTimer = setTimeout(function() { - self.mouseDelayMet = true; - }, this.options.delay); - } - - if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { - this._mouseStarted = (this._mouseStart(event) !== false); - if (!this._mouseStarted) { - event.preventDefault(); - return true; - } - } - - // these delegates are required to keep context - this._mouseMoveDelegate = function(event) { - return self._mouseMove(event); - }; - this._mouseUpDelegate = function(event) { - return self._mouseUp(event); - }; - $(document) - .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate) - .bind('mouseup.'+this.widgetName, this._mouseUpDelegate); - - // preventDefault() is used to prevent the selection of text here - - // however, in Safari, this causes select boxes not to be selectable - // anymore, so this fix is needed - ($.browser.safari || event.preventDefault()); - - event.originalEvent.mouseHandled = true; - return true; - }, - - _mouseMove: function(event) { - // IE mouseup check - mouseup happened when mouse was out of window - if ($.browser.msie && !event.button) { - return this._mouseUp(event); - } - - if (this._mouseStarted) { - this._mouseDrag(event); - return event.preventDefault(); - } - - if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { - this._mouseStarted = - (this._mouseStart(this._mouseDownEvent, event) !== false); - (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event)); - } - - return !this._mouseStarted; - }, - - _mouseUp: function(event) { - $(document) - .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate) - .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate); - - if (this._mouseStarted) { - this._mouseStarted = false; - this._preventClickEvent = (event.target == this._mouseDownEvent.target); - this._mouseStop(event); - } - - return false; - }, - - _mouseDistanceMet: function(event) { - return (Math.max( - Math.abs(this._mouseDownEvent.pageX - event.pageX), - Math.abs(this._mouseDownEvent.pageY - event.pageY) - ) >= this.options.distance - ); - }, - - _mouseDelayMet: function(event) { - return this.mouseDelayMet; - }, - - // These are placeholder methods, to be overriden by extending plugin - _mouseStart: function(event) {}, - _mouseDrag: function(event) {}, - _mouseStop: function(event) {}, - _mouseCapture: function(event) { return true; } -}; - -$.ui.mouse.defaults = { - cancel: ':input,option', - distance: 1, - delay: 0 -}; - })(jQuery); diff --git a/ui/jquery.ui.datepicker.js b/ui/jquery.ui.datepicker.js index 2e191355f..e2ed856a4 100644 --- a/ui/jquery.ui.datepicker.js +++ b/ui/jquery.ui.datepicker.js @@ -9,6 +9,7 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.widget.js */ (function($) { // hide the namespace diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 0aa68f4d4..bd5ac04a8 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -10,8 +10,10 @@ * Depends: * jquery.ui.core.js * jquery.ui.draggable.js + * jquery.ui.mouse.js * jquery.ui.position.js * jquery.ui.resizable.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index aa24b1333..8aa52ac5e 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -9,6 +9,8 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.mouse.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index 3d1a7f5eb..f9a9e8672 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -10,6 +10,8 @@ * Depends: * jquery.ui.core.js * jquery.ui.draggable.js + * jquery.ui.mouse.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.mouse.js b/ui/jquery.ui.mouse.js new file mode 100644 index 000000000..43fe2fbc5 --- /dev/null +++ b/ui/jquery.ui.mouse.js @@ -0,0 +1,163 @@ +/*! + * jQuery UI Mouse @VERSION + * + * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * http://docs.jquery.com/UI/Mouse + * + * Depends: + * jquery.ui.widget.js + */ +(function($) { + +$.ui.mouse = { + _mouseInit: function() { + var self = this; + + this.element + .bind('mousedown.'+this.widgetName, function(event) { + return self._mouseDown(event); + }) + .bind('click.'+this.widgetName, function(event) { + if(self._preventClickEvent) { + self._preventClickEvent = false; + event.stopImmediatePropagation(); + return false; + } + }); + + // Prevent text selection in IE + if ($.browser.msie) { + this._mouseUnselectable = this.element.attr('unselectable'); + this.element.attr('unselectable', 'on'); + } + + this.started = false; + }, + + // TODO: make sure destroying one instance of mouse doesn't mess with + // other instances of mouse + _mouseDestroy: function() { + this.element.unbind('.'+this.widgetName); + + // Restore text selection in IE + ($.browser.msie + && this.element.attr('unselectable', this._mouseUnselectable)); + }, + + _mouseDown: function(event) { + // don't let more than one widget handle mouseStart + // TODO: figure out why we have to use originalEvent + event.originalEvent = event.originalEvent || {}; + if (event.originalEvent.mouseHandled) { return; } + + // we may have missed mouseup (out of window) + (this._mouseStarted && this._mouseUp(event)); + + this._mouseDownEvent = event; + + var self = this, + btnIsLeft = (event.which == 1), + elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false); + if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) { + return true; + } + + this.mouseDelayMet = !this.options.delay; + if (!this.mouseDelayMet) { + this._mouseDelayTimer = setTimeout(function() { + self.mouseDelayMet = true; + }, this.options.delay); + } + + if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { + this._mouseStarted = (this._mouseStart(event) !== false); + if (!this._mouseStarted) { + event.preventDefault(); + return true; + } + } + + // these delegates are required to keep context + this._mouseMoveDelegate = function(event) { + return self._mouseMove(event); + }; + this._mouseUpDelegate = function(event) { + return self._mouseUp(event); + }; + $(document) + .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate) + .bind('mouseup.'+this.widgetName, this._mouseUpDelegate); + + // preventDefault() is used to prevent the selection of text here - + // however, in Safari, this causes select boxes not to be selectable + // anymore, so this fix is needed + ($.browser.safari || event.preventDefault()); + + event.originalEvent.mouseHandled = true; + return true; + }, + + _mouseMove: function(event) { + // IE mouseup check - mouseup happened when mouse was out of window + if ($.browser.msie && !event.button) { + return this._mouseUp(event); + } + + if (this._mouseStarted) { + this._mouseDrag(event); + return event.preventDefault(); + } + + if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { + this._mouseStarted = + (this._mouseStart(this._mouseDownEvent, event) !== false); + (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event)); + } + + return !this._mouseStarted; + }, + + _mouseUp: function(event) { + $(document) + .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate) + .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate); + + if (this._mouseStarted) { + this._mouseStarted = false; + this._preventClickEvent = (event.target == this._mouseDownEvent.target); + this._mouseStop(event); + } + + return false; + }, + + _mouseDistanceMet: function(event) { + return (Math.max( + Math.abs(this._mouseDownEvent.pageX - event.pageX), + Math.abs(this._mouseDownEvent.pageY - event.pageY) + ) >= this.options.distance + ); + }, + + _mouseDelayMet: function(event) { + return this.mouseDelayMet; + }, + + // These are placeholder methods, to be overriden by extending plugin + _mouseStart: function(event) {}, + _mouseDrag: function(event) {}, + _mouseStop: function(event) {}, + _mouseCapture: function(event) { return true; } +}; + +$.ui.mouse.defaults = { + cancel: ':input,option', + distance: 1, + delay: 0 +}; + +})(jQuery); + diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 079216877..866bfb172 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -9,6 +9,7 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.resizable.js b/ui/jquery.ui.resizable.js index 0a0c228da..70f92f591 100644 --- a/ui/jquery.ui.resizable.js +++ b/ui/jquery.ui.resizable.js @@ -9,6 +9,8 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.mouse.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.selectable.js b/ui/jquery.ui.selectable.js index 933c6ca96..153f17c7f 100644 --- a/ui/jquery.ui.selectable.js +++ b/ui/jquery.ui.selectable.js @@ -9,6 +9,8 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.mouse.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index 2c96bd018..0e3fa0170 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -9,6 +9,8 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.mouse.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index bb6844d3e..d627bcea6 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -9,6 +9,8 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.mouse.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index b13aebaa9..32f326d00 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -9,6 +9,7 @@ * * Depends: * jquery.ui.core.js + * jquery.ui.widget.js */ (function($) { diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 2047c4723..9321e05db 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -1,14 +1,14 @@ /*! - * jQuery UI @VERSION + * jQuery UI Widget @VERSION * * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * - * http://docs.jquery.com/UI + * http://docs.jquery.com/UI/Widget */ (function($) { - + var _remove = $.fn.remove; $.fn.remove = function() { @@ -17,10 +17,10 @@ $.fn.remove = function() { $("*", this).add(this).each(function() { $(this).triggerHandler("remove"); }); - return _remove.apply(this, arguments ); + return _remove.apply(this, arguments); }; - - // $.widget is a factory to create jQuery plugins + +// $.widget is a factory to create jQuery plugins // taking some boilerplate code out of the plugin code $.widget = function(name, prototype) { var namespace = name.split(".")[0], |