[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1