From: Alexander Schmitz Date: Wed, 15 Jul 2015 02:18:43 +0000 (-0400) Subject: Mouse: Move mouse into widgets folder X-Git-Tag: 1.12.0-beta.1~203 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5dc88353d49636798e99ae7c276c4a5ec14055d8;p=jquery-ui.git Mouse: Move mouse into widgets folder Ref #13885 --- diff --git a/demos/bootstrap.js b/demos/bootstrap.js index 5a5d88889..37f3321db 100644 --- a/demos/bootstrap.js +++ b/demos/bootstrap.js @@ -33,7 +33,9 @@ var widgets = [ "draggable", "droppable", "menu", + "mouse", "progressbar" + ]; function getPath( module ) { diff --git a/ui/mouse.js b/ui/mouse.js deleted file mode 100644 index a48a799c5..000000000 --- a/ui/mouse.js +++ /dev/null @@ -1,205 +0,0 @@ -/*! - * jQuery UI Mouse @VERSION - * http://jqueryui.com - * - * Copyright jQuery Foundation and other contributors - * Released under the MIT license. - * http://jquery.org/license - */ - -//>>label: Mouse -//>>group: UI Core -//>>description: Abstracts mouse-based interactions to assist in creating certain widgets. -//>>docs: http://api.jqueryui.com/mouse/ - -(function( factory ) { - if ( typeof define === "function" && define.amd ) { - - // AMD. Register as an anonymous module. - define([ - "jquery", - "./ie", - "./version", - "./widget" - ], factory ); - } else { - - // Browser globals - factory( jQuery ); - } -}(function( $ ) { - -var mouseHandled = false; -$( document ).on( "mouseup", function() { - mouseHandled = false; -}); - -return $.widget("ui.mouse", { - version: "@VERSION", - options: { - cancel: "input, textarea, button, select, option", - distance: 1, - delay: 0 - }, - _mouseInit: function() { - var that = this; - - this.element - .on("mousedown." + this.widgetName, function(event) { - return that._mouseDown(event); - }) - .on("click." + this.widgetName, function(event) { - if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) { - $.removeData(event.target, that.widgetName + ".preventClickEvent"); - event.stopImmediatePropagation(); - return false; - } - }); - - this.started = false; - }, - - // TODO: make sure destroying one instance of mouse doesn't mess with - // other instances of mouse - _mouseDestroy: function() { - this.element.off("." + this.widgetName); - if ( this._mouseMoveDelegate ) { - this.document - .off("mousemove." + this.widgetName, this._mouseMoveDelegate) - .off("mouseup." + this.widgetName, this._mouseUpDelegate); - } - }, - - _mouseDown: function(event) { - // don't let more than one widget handle mouseStart - if ( mouseHandled ) { - return; - } - - this._mouseMoved = false; - - // we may have missed mouseup (out of window) - (this._mouseStarted && this._mouseUp(event)); - - this._mouseDownEvent = event; - - var that = this, - btnIsLeft = (event.which === 1), - // event.target.nodeName works around a bug in IE 8 with - // disabled inputs (#7620) - elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(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() { - that.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; - } - } - - // Click event may never have fired (Gecko & Opera) - if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) { - $.removeData(event.target, this.widgetName + ".preventClickEvent"); - } - - // these delegates are required to keep context - this._mouseMoveDelegate = function(event) { - return that._mouseMove(event); - }; - this._mouseUpDelegate = function(event) { - return that._mouseUp(event); - }; - - this.document - .on( "mousemove." + this.widgetName, this._mouseMoveDelegate ) - .on( "mouseup." + this.widgetName, this._mouseUpDelegate ); - - event.preventDefault(); - - mouseHandled = true; - return true; - }, - - _mouseMove: function(event) { - // Only check for mouseups outside the document if you've moved inside the document - // at least once. This prevents the firing of mouseup in the case of IE<9, which will - // fire a mousemove event if content is placed under the cursor. See #7778 - // Support: IE <9 - if ( this._mouseMoved ) { - // IE mouseup check - mouseup happened when mouse was out of window - if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) { - return this._mouseUp(event); - - // Iframe mouseup check - mouseup occurred in another document - } else if ( !event.which ) { - return this._mouseUp( event ); - } - } - - if ( event.which || event.button ) { - this._mouseMoved = true; - } - - 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) { - this.document - .off( "mousemove." + this.widgetName, this._mouseMoveDelegate ) - .off( "mouseup." + this.widgetName, this._mouseUpDelegate ); - - if (this._mouseStarted) { - this._mouseStarted = false; - - if (event.target === this._mouseDownEvent.target) { - $.data(event.target, this.widgetName + ".preventClickEvent", true); - } - - this._mouseStop(event); - } - - mouseHandled = false; - 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; } -}); - -})); diff --git a/ui/resizable.js b/ui/resizable.js index ca36f2ca2..8513efe81 100644 --- a/ui/resizable.js +++ b/ui/resizable.js @@ -23,7 +23,7 @@ define([ "jquery", "./disable-selection", - "./mouse", + "./widgets/mouse", "./plugin", "./version", "./widget" diff --git a/ui/selectable.js b/ui/selectable.js index ec4895d15..160fcf56d 100644 --- a/ui/selectable.js +++ b/ui/selectable.js @@ -21,7 +21,7 @@ define([ "jquery", "./version", - "./mouse", + "./widgets/mouse", "./widget" ], factory ); } else { diff --git a/ui/slider.js b/ui/slider.js index ff883a1eb..3690fbc3c 100644 --- a/ui/slider.js +++ b/ui/slider.js @@ -23,7 +23,7 @@ define([ "jquery", "./keycode", - "./mouse", + "./widgets/mouse", "./version", "./widget" ], factory ); diff --git a/ui/sortable.js b/ui/sortable.js index cb89c30e6..ecf8bffb4 100644 --- a/ui/sortable.js +++ b/ui/sortable.js @@ -24,7 +24,7 @@ "./data", "./version", "./ie", - "./mouse", + "./widgets/mouse", "./scroll-parent", "./widget" ], factory ); diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js index 856ad9bb0..88f8c93de 100644 --- a/ui/widgets/dialog.js +++ b/ui/widgets/dialog.js @@ -24,7 +24,7 @@ "jquery", "./button", "./draggable", - "../mouse", + "./mouse", "../resizable", "../focusable", "../keycode", diff --git a/ui/widgets/draggable.js b/ui/widgets/draggable.js index e26be73b1..ab9d24667 100644 --- a/ui/widgets/draggable.js +++ b/ui/widgets/draggable.js @@ -20,7 +20,7 @@ // AMD. Register as an anonymous module. define([ "jquery", - "../mouse", + "./mouse", "../data", "../plugin", "../safe-active-element", diff --git a/ui/widgets/droppable.js b/ui/widgets/droppable.js index 551828b6d..3a8bd7109 100644 --- a/ui/widgets/droppable.js +++ b/ui/widgets/droppable.js @@ -20,7 +20,7 @@ define([ "jquery", "./draggable", - "../mouse", + "./mouse", "../version", "../widget" ], factory ); diff --git a/ui/widgets/mouse.js b/ui/widgets/mouse.js new file mode 100644 index 000000000..80242c0b7 --- /dev/null +++ b/ui/widgets/mouse.js @@ -0,0 +1,205 @@ +/*! + * jQuery UI Mouse @VERSION + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + */ + +//>>label: Mouse +//>>group: UI Core +//>>description: Abstracts mouse-based interactions to assist in creating certain widgets. +//>>docs: http://api.jqueryui.com/mouse/ + +(function( factory ) { + if ( typeof define === "function" && define.amd ) { + + // AMD. Register as an anonymous module. + define([ + "jquery", + "../ie", + "../version", + "../widget" + ], factory ); + } else { + + // Browser globals + factory( jQuery ); + } +}(function( $ ) { + +var mouseHandled = false; +$( document ).on( "mouseup", function() { + mouseHandled = false; +}); + +return $.widget("ui.mouse", { + version: "@VERSION", + options: { + cancel: "input, textarea, button, select, option", + distance: 1, + delay: 0 + }, + _mouseInit: function() { + var that = this; + + this.element + .on("mousedown." + this.widgetName, function(event) { + return that._mouseDown(event); + }) + .on("click." + this.widgetName, function(event) { + if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) { + $.removeData(event.target, that.widgetName + ".preventClickEvent"); + event.stopImmediatePropagation(); + return false; + } + }); + + this.started = false; + }, + + // TODO: make sure destroying one instance of mouse doesn't mess with + // other instances of mouse + _mouseDestroy: function() { + this.element.off("." + this.widgetName); + if ( this._mouseMoveDelegate ) { + this.document + .off("mousemove." + this.widgetName, this._mouseMoveDelegate) + .off("mouseup." + this.widgetName, this._mouseUpDelegate); + } + }, + + _mouseDown: function(event) { + // don't let more than one widget handle mouseStart + if ( mouseHandled ) { + return; + } + + this._mouseMoved = false; + + // we may have missed mouseup (out of window) + (this._mouseStarted && this._mouseUp(event)); + + this._mouseDownEvent = event; + + var that = this, + btnIsLeft = (event.which === 1), + // event.target.nodeName works around a bug in IE 8 with + // disabled inputs (#7620) + elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(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() { + that.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; + } + } + + // Click event may never have fired (Gecko & Opera) + if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) { + $.removeData(event.target, this.widgetName + ".preventClickEvent"); + } + + // these delegates are required to keep context + this._mouseMoveDelegate = function(event) { + return that._mouseMove(event); + }; + this._mouseUpDelegate = function(event) { + return that._mouseUp(event); + }; + + this.document + .on( "mousemove." + this.widgetName, this._mouseMoveDelegate ) + .on( "mouseup." + this.widgetName, this._mouseUpDelegate ); + + event.preventDefault(); + + mouseHandled = true; + return true; + }, + + _mouseMove: function(event) { + // Only check for mouseups outside the document if you've moved inside the document + // at least once. This prevents the firing of mouseup in the case of IE<9, which will + // fire a mousemove event if content is placed under the cursor. See #7778 + // Support: IE <9 + if ( this._mouseMoved ) { + // IE mouseup check - mouseup happened when mouse was out of window + if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) { + return this._mouseUp(event); + + // Iframe mouseup check - mouseup occurred in another document + } else if ( !event.which ) { + return this._mouseUp( event ); + } + } + + if ( event.which || event.button ) { + this._mouseMoved = true; + } + + 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) { + this.document + .off( "mousemove." + this.widgetName, this._mouseMoveDelegate ) + .off( "mouseup." + this.widgetName, this._mouseUpDelegate ); + + if (this._mouseStarted) { + this._mouseStarted = false; + + if (event.target === this._mouseDownEvent.target) { + $.data(event.target, this.widgetName + ".preventClickEvent", true); + } + + this._mouseStop(event); + } + + mouseHandled = false; + 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; } +}); + +}));