You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

238 rivejä
6.1 KiB

  1. /*!
  2. * jQuery UI Mouse 1.13.1
  3. * http://jqueryui.com
  4. *
  5. * Copyright jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. */
  9. //>>label: Mouse
  10. //>>group: Widgets
  11. //>>description: Abstracts mouse-based interactions to assist in creating certain widgets.
  12. //>>docs: http://api.jqueryui.com/mouse/
  13. ( function( factory ) {
  14. "use strict";
  15. if ( typeof define === "function" && define.amd ) {
  16. // AMD. Register as an anonymous module.
  17. define( [
  18. "jquery",
  19. "../ie",
  20. "../version",
  21. "../widget"
  22. ], factory );
  23. } else {
  24. // Browser globals
  25. factory( jQuery );
  26. }
  27. } )( function( $ ) {
  28. "use strict";
  29. var mouseHandled = false;
  30. $( document ).on( "mouseup", function() {
  31. mouseHandled = false;
  32. } );
  33. return $.widget( "ui.mouse", {
  34. version: "1.13.1",
  35. options: {
  36. cancel: "input, textarea, button, select, option",
  37. distance: 1,
  38. delay: 0
  39. },
  40. _mouseInit: function() {
  41. var that = this;
  42. this.element
  43. .on( "mousedown." + this.widgetName, function( event ) {
  44. return that._mouseDown( event );
  45. } )
  46. .on( "click." + this.widgetName, function( event ) {
  47. if ( true === $.data( event.target, that.widgetName + ".preventClickEvent" ) ) {
  48. $.removeData( event.target, that.widgetName + ".preventClickEvent" );
  49. event.stopImmediatePropagation();
  50. return false;
  51. }
  52. } );
  53. this.started = false;
  54. },
  55. // TODO: make sure destroying one instance of mouse doesn't mess with
  56. // other instances of mouse
  57. _mouseDestroy: function() {
  58. this.element.off( "." + this.widgetName );
  59. if ( this._mouseMoveDelegate ) {
  60. this.document
  61. .off( "mousemove." + this.widgetName, this._mouseMoveDelegate )
  62. .off( "mouseup." + this.widgetName, this._mouseUpDelegate );
  63. }
  64. },
  65. _mouseDown: function( event ) {
  66. // don't let more than one widget handle mouseStart
  67. if ( mouseHandled ) {
  68. return;
  69. }
  70. this._mouseMoved = false;
  71. // We may have missed mouseup (out of window)
  72. if ( this._mouseStarted ) {
  73. this._mouseUp( event );
  74. }
  75. this._mouseDownEvent = event;
  76. var that = this,
  77. btnIsLeft = ( event.which === 1 ),
  78. // event.target.nodeName works around a bug in IE 8 with
  79. // disabled inputs (#7620)
  80. elIsCancel = ( typeof this.options.cancel === "string" && event.target.nodeName ?
  81. $( event.target ).closest( this.options.cancel ).length : false );
  82. if ( !btnIsLeft || elIsCancel || !this._mouseCapture( event ) ) {
  83. return true;
  84. }
  85. this.mouseDelayMet = !this.options.delay;
  86. if ( !this.mouseDelayMet ) {
  87. this._mouseDelayTimer = setTimeout( function() {
  88. that.mouseDelayMet = true;
  89. }, this.options.delay );
  90. }
  91. if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {
  92. this._mouseStarted = ( this._mouseStart( event ) !== false );
  93. if ( !this._mouseStarted ) {
  94. event.preventDefault();
  95. return true;
  96. }
  97. }
  98. // Click event may never have fired (Gecko & Opera)
  99. if ( true === $.data( event.target, this.widgetName + ".preventClickEvent" ) ) {
  100. $.removeData( event.target, this.widgetName + ".preventClickEvent" );
  101. }
  102. // These delegates are required to keep context
  103. this._mouseMoveDelegate = function( event ) {
  104. return that._mouseMove( event );
  105. };
  106. this._mouseUpDelegate = function( event ) {
  107. return that._mouseUp( event );
  108. };
  109. this.document
  110. .on( "mousemove." + this.widgetName, this._mouseMoveDelegate )
  111. .on( "mouseup." + this.widgetName, this._mouseUpDelegate );
  112. event.preventDefault();
  113. mouseHandled = true;
  114. return true;
  115. },
  116. _mouseMove: function( event ) {
  117. // Only check for mouseups outside the document if you've moved inside the document
  118. // at least once. This prevents the firing of mouseup in the case of IE<9, which will
  119. // fire a mousemove event if content is placed under the cursor. See #7778
  120. // Support: IE <9
  121. if ( this._mouseMoved ) {
  122. // IE mouseup check - mouseup happened when mouse was out of window
  123. if ( $.ui.ie && ( !document.documentMode || document.documentMode < 9 ) &&
  124. !event.button ) {
  125. return this._mouseUp( event );
  126. // Iframe mouseup check - mouseup occurred in another document
  127. } else if ( !event.which ) {
  128. // Support: Safari <=8 - 9
  129. // Safari sets which to 0 if you press any of the following keys
  130. // during a drag (#14461)
  131. if ( event.originalEvent.altKey || event.originalEvent.ctrlKey ||
  132. event.originalEvent.metaKey || event.originalEvent.shiftKey ) {
  133. this.ignoreMissingWhich = true;
  134. } else if ( !this.ignoreMissingWhich ) {
  135. return this._mouseUp( event );
  136. }
  137. }
  138. }
  139. if ( event.which || event.button ) {
  140. this._mouseMoved = true;
  141. }
  142. if ( this._mouseStarted ) {
  143. this._mouseDrag( event );
  144. return event.preventDefault();
  145. }
  146. if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {
  147. this._mouseStarted =
  148. ( this._mouseStart( this._mouseDownEvent, event ) !== false );
  149. if ( this._mouseStarted ) {
  150. this._mouseDrag( event );
  151. } else {
  152. this._mouseUp( event );
  153. }
  154. }
  155. return !this._mouseStarted;
  156. },
  157. _mouseUp: function( event ) {
  158. this.document
  159. .off( "mousemove." + this.widgetName, this._mouseMoveDelegate )
  160. .off( "mouseup." + this.widgetName, this._mouseUpDelegate );
  161. if ( this._mouseStarted ) {
  162. this._mouseStarted = false;
  163. if ( event.target === this._mouseDownEvent.target ) {
  164. $.data( event.target, this.widgetName + ".preventClickEvent", true );
  165. }
  166. this._mouseStop( event );
  167. }
  168. if ( this._mouseDelayTimer ) {
  169. clearTimeout( this._mouseDelayTimer );
  170. delete this._mouseDelayTimer;
  171. }
  172. this.ignoreMissingWhich = false;
  173. mouseHandled = false;
  174. event.preventDefault();
  175. },
  176. _mouseDistanceMet: function( event ) {
  177. return ( Math.max(
  178. Math.abs( this._mouseDownEvent.pageX - event.pageX ),
  179. Math.abs( this._mouseDownEvent.pageY - event.pageY )
  180. ) >= this.options.distance
  181. );
  182. },
  183. _mouseDelayMet: function( /* event */ ) {
  184. return this.mouseDelayMet;
  185. },
  186. // These are placeholder methods, to be overriden by extending plugin
  187. _mouseStart: function( /* event */ ) {},
  188. _mouseDrag: function( /* event */ ) {},
  189. _mouseStop: function( /* event */ ) {},
  190. _mouseCapture: function( /* event */ ) {
  191. return true;
  192. }
  193. } );
  194. } );