[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/jquery/ui/ -> mouse.js (source)

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


Generated : Fri Nov 15 08:20:01 2024 Cross-referenced by PHPXref