2009-12-22 19:51:24 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Mouse @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2009-12-22 19:51:24 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2009-12-22 19:51:24 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Mouse
|
|
|
|
//>>group: UI Core
|
|
|
|
//>>description: Abstracts mouse-based interactions to assist in creating certain widgets.
|
|
|
|
//>>docs: http://api.jqueryui.com/mouse/
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
( function( factory ) {
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-08-24 12:59:04 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2015-07-15 02:18:43 +00:00
|
|
|
"../ie",
|
|
|
|
"../version",
|
|
|
|
"../widget"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2015-08-24 12:59:04 +00:00
|
|
|
}( function( $ ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2011-08-02 13:36:22 +00:00
|
|
|
var mouseHandled = false;
|
2015-05-14 02:11:56 +00:00
|
|
|
$( document ).on( "mouseup", function() {
|
2011-08-02 13:36:22 +00:00
|
|
|
mouseHandled = false;
|
2015-08-24 12:59:04 +00:00
|
|
|
} );
|
2011-08-02 13:36:22 +00:00
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
return $.widget( "ui.mouse", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2015-03-26 11:41:37 +00:00
|
|
|
cancel: "input, textarea, button, select, option",
|
2010-01-07 03:19:50 +00:00
|
|
|
distance: 1,
|
|
|
|
delay: 0
|
|
|
|
},
|
2009-12-22 19:51:24 +00:00
|
|
|
_mouseInit: function() {
|
2012-02-12 14:31:06 +00:00
|
|
|
var that = this;
|
2009-12-22 19:51:24 +00:00
|
|
|
|
|
|
|
this.element
|
2015-08-24 12:59:04 +00:00
|
|
|
.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" );
|
2009-12-22 19:51:24 +00:00
|
|
|
event.stopImmediatePropagation();
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-24 12:59:04 +00:00
|
|
|
} );
|
2009-12-22 19:51:24 +00:00
|
|
|
|
|
|
|
this.started = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// TODO: make sure destroying one instance of mouse doesn't mess with
|
|
|
|
// other instances of mouse
|
|
|
|
_mouseDestroy: function() {
|
2015-08-24 12:59:04 +00:00
|
|
|
this.element.off( "." + this.widgetName );
|
2012-07-31 20:27:43 +00:00
|
|
|
if ( this._mouseMoveDelegate ) {
|
2010-06-14 15:20:03 +00:00
|
|
|
this.document
|
2015-08-24 12:59:04 +00:00
|
|
|
.off( "mousemove." + this.widgetName, this._mouseMoveDelegate )
|
|
|
|
.off( "mouseup." + this.widgetName, this._mouseUpDelegate );
|
2012-07-31 20:27:43 +00:00
|
|
|
}
|
2009-12-22 19:51:24 +00:00
|
|
|
},
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
_mouseDown: function( event ) {
|
|
|
|
|
2009-12-22 19:51:24 +00:00
|
|
|
// don't let more than one widget handle mouseStart
|
2013-10-16 18:43:09 +00:00
|
|
|
if ( mouseHandled ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2014-08-19 19:09:28 +00:00
|
|
|
this._mouseMoved = false;
|
|
|
|
|
2015-08-21 04:08:12 +00:00
|
|
|
// We may have missed mouseup (out of window)
|
2015-08-24 12:59:04 +00:00
|
|
|
( this._mouseStarted && this._mouseUp( event ) );
|
2009-12-22 19:51:24 +00:00
|
|
|
|
|
|
|
this._mouseDownEvent = event;
|
|
|
|
|
2012-02-12 14:31:06 +00:00
|
|
|
var that = this,
|
2015-08-24 12:59:04 +00:00
|
|
|
btnIsLeft = ( event.which === 1 ),
|
|
|
|
|
2011-08-09 13:32:01 +00:00
|
|
|
// event.target.nodeName works around a bug in IE 8 with
|
|
|
|
// disabled inputs (#7620)
|
2015-08-24 12:59:04 +00:00
|
|
|
elIsCancel = ( typeof this.options.cancel === "string" && event.target.nodeName ? $( event.target ).closest( this.options.cancel ).length : false );
|
|
|
|
if ( !btnIsLeft || elIsCancel || !this._mouseCapture( event ) ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mouseDelayMet = !this.options.delay;
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( !this.mouseDelayMet ) {
|
|
|
|
this._mouseDelayTimer = setTimeout( function() {
|
2012-02-12 14:31:06 +00:00
|
|
|
that.mouseDelayMet = true;
|
2015-08-24 12:59:04 +00:00
|
|
|
}, this.options.delay );
|
2009-12-22 19:51:24 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {
|
|
|
|
this._mouseStarted = ( this._mouseStart( event ) !== false );
|
|
|
|
if ( !this._mouseStarted ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
event.preventDefault();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 08:13:55 +00:00
|
|
|
// Click event may never have fired (Gecko & Opera)
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( true === $.data( event.target, this.widgetName + ".preventClickEvent" ) ) {
|
|
|
|
$.removeData( event.target, this.widgetName + ".preventClickEvent" );
|
2011-02-05 08:13:55 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:08:12 +00:00
|
|
|
// These delegates are required to keep context
|
2015-08-24 12:59:04 +00:00
|
|
|
this._mouseMoveDelegate = function( event ) {
|
|
|
|
return that._mouseMove( event );
|
2009-12-22 19:51:24 +00:00
|
|
|
};
|
2015-08-24 12:59:04 +00:00
|
|
|
this._mouseUpDelegate = function( event ) {
|
|
|
|
return that._mouseUp( event );
|
2009-12-22 19:51:24 +00:00
|
|
|
};
|
2010-06-14 15:20:03 +00:00
|
|
|
|
|
|
|
this.document
|
2015-05-14 02:11:56 +00:00
|
|
|
.on( "mousemove." + this.widgetName, this._mouseMoveDelegate )
|
|
|
|
.on( "mouseup." + this.widgetName, this._mouseUpDelegate );
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2010-10-13 17:30:50 +00:00
|
|
|
event.preventDefault();
|
2012-10-22 01:50:03 +00:00
|
|
|
|
2011-08-02 13:36:22 +00:00
|
|
|
mouseHandled = true;
|
2009-12-22 19:51:24 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
_mouseMove: function( event ) {
|
|
|
|
|
2014-08-19 19:09:28 +00:00
|
|
|
// 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 ) {
|
2015-08-24 12:59:04 +00:00
|
|
|
|
2014-08-19 19:09:28 +00:00
|
|
|
// IE mouseup check - mouseup happened when mouse was out of window
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( $.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button ) {
|
|
|
|
return this._mouseUp( event );
|
2014-08-19 19:09:28 +00:00
|
|
|
|
|
|
|
// Iframe mouseup check - mouseup occurred in another document
|
|
|
|
} else if ( !event.which ) {
|
|
|
|
return this._mouseUp( event );
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 18:43:09 +00:00
|
|
|
|
2014-08-19 19:09:28 +00:00
|
|
|
if ( event.which || event.button ) {
|
|
|
|
this._mouseMoved = true;
|
2010-06-14 15:20:03 +00:00
|
|
|
}
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( this._mouseStarted ) {
|
|
|
|
this._mouseDrag( event );
|
2009-12-22 19:51:24 +00:00
|
|
|
return event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
this._mouseStarted =
|
2015-08-24 12:59:04 +00:00
|
|
|
( this._mouseStart( this._mouseDownEvent, event ) !== false );
|
|
|
|
( this._mouseStarted ? this._mouseDrag( event ) : this._mouseUp( event ) );
|
2009-12-22 19:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return !this._mouseStarted;
|
|
|
|
},
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
_mouseUp: function( event ) {
|
2010-06-14 15:20:03 +00:00
|
|
|
this.document
|
2015-05-14 02:11:56 +00:00
|
|
|
.off( "mousemove." + this.widgetName, this._mouseMoveDelegate )
|
|
|
|
.off( "mouseup." + this.widgetName, this._mouseUpDelegate );
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( this._mouseStarted ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
this._mouseStarted = false;
|
2010-11-03 07:45:47 +00:00
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
if ( event.target === this._mouseDownEvent.target ) {
|
|
|
|
$.data( event.target, this.widgetName + ".preventClickEvent", true );
|
2010-11-03 07:45:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
this._mouseStop( event );
|
2009-12-22 19:51:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 12:42:02 +00:00
|
|
|
if ( this._mouseDelayTimer ) {
|
|
|
|
clearTimeout( this._mouseDelayTimer );
|
2015-07-22 12:58:47 +00:00
|
|
|
delete this._mouseDelayTimer;
|
|
|
|
}
|
|
|
|
|
2010-06-14 15:20:03 +00:00
|
|
|
mouseHandled = false;
|
2009-12-22 19:51:24 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
_mouseDistanceMet: function( event ) {
|
|
|
|
return ( Math.max(
|
|
|
|
Math.abs( this._mouseDownEvent.pageX - event.pageX ),
|
|
|
|
Math.abs( this._mouseDownEvent.pageY - event.pageY )
|
2009-12-22 19:51:24 +00:00
|
|
|
) >= this.options.distance
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
_mouseDelayMet: function( /* event */ ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
return this.mouseDelayMet;
|
|
|
|
},
|
|
|
|
|
|
|
|
// These are placeholder methods, to be overriden by extending plugin
|
2015-08-24 12:59:04 +00:00
|
|
|
_mouseStart: function( /* event */ ) {},
|
|
|
|
_mouseDrag: function( /* event */ ) {},
|
|
|
|
_mouseStop: function( /* event */ ) {},
|
|
|
|
_mouseCapture: function( /* event */ ) { return true; }
|
|
|
|
} );
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2015-08-24 12:59:04 +00:00
|
|
|
} ) );
|