6248 lines
169 KiB
JavaScript
6248 lines
169 KiB
JavaScript
/*! jQuery UI - v1.13.1 - 2022-02-09
|
|
* http://jqueryui.com
|
|
* Includes: widget.js, data.js, disable-selection.js, form-reset-mixin.js, jquery-patch.js, keycode.js, labels.js, scroll-parent.js, widgets/draggable.js, widgets/droppable.js, widgets/sortable.js, widgets/button.js, widgets/checkboxradio.js, widgets/controlgroup.js, widgets/mouse.js, widgets/spinner.js
|
|
* Copyright jQuery Foundation and other contributors; Licensed MIT */
|
|
|
|
( function( factory ) {
|
|
"use strict";
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
// AMD. Register as an anonymous module.
|
|
define( [ "jquery" ], factory );
|
|
} else {
|
|
|
|
// Browser globals
|
|
factory( jQuery );
|
|
}
|
|
} )( function( $ ) {
|
|
"use strict";
|
|
|
|
$.ui = $.ui || {};
|
|
|
|
var version = $.ui.version = "1.13.1";
|
|
|
|
|
|
/*!
|
|
* jQuery UI Widget 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Widget
|
|
//>>group: Core
|
|
//>>description: Provides a factory for creating stateful widgets with a common API.
|
|
//>>docs: http://api.jqueryui.com/jQuery.widget/
|
|
//>>demos: http://jqueryui.com/widget/
|
|
|
|
|
|
var widgetUuid = 0;
|
|
var widgetHasOwnProperty = Array.prototype.hasOwnProperty;
|
|
var widgetSlice = Array.prototype.slice;
|
|
|
|
$.cleanData = ( function( orig ) {
|
|
return function( elems ) {
|
|
var events, elem, i;
|
|
for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
|
|
|
|
// Only trigger remove when necessary to save time
|
|
events = $._data( elem, "events" );
|
|
if ( events && events.remove ) {
|
|
$( elem ).triggerHandler( "remove" );
|
|
}
|
|
}
|
|
orig( elems );
|
|
};
|
|
} )( $.cleanData );
|
|
|
|
$.widget = function( name, base, prototype ) {
|
|
var existingConstructor, constructor, basePrototype;
|
|
|
|
// ProxiedPrototype allows the provided prototype to remain unmodified
|
|
// so that it can be used as a mixin for multiple widgets (#8876)
|
|
var proxiedPrototype = {};
|
|
|
|
var namespace = name.split( "." )[ 0 ];
|
|
name = name.split( "." )[ 1 ];
|
|
var fullName = namespace + "-" + name;
|
|
|
|
if ( !prototype ) {
|
|
prototype = base;
|
|
base = $.Widget;
|
|
}
|
|
|
|
if ( Array.isArray( prototype ) ) {
|
|
prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
|
|
}
|
|
|
|
// Create selector for plugin
|
|
$.expr.pseudos[ fullName.toLowerCase() ] = function( elem ) {
|
|
return !!$.data( elem, fullName );
|
|
};
|
|
|
|
$[ namespace ] = $[ namespace ] || {};
|
|
existingConstructor = $[ namespace ][ name ];
|
|
constructor = $[ namespace ][ name ] = function( options, element ) {
|
|
|
|
// Allow instantiation without "new" keyword
|
|
if ( !this || !this._createWidget ) {
|
|
return new constructor( options, element );
|
|
}
|
|
|
|
// Allow instantiation without initializing for simple inheritance
|
|
// must use "new" keyword (the code above always passes args)
|
|
if ( arguments.length ) {
|
|
this._createWidget( options, element );
|
|
}
|
|
};
|
|
|
|
// Extend with the existing constructor to carry over any static properties
|
|
$.extend( constructor, existingConstructor, {
|
|
version: prototype.version,
|
|
|
|
// Copy the object used to create the prototype in case we need to
|
|
// redefine the widget later
|
|
_proto: $.extend( {}, prototype ),
|
|
|
|
// Track widgets that inherit from this widget in case this widget is
|
|
// redefined after a widget inherits from it
|
|
_childConstructors: []
|
|
} );
|
|
|
|
basePrototype = new base();
|
|
|
|
// We need to make the options hash a property directly on the new instance
|
|
// otherwise we'll modify the options hash on the prototype that we're
|
|
// inheriting from
|
|
basePrototype.options = $.widget.extend( {}, basePrototype.options );
|
|
$.each( prototype, function( prop, value ) {
|
|
if ( typeof value !== "function" ) {
|
|
proxiedPrototype[ prop ] = value;
|
|
return;
|
|
}
|
|
proxiedPrototype[ prop ] = ( function() {
|
|
function _super() {
|
|
return base.prototype[ prop ].apply( this, arguments );
|
|
}
|
|
|
|
function _superApply( args ) {
|
|
return base.prototype[ prop ].apply( this, args );
|
|
}
|
|
|
|
return function() {
|
|
var __super = this._super;
|
|
var __superApply = this._superApply;
|
|
var returnValue;
|
|
|
|
this._super = _super;
|
|
this._superApply = _superApply;
|
|
|
|
returnValue = value.apply( this, arguments );
|
|
|
|
this._super = __super;
|
|
this._superApply = __superApply;
|
|
|
|
return returnValue;
|
|
};
|
|
} )();
|
|
} );
|
|
constructor.prototype = $.widget.extend( basePrototype, {
|
|
|
|
// TODO: remove support for widgetEventPrefix
|
|
// always use the name + a colon as the prefix, e.g., draggable:start
|
|
// don't prefix for widgets that aren't DOM-based
|
|
widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
|
|
}, proxiedPrototype, {
|
|
constructor: constructor,
|
|
namespace: namespace,
|
|
widgetName: name,
|
|
widgetFullName: fullName
|
|
} );
|
|
|
|
// If this widget is being redefined then we need to find all widgets that
|
|
// are inheriting from it and redefine all of them so that they inherit from
|
|
// the new version of this widget. We're essentially trying to replace one
|
|
// level in the prototype chain.
|
|
if ( existingConstructor ) {
|
|
$.each( existingConstructor._childConstructors, function( i, child ) {
|
|
var childPrototype = child.prototype;
|
|
|
|
// Redefine the child widget using the same prototype that was
|
|
// originally used, but inherit from the new version of the base
|
|
$.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
|
|
child._proto );
|
|
} );
|
|
|
|
// Remove the list of existing child constructors from the old constructor
|
|
// so the old child constructors can be garbage collected
|
|
delete existingConstructor._childConstructors;
|
|
} else {
|
|
base._childConstructors.push( constructor );
|
|
}
|
|
|
|
$.widget.bridge( name, constructor );
|
|
|
|
return constructor;
|
|
};
|
|
|
|
$.widget.extend = function( target ) {
|
|
var input = widgetSlice.call( arguments, 1 );
|
|
var inputIndex = 0;
|
|
var inputLength = input.length;
|
|
var key;
|
|
var value;
|
|
|
|
for ( ; inputIndex < inputLength; inputIndex++ ) {
|
|
for ( key in input[ inputIndex ] ) {
|
|
value = input[ inputIndex ][ key ];
|
|
if ( widgetHasOwnProperty.call( input[ inputIndex ], key ) && value !== undefined ) {
|
|
|
|
// Clone objects
|
|
if ( $.isPlainObject( value ) ) {
|
|
target[ key ] = $.isPlainObject( target[ key ] ) ?
|
|
$.widget.extend( {}, target[ key ], value ) :
|
|
|
|
// Don't extend strings, arrays, etc. with objects
|
|
$.widget.extend( {}, value );
|
|
|
|
// Copy everything else by reference
|
|
} else {
|
|
target[ key ] = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return target;
|
|
};
|
|
|
|
$.widget.bridge = function( name, object ) {
|
|
var fullName = object.prototype.widgetFullName || name;
|
|
$.fn[ name ] = function( options ) {
|
|
var isMethodCall = typeof options === "string";
|
|
var args = widgetSlice.call( arguments, 1 );
|
|
var returnValue = this;
|
|
|
|
if ( isMethodCall ) {
|
|
|
|
// If this is an empty collection, we need to have the instance method
|
|
// return undefined instead of the jQuery instance
|
|
if ( !this.length && options === "instance" ) {
|
|
returnValue = undefined;
|
|
} else {
|
|
this.each( function() {
|
|
var methodValue;
|
|
var instance = $.data( this, fullName );
|
|
|
|
if ( options === "instance" ) {
|
|
returnValue = instance;
|
|
return false;
|
|
}
|
|
|
|
if ( !instance ) {
|
|
return $.error( "cannot call methods on " + name +
|
|
" prior to initialization; " +
|
|
"attempted to call method '" + options + "'" );
|
|
}
|
|
|
|
if ( typeof instance[ options ] !== "function" ||
|
|
options.charAt( 0 ) === "_" ) {
|
|
return $.error( "no such method '" + options + "' for " + name +
|
|
" widget instance" );
|
|
}
|
|
|
|
methodValue = instance[ options ].apply( instance, args );
|
|
|
|
if ( methodValue !== instance && methodValue !== undefined ) {
|
|
returnValue = methodValue && methodValue.jquery ?
|
|
returnValue.pushStack( methodValue.get() ) :
|
|
methodValue;
|
|
return false;
|
|
}
|
|
} );
|
|
}
|
|
} else {
|
|
|
|
// Allow multiple hashes to be passed on init
|
|
if ( args.length ) {
|
|
options = $.widget.extend.apply( null, [ options ].concat( args ) );
|
|
}
|
|
|
|
this.each( function() {
|
|
var instance = $.data( this, fullName );
|
|
if ( instance ) {
|
|
instance.option( options || {} );
|
|
if ( instance._init ) {
|
|
instance._init();
|
|
}
|
|
} else {
|
|
$.data( this, fullName, new object( options, this ) );
|
|
}
|
|
} );
|
|
}
|
|
|
|
return returnValue;
|
|
};
|
|
};
|
|
|
|
$.Widget = function( /* options, element */ ) {};
|
|
$.Widget._childConstructors = [];
|
|
|
|
$.Widget.prototype = {
|
|
widgetName: "widget",
|
|
widgetEventPrefix: "",
|
|
defaultElement: "<div>",
|
|
|
|
options: {
|
|
classes: {},
|
|
disabled: false,
|
|
|
|
// Callbacks
|
|
create: null
|
|
},
|
|
|
|
_createWidget: function( options, element ) {
|
|
element = $( element || this.defaultElement || this )[ 0 ];
|
|
this.element = $( element );
|
|
this.uuid = widgetUuid++;
|
|
this.eventNamespace = "." + this.widgetName + this.uuid;
|
|
|
|
this.bindings = $();
|
|
this.hoverable = $();
|
|
this.focusable = $();
|
|
this.classesElementLookup = {};
|
|
|
|
if ( element !== this ) {
|
|
$.data( element, this.widgetFullName, this );
|
|
this._on( true, this.element, {
|
|
remove: function( event ) {
|
|
if ( event.target === element ) {
|
|
this.destroy();
|
|
}
|
|
}
|
|
} );
|
|
this.document = $( element.style ?
|
|
|
|
// Element within the document
|
|
element.ownerDocument :
|
|
|
|
// Element is window or document
|
|
element.document || element );
|
|
this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
|
|
}
|
|
|
|
this.options = $.widget.extend( {},
|
|
this.options,
|
|
this._getCreateOptions(),
|
|
options );
|
|
|
|
this._create();
|
|
|
|
if ( this.options.disabled ) {
|
|
this._setOptionDisabled( this.options.disabled );
|
|
}
|
|
|
|
this._trigger( "create", null, this._getCreateEventData() );
|
|
this._init();
|
|
},
|
|
|
|
_getCreateOptions: function() {
|
|
return {};
|
|
},
|
|
|
|
_getCreateEventData: $.noop,
|
|
|
|
_create: $.noop,
|
|
|
|
_init: $.noop,
|
|
|
|
destroy: function() {
|
|
var that = this;
|
|
|
|
this._destroy();
|
|
$.each( this.classesElementLookup, function( key, value ) {
|
|
that._removeClass( value, key );
|
|
} );
|
|
|
|
// We can probably remove the unbind calls in 2.0
|
|
// all event bindings should go through this._on()
|
|
this.element
|
|
.off( this.eventNamespace )
|
|
.removeData( this.widgetFullName );
|
|
this.widget()
|
|
.off( this.eventNamespace )
|
|
.removeAttr( "aria-disabled" );
|
|
|
|
// Clean up events and states
|
|
this.bindings.off( this.eventNamespace );
|
|
},
|
|
|
|
_destroy: $.noop,
|
|
|
|
widget: function() {
|
|
return this.element;
|
|
},
|
|
|
|
option: function( key, value ) {
|
|
var options = key;
|
|
var parts;
|
|
var curOption;
|
|
var i;
|
|
|
|
if ( arguments.length === 0 ) {
|
|
|
|
// Don't return a reference to the internal hash
|
|
return $.widget.extend( {}, this.options );
|
|
}
|
|
|
|
if ( typeof key === "string" ) {
|
|
|
|
// Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
|
|
options = {};
|
|
parts = key.split( "." );
|
|
key = parts.shift();
|
|
if ( parts.length ) {
|
|
curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
|
|
for ( i = 0; i < parts.length - 1; i++ ) {
|
|
curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
|
|
curOption = curOption[ parts[ i ] ];
|
|
}
|
|
key = parts.pop();
|
|
if ( arguments.length === 1 ) {
|
|
return curOption[ key ] === undefined ? null : curOption[ key ];
|
|
}
|
|
curOption[ key ] = value;
|
|
} else {
|
|
if ( arguments.length === 1 ) {
|
|
return this.options[ key ] === undefined ? null : this.options[ key ];
|
|
}
|
|
options[ key ] = value;
|
|
}
|
|
}
|
|
|
|
this._setOptions( options );
|
|
|
|
return this;
|
|
},
|
|
|
|
_setOptions: function( options ) {
|
|
var key;
|
|
|
|
for ( key in options ) {
|
|
this._setOption( key, options[ key ] );
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
if ( key === "classes" ) {
|
|
this._setOptionClasses( value );
|
|
}
|
|
|
|
this.options[ key ] = value;
|
|
|
|
if ( key === "disabled" ) {
|
|
this._setOptionDisabled( value );
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
_setOptionClasses: function( value ) {
|
|
var classKey, elements, currentElements;
|
|
|
|
for ( classKey in value ) {
|
|
currentElements = this.classesElementLookup[ classKey ];
|
|
if ( value[ classKey ] === this.options.classes[ classKey ] ||
|
|
!currentElements ||
|
|
!currentElements.length ) {
|
|
continue;
|
|
}
|
|
|
|
// We are doing this to create a new jQuery object because the _removeClass() call
|
|
// on the next line is going to destroy the reference to the current elements being
|
|
// tracked. We need to save a copy of this collection so that we can add the new classes
|
|
// below.
|
|
elements = $( currentElements.get() );
|
|
this._removeClass( currentElements, classKey );
|
|
|
|
// We don't use _addClass() here, because that uses this.options.classes
|
|
// for generating the string of classes. We want to use the value passed in from
|
|
// _setOption(), this is the new value of the classes option which was passed to
|
|
// _setOption(). We pass this value directly to _classes().
|
|
elements.addClass( this._classes( {
|
|
element: elements,
|
|
keys: classKey,
|
|
classes: value,
|
|
add: true
|
|
} ) );
|
|
}
|
|
},
|
|
|
|
_setOptionDisabled: function( value ) {
|
|
this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
|
|
|
|
// If the widget is becoming disabled, then nothing is interactive
|
|
if ( value ) {
|
|
this._removeClass( this.hoverable, null, "ui-state-hover" );
|
|
this._removeClass( this.focusable, null, "ui-state-focus" );
|
|
}
|
|
},
|
|
|
|
enable: function() {
|
|
return this._setOptions( { disabled: false } );
|
|
},
|
|
|
|
disable: function() {
|
|
return this._setOptions( { disabled: true } );
|
|
},
|
|
|
|
_classes: function( options ) {
|
|
var full = [];
|
|
var that = this;
|
|
|
|
options = $.extend( {
|
|
element: this.element,
|
|
classes: this.options.classes || {}
|
|
}, options );
|
|
|
|
function bindRemoveEvent() {
|
|
var nodesToBind = [];
|
|
|
|
options.element.each( function( _, element ) {
|
|
var isTracked = $.map( that.classesElementLookup, function( elements ) {
|
|
return elements;
|
|
} )
|
|
.some( function( elements ) {
|
|
return elements.is( element );
|
|
} );
|
|
|
|
if ( !isTracked ) {
|
|
nodesToBind.push( element );
|
|
}
|
|
} );
|
|
|
|
that._on( $( nodesToBind ), {
|
|
remove: "_untrackClassesElement"
|
|
} );
|
|
}
|
|
|
|
function processClassString( classes, checkOption ) {
|
|
var current, i;
|
|
for ( i = 0; i < classes.length; i++ ) {
|
|
current = that.classesElementLookup[ classes[ i ] ] || $();
|
|
if ( options.add ) {
|
|
bindRemoveEvent();
|
|
current = $( $.uniqueSort( current.get().concat( options.element.get() ) ) );
|
|
} else {
|
|
current = $( current.not( options.element ).get() );
|
|
}
|
|
that.classesElementLookup[ classes[ i ] ] = current;
|
|
full.push( classes[ i ] );
|
|
if ( checkOption && options.classes[ classes[ i ] ] ) {
|
|
full.push( options.classes[ classes[ i ] ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( options.keys ) {
|
|
processClassString( options.keys.match( /\S+/g ) || [], true );
|
|
}
|
|
if ( options.extra ) {
|
|
processClassString( options.extra.match( /\S+/g ) || [] );
|
|
}
|
|
|
|
return full.join( " " );
|
|
},
|
|
|
|
_untrackClassesElement: function( event ) {
|
|
var that = this;
|
|
$.each( that.classesElementLookup, function( key, value ) {
|
|
if ( $.inArray( event.target, value ) !== -1 ) {
|
|
that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
|
|
}
|
|
} );
|
|
|
|
this._off( $( event.target ) );
|
|
},
|
|
|
|
_removeClass: function( element, keys, extra ) {
|
|
return this._toggleClass( element, keys, extra, false );
|
|
},
|
|
|
|
_addClass: function( element, keys, extra ) {
|
|
return this._toggleClass( element, keys, extra, true );
|
|
},
|
|
|
|
_toggleClass: function( element, keys, extra, add ) {
|
|
add = ( typeof add === "boolean" ) ? add : extra;
|
|
var shift = ( typeof element === "string" || element === null ),
|
|
options = {
|
|
extra: shift ? keys : extra,
|
|
keys: shift ? element : keys,
|
|
element: shift ? this.element : element,
|
|
add: add
|
|
};
|
|
options.element.toggleClass( this._classes( options ), add );
|
|
return this;
|
|
},
|
|
|
|
_on: function( suppressDisabledCheck, element, handlers ) {
|
|
var delegateElement;
|
|
var instance = this;
|
|
|
|
// No suppressDisabledCheck flag, shuffle arguments
|
|
if ( typeof suppressDisabledCheck !== "boolean" ) {
|
|
handlers = element;
|
|
element = suppressDisabledCheck;
|
|
suppressDisabledCheck = false;
|
|
}
|
|
|
|
// No element argument, shuffle and use this.element
|
|
if ( !handlers ) {
|
|
handlers = element;
|
|
element = this.element;
|
|
delegateElement = this.widget();
|
|
} else {
|
|
element = delegateElement = $( element );
|
|
this.bindings = this.bindings.add( element );
|
|
}
|
|
|
|
$.each( handlers, function( event, handler ) {
|
|
function handlerProxy() {
|
|
|
|
// Allow widgets to customize the disabled handling
|
|
// - disabled as an array instead of boolean
|
|
// - disabled class as method for disabling individual parts
|
|
if ( !suppressDisabledCheck &&
|
|
( instance.options.disabled === true ||
|
|
$( this ).hasClass( "ui-state-disabled" ) ) ) {
|
|
return;
|
|
}
|
|
return ( typeof handler === "string" ? instance[ handler ] : handler )
|
|
.apply( instance, arguments );
|
|
}
|
|
|
|
// Copy the guid so direct unbinding works
|
|
if ( typeof handler !== "string" ) {
|
|
handlerProxy.guid = handler.guid =
|
|
handler.guid || handlerProxy.guid || $.guid++;
|
|
}
|
|
|
|
var match = event.match( /^([\w:-]*)\s*(.*)$/ );
|
|
var eventName = match[ 1 ] + instance.eventNamespace;
|
|
var selector = match[ 2 ];
|
|
|
|
if ( selector ) {
|
|
delegateElement.on( eventName, selector, handlerProxy );
|
|
} else {
|
|
element.on( eventName, handlerProxy );
|
|
}
|
|
} );
|
|
},
|
|
|
|
_off: function( element, eventName ) {
|
|
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
|
|
this.eventNamespace;
|
|
element.off( eventName );
|
|
|
|
// Clear the stack to avoid memory leaks (#10056)
|
|
this.bindings = $( this.bindings.not( element ).get() );
|
|
this.focusable = $( this.focusable.not( element ).get() );
|
|
this.hoverable = $( this.hoverable.not( element ).get() );
|
|
},
|
|
|
|
_delay: function( handler, delay ) {
|
|
function handlerProxy() {
|
|
return ( typeof handler === "string" ? instance[ handler ] : handler )
|
|
.apply( instance, arguments );
|
|
}
|
|
var instance = this;
|
|
return setTimeout( handlerProxy, delay || 0 );
|
|
},
|
|
|
|
_hoverable: function( element ) {
|
|
this.hoverable = this.hoverable.add( element );
|
|
this._on( element, {
|
|
mouseenter: function( event ) {
|
|
this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
|
|
},
|
|
mouseleave: function( event ) {
|
|
this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
|
|
}
|
|
} );
|
|
},
|
|
|
|
_focusable: function( element ) {
|
|
this.focusable = this.focusable.add( element );
|
|
this._on( element, {
|
|
focusin: function( event ) {
|
|
this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
|
|
},
|
|
focusout: function( event ) {
|
|
this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
|
|
}
|
|
} );
|
|
},
|
|
|
|
_trigger: function( type, event, data ) {
|
|
var prop, orig;
|
|
var callback = this.options[ type ];
|
|
|
|
data = data || {};
|
|
event = $.Event( event );
|
|
event.type = ( type === this.widgetEventPrefix ?
|
|
type :
|
|
this.widgetEventPrefix + type ).toLowerCase();
|
|
|
|
// The original event may come from any element
|
|
// so we need to reset the target on the new event
|
|
event.target = this.element[ 0 ];
|
|
|
|
// Copy original event properties over to the new event
|
|
orig = event.originalEvent;
|
|
if ( orig ) {
|
|
for ( prop in orig ) {
|
|
if ( !( prop in event ) ) {
|
|
event[ prop ] = orig[ prop ];
|
|
}
|
|
}
|
|
}
|
|
|
|
this.element.trigger( event, data );
|
|
return !( typeof callback === "function" &&
|
|
callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
|
|
event.isDefaultPrevented() );
|
|
}
|
|
};
|
|
|
|
$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
|
|
$.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
|
|
if ( typeof options === "string" ) {
|
|
options = { effect: options };
|
|
}
|
|
|
|
var hasOptions;
|
|
var effectName = !options ?
|
|
method :
|
|
options === true || typeof options === "number" ?
|
|
defaultEffect :
|
|
options.effect || defaultEffect;
|
|
|
|
options = options || {};
|
|
if ( typeof options === "number" ) {
|
|
options = { duration: options };
|
|
} else if ( options === true ) {
|
|
options = {};
|
|
}
|
|
|
|
hasOptions = !$.isEmptyObject( options );
|
|
options.complete = callback;
|
|
|
|
if ( options.delay ) {
|
|
element.delay( options.delay );
|
|
}
|
|
|
|
if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
|
|
element[ method ]( options );
|
|
} else if ( effectName !== method && element[ effectName ] ) {
|
|
element[ effectName ]( options.duration, options.easing, callback );
|
|
} else {
|
|
element.queue( function( next ) {
|
|
$( this )[ method ]();
|
|
if ( callback ) {
|
|
callback.call( element[ 0 ] );
|
|
}
|
|
next();
|
|
} );
|
|
}
|
|
};
|
|
} );
|
|
|
|
var widget = $.widget;
|
|
|
|
|
|
/*!
|
|
* jQuery UI :data 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: :data Selector
|
|
//>>group: Core
|
|
//>>description: Selects elements which have data stored under the specified key.
|
|
//>>docs: http://api.jqueryui.com/data-selector/
|
|
|
|
|
|
var data = $.extend( $.expr.pseudos, {
|
|
data: $.expr.createPseudo ?
|
|
$.expr.createPseudo( function( dataName ) {
|
|
return function( elem ) {
|
|
return !!$.data( elem, dataName );
|
|
};
|
|
} ) :
|
|
|
|
// Support: jQuery <1.8
|
|
function( elem, i, match ) {
|
|
return !!$.data( elem, match[ 3 ] );
|
|
}
|
|
} );
|
|
|
|
/*!
|
|
* jQuery UI Disable Selection 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: disableSelection
|
|
//>>group: Core
|
|
//>>description: Disable selection of text content within the set of matched elements.
|
|
//>>docs: http://api.jqueryui.com/disableSelection/
|
|
|
|
// This file is deprecated
|
|
|
|
var disableSelection = $.fn.extend( {
|
|
disableSelection: ( function() {
|
|
var eventType = "onselectstart" in document.createElement( "div" ) ?
|
|
"selectstart" :
|
|
"mousedown";
|
|
|
|
return function() {
|
|
return this.on( eventType + ".ui-disableSelection", function( event ) {
|
|
event.preventDefault();
|
|
} );
|
|
};
|
|
} )(),
|
|
|
|
enableSelection: function() {
|
|
return this.off( ".ui-disableSelection" );
|
|
}
|
|
} );
|
|
|
|
|
|
|
|
// Support: IE8 Only
|
|
// IE8 does not support the form attribute and when it is supplied. It overwrites the form prop
|
|
// with a string, so we need to find the proper form.
|
|
var form = $.fn._form = function() {
|
|
return typeof this[ 0 ].form === "string" ? this.closest( "form" ) : $( this[ 0 ].form );
|
|
};
|
|
|
|
|
|
/*!
|
|
* jQuery UI Form Reset Mixin 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Form Reset Mixin
|
|
//>>group: Core
|
|
//>>description: Refresh input widgets when their form is reset
|
|
//>>docs: http://api.jqueryui.com/form-reset-mixin/
|
|
|
|
|
|
var formResetMixin = $.ui.formResetMixin = {
|
|
_formResetHandler: function() {
|
|
var form = $( this );
|
|
|
|
// Wait for the form reset to actually happen before refreshing
|
|
setTimeout( function() {
|
|
var instances = form.data( "ui-form-reset-instances" );
|
|
$.each( instances, function() {
|
|
this.refresh();
|
|
} );
|
|
} );
|
|
},
|
|
|
|
_bindFormResetHandler: function() {
|
|
this.form = this.element._form();
|
|
if ( !this.form.length ) {
|
|
return;
|
|
}
|
|
|
|
var instances = this.form.data( "ui-form-reset-instances" ) || [];
|
|
if ( !instances.length ) {
|
|
|
|
// We don't use _on() here because we use a single event handler per form
|
|
this.form.on( "reset.ui-form-reset", this._formResetHandler );
|
|
}
|
|
instances.push( this );
|
|
this.form.data( "ui-form-reset-instances", instances );
|
|
},
|
|
|
|
_unbindFormResetHandler: function() {
|
|
if ( !this.form.length ) {
|
|
return;
|
|
}
|
|
|
|
var instances = this.form.data( "ui-form-reset-instances" );
|
|
instances.splice( $.inArray( this, instances ), 1 );
|
|
if ( instances.length ) {
|
|
this.form.data( "ui-form-reset-instances", instances );
|
|
} else {
|
|
this.form
|
|
.removeData( "ui-form-reset-instances" )
|
|
.off( "reset.ui-form-reset" );
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
/*!
|
|
* jQuery UI Support for jQuery core 1.8.x and newer 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*
|
|
*/
|
|
|
|
//>>label: jQuery 1.8+ Support
|
|
//>>group: Core
|
|
//>>description: Support version 1.8.x and newer of jQuery core
|
|
|
|
|
|
// Support: jQuery 1.9.x or older
|
|
// $.expr[ ":" ] is deprecated.
|
|
if ( !$.expr.pseudos ) {
|
|
$.expr.pseudos = $.expr[ ":" ];
|
|
}
|
|
|
|
// Support: jQuery 1.11.x or older
|
|
// $.unique has been renamed to $.uniqueSort
|
|
if ( !$.uniqueSort ) {
|
|
$.uniqueSort = $.unique;
|
|
}
|
|
|
|
// Support: jQuery 2.2.x or older.
|
|
// This method has been defined in jQuery 3.0.0.
|
|
// Code from https://github.com/jquery/jquery/blob/e539bac79e666bba95bba86d690b4e609dca2286/src/selector/escapeSelector.js
|
|
if ( !$.escapeSelector ) {
|
|
|
|
// CSS string/identifier serialization
|
|
// https://drafts.csswg.org/cssom/#common-serializing-idioms
|
|
var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;
|
|
|
|
var fcssescape = function( ch, asCodePoint ) {
|
|
if ( asCodePoint ) {
|
|
|
|
// U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
|
|
if ( ch === "\0" ) {
|
|
return "\uFFFD";
|
|
}
|
|
|
|
// Control characters and (dependent upon position) numbers get escaped as code points
|
|
return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " ";
|
|
}
|
|
|
|
// Other potentially-special ASCII characters get backslash-escaped
|
|
return "\\" + ch;
|
|
};
|
|
|
|
$.escapeSelector = function( sel ) {
|
|
return ( sel + "" ).replace( rcssescape, fcssescape );
|
|
};
|
|
}
|
|
|
|
// Support: jQuery 3.4.x or older
|
|
// These methods have been defined in jQuery 3.5.0.
|
|
if ( !$.fn.even || !$.fn.odd ) {
|
|
$.fn.extend( {
|
|
even: function() {
|
|
return this.filter( function( i ) {
|
|
return i % 2 === 0;
|
|
} );
|
|
},
|
|
odd: function() {
|
|
return this.filter( function( i ) {
|
|
return i % 2 === 1;
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
|
|
;
|
|
/*!
|
|
* jQuery UI Keycode 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Keycode
|
|
//>>group: Core
|
|
//>>description: Provide keycodes as keynames
|
|
//>>docs: http://api.jqueryui.com/jQuery.ui.keyCode/
|
|
|
|
|
|
var keycode = $.ui.keyCode = {
|
|
BACKSPACE: 8,
|
|
COMMA: 188,
|
|
DELETE: 46,
|
|
DOWN: 40,
|
|
END: 35,
|
|
ENTER: 13,
|
|
ESCAPE: 27,
|
|
HOME: 36,
|
|
LEFT: 37,
|
|
PAGE_DOWN: 34,
|
|
PAGE_UP: 33,
|
|
PERIOD: 190,
|
|
RIGHT: 39,
|
|
SPACE: 32,
|
|
TAB: 9,
|
|
UP: 38
|
|
};
|
|
|
|
|
|
/*!
|
|
* jQuery UI Labels 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: labels
|
|
//>>group: Core
|
|
//>>description: Find all the labels associated with a given input
|
|
//>>docs: http://api.jqueryui.com/labels/
|
|
|
|
|
|
var labels = $.fn.labels = function() {
|
|
var ancestor, selector, id, labels, ancestors;
|
|
|
|
if ( !this.length ) {
|
|
return this.pushStack( [] );
|
|
}
|
|
|
|
// Check control.labels first
|
|
if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
|
|
return this.pushStack( this[ 0 ].labels );
|
|
}
|
|
|
|
// Support: IE <= 11, FF <= 37, Android <= 2.3 only
|
|
// Above browsers do not support control.labels. Everything below is to support them
|
|
// as well as document fragments. control.labels does not work on document fragments
|
|
labels = this.eq( 0 ).parents( "label" );
|
|
|
|
// Look for the label based on the id
|
|
id = this.attr( "id" );
|
|
if ( id ) {
|
|
|
|
// We don't search against the document in case the element
|
|
// is disconnected from the DOM
|
|
ancestor = this.eq( 0 ).parents().last();
|
|
|
|
// Get a full set of top level ancestors
|
|
ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );
|
|
|
|
// Create a selector for the label based on the id
|
|
selector = "label[for='" + $.escapeSelector( id ) + "']";
|
|
|
|
labels = labels.add( ancestors.find( selector ).addBack( selector ) );
|
|
|
|
}
|
|
|
|
// Return whatever we have found for labels
|
|
return this.pushStack( labels );
|
|
};
|
|
|
|
|
|
/*!
|
|
* jQuery UI Scroll Parent 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: scrollParent
|
|
//>>group: Core
|
|
//>>description: Get the closest ancestor element that is scrollable.
|
|
//>>docs: http://api.jqueryui.com/scrollParent/
|
|
|
|
|
|
var scrollParent = $.fn.scrollParent = function( includeHidden ) {
|
|
var position = this.css( "position" ),
|
|
excludeStaticParent = position === "absolute",
|
|
overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
|
|
scrollParent = this.parents().filter( function() {
|
|
var parent = $( this );
|
|
if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
|
|
return false;
|
|
}
|
|
return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) +
|
|
parent.css( "overflow-x" ) );
|
|
} ).eq( 0 );
|
|
|
|
return position === "fixed" || !scrollParent.length ?
|
|
$( this[ 0 ].ownerDocument || document ) :
|
|
scrollParent;
|
|
};
|
|
|
|
|
|
|
|
// This file is deprecated
|
|
var ie = $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
|
|
|
|
/*!
|
|
* jQuery UI Mouse 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Mouse
|
|
//>>group: Widgets
|
|
//>>description: Abstracts mouse-based interactions to assist in creating certain widgets.
|
|
//>>docs: http://api.jqueryui.com/mouse/
|
|
|
|
|
|
var mouseHandled = false;
|
|
$( document ).on( "mouseup", function() {
|
|
mouseHandled = false;
|
|
} );
|
|
|
|
var widgetsMouse = $.widget( "ui.mouse", {
|
|
version: "1.13.1",
|
|
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)
|
|
if ( 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 ) {
|
|
|
|
// Support: Safari <=8 - 9
|
|
// Safari sets which to 0 if you press any of the following keys
|
|
// during a drag (#14461)
|
|
if ( event.originalEvent.altKey || event.originalEvent.ctrlKey ||
|
|
event.originalEvent.metaKey || event.originalEvent.shiftKey ) {
|
|
this.ignoreMissingWhich = true;
|
|
} else if ( !this.ignoreMissingWhich ) {
|
|
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 );
|
|
if ( this._mouseStarted ) {
|
|
this._mouseDrag( event );
|
|
} else {
|
|
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 );
|
|
}
|
|
|
|
if ( this._mouseDelayTimer ) {
|
|
clearTimeout( this._mouseDelayTimer );
|
|
delete this._mouseDelayTimer;
|
|
}
|
|
|
|
this.ignoreMissingWhich = false;
|
|
mouseHandled = false;
|
|
event.preventDefault();
|
|
},
|
|
|
|
_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;
|
|
}
|
|
} );
|
|
|
|
|
|
|
|
// $.ui.plugin is deprecated. Use $.widget() extensions instead.
|
|
var plugin = $.ui.plugin = {
|
|
add: function( module, option, set ) {
|
|
var i,
|
|
proto = $.ui[ module ].prototype;
|
|
for ( i in set ) {
|
|
proto.plugins[ i ] = proto.plugins[ i ] || [];
|
|
proto.plugins[ i ].push( [ option, set[ i ] ] );
|
|
}
|
|
},
|
|
call: function( instance, name, args, allowDisconnected ) {
|
|
var i,
|
|
set = instance.plugins[ name ];
|
|
|
|
if ( !set ) {
|
|
return;
|
|
}
|
|
|
|
if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode ||
|
|
instance.element[ 0 ].parentNode.nodeType === 11 ) ) {
|
|
return;
|
|
}
|
|
|
|
for ( i = 0; i < set.length; i++ ) {
|
|
if ( instance.options[ set[ i ][ 0 ] ] ) {
|
|
set[ i ][ 1 ].apply( instance.element, args );
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
|
|
var safeActiveElement = $.ui.safeActiveElement = function( document ) {
|
|
var activeElement;
|
|
|
|
// Support: IE 9 only
|
|
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
|
|
try {
|
|
activeElement = document.activeElement;
|
|
} catch ( error ) {
|
|
activeElement = document.body;
|
|
}
|
|
|
|
// Support: IE 9 - 11 only
|
|
// IE may return null instead of an element
|
|
// Interestingly, this only seems to occur when NOT in an iframe
|
|
if ( !activeElement ) {
|
|
activeElement = document.body;
|
|
}
|
|
|
|
// Support: IE 11 only
|
|
// IE11 returns a seemingly empty object in some cases when accessing
|
|
// document.activeElement from an <iframe>
|
|
if ( !activeElement.nodeName ) {
|
|
activeElement = document.body;
|
|
}
|
|
|
|
return activeElement;
|
|
};
|
|
|
|
|
|
|
|
var safeBlur = $.ui.safeBlur = function( element ) {
|
|
|
|
// Support: IE9 - 10 only
|
|
// If the <body> is blurred, IE will switch windows, see #9420
|
|
if ( element && element.nodeName.toLowerCase() !== "body" ) {
|
|
$( element ).trigger( "blur" );
|
|
}
|
|
};
|
|
|
|
|
|
/*!
|
|
* jQuery UI Draggable 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Draggable
|
|
//>>group: Interactions
|
|
//>>description: Enables dragging functionality for any element.
|
|
//>>docs: http://api.jqueryui.com/draggable/
|
|
//>>demos: http://jqueryui.com/draggable/
|
|
//>>css.structure: ../../themes/base/draggable.css
|
|
|
|
|
|
$.widget( "ui.draggable", $.ui.mouse, {
|
|
version: "1.13.1",
|
|
widgetEventPrefix: "drag",
|
|
options: {
|
|
addClasses: true,
|
|
appendTo: "parent",
|
|
axis: false,
|
|
connectToSortable: false,
|
|
containment: false,
|
|
cursor: "auto",
|
|
cursorAt: false,
|
|
grid: false,
|
|
handle: false,
|
|
helper: "original",
|
|
iframeFix: false,
|
|
opacity: false,
|
|
refreshPositions: false,
|
|
revert: false,
|
|
revertDuration: 500,
|
|
scope: "default",
|
|
scroll: true,
|
|
scrollSensitivity: 20,
|
|
scrollSpeed: 20,
|
|
snap: false,
|
|
snapMode: "both",
|
|
snapTolerance: 20,
|
|
stack: false,
|
|
zIndex: false,
|
|
|
|
// Callbacks
|
|
drag: null,
|
|
start: null,
|
|
stop: null
|
|
},
|
|
_create: function() {
|
|
|
|
if ( this.options.helper === "original" ) {
|
|
this._setPositionRelative();
|
|
}
|
|
if ( this.options.addClasses ) {
|
|
this._addClass( "ui-draggable" );
|
|
}
|
|
this._setHandleClassName();
|
|
|
|
this._mouseInit();
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
this._super( key, value );
|
|
if ( key === "handle" ) {
|
|
this._removeHandleClassName();
|
|
this._setHandleClassName();
|
|
}
|
|
},
|
|
|
|
_destroy: function() {
|
|
if ( ( this.helper || this.element ).is( ".ui-draggable-dragging" ) ) {
|
|
this.destroyOnClear = true;
|
|
return;
|
|
}
|
|
this._removeHandleClassName();
|
|
this._mouseDestroy();
|
|
},
|
|
|
|
_mouseCapture: function( event ) {
|
|
var o = this.options;
|
|
|
|
// Among others, prevent a drag on a resizable-handle
|
|
if ( this.helper || o.disabled ||
|
|
$( event.target ).closest( ".ui-resizable-handle" ).length > 0 ) {
|
|
return false;
|
|
}
|
|
|
|
//Quit if we're not on a valid handle
|
|
this.handle = this._getHandle( event );
|
|
if ( !this.handle ) {
|
|
return false;
|
|
}
|
|
|
|
this._blurActiveElement( event );
|
|
|
|
this._blockFrames( o.iframeFix === true ? "iframe" : o.iframeFix );
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
_blockFrames: function( selector ) {
|
|
this.iframeBlocks = this.document.find( selector ).map( function() {
|
|
var iframe = $( this );
|
|
|
|
return $( "<div>" )
|
|
.css( "position", "absolute" )
|
|
.appendTo( iframe.parent() )
|
|
.outerWidth( iframe.outerWidth() )
|
|
.outerHeight( iframe.outerHeight() )
|
|
.offset( iframe.offset() )[ 0 ];
|
|
} );
|
|
},
|
|
|
|
_unblockFrames: function() {
|
|
if ( this.iframeBlocks ) {
|
|
this.iframeBlocks.remove();
|
|
delete this.iframeBlocks;
|
|
}
|
|
},
|
|
|
|
_blurActiveElement: function( event ) {
|
|
var activeElement = $.ui.safeActiveElement( this.document[ 0 ] ),
|
|
target = $( event.target );
|
|
|
|
// Don't blur if the event occurred on an element that is within
|
|
// the currently focused element
|
|
// See #10527, #12472
|
|
if ( target.closest( activeElement ).length ) {
|
|
return;
|
|
}
|
|
|
|
// Blur any element that currently has focus, see #4261
|
|
$.ui.safeBlur( activeElement );
|
|
},
|
|
|
|
_mouseStart: function( event ) {
|
|
|
|
var o = this.options;
|
|
|
|
//Create and append the visible helper
|
|
this.helper = this._createHelper( event );
|
|
|
|
this._addClass( this.helper, "ui-draggable-dragging" );
|
|
|
|
//Cache the helper size
|
|
this._cacheHelperProportions();
|
|
|
|
//If ddmanager is used for droppables, set the global draggable
|
|
if ( $.ui.ddmanager ) {
|
|
$.ui.ddmanager.current = this;
|
|
}
|
|
|
|
/*
|
|
* - Position generation -
|
|
* This block generates everything position related - it's the core of draggables.
|
|
*/
|
|
|
|
//Cache the margins of the original element
|
|
this._cacheMargins();
|
|
|
|
//Store the helper's css position
|
|
this.cssPosition = this.helper.css( "position" );
|
|
this.scrollParent = this.helper.scrollParent( true );
|
|
this.offsetParent = this.helper.offsetParent();
|
|
this.hasFixedAncestor = this.helper.parents().filter( function() {
|
|
return $( this ).css( "position" ) === "fixed";
|
|
} ).length > 0;
|
|
|
|
//The element's absolute position on the page minus margins
|
|
this.positionAbs = this.element.offset();
|
|
this._refreshOffsets( event );
|
|
|
|
//Generate the original position
|
|
this.originalPosition = this.position = this._generatePosition( event, false );
|
|
this.originalPageX = event.pageX;
|
|
this.originalPageY = event.pageY;
|
|
|
|
//Adjust the mouse offset relative to the helper if "cursorAt" is supplied
|
|
if ( o.cursorAt ) {
|
|
this._adjustOffsetFromHelper( o.cursorAt );
|
|
}
|
|
|
|
//Set a containment if given in the options
|
|
this._setContainment();
|
|
|
|
//Trigger event + callbacks
|
|
if ( this._trigger( "start", event ) === false ) {
|
|
this._clear();
|
|
return false;
|
|
}
|
|
|
|
//Recache the helper size
|
|
this._cacheHelperProportions();
|
|
|
|
//Prepare the droppable offsets
|
|
if ( $.ui.ddmanager && !o.dropBehaviour ) {
|
|
$.ui.ddmanager.prepareOffsets( this, event );
|
|
}
|
|
|
|
// Execute the drag once - this causes the helper not to be visible before getting its
|
|
// correct position
|
|
this._mouseDrag( event, true );
|
|
|
|
// If the ddmanager is used for droppables, inform the manager that dragging has started
|
|
// (see #5003)
|
|
if ( $.ui.ddmanager ) {
|
|
$.ui.ddmanager.dragStart( this, event );
|
|
}
|
|
|
|
return true;
|
|
},
|
|
|
|
_refreshOffsets: function( event ) {
|
|
this.offset = {
|
|
top: this.positionAbs.top - this.margins.top,
|
|
left: this.positionAbs.left - this.margins.left,
|
|
scroll: false,
|
|
parent: this._getParentOffset(),
|
|
relative: this._getRelativeOffset()
|
|
};
|
|
|
|
this.offset.click = {
|
|
left: event.pageX - this.offset.left,
|
|
top: event.pageY - this.offset.top
|
|
};
|
|
},
|
|
|
|
_mouseDrag: function( event, noPropagation ) {
|
|
|
|
// reset any necessary cached properties (see #5009)
|
|
if ( this.hasFixedAncestor ) {
|
|
this.offset.parent = this._getParentOffset();
|
|
}
|
|
|
|
//Compute the helpers position
|
|
this.position = this._generatePosition( event, true );
|
|
this.positionAbs = this._convertPositionTo( "absolute" );
|
|
|
|
//Call plugins and callbacks and use the resulting position if something is returned
|
|
if ( !noPropagation ) {
|
|
var ui = this._uiHash();
|
|
if ( this._trigger( "drag", event, ui ) === false ) {
|
|
this._mouseUp( new $.Event( "mouseup", event ) );
|
|
return false;
|
|
}
|
|
this.position = ui.position;
|
|
}
|
|
|
|
this.helper[ 0 ].style.left = this.position.left + "px";
|
|
this.helper[ 0 ].style.top = this.position.top + "px";
|
|
|
|
if ( $.ui.ddmanager ) {
|
|
$.ui.ddmanager.drag( this, event );
|
|
}
|
|
|
|
return false;
|
|
},
|
|
|
|
_mouseStop: function( event ) {
|
|
|
|
//If we are using droppables, inform the manager about the drop
|
|
var that = this,
|
|
dropped = false;
|
|
if ( $.ui.ddmanager && !this.options.dropBehaviour ) {
|
|
dropped = $.ui.ddmanager.drop( this, event );
|
|
}
|
|
|
|
//if a drop comes from outside (a sortable)
|
|
if ( this.dropped ) {
|
|
dropped = this.dropped;
|
|
this.dropped = false;
|
|
}
|
|
|
|
if ( ( this.options.revert === "invalid" && !dropped ) ||
|
|
( this.options.revert === "valid" && dropped ) ||
|
|
this.options.revert === true || ( typeof this.options.revert === "function" &&
|
|
this.options.revert.call( this.element, dropped ) )
|
|
) {
|
|
$( this.helper ).animate(
|
|
this.originalPosition,
|
|
parseInt( this.options.revertDuration, 10 ),
|
|
function() {
|
|
if ( that._trigger( "stop", event ) !== false ) {
|
|
that._clear();
|
|
}
|
|
}
|
|
);
|
|
} else {
|
|
if ( this._trigger( "stop", event ) !== false ) {
|
|
this._clear();
|
|
}
|
|
}
|
|
|
|
return false;
|
|
},
|
|
|
|
_mouseUp: function( event ) {
|
|
this._unblockFrames();
|
|
|
|
// If the ddmanager is used for droppables, inform the manager that dragging has stopped
|
|
// (see #5003)
|
|
if ( $.ui.ddmanager ) {
|
|
$.ui.ddmanager.dragStop( this, event );
|
|
}
|
|
|
|
// Only need to focus if the event occurred on the draggable itself, see #10527
|
|
if ( this.handleElement.is( event.target ) ) {
|
|
|
|
// The interaction is over; whether or not the click resulted in a drag,
|
|
// focus the element
|
|
this.element.trigger( "focus" );
|
|
}
|
|
|
|
return $.ui.mouse.prototype._mouseUp.call( this, event );
|
|
},
|
|
|
|
cancel: function() {
|
|
|
|
if ( this.helper.is( ".ui-draggable-dragging" ) ) {
|
|
this._mouseUp( new $.Event( "mouseup", { target: this.element[ 0 ] } ) );
|
|
} else {
|
|
this._clear();
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
_getHandle: function( event ) {
|
|
return this.options.handle ?
|
|
!!$( event.target ).closest( this.element.find( this.options.handle ) ).length :
|
|
true;
|
|
},
|
|
|
|
_setHandleClassName: function() {
|
|
this.handleElement = this.options.handle ?
|
|
this.element.find( this.options.handle ) : this.element;
|
|
this._addClass( this.handleElement, "ui-draggable-handle" );
|
|
},
|
|
|
|
_removeHandleClassName: function() {
|
|
this._removeClass( this.handleElement, "ui-draggable-handle" );
|
|
},
|
|
|
|
_createHelper: function( event ) {
|
|
|
|
var o = this.options,
|
|
helperIsFunction = typeof o.helper === "function",
|
|
helper = helperIsFunction ?
|
|
$( o.helper.apply( this.element[ 0 ], [ event ] ) ) :
|
|
( o.helper === "clone" ?
|
|
this.element.clone().removeAttr( "id" ) :
|
|
this.element );
|
|
|
|
if ( !helper.parents( "body" ).length ) {
|
|
helper.appendTo( ( o.appendTo === "parent" ?
|
|
this.element[ 0 ].parentNode :
|
|
o.appendTo ) );
|
|
}
|
|
|
|
// Http://bugs.jqueryui.com/ticket/9446
|
|
// a helper function can return the original element
|
|
// which wouldn't have been set to relative in _create
|
|
if ( helperIsFunction && helper[ 0 ] === this.element[ 0 ] ) {
|
|
this._setPositionRelative();
|
|
}
|
|
|
|
if ( helper[ 0 ] !== this.element[ 0 ] &&
|
|
!( /(fixed|absolute)/ ).test( helper.css( "position" ) ) ) {
|
|
helper.css( "position", "absolute" );
|
|
}
|
|
|
|
return helper;
|
|
|
|
},
|
|
|
|
_setPositionRelative: function() {
|
|
if ( !( /^(?:r|a|f)/ ).test( this.element.css( "position" ) ) ) {
|
|
this.element[ 0 ].style.position = "relative";
|
|
}
|
|
},
|
|
|
|
_adjustOffsetFromHelper: function( obj ) {
|
|
if ( typeof obj === "string" ) {
|
|
obj = obj.split( " " );
|
|
}
|
|
if ( Array.isArray( obj ) ) {
|
|
obj = { left: +obj[ 0 ], top: +obj[ 1 ] || 0 };
|
|
}
|
|
if ( "left" in obj ) {
|
|
this.offset.click.left = obj.left + this.margins.left;
|
|
}
|
|
if ( "right" in obj ) {
|
|
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
|
|
}
|
|
if ( "top" in obj ) {
|
|
this.offset.click.top = obj.top + this.margins.top;
|
|
}
|
|
if ( "bottom" in obj ) {
|
|
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
|
|
}
|
|
},
|
|
|
|
_isRootNode: function( element ) {
|
|
return ( /(html|body)/i ).test( element.tagName ) || element === this.document[ 0 ];
|
|
},
|
|
|
|
_getParentOffset: function() {
|
|
|
|
//Get the offsetParent and cache its position
|
|
var po = this.offsetParent.offset(),
|
|
document = this.document[ 0 ];
|
|
|
|
// This is a special case where we need to modify a offset calculated on start, since the
|
|
// following happened:
|
|
// 1. The position of the helper is absolute, so it's position is calculated based on the
|
|
// next positioned parent
|
|
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't
|
|
// the document, which means that the scroll is included in the initial calculation of the
|
|
// offset of the parent, and never recalculated upon drag
|
|
if ( this.cssPosition === "absolute" && this.scrollParent[ 0 ] !== document &&
|
|
$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) {
|
|
po.left += this.scrollParent.scrollLeft();
|
|
po.top += this.scrollParent.scrollTop();
|
|
}
|
|
|
|
if ( this._isRootNode( this.offsetParent[ 0 ] ) ) {
|
|
po = { top: 0, left: 0 };
|
|
}
|
|
|
|
return {
|
|
top: po.top + ( parseInt( this.offsetParent.css( "borderTopWidth" ), 10 ) || 0 ),
|
|
left: po.left + ( parseInt( this.offsetParent.css( "borderLeftWidth" ), 10 ) || 0 )
|
|
};
|
|
|
|
},
|
|
|
|
_getRelativeOffset: function() {
|
|
if ( this.cssPosition !== "relative" ) {
|
|
return { top: 0, left: 0 };
|
|
}
|
|
|
|
var p = this.element.position(),
|
|
scrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] );
|
|
|
|
return {
|
|
top: p.top - ( parseInt( this.helper.css( "top" ), 10 ) || 0 ) +
|
|
( !scrollIsRootNode ? this.scrollParent.scrollTop() : 0 ),
|
|
left: p.left - ( parseInt( this.helper.css( "left" ), 10 ) || 0 ) +
|
|
( !scrollIsRootNode ? this.scrollParent.scrollLeft() : 0 )
|
|
};
|
|
|
|
},
|
|
|
|
_cacheMargins: function() {
|
|
this.margins = {
|
|
left: ( parseInt( this.element.css( "marginLeft" ), 10 ) || 0 ),
|
|
top: ( parseInt( this.element.css( "marginTop" ), 10 ) || 0 ),
|
|
right: ( parseInt( this.element.css( "marginRight" ), 10 ) || 0 ),
|
|
bottom: ( parseInt( this.element.css( "marginBottom" ), 10 ) || 0 )
|
|
};
|
|
},
|
|
|
|
_cacheHelperProportions: function() {
|
|
this.helperProportions = {
|
|
width: this.helper.outerWidth(),
|
|
height: this.helper.outerHeight()
|
|
};
|
|
},
|
|
|
|
_setContainment: function() {
|
|
|
|
var isUserScrollable, c, ce,
|
|
o = this.options,
|
|
document = this.document[ 0 ];
|
|
|
|
this.relativeContainer = null;
|
|
|
|
if ( !o.containment ) {
|
|
this.containment = null;
|
|
return;
|
|
}
|
|
|
|
if ( o.containment === "window" ) {
|
|
this.containment = [
|
|
$( window ).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
|
|
$( window ).scrollTop() - this.offset.relative.top - this.offset.parent.top,
|
|
$( window ).scrollLeft() + $( window ).width() -
|
|
this.helperProportions.width - this.margins.left,
|
|
$( window ).scrollTop() +
|
|
( $( window ).height() || document.body.parentNode.scrollHeight ) -
|
|
this.helperProportions.height - this.margins.top
|
|
];
|
|
return;
|
|
}
|
|
|
|
if ( o.containment === "document" ) {
|
|
this.containment = [
|
|
0,
|
|
0,
|
|
$( document ).width() - this.helperProportions.width - this.margins.left,
|
|
( $( document ).height() || document.body.parentNode.scrollHeight ) -
|
|
this.helperProportions.height - this.margins.top
|
|
];
|
|
return;
|
|
}
|
|
|
|
if ( o.containment.constructor === Array ) {
|
|
this.containment = o.containment;
|
|
return;
|
|
}
|
|
|
|
if ( o.containment === "parent" ) {
|
|
o.containment = this.helper[ 0 ].parentNode;
|
|
}
|
|
|
|
c = $( o.containment );
|
|
ce = c[ 0 ];
|
|
|
|
if ( !ce ) {
|
|
return;
|
|
}
|
|
|
|
isUserScrollable = /(scroll|auto)/.test( c.css( "overflow" ) );
|
|
|
|
this.containment = [
|
|
( parseInt( c.css( "borderLeftWidth" ), 10 ) || 0 ) +
|
|
( parseInt( c.css( "paddingLeft" ), 10 ) || 0 ),
|
|
( parseInt( c.css( "borderTopWidth" ), 10 ) || 0 ) +
|
|
( parseInt( c.css( "paddingTop" ), 10 ) || 0 ),
|
|
( isUserScrollable ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) -
|
|
( parseInt( c.css( "borderRightWidth" ), 10 ) || 0 ) -
|
|
( parseInt( c.css( "paddingRight" ), 10 ) || 0 ) -
|
|
this.helperProportions.width -
|
|
this.margins.left -
|
|
this.margins.right,
|
|
( isUserScrollable ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) -
|
|
( parseInt( c.css( "borderBottomWidth" ), 10 ) || 0 ) -
|
|
( parseInt( c.css( "paddingBottom" ), 10 ) || 0 ) -
|
|
this.helperProportions.height -
|
|
this.margins.top -
|
|
this.margins.bottom
|
|
];
|
|
this.relativeContainer = c;
|
|
},
|
|
|
|
_convertPositionTo: function( d, pos ) {
|
|
|
|
if ( !pos ) {
|
|
pos = this.position;
|
|
}
|
|
|
|
var mod = d === "absolute" ? 1 : -1,
|
|
scrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] );
|
|
|
|
return {
|
|
top: (
|
|
|
|
// The absolute mouse position
|
|
pos.top +
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.top * mod +
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.top * mod -
|
|
( ( this.cssPosition === "fixed" ?
|
|
-this.offset.scroll.top :
|
|
( scrollIsRootNode ? 0 : this.offset.scroll.top ) ) * mod )
|
|
),
|
|
left: (
|
|
|
|
// The absolute mouse position
|
|
pos.left +
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.left * mod +
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.left * mod -
|
|
( ( this.cssPosition === "fixed" ?
|
|
-this.offset.scroll.left :
|
|
( scrollIsRootNode ? 0 : this.offset.scroll.left ) ) * mod )
|
|
)
|
|
};
|
|
|
|
},
|
|
|
|
_generatePosition: function( event, constrainPosition ) {
|
|
|
|
var containment, co, top, left,
|
|
o = this.options,
|
|
scrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] ),
|
|
pageX = event.pageX,
|
|
pageY = event.pageY;
|
|
|
|
// Cache the scroll
|
|
if ( !scrollIsRootNode || !this.offset.scroll ) {
|
|
this.offset.scroll = {
|
|
top: this.scrollParent.scrollTop(),
|
|
left: this.scrollParent.scrollLeft()
|
|
};
|
|
}
|
|
|
|
/*
|
|
* - Position constraining -
|
|
* Constrain the position to a mix of grid, containment.
|
|
*/
|
|
|
|
// If we are not dragging yet, we won't check for options
|
|
if ( constrainPosition ) {
|
|
if ( this.containment ) {
|
|
if ( this.relativeContainer ) {
|
|
co = this.relativeContainer.offset();
|
|
containment = [
|
|
this.containment[ 0 ] + co.left,
|
|
this.containment[ 1 ] + co.top,
|
|
this.containment[ 2 ] + co.left,
|
|
this.containment[ 3 ] + co.top
|
|
];
|
|
} else {
|
|
containment = this.containment;
|
|
}
|
|
|
|
if ( event.pageX - this.offset.click.left < containment[ 0 ] ) {
|
|
pageX = containment[ 0 ] + this.offset.click.left;
|
|
}
|
|
if ( event.pageY - this.offset.click.top < containment[ 1 ] ) {
|
|
pageY = containment[ 1 ] + this.offset.click.top;
|
|
}
|
|
if ( event.pageX - this.offset.click.left > containment[ 2 ] ) {
|
|
pageX = containment[ 2 ] + this.offset.click.left;
|
|
}
|
|
if ( event.pageY - this.offset.click.top > containment[ 3 ] ) {
|
|
pageY = containment[ 3 ] + this.offset.click.top;
|
|
}
|
|
}
|
|
|
|
if ( o.grid ) {
|
|
|
|
//Check for grid elements set to 0 to prevent divide by 0 error causing invalid
|
|
// argument errors in IE (see ticket #6950)
|
|
top = o.grid[ 1 ] ? this.originalPageY + Math.round( ( pageY -
|
|
this.originalPageY ) / o.grid[ 1 ] ) * o.grid[ 1 ] : this.originalPageY;
|
|
pageY = containment ? ( ( top - this.offset.click.top >= containment[ 1 ] ||
|
|
top - this.offset.click.top > containment[ 3 ] ) ?
|
|
top :
|
|
( ( top - this.offset.click.top >= containment[ 1 ] ) ?
|
|
top - o.grid[ 1 ] : top + o.grid[ 1 ] ) ) : top;
|
|
|
|
left = o.grid[ 0 ] ? this.originalPageX +
|
|
Math.round( ( pageX - this.originalPageX ) / o.grid[ 0 ] ) * o.grid[ 0 ] :
|
|
this.originalPageX;
|
|
pageX = containment ? ( ( left - this.offset.click.left >= containment[ 0 ] ||
|
|
left - this.offset.click.left > containment[ 2 ] ) ?
|
|
left :
|
|
( ( left - this.offset.click.left >= containment[ 0 ] ) ?
|
|
left - o.grid[ 0 ] : left + o.grid[ 0 ] ) ) : left;
|
|
}
|
|
|
|
if ( o.axis === "y" ) {
|
|
pageX = this.originalPageX;
|
|
}
|
|
|
|
if ( o.axis === "x" ) {
|
|
pageY = this.originalPageY;
|
|
}
|
|
}
|
|
|
|
return {
|
|
top: (
|
|
|
|
// The absolute mouse position
|
|
pageY -
|
|
|
|
// Click offset (relative to the element)
|
|
this.offset.click.top -
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.top -
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.top +
|
|
( this.cssPosition === "fixed" ?
|
|
-this.offset.scroll.top :
|
|
( scrollIsRootNode ? 0 : this.offset.scroll.top ) )
|
|
),
|
|
left: (
|
|
|
|
// The absolute mouse position
|
|
pageX -
|
|
|
|
// Click offset (relative to the element)
|
|
this.offset.click.left -
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.left -
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.left +
|
|
( this.cssPosition === "fixed" ?
|
|
-this.offset.scroll.left :
|
|
( scrollIsRootNode ? 0 : this.offset.scroll.left ) )
|
|
)
|
|
};
|
|
|
|
},
|
|
|
|
_clear: function() {
|
|
this._removeClass( this.helper, "ui-draggable-dragging" );
|
|
if ( this.helper[ 0 ] !== this.element[ 0 ] && !this.cancelHelperRemoval ) {
|
|
this.helper.remove();
|
|
}
|
|
this.helper = null;
|
|
this.cancelHelperRemoval = false;
|
|
if ( this.destroyOnClear ) {
|
|
this.destroy();
|
|
}
|
|
},
|
|
|
|
// From now on bulk stuff - mainly helpers
|
|
|
|
_trigger: function( type, event, ui ) {
|
|
ui = ui || this._uiHash();
|
|
$.ui.plugin.call( this, type, [ event, ui, this ], true );
|
|
|
|
// Absolute position and offset (see #6884 ) have to be recalculated after plugins
|
|
if ( /^(drag|start|stop)/.test( type ) ) {
|
|
this.positionAbs = this._convertPositionTo( "absolute" );
|
|
ui.offset = this.positionAbs;
|
|
}
|
|
return $.Widget.prototype._trigger.call( this, type, event, ui );
|
|
},
|
|
|
|
plugins: {},
|
|
|
|
_uiHash: function() {
|
|
return {
|
|
helper: this.helper,
|
|
position: this.position,
|
|
originalPosition: this.originalPosition,
|
|
offset: this.positionAbs
|
|
};
|
|
}
|
|
|
|
} );
|
|
|
|
$.ui.plugin.add( "draggable", "connectToSortable", {
|
|
start: function( event, ui, draggable ) {
|
|
var uiSortable = $.extend( {}, ui, {
|
|
item: draggable.element
|
|
} );
|
|
|
|
draggable.sortables = [];
|
|
$( draggable.options.connectToSortable ).each( function() {
|
|
var sortable = $( this ).sortable( "instance" );
|
|
|
|
if ( sortable && !sortable.options.disabled ) {
|
|
draggable.sortables.push( sortable );
|
|
|
|
// RefreshPositions is called at drag start to refresh the containerCache
|
|
// which is used in drag. This ensures it's initialized and synchronized
|
|
// with any changes that might have happened on the page since initialization.
|
|
sortable.refreshPositions();
|
|
sortable._trigger( "activate", event, uiSortable );
|
|
}
|
|
} );
|
|
},
|
|
stop: function( event, ui, draggable ) {
|
|
var uiSortable = $.extend( {}, ui, {
|
|
item: draggable.element
|
|
} );
|
|
|
|
draggable.cancelHelperRemoval = false;
|
|
|
|
$.each( draggable.sortables, function() {
|
|
var sortable = this;
|
|
|
|
if ( sortable.isOver ) {
|
|
sortable.isOver = 0;
|
|
|
|
// Allow this sortable to handle removing the helper
|
|
draggable.cancelHelperRemoval = true;
|
|
sortable.cancelHelperRemoval = false;
|
|
|
|
// Use _storedCSS To restore properties in the sortable,
|
|
// as this also handles revert (#9675) since the draggable
|
|
// may have modified them in unexpected ways (#8809)
|
|
sortable._storedCSS = {
|
|
position: sortable.placeholder.css( "position" ),
|
|
top: sortable.placeholder.css( "top" ),
|
|
left: sortable.placeholder.css( "left" )
|
|
};
|
|
|
|
sortable._mouseStop( event );
|
|
|
|
// Once drag has ended, the sortable should return to using
|
|
// its original helper, not the shared helper from draggable
|
|
sortable.options.helper = sortable.options._helper;
|
|
} else {
|
|
|
|
// Prevent this Sortable from removing the helper.
|
|
// However, don't set the draggable to remove the helper
|
|
// either as another connected Sortable may yet handle the removal.
|
|
sortable.cancelHelperRemoval = true;
|
|
|
|
sortable._trigger( "deactivate", event, uiSortable );
|
|
}
|
|
} );
|
|
},
|
|
drag: function( event, ui, draggable ) {
|
|
$.each( draggable.sortables, function() {
|
|
var innermostIntersecting = false,
|
|
sortable = this;
|
|
|
|
// Copy over variables that sortable's _intersectsWith uses
|
|
sortable.positionAbs = draggable.positionAbs;
|
|
sortable.helperProportions = draggable.helperProportions;
|
|
sortable.offset.click = draggable.offset.click;
|
|
|
|
if ( sortable._intersectsWith( sortable.containerCache ) ) {
|
|
innermostIntersecting = true;
|
|
|
|
$.each( draggable.sortables, function() {
|
|
|
|
// Copy over variables that sortable's _intersectsWith uses
|
|
this.positionAbs = draggable.positionAbs;
|
|
this.helperProportions = draggable.helperProportions;
|
|
this.offset.click = draggable.offset.click;
|
|
|
|
if ( this !== sortable &&
|
|
this._intersectsWith( this.containerCache ) &&
|
|
$.contains( sortable.element[ 0 ], this.element[ 0 ] ) ) {
|
|
innermostIntersecting = false;
|
|
}
|
|
|
|
return innermostIntersecting;
|
|
} );
|
|
}
|
|
|
|
if ( innermostIntersecting ) {
|
|
|
|
// If it intersects, we use a little isOver variable and set it once,
|
|
// so that the move-in stuff gets fired only once.
|
|
if ( !sortable.isOver ) {
|
|
sortable.isOver = 1;
|
|
|
|
// Store draggable's parent in case we need to reappend to it later.
|
|
draggable._parent = ui.helper.parent();
|
|
|
|
sortable.currentItem = ui.helper
|
|
.appendTo( sortable.element )
|
|
.data( "ui-sortable-item", true );
|
|
|
|
// Store helper option to later restore it
|
|
sortable.options._helper = sortable.options.helper;
|
|
|
|
sortable.options.helper = function() {
|
|
return ui.helper[ 0 ];
|
|
};
|
|
|
|
// Fire the start events of the sortable with our passed browser event,
|
|
// and our own helper (so it doesn't create a new one)
|
|
event.target = sortable.currentItem[ 0 ];
|
|
sortable._mouseCapture( event, true );
|
|
sortable._mouseStart( event, true, true );
|
|
|
|
// Because the browser event is way off the new appended portlet,
|
|
// modify necessary variables to reflect the changes
|
|
sortable.offset.click.top = draggable.offset.click.top;
|
|
sortable.offset.click.left = draggable.offset.click.left;
|
|
sortable.offset.parent.left -= draggable.offset.parent.left -
|
|
sortable.offset.parent.left;
|
|
sortable.offset.parent.top -= draggable.offset.parent.top -
|
|
sortable.offset.parent.top;
|
|
|
|
draggable._trigger( "toSortable", event );
|
|
|
|
// Inform draggable that the helper is in a valid drop zone,
|
|
// used solely in the revert option to handle "valid/invalid".
|
|
draggable.dropped = sortable.element;
|
|
|
|
// Need to refreshPositions of all sortables in the case that
|
|
// adding to one sortable changes the location of the other sortables (#9675)
|
|
$.each( draggable.sortables, function() {
|
|
this.refreshPositions();
|
|
} );
|
|
|
|
// Hack so receive/update callbacks work (mostly)
|
|
draggable.currentItem = draggable.element;
|
|
sortable.fromOutside = draggable;
|
|
}
|
|
|
|
if ( sortable.currentItem ) {
|
|
sortable._mouseDrag( event );
|
|
|
|
// Copy the sortable's position because the draggable's can potentially reflect
|
|
// a relative position, while sortable is always absolute, which the dragged
|
|
// element has now become. (#8809)
|
|
ui.position = sortable.position;
|
|
}
|
|
} else {
|
|
|
|
// If it doesn't intersect with the sortable, and it intersected before,
|
|
// we fake the drag stop of the sortable, but make sure it doesn't remove
|
|
// the helper by using cancelHelperRemoval.
|
|
if ( sortable.isOver ) {
|
|
|
|
sortable.isOver = 0;
|
|
sortable.cancelHelperRemoval = true;
|
|
|
|
// Calling sortable's mouseStop would trigger a revert,
|
|
// so revert must be temporarily false until after mouseStop is called.
|
|
sortable.options._revert = sortable.options.revert;
|
|
sortable.options.revert = false;
|
|
|
|
sortable._trigger( "out", event, sortable._uiHash( sortable ) );
|
|
sortable._mouseStop( event, true );
|
|
|
|
// Restore sortable behaviors that were modfied
|
|
// when the draggable entered the sortable area (#9481)
|
|
sortable.options.revert = sortable.options._revert;
|
|
sortable.options.helper = sortable.options._helper;
|
|
|
|
if ( sortable.placeholder ) {
|
|
sortable.placeholder.remove();
|
|
}
|
|
|
|
// Restore and recalculate the draggable's offset considering the sortable
|
|
// may have modified them in unexpected ways. (#8809, #10669)
|
|
ui.helper.appendTo( draggable._parent );
|
|
draggable._refreshOffsets( event );
|
|
ui.position = draggable._generatePosition( event, true );
|
|
|
|
draggable._trigger( "fromSortable", event );
|
|
|
|
// Inform draggable that the helper is no longer in a valid drop zone
|
|
draggable.dropped = false;
|
|
|
|
// Need to refreshPositions of all sortables just in case removing
|
|
// from one sortable changes the location of other sortables (#9675)
|
|
$.each( draggable.sortables, function() {
|
|
this.refreshPositions();
|
|
} );
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
|
|
$.ui.plugin.add( "draggable", "cursor", {
|
|
start: function( event, ui, instance ) {
|
|
var t = $( "body" ),
|
|
o = instance.options;
|
|
|
|
if ( t.css( "cursor" ) ) {
|
|
o._cursor = t.css( "cursor" );
|
|
}
|
|
t.css( "cursor", o.cursor );
|
|
},
|
|
stop: function( event, ui, instance ) {
|
|
var o = instance.options;
|
|
if ( o._cursor ) {
|
|
$( "body" ).css( "cursor", o._cursor );
|
|
}
|
|
}
|
|
} );
|
|
|
|
$.ui.plugin.add( "draggable", "opacity", {
|
|
start: function( event, ui, instance ) {
|
|
var t = $( ui.helper ),
|
|
o = instance.options;
|
|
if ( t.css( "opacity" ) ) {
|
|
o._opacity = t.css( "opacity" );
|
|
}
|
|
t.css( "opacity", o.opacity );
|
|
},
|
|
stop: function( event, ui, instance ) {
|
|
var o = instance.options;
|
|
if ( o._opacity ) {
|
|
$( ui.helper ).css( "opacity", o._opacity );
|
|
}
|
|
}
|
|
} );
|
|
|
|
$.ui.plugin.add( "draggable", "scroll", {
|
|
start: function( event, ui, i ) {
|
|
if ( !i.scrollParentNotHidden ) {
|
|
i.scrollParentNotHidden = i.helper.scrollParent( false );
|
|
}
|
|
|
|
if ( i.scrollParentNotHidden[ 0 ] !== i.document[ 0 ] &&
|
|
i.scrollParentNotHidden[ 0 ].tagName !== "HTML" ) {
|
|
i.overflowOffset = i.scrollParentNotHidden.offset();
|
|
}
|
|
},
|
|
drag: function( event, ui, i ) {
|
|
|
|
var o = i.options,
|
|
scrolled = false,
|
|
scrollParent = i.scrollParentNotHidden[ 0 ],
|
|
document = i.document[ 0 ];
|
|
|
|
if ( scrollParent !== document && scrollParent.tagName !== "HTML" ) {
|
|
if ( !o.axis || o.axis !== "x" ) {
|
|
if ( ( i.overflowOffset.top + scrollParent.offsetHeight ) - event.pageY <
|
|
o.scrollSensitivity ) {
|
|
scrollParent.scrollTop = scrolled = scrollParent.scrollTop + o.scrollSpeed;
|
|
} else if ( event.pageY - i.overflowOffset.top < o.scrollSensitivity ) {
|
|
scrollParent.scrollTop = scrolled = scrollParent.scrollTop - o.scrollSpeed;
|
|
}
|
|
}
|
|
|
|
if ( !o.axis || o.axis !== "y" ) {
|
|
if ( ( i.overflowOffset.left + scrollParent.offsetWidth ) - event.pageX <
|
|
o.scrollSensitivity ) {
|
|
scrollParent.scrollLeft = scrolled = scrollParent.scrollLeft + o.scrollSpeed;
|
|
} else if ( event.pageX - i.overflowOffset.left < o.scrollSensitivity ) {
|
|
scrollParent.scrollLeft = scrolled = scrollParent.scrollLeft - o.scrollSpeed;
|
|
}
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( !o.axis || o.axis !== "x" ) {
|
|
if ( event.pageY - $( document ).scrollTop() < o.scrollSensitivity ) {
|
|
scrolled = $( document ).scrollTop( $( document ).scrollTop() - o.scrollSpeed );
|
|
} else if ( $( window ).height() - ( event.pageY - $( document ).scrollTop() ) <
|
|
o.scrollSensitivity ) {
|
|
scrolled = $( document ).scrollTop( $( document ).scrollTop() + o.scrollSpeed );
|
|
}
|
|
}
|
|
|
|
if ( !o.axis || o.axis !== "y" ) {
|
|
if ( event.pageX - $( document ).scrollLeft() < o.scrollSensitivity ) {
|
|
scrolled = $( document ).scrollLeft(
|
|
$( document ).scrollLeft() - o.scrollSpeed
|
|
);
|
|
} else if ( $( window ).width() - ( event.pageX - $( document ).scrollLeft() ) <
|
|
o.scrollSensitivity ) {
|
|
scrolled = $( document ).scrollLeft(
|
|
$( document ).scrollLeft() + o.scrollSpeed
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if ( scrolled !== false && $.ui.ddmanager && !o.dropBehaviour ) {
|
|
$.ui.ddmanager.prepareOffsets( i, event );
|
|
}
|
|
|
|
}
|
|
} );
|
|
|
|
$.ui.plugin.add( "draggable", "snap", {
|
|
start: function( event, ui, i ) {
|
|
|
|
var o = i.options;
|
|
|
|
i.snapElements = [];
|
|
|
|
$( o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap )
|
|
.each( function() {
|
|
var $t = $( this ),
|
|
$o = $t.offset();
|
|
if ( this !== i.element[ 0 ] ) {
|
|
i.snapElements.push( {
|
|
item: this,
|
|
width: $t.outerWidth(), height: $t.outerHeight(),
|
|
top: $o.top, left: $o.left
|
|
} );
|
|
}
|
|
} );
|
|
|
|
},
|
|
drag: function( event, ui, inst ) {
|
|
|
|
var ts, bs, ls, rs, l, r, t, b, i, first,
|
|
o = inst.options,
|
|
d = o.snapTolerance,
|
|
x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
|
|
y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
|
|
|
|
for ( i = inst.snapElements.length - 1; i >= 0; i-- ) {
|
|
|
|
l = inst.snapElements[ i ].left - inst.margins.left;
|
|
r = l + inst.snapElements[ i ].width;
|
|
t = inst.snapElements[ i ].top - inst.margins.top;
|
|
b = t + inst.snapElements[ i ].height;
|
|
|
|
if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d ||
|
|
!$.contains( inst.snapElements[ i ].item.ownerDocument,
|
|
inst.snapElements[ i ].item ) ) {
|
|
if ( inst.snapElements[ i ].snapping ) {
|
|
if ( inst.options.snap.release ) {
|
|
inst.options.snap.release.call(
|
|
inst.element,
|
|
event,
|
|
$.extend( inst._uiHash(), { snapItem: inst.snapElements[ i ].item } )
|
|
);
|
|
}
|
|
}
|
|
inst.snapElements[ i ].snapping = false;
|
|
continue;
|
|
}
|
|
|
|
if ( o.snapMode !== "inner" ) {
|
|
ts = Math.abs( t - y2 ) <= d;
|
|
bs = Math.abs( b - y1 ) <= d;
|
|
ls = Math.abs( l - x2 ) <= d;
|
|
rs = Math.abs( r - x1 ) <= d;
|
|
if ( ts ) {
|
|
ui.position.top = inst._convertPositionTo( "relative", {
|
|
top: t - inst.helperProportions.height,
|
|
left: 0
|
|
} ).top;
|
|
}
|
|
if ( bs ) {
|
|
ui.position.top = inst._convertPositionTo( "relative", {
|
|
top: b,
|
|
left: 0
|
|
} ).top;
|
|
}
|
|
if ( ls ) {
|
|
ui.position.left = inst._convertPositionTo( "relative", {
|
|
top: 0,
|
|
left: l - inst.helperProportions.width
|
|
} ).left;
|
|
}
|
|
if ( rs ) {
|
|
ui.position.left = inst._convertPositionTo( "relative", {
|
|
top: 0,
|
|
left: r
|
|
} ).left;
|
|
}
|
|
}
|
|
|
|
first = ( ts || bs || ls || rs );
|
|
|
|
if ( o.snapMode !== "outer" ) {
|
|
ts = Math.abs( t - y1 ) <= d;
|
|
bs = Math.abs( b - y2 ) <= d;
|
|
ls = Math.abs( l - x1 ) <= d;
|
|
rs = Math.abs( r - x2 ) <= d;
|
|
if ( ts ) {
|
|
ui.position.top = inst._convertPositionTo( "relative", {
|
|
top: t,
|
|
left: 0
|
|
} ).top;
|
|
}
|
|
if ( bs ) {
|
|
ui.position.top = inst._convertPositionTo( "relative", {
|
|
top: b - inst.helperProportions.height,
|
|
left: 0
|
|
} ).top;
|
|
}
|
|
if ( ls ) {
|
|
ui.position.left = inst._convertPositionTo( "relative", {
|
|
top: 0,
|
|
left: l
|
|
} ).left;
|
|
}
|
|
if ( rs ) {
|
|
ui.position.left = inst._convertPositionTo( "relative", {
|
|
top: 0,
|
|
left: r - inst.helperProportions.width
|
|
} ).left;
|
|
}
|
|
}
|
|
|
|
if ( !inst.snapElements[ i ].snapping && ( ts || bs || ls || rs || first ) ) {
|
|
if ( inst.options.snap.snap ) {
|
|
inst.options.snap.snap.call(
|
|
inst.element,
|
|
event,
|
|
$.extend( inst._uiHash(), {
|
|
snapItem: inst.snapElements[ i ].item
|
|
} ) );
|
|
}
|
|
}
|
|
inst.snapElements[ i ].snapping = ( ts || bs || ls || rs || first );
|
|
|
|
}
|
|
|
|
}
|
|
} );
|
|
|
|
$.ui.plugin.add( "draggable", "stack", {
|
|
start: function( event, ui, instance ) {
|
|
var min,
|
|
o = instance.options,
|
|
group = $.makeArray( $( o.stack ) ).sort( function( a, b ) {
|
|
return ( parseInt( $( a ).css( "zIndex" ), 10 ) || 0 ) -
|
|
( parseInt( $( b ).css( "zIndex" ), 10 ) || 0 );
|
|
} );
|
|
|
|
if ( !group.length ) {
|
|
return;
|
|
}
|
|
|
|
min = parseInt( $( group[ 0 ] ).css( "zIndex" ), 10 ) || 0;
|
|
$( group ).each( function( i ) {
|
|
$( this ).css( "zIndex", min + i );
|
|
} );
|
|
this.css( "zIndex", ( min + group.length ) );
|
|
}
|
|
} );
|
|
|
|
$.ui.plugin.add( "draggable", "zIndex", {
|
|
start: function( event, ui, instance ) {
|
|
var t = $( ui.helper ),
|
|
o = instance.options;
|
|
|
|
if ( t.css( "zIndex" ) ) {
|
|
o._zIndex = t.css( "zIndex" );
|
|
}
|
|
t.css( "zIndex", o.zIndex );
|
|
},
|
|
stop: function( event, ui, instance ) {
|
|
var o = instance.options;
|
|
|
|
if ( o._zIndex ) {
|
|
$( ui.helper ).css( "zIndex", o._zIndex );
|
|
}
|
|
}
|
|
} );
|
|
|
|
var widgetsDraggable = $.ui.draggable;
|
|
|
|
|
|
/*!
|
|
* jQuery UI Droppable 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Droppable
|
|
//>>group: Interactions
|
|
//>>description: Enables drop targets for draggable elements.
|
|
//>>docs: http://api.jqueryui.com/droppable/
|
|
//>>demos: http://jqueryui.com/droppable/
|
|
|
|
|
|
$.widget( "ui.droppable", {
|
|
version: "1.13.1",
|
|
widgetEventPrefix: "drop",
|
|
options: {
|
|
accept: "*",
|
|
addClasses: true,
|
|
greedy: false,
|
|
scope: "default",
|
|
tolerance: "intersect",
|
|
|
|
// Callbacks
|
|
activate: null,
|
|
deactivate: null,
|
|
drop: null,
|
|
out: null,
|
|
over: null
|
|
},
|
|
_create: function() {
|
|
|
|
var proportions,
|
|
o = this.options,
|
|
accept = o.accept;
|
|
|
|
this.isover = false;
|
|
this.isout = true;
|
|
|
|
this.accept = typeof accept === "function" ? accept : function( d ) {
|
|
return d.is( accept );
|
|
};
|
|
|
|
this.proportions = function( /* valueToWrite */ ) {
|
|
if ( arguments.length ) {
|
|
|
|
// Store the droppable's proportions
|
|
proportions = arguments[ 0 ];
|
|
} else {
|
|
|
|
// Retrieve or derive the droppable's proportions
|
|
return proportions ?
|
|
proportions :
|
|
proportions = {
|
|
width: this.element[ 0 ].offsetWidth,
|
|
height: this.element[ 0 ].offsetHeight
|
|
};
|
|
}
|
|
};
|
|
|
|
this._addToManager( o.scope );
|
|
|
|
if ( o.addClasses ) {
|
|
this._addClass( "ui-droppable" );
|
|
}
|
|
|
|
},
|
|
|
|
_addToManager: function( scope ) {
|
|
|
|
// Add the reference and positions to the manager
|
|
$.ui.ddmanager.droppables[ scope ] = $.ui.ddmanager.droppables[ scope ] || [];
|
|
$.ui.ddmanager.droppables[ scope ].push( this );
|
|
},
|
|
|
|
_splice: function( drop ) {
|
|
var i = 0;
|
|
for ( ; i < drop.length; i++ ) {
|
|
if ( drop[ i ] === this ) {
|
|
drop.splice( i, 1 );
|
|
}
|
|
}
|
|
},
|
|
|
|
_destroy: function() {
|
|
var drop = $.ui.ddmanager.droppables[ this.options.scope ];
|
|
|
|
this._splice( drop );
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
|
|
if ( key === "accept" ) {
|
|
this.accept = typeof value === "function" ? value : function( d ) {
|
|
return d.is( value );
|
|
};
|
|
} else if ( key === "scope" ) {
|
|
var drop = $.ui.ddmanager.droppables[ this.options.scope ];
|
|
|
|
this._splice( drop );
|
|
this._addToManager( value );
|
|
}
|
|
|
|
this._super( key, value );
|
|
},
|
|
|
|
_activate: function( event ) {
|
|
var draggable = $.ui.ddmanager.current;
|
|
|
|
this._addActiveClass();
|
|
if ( draggable ) {
|
|
this._trigger( "activate", event, this.ui( draggable ) );
|
|
}
|
|
},
|
|
|
|
_deactivate: function( event ) {
|
|
var draggable = $.ui.ddmanager.current;
|
|
|
|
this._removeActiveClass();
|
|
if ( draggable ) {
|
|
this._trigger( "deactivate", event, this.ui( draggable ) );
|
|
}
|
|
},
|
|
|
|
_over: function( event ) {
|
|
|
|
var draggable = $.ui.ddmanager.current;
|
|
|
|
// Bail if draggable and droppable are same element
|
|
if ( !draggable || ( draggable.currentItem ||
|
|
draggable.element )[ 0 ] === this.element[ 0 ] ) {
|
|
return;
|
|
}
|
|
|
|
if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem ||
|
|
draggable.element ) ) ) {
|
|
this._addHoverClass();
|
|
this._trigger( "over", event, this.ui( draggable ) );
|
|
}
|
|
|
|
},
|
|
|
|
_out: function( event ) {
|
|
|
|
var draggable = $.ui.ddmanager.current;
|
|
|
|
// Bail if draggable and droppable are same element
|
|
if ( !draggable || ( draggable.currentItem ||
|
|
draggable.element )[ 0 ] === this.element[ 0 ] ) {
|
|
return;
|
|
}
|
|
|
|
if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem ||
|
|
draggable.element ) ) ) {
|
|
this._removeHoverClass();
|
|
this._trigger( "out", event, this.ui( draggable ) );
|
|
}
|
|
|
|
},
|
|
|
|
_drop: function( event, custom ) {
|
|
|
|
var draggable = custom || $.ui.ddmanager.current,
|
|
childrenIntersection = false;
|
|
|
|
// Bail if draggable and droppable are same element
|
|
if ( !draggable || ( draggable.currentItem ||
|
|
draggable.element )[ 0 ] === this.element[ 0 ] ) {
|
|
return false;
|
|
}
|
|
|
|
this.element
|
|
.find( ":data(ui-droppable)" )
|
|
.not( ".ui-draggable-dragging" )
|
|
.each( function() {
|
|
var inst = $( this ).droppable( "instance" );
|
|
if (
|
|
inst.options.greedy &&
|
|
!inst.options.disabled &&
|
|
inst.options.scope === draggable.options.scope &&
|
|
inst.accept.call(
|
|
inst.element[ 0 ], ( draggable.currentItem || draggable.element )
|
|
) &&
|
|
$.ui.intersect(
|
|
draggable,
|
|
$.extend( inst, { offset: inst.element.offset() } ),
|
|
inst.options.tolerance, event
|
|
)
|
|
) {
|
|
childrenIntersection = true;
|
|
return false;
|
|
}
|
|
} );
|
|
if ( childrenIntersection ) {
|
|
return false;
|
|
}
|
|
|
|
if ( this.accept.call( this.element[ 0 ],
|
|
( draggable.currentItem || draggable.element ) ) ) {
|
|
this._removeActiveClass();
|
|
this._removeHoverClass();
|
|
|
|
this._trigger( "drop", event, this.ui( draggable ) );
|
|
return this.element;
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
ui: function( c ) {
|
|
return {
|
|
draggable: ( c.currentItem || c.element ),
|
|
helper: c.helper,
|
|
position: c.position,
|
|
offset: c.positionAbs
|
|
};
|
|
},
|
|
|
|
// Extension points just to make backcompat sane and avoid duplicating logic
|
|
// TODO: Remove in 1.14 along with call to it below
|
|
_addHoverClass: function() {
|
|
this._addClass( "ui-droppable-hover" );
|
|
},
|
|
|
|
_removeHoverClass: function() {
|
|
this._removeClass( "ui-droppable-hover" );
|
|
},
|
|
|
|
_addActiveClass: function() {
|
|
this._addClass( "ui-droppable-active" );
|
|
},
|
|
|
|
_removeActiveClass: function() {
|
|
this._removeClass( "ui-droppable-active" );
|
|
}
|
|
} );
|
|
|
|
$.ui.intersect = ( function() {
|
|
function isOverAxis( x, reference, size ) {
|
|
return ( x >= reference ) && ( x < ( reference + size ) );
|
|
}
|
|
|
|
return function( draggable, droppable, toleranceMode, event ) {
|
|
|
|
if ( !droppable.offset ) {
|
|
return false;
|
|
}
|
|
|
|
var x1 = ( draggable.positionAbs ||
|
|
draggable.position.absolute ).left + draggable.margins.left,
|
|
y1 = ( draggable.positionAbs ||
|
|
draggable.position.absolute ).top + draggable.margins.top,
|
|
x2 = x1 + draggable.helperProportions.width,
|
|
y2 = y1 + draggable.helperProportions.height,
|
|
l = droppable.offset.left,
|
|
t = droppable.offset.top,
|
|
r = l + droppable.proportions().width,
|
|
b = t + droppable.proportions().height;
|
|
|
|
switch ( toleranceMode ) {
|
|
case "fit":
|
|
return ( l <= x1 && x2 <= r && t <= y1 && y2 <= b );
|
|
case "intersect":
|
|
return ( l < x1 + ( draggable.helperProportions.width / 2 ) && // Right Half
|
|
x2 - ( draggable.helperProportions.width / 2 ) < r && // Left Half
|
|
t < y1 + ( draggable.helperProportions.height / 2 ) && // Bottom Half
|
|
y2 - ( draggable.helperProportions.height / 2 ) < b ); // Top Half
|
|
case "pointer":
|
|
return isOverAxis( event.pageY, t, droppable.proportions().height ) &&
|
|
isOverAxis( event.pageX, l, droppable.proportions().width );
|
|
case "touch":
|
|
return (
|
|
( y1 >= t && y1 <= b ) || // Top edge touching
|
|
( y2 >= t && y2 <= b ) || // Bottom edge touching
|
|
( y1 < t && y2 > b ) // Surrounded vertically
|
|
) && (
|
|
( x1 >= l && x1 <= r ) || // Left edge touching
|
|
( x2 >= l && x2 <= r ) || // Right edge touching
|
|
( x1 < l && x2 > r ) // Surrounded horizontally
|
|
);
|
|
default:
|
|
return false;
|
|
}
|
|
};
|
|
} )();
|
|
|
|
/*
|
|
This manager tracks offsets of draggables and droppables
|
|
*/
|
|
$.ui.ddmanager = {
|
|
current: null,
|
|
droppables: { "default": [] },
|
|
prepareOffsets: function( t, event ) {
|
|
|
|
var i, j,
|
|
m = $.ui.ddmanager.droppables[ t.options.scope ] || [],
|
|
type = event ? event.type : null, // workaround for #2317
|
|
list = ( t.currentItem || t.element ).find( ":data(ui-droppable)" ).addBack();
|
|
|
|
droppablesLoop: for ( i = 0; i < m.length; i++ ) {
|
|
|
|
// No disabled and non-accepted
|
|
if ( m[ i ].options.disabled || ( t && !m[ i ].accept.call( m[ i ].element[ 0 ],
|
|
( t.currentItem || t.element ) ) ) ) {
|
|
continue;
|
|
}
|
|
|
|
// Filter out elements in the current dragged item
|
|
for ( j = 0; j < list.length; j++ ) {
|
|
if ( list[ j ] === m[ i ].element[ 0 ] ) {
|
|
m[ i ].proportions().height = 0;
|
|
continue droppablesLoop;
|
|
}
|
|
}
|
|
|
|
m[ i ].visible = m[ i ].element.css( "display" ) !== "none";
|
|
if ( !m[ i ].visible ) {
|
|
continue;
|
|
}
|
|
|
|
// Activate the droppable if used directly from draggables
|
|
if ( type === "mousedown" ) {
|
|
m[ i ]._activate.call( m[ i ], event );
|
|
}
|
|
|
|
m[ i ].offset = m[ i ].element.offset();
|
|
m[ i ].proportions( {
|
|
width: m[ i ].element[ 0 ].offsetWidth,
|
|
height: m[ i ].element[ 0 ].offsetHeight
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
drop: function( draggable, event ) {
|
|
|
|
var dropped = false;
|
|
|
|
// Create a copy of the droppables in case the list changes during the drop (#9116)
|
|
$.each( ( $.ui.ddmanager.droppables[ draggable.options.scope ] || [] ).slice(), function() {
|
|
|
|
if ( !this.options ) {
|
|
return;
|
|
}
|
|
if ( !this.options.disabled && this.visible &&
|
|
$.ui.intersect( draggable, this, this.options.tolerance, event ) ) {
|
|
dropped = this._drop.call( this, event ) || dropped;
|
|
}
|
|
|
|
if ( !this.options.disabled && this.visible && this.accept.call( this.element[ 0 ],
|
|
( draggable.currentItem || draggable.element ) ) ) {
|
|
this.isout = true;
|
|
this.isover = false;
|
|
this._deactivate.call( this, event );
|
|
}
|
|
|
|
} );
|
|
return dropped;
|
|
|
|
},
|
|
dragStart: function( draggable, event ) {
|
|
|
|
// Listen for scrolling so that if the dragging causes scrolling the position of the
|
|
// droppables can be recalculated (see #5003)
|
|
draggable.element.parentsUntil( "body" ).on( "scroll.droppable", function() {
|
|
if ( !draggable.options.refreshPositions ) {
|
|
$.ui.ddmanager.prepareOffsets( draggable, event );
|
|
}
|
|
} );
|
|
},
|
|
drag: function( draggable, event ) {
|
|
|
|
// If you have a highly dynamic page, you might try this option. It renders positions
|
|
// every time you move the mouse.
|
|
if ( draggable.options.refreshPositions ) {
|
|
$.ui.ddmanager.prepareOffsets( draggable, event );
|
|
}
|
|
|
|
// Run through all droppables and check their positions based on specific tolerance options
|
|
$.each( $.ui.ddmanager.droppables[ draggable.options.scope ] || [], function() {
|
|
|
|
if ( this.options.disabled || this.greedyChild || !this.visible ) {
|
|
return;
|
|
}
|
|
|
|
var parentInstance, scope, parent,
|
|
intersects = $.ui.intersect( draggable, this, this.options.tolerance, event ),
|
|
c = !intersects && this.isover ?
|
|
"isout" :
|
|
( intersects && !this.isover ? "isover" : null );
|
|
if ( !c ) {
|
|
return;
|
|
}
|
|
|
|
if ( this.options.greedy ) {
|
|
|
|
// find droppable parents with same scope
|
|
scope = this.options.scope;
|
|
parent = this.element.parents( ":data(ui-droppable)" ).filter( function() {
|
|
return $( this ).droppable( "instance" ).options.scope === scope;
|
|
} );
|
|
|
|
if ( parent.length ) {
|
|
parentInstance = $( parent[ 0 ] ).droppable( "instance" );
|
|
parentInstance.greedyChild = ( c === "isover" );
|
|
}
|
|
}
|
|
|
|
// We just moved into a greedy child
|
|
if ( parentInstance && c === "isover" ) {
|
|
parentInstance.isover = false;
|
|
parentInstance.isout = true;
|
|
parentInstance._out.call( parentInstance, event );
|
|
}
|
|
|
|
this[ c ] = true;
|
|
this[ c === "isout" ? "isover" : "isout" ] = false;
|
|
this[ c === "isover" ? "_over" : "_out" ].call( this, event );
|
|
|
|
// We just moved out of a greedy child
|
|
if ( parentInstance && c === "isout" ) {
|
|
parentInstance.isout = false;
|
|
parentInstance.isover = true;
|
|
parentInstance._over.call( parentInstance, event );
|
|
}
|
|
} );
|
|
|
|
},
|
|
dragStop: function( draggable, event ) {
|
|
draggable.element.parentsUntil( "body" ).off( "scroll.droppable" );
|
|
|
|
// Call prepareOffsets one final time since IE does not fire return scroll events when
|
|
// overflow was caused by drag (see #5003)
|
|
if ( !draggable.options.refreshPositions ) {
|
|
$.ui.ddmanager.prepareOffsets( draggable, event );
|
|
}
|
|
}
|
|
};
|
|
|
|
// DEPRECATED
|
|
// TODO: switch return back to widget declaration at top of file when this is removed
|
|
if ( $.uiBackCompat !== false ) {
|
|
|
|
// Backcompat for activeClass and hoverClass options
|
|
$.widget( "ui.droppable", $.ui.droppable, {
|
|
options: {
|
|
hoverClass: false,
|
|
activeClass: false
|
|
},
|
|
_addActiveClass: function() {
|
|
this._super();
|
|
if ( this.options.activeClass ) {
|
|
this.element.addClass( this.options.activeClass );
|
|
}
|
|
},
|
|
_removeActiveClass: function() {
|
|
this._super();
|
|
if ( this.options.activeClass ) {
|
|
this.element.removeClass( this.options.activeClass );
|
|
}
|
|
},
|
|
_addHoverClass: function() {
|
|
this._super();
|
|
if ( this.options.hoverClass ) {
|
|
this.element.addClass( this.options.hoverClass );
|
|
}
|
|
},
|
|
_removeHoverClass: function() {
|
|
this._super();
|
|
if ( this.options.hoverClass ) {
|
|
this.element.removeClass( this.options.hoverClass );
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
|
|
var widgetsDroppable = $.ui.droppable;
|
|
|
|
|
|
/*!
|
|
* jQuery UI Sortable 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Sortable
|
|
//>>group: Interactions
|
|
//>>description: Enables items in a list to be sorted using the mouse.
|
|
//>>docs: http://api.jqueryui.com/sortable/
|
|
//>>demos: http://jqueryui.com/sortable/
|
|
//>>css.structure: ../../themes/base/sortable.css
|
|
|
|
|
|
var widgetsSortable = $.widget( "ui.sortable", $.ui.mouse, {
|
|
version: "1.13.1",
|
|
widgetEventPrefix: "sort",
|
|
ready: false,
|
|
options: {
|
|
appendTo: "parent",
|
|
axis: false,
|
|
connectWith: false,
|
|
containment: false,
|
|
cursor: "auto",
|
|
cursorAt: false,
|
|
dropOnEmpty: true,
|
|
forcePlaceholderSize: false,
|
|
forceHelperSize: false,
|
|
grid: false,
|
|
handle: false,
|
|
helper: "original",
|
|
items: "> *",
|
|
opacity: false,
|
|
placeholder: false,
|
|
revert: false,
|
|
scroll: true,
|
|
scrollSensitivity: 20,
|
|
scrollSpeed: 20,
|
|
scope: "default",
|
|
tolerance: "intersect",
|
|
zIndex: 1000,
|
|
|
|
// Callbacks
|
|
activate: null,
|
|
beforeStop: null,
|
|
change: null,
|
|
deactivate: null,
|
|
out: null,
|
|
over: null,
|
|
receive: null,
|
|
remove: null,
|
|
sort: null,
|
|
start: null,
|
|
stop: null,
|
|
update: null
|
|
},
|
|
|
|
_isOverAxis: function( x, reference, size ) {
|
|
return ( x >= reference ) && ( x < ( reference + size ) );
|
|
},
|
|
|
|
_isFloating: function( item ) {
|
|
return ( /left|right/ ).test( item.css( "float" ) ) ||
|
|
( /inline|table-cell/ ).test( item.css( "display" ) );
|
|
},
|
|
|
|
_create: function() {
|
|
this.containerCache = {};
|
|
this._addClass( "ui-sortable" );
|
|
|
|
//Get the items
|
|
this.refresh();
|
|
|
|
//Let's determine the parent's offset
|
|
this.offset = this.element.offset();
|
|
|
|
//Initialize mouse events for interaction
|
|
this._mouseInit();
|
|
|
|
this._setHandleClassName();
|
|
|
|
//We're ready to go
|
|
this.ready = true;
|
|
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
this._super( key, value );
|
|
|
|
if ( key === "handle" ) {
|
|
this._setHandleClassName();
|
|
}
|
|
},
|
|
|
|
_setHandleClassName: function() {
|
|
var that = this;
|
|
this._removeClass( this.element.find( ".ui-sortable-handle" ), "ui-sortable-handle" );
|
|
$.each( this.items, function() {
|
|
that._addClass(
|
|
this.instance.options.handle ?
|
|
this.item.find( this.instance.options.handle ) :
|
|
this.item,
|
|
"ui-sortable-handle"
|
|
);
|
|
} );
|
|
},
|
|
|
|
_destroy: function() {
|
|
this._mouseDestroy();
|
|
|
|
for ( var i = this.items.length - 1; i >= 0; i-- ) {
|
|
this.items[ i ].item.removeData( this.widgetName + "-item" );
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
_mouseCapture: function( event, overrideHandle ) {
|
|
var currentItem = null,
|
|
validHandle = false,
|
|
that = this;
|
|
|
|
if ( this.reverting ) {
|
|
return false;
|
|
}
|
|
|
|
if ( this.options.disabled || this.options.type === "static" ) {
|
|
return false;
|
|
}
|
|
|
|
//We have to refresh the items data once first
|
|
this._refreshItems( event );
|
|
|
|
//Find out if the clicked node (or one of its parents) is a actual item in this.items
|
|
$( event.target ).parents().each( function() {
|
|
if ( $.data( this, that.widgetName + "-item" ) === that ) {
|
|
currentItem = $( this );
|
|
return false;
|
|
}
|
|
} );
|
|
if ( $.data( event.target, that.widgetName + "-item" ) === that ) {
|
|
currentItem = $( event.target );
|
|
}
|
|
|
|
if ( !currentItem ) {
|
|
return false;
|
|
}
|
|
if ( this.options.handle && !overrideHandle ) {
|
|
$( this.options.handle, currentItem ).find( "*" ).addBack().each( function() {
|
|
if ( this === event.target ) {
|
|
validHandle = true;
|
|
}
|
|
} );
|
|
if ( !validHandle ) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
this.currentItem = currentItem;
|
|
this._removeCurrentsFromItems();
|
|
return true;
|
|
|
|
},
|
|
|
|
_mouseStart: function( event, overrideHandle, noActivation ) {
|
|
|
|
var i, body,
|
|
o = this.options;
|
|
|
|
this.currentContainer = this;
|
|
|
|
//We only need to call refreshPositions, because the refreshItems call has been moved to
|
|
// mouseCapture
|
|
this.refreshPositions();
|
|
|
|
//Prepare the dragged items parent
|
|
this.appendTo = $( o.appendTo !== "parent" ?
|
|
o.appendTo :
|
|
this.currentItem.parent() );
|
|
|
|
//Create and append the visible helper
|
|
this.helper = this._createHelper( event );
|
|
|
|
//Cache the helper size
|
|
this._cacheHelperProportions();
|
|
|
|
/*
|
|
* - Position generation -
|
|
* This block generates everything position related - it's the core of draggables.
|
|
*/
|
|
|
|
//Cache the margins of the original element
|
|
this._cacheMargins();
|
|
|
|
//The element's absolute position on the page minus margins
|
|
this.offset = this.currentItem.offset();
|
|
this.offset = {
|
|
top: this.offset.top - this.margins.top,
|
|
left: this.offset.left - this.margins.left
|
|
};
|
|
|
|
$.extend( this.offset, {
|
|
click: { //Where the click happened, relative to the element
|
|
left: event.pageX - this.offset.left,
|
|
top: event.pageY - this.offset.top
|
|
},
|
|
|
|
// This is a relative to absolute position minus the actual position calculation -
|
|
// only used for relative positioned helper
|
|
relative: this._getRelativeOffset()
|
|
} );
|
|
|
|
// After we get the helper offset, but before we get the parent offset we can
|
|
// change the helper's position to absolute
|
|
// TODO: Still need to figure out a way to make relative sorting possible
|
|
this.helper.css( "position", "absolute" );
|
|
this.cssPosition = this.helper.css( "position" );
|
|
|
|
//Adjust the mouse offset relative to the helper if "cursorAt" is supplied
|
|
if ( o.cursorAt ) {
|
|
this._adjustOffsetFromHelper( o.cursorAt );
|
|
}
|
|
|
|
//Cache the former DOM position
|
|
this.domPosition = {
|
|
prev: this.currentItem.prev()[ 0 ],
|
|
parent: this.currentItem.parent()[ 0 ]
|
|
};
|
|
|
|
// If the helper is not the original, hide the original so it's not playing any role during
|
|
// the drag, won't cause anything bad this way
|
|
if ( this.helper[ 0 ] !== this.currentItem[ 0 ] ) {
|
|
this.currentItem.hide();
|
|
}
|
|
|
|
//Create the placeholder
|
|
this._createPlaceholder();
|
|
|
|
//Get the next scrolling parent
|
|
this.scrollParent = this.placeholder.scrollParent();
|
|
|
|
$.extend( this.offset, {
|
|
parent: this._getParentOffset()
|
|
} );
|
|
|
|
//Set a containment if given in the options
|
|
if ( o.containment ) {
|
|
this._setContainment();
|
|
}
|
|
|
|
if ( o.cursor && o.cursor !== "auto" ) { // cursor option
|
|
body = this.document.find( "body" );
|
|
|
|
// Support: IE
|
|
this.storedCursor = body.css( "cursor" );
|
|
body.css( "cursor", o.cursor );
|
|
|
|
this.storedStylesheet =
|
|
$( "<style>*{ cursor: " + o.cursor + " !important; }</style>" ).appendTo( body );
|
|
}
|
|
|
|
// We need to make sure to grab the zIndex before setting the
|
|
// opacity, because setting the opacity to anything lower than 1
|
|
// causes the zIndex to change from "auto" to 0.
|
|
if ( o.zIndex ) { // zIndex option
|
|
if ( this.helper.css( "zIndex" ) ) {
|
|
this._storedZIndex = this.helper.css( "zIndex" );
|
|
}
|
|
this.helper.css( "zIndex", o.zIndex );
|
|
}
|
|
|
|
if ( o.opacity ) { // opacity option
|
|
if ( this.helper.css( "opacity" ) ) {
|
|
this._storedOpacity = this.helper.css( "opacity" );
|
|
}
|
|
this.helper.css( "opacity", o.opacity );
|
|
}
|
|
|
|
//Prepare scrolling
|
|
if ( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
|
|
this.scrollParent[ 0 ].tagName !== "HTML" ) {
|
|
this.overflowOffset = this.scrollParent.offset();
|
|
}
|
|
|
|
//Call callbacks
|
|
this._trigger( "start", event, this._uiHash() );
|
|
|
|
//Recache the helper size
|
|
if ( !this._preserveHelperProportions ) {
|
|
this._cacheHelperProportions();
|
|
}
|
|
|
|
//Post "activate" events to possible containers
|
|
if ( !noActivation ) {
|
|
for ( i = this.containers.length - 1; i >= 0; i-- ) {
|
|
this.containers[ i ]._trigger( "activate", event, this._uiHash( this ) );
|
|
}
|
|
}
|
|
|
|
//Prepare possible droppables
|
|
if ( $.ui.ddmanager ) {
|
|
$.ui.ddmanager.current = this;
|
|
}
|
|
|
|
if ( $.ui.ddmanager && !o.dropBehaviour ) {
|
|
$.ui.ddmanager.prepareOffsets( this, event );
|
|
}
|
|
|
|
this.dragging = true;
|
|
|
|
this._addClass( this.helper, "ui-sortable-helper" );
|
|
|
|
//Move the helper, if needed
|
|
if ( !this.helper.parent().is( this.appendTo ) ) {
|
|
this.helper.detach().appendTo( this.appendTo );
|
|
|
|
//Update position
|
|
this.offset.parent = this._getParentOffset();
|
|
}
|
|
|
|
//Generate the original position
|
|
this.position = this.originalPosition = this._generatePosition( event );
|
|
this.originalPageX = event.pageX;
|
|
this.originalPageY = event.pageY;
|
|
this.lastPositionAbs = this.positionAbs = this._convertPositionTo( "absolute" );
|
|
|
|
this._mouseDrag( event );
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
_scroll: function( event ) {
|
|
var o = this.options,
|
|
scrolled = false;
|
|
|
|
if ( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
|
|
this.scrollParent[ 0 ].tagName !== "HTML" ) {
|
|
|
|
if ( ( this.overflowOffset.top + this.scrollParent[ 0 ].offsetHeight ) -
|
|
event.pageY < o.scrollSensitivity ) {
|
|
this.scrollParent[ 0 ].scrollTop =
|
|
scrolled = this.scrollParent[ 0 ].scrollTop + o.scrollSpeed;
|
|
} else if ( event.pageY - this.overflowOffset.top < o.scrollSensitivity ) {
|
|
this.scrollParent[ 0 ].scrollTop =
|
|
scrolled = this.scrollParent[ 0 ].scrollTop - o.scrollSpeed;
|
|
}
|
|
|
|
if ( ( this.overflowOffset.left + this.scrollParent[ 0 ].offsetWidth ) -
|
|
event.pageX < o.scrollSensitivity ) {
|
|
this.scrollParent[ 0 ].scrollLeft = scrolled =
|
|
this.scrollParent[ 0 ].scrollLeft + o.scrollSpeed;
|
|
} else if ( event.pageX - this.overflowOffset.left < o.scrollSensitivity ) {
|
|
this.scrollParent[ 0 ].scrollLeft = scrolled =
|
|
this.scrollParent[ 0 ].scrollLeft - o.scrollSpeed;
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( event.pageY - this.document.scrollTop() < o.scrollSensitivity ) {
|
|
scrolled = this.document.scrollTop( this.document.scrollTop() - o.scrollSpeed );
|
|
} else if ( this.window.height() - ( event.pageY - this.document.scrollTop() ) <
|
|
o.scrollSensitivity ) {
|
|
scrolled = this.document.scrollTop( this.document.scrollTop() + o.scrollSpeed );
|
|
}
|
|
|
|
if ( event.pageX - this.document.scrollLeft() < o.scrollSensitivity ) {
|
|
scrolled = this.document.scrollLeft(
|
|
this.document.scrollLeft() - o.scrollSpeed
|
|
);
|
|
} else if ( this.window.width() - ( event.pageX - this.document.scrollLeft() ) <
|
|
o.scrollSensitivity ) {
|
|
scrolled = this.document.scrollLeft(
|
|
this.document.scrollLeft() + o.scrollSpeed
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
return scrolled;
|
|
},
|
|
|
|
_mouseDrag: function( event ) {
|
|
var i, item, itemElement, intersection,
|
|
o = this.options;
|
|
|
|
//Compute the helpers position
|
|
this.position = this._generatePosition( event );
|
|
this.positionAbs = this._convertPositionTo( "absolute" );
|
|
|
|
//Set the helper position
|
|
if ( !this.options.axis || this.options.axis !== "y" ) {
|
|
this.helper[ 0 ].style.left = this.position.left + "px";
|
|
}
|
|
if ( !this.options.axis || this.options.axis !== "x" ) {
|
|
this.helper[ 0 ].style.top = this.position.top + "px";
|
|
}
|
|
|
|
//Do scrolling
|
|
if ( o.scroll ) {
|
|
if ( this._scroll( event ) !== false ) {
|
|
|
|
//Update item positions used in position checks
|
|
this._refreshItemPositions( true );
|
|
|
|
if ( $.ui.ddmanager && !o.dropBehaviour ) {
|
|
$.ui.ddmanager.prepareOffsets( this, event );
|
|
}
|
|
}
|
|
}
|
|
|
|
this.dragDirection = {
|
|
vertical: this._getDragVerticalDirection(),
|
|
horizontal: this._getDragHorizontalDirection()
|
|
};
|
|
|
|
//Rearrange
|
|
for ( i = this.items.length - 1; i >= 0; i-- ) {
|
|
|
|
//Cache variables and intersection, continue if no intersection
|
|
item = this.items[ i ];
|
|
itemElement = item.item[ 0 ];
|
|
intersection = this._intersectsWithPointer( item );
|
|
if ( !intersection ) {
|
|
continue;
|
|
}
|
|
|
|
// Only put the placeholder inside the current Container, skip all
|
|
// items from other containers. This works because when moving
|
|
// an item from one container to another the
|
|
// currentContainer is switched before the placeholder is moved.
|
|
//
|
|
// Without this, moving items in "sub-sortables" can cause
|
|
// the placeholder to jitter between the outer and inner container.
|
|
if ( item.instance !== this.currentContainer ) {
|
|
continue;
|
|
}
|
|
|
|
// Cannot intersect with itself
|
|
// no useless actions that have been done before
|
|
// no action if the item moved is the parent of the item checked
|
|
if ( itemElement !== this.currentItem[ 0 ] &&
|
|
this.placeholder[ intersection === 1 ?
|
|
"next" : "prev" ]()[ 0 ] !== itemElement &&
|
|
!$.contains( this.placeholder[ 0 ], itemElement ) &&
|
|
( this.options.type === "semi-dynamic" ?
|
|
!$.contains( this.element[ 0 ], itemElement ) :
|
|
true
|
|
)
|
|
) {
|
|
|
|
this.direction = intersection === 1 ? "down" : "up";
|
|
|
|
if ( this.options.tolerance === "pointer" ||
|
|
this._intersectsWithSides( item ) ) {
|
|
this._rearrange( event, item );
|
|
} else {
|
|
break;
|
|
}
|
|
|
|
this._trigger( "change", event, this._uiHash() );
|
|
break;
|
|
}
|
|
}
|
|
|
|
//Post events to containers
|
|
this._contactContainers( event );
|
|
|
|
//Interconnect with droppables
|
|
if ( $.ui.ddmanager ) {
|
|
$.ui.ddmanager.drag( this, event );
|
|
}
|
|
|
|
//Call callbacks
|
|
this._trigger( "sort", event, this._uiHash() );
|
|
|
|
this.lastPositionAbs = this.positionAbs;
|
|
return false;
|
|
|
|
},
|
|
|
|
_mouseStop: function( event, noPropagation ) {
|
|
|
|
if ( !event ) {
|
|
return;
|
|
}
|
|
|
|
//If we are using droppables, inform the manager about the drop
|
|
if ( $.ui.ddmanager && !this.options.dropBehaviour ) {
|
|
$.ui.ddmanager.drop( this, event );
|
|
}
|
|
|
|
if ( this.options.revert ) {
|
|
var that = this,
|
|
cur = this.placeholder.offset(),
|
|
axis = this.options.axis,
|
|
animation = {};
|
|
|
|
if ( !axis || axis === "x" ) {
|
|
animation.left = cur.left - this.offset.parent.left - this.margins.left +
|
|
( this.offsetParent[ 0 ] === this.document[ 0 ].body ?
|
|
0 :
|
|
this.offsetParent[ 0 ].scrollLeft
|
|
);
|
|
}
|
|
if ( !axis || axis === "y" ) {
|
|
animation.top = cur.top - this.offset.parent.top - this.margins.top +
|
|
( this.offsetParent[ 0 ] === this.document[ 0 ].body ?
|
|
0 :
|
|
this.offsetParent[ 0 ].scrollTop
|
|
);
|
|
}
|
|
this.reverting = true;
|
|
$( this.helper ).animate(
|
|
animation,
|
|
parseInt( this.options.revert, 10 ) || 500,
|
|
function() {
|
|
that._clear( event );
|
|
}
|
|
);
|
|
} else {
|
|
this._clear( event, noPropagation );
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
cancel: function() {
|
|
|
|
if ( this.dragging ) {
|
|
|
|
this._mouseUp( new $.Event( "mouseup", { target: null } ) );
|
|
|
|
if ( this.options.helper === "original" ) {
|
|
this.currentItem.css( this._storedCSS );
|
|
this._removeClass( this.currentItem, "ui-sortable-helper" );
|
|
} else {
|
|
this.currentItem.show();
|
|
}
|
|
|
|
//Post deactivating events to containers
|
|
for ( var i = this.containers.length - 1; i >= 0; i-- ) {
|
|
this.containers[ i ]._trigger( "deactivate", null, this._uiHash( this ) );
|
|
if ( this.containers[ i ].containerCache.over ) {
|
|
this.containers[ i ]._trigger( "out", null, this._uiHash( this ) );
|
|
this.containers[ i ].containerCache.over = 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if ( this.placeholder ) {
|
|
|
|
//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately,
|
|
// it unbinds ALL events from the original node!
|
|
if ( this.placeholder[ 0 ].parentNode ) {
|
|
this.placeholder[ 0 ].parentNode.removeChild( this.placeholder[ 0 ] );
|
|
}
|
|
if ( this.options.helper !== "original" && this.helper &&
|
|
this.helper[ 0 ].parentNode ) {
|
|
this.helper.remove();
|
|
}
|
|
|
|
$.extend( this, {
|
|
helper: null,
|
|
dragging: false,
|
|
reverting: false,
|
|
_noFinalSort: null
|
|
} );
|
|
|
|
if ( this.domPosition.prev ) {
|
|
$( this.domPosition.prev ).after( this.currentItem );
|
|
} else {
|
|
$( this.domPosition.parent ).prepend( this.currentItem );
|
|
}
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
serialize: function( o ) {
|
|
|
|
var items = this._getItemsAsjQuery( o && o.connected ),
|
|
str = [];
|
|
o = o || {};
|
|
|
|
$( items ).each( function() {
|
|
var res = ( $( o.item || this ).attr( o.attribute || "id" ) || "" )
|
|
.match( o.expression || ( /(.+)[\-=_](.+)/ ) );
|
|
if ( res ) {
|
|
str.push(
|
|
( o.key || res[ 1 ] + "[]" ) +
|
|
"=" + ( o.key && o.expression ? res[ 1 ] : res[ 2 ] ) );
|
|
}
|
|
} );
|
|
|
|
if ( !str.length && o.key ) {
|
|
str.push( o.key + "=" );
|
|
}
|
|
|
|
return str.join( "&" );
|
|
|
|
},
|
|
|
|
toArray: function( o ) {
|
|
|
|
var items = this._getItemsAsjQuery( o && o.connected ),
|
|
ret = [];
|
|
|
|
o = o || {};
|
|
|
|
items.each( function() {
|
|
ret.push( $( o.item || this ).attr( o.attribute || "id" ) || "" );
|
|
} );
|
|
return ret;
|
|
|
|
},
|
|
|
|
/* Be careful with the following core functions */
|
|
_intersectsWith: function( item ) {
|
|
|
|
var x1 = this.positionAbs.left,
|
|
x2 = x1 + this.helperProportions.width,
|
|
y1 = this.positionAbs.top,
|
|
y2 = y1 + this.helperProportions.height,
|
|
l = item.left,
|
|
r = l + item.width,
|
|
t = item.top,
|
|
b = t + item.height,
|
|
dyClick = this.offset.click.top,
|
|
dxClick = this.offset.click.left,
|
|
isOverElementHeight = ( this.options.axis === "x" ) || ( ( y1 + dyClick ) > t &&
|
|
( y1 + dyClick ) < b ),
|
|
isOverElementWidth = ( this.options.axis === "y" ) || ( ( x1 + dxClick ) > l &&
|
|
( x1 + dxClick ) < r ),
|
|
isOverElement = isOverElementHeight && isOverElementWidth;
|
|
|
|
if ( this.options.tolerance === "pointer" ||
|
|
this.options.forcePointerForContainers ||
|
|
( this.options.tolerance !== "pointer" &&
|
|
this.helperProportions[ this.floating ? "width" : "height" ] >
|
|
item[ this.floating ? "width" : "height" ] )
|
|
) {
|
|
return isOverElement;
|
|
} else {
|
|
|
|
return ( l < x1 + ( this.helperProportions.width / 2 ) && // Right Half
|
|
x2 - ( this.helperProportions.width / 2 ) < r && // Left Half
|
|
t < y1 + ( this.helperProportions.height / 2 ) && // Bottom Half
|
|
y2 - ( this.helperProportions.height / 2 ) < b ); // Top Half
|
|
|
|
}
|
|
},
|
|
|
|
_intersectsWithPointer: function( item ) {
|
|
var verticalDirection, horizontalDirection,
|
|
isOverElementHeight = ( this.options.axis === "x" ) ||
|
|
this._isOverAxis(
|
|
this.positionAbs.top + this.offset.click.top, item.top, item.height ),
|
|
isOverElementWidth = ( this.options.axis === "y" ) ||
|
|
this._isOverAxis(
|
|
this.positionAbs.left + this.offset.click.left, item.left, item.width ),
|
|
isOverElement = isOverElementHeight && isOverElementWidth;
|
|
|
|
if ( !isOverElement ) {
|
|
return false;
|
|
}
|
|
|
|
verticalDirection = this.dragDirection.vertical;
|
|
horizontalDirection = this.dragDirection.horizontal;
|
|
|
|
return this.floating ?
|
|
( ( horizontalDirection === "right" || verticalDirection === "down" ) ? 2 : 1 ) :
|
|
( verticalDirection && ( verticalDirection === "down" ? 2 : 1 ) );
|
|
|
|
},
|
|
|
|
_intersectsWithSides: function( item ) {
|
|
|
|
var isOverBottomHalf = this._isOverAxis( this.positionAbs.top +
|
|
this.offset.click.top, item.top + ( item.height / 2 ), item.height ),
|
|
isOverRightHalf = this._isOverAxis( this.positionAbs.left +
|
|
this.offset.click.left, item.left + ( item.width / 2 ), item.width ),
|
|
verticalDirection = this.dragDirection.vertical,
|
|
horizontalDirection = this.dragDirection.horizontal;
|
|
|
|
if ( this.floating && horizontalDirection ) {
|
|
return ( ( horizontalDirection === "right" && isOverRightHalf ) ||
|
|
( horizontalDirection === "left" && !isOverRightHalf ) );
|
|
} else {
|
|
return verticalDirection && ( ( verticalDirection === "down" && isOverBottomHalf ) ||
|
|
( verticalDirection === "up" && !isOverBottomHalf ) );
|
|
}
|
|
|
|
},
|
|
|
|
_getDragVerticalDirection: function() {
|
|
var delta = this.positionAbs.top - this.lastPositionAbs.top;
|
|
return delta !== 0 && ( delta > 0 ? "down" : "up" );
|
|
},
|
|
|
|
_getDragHorizontalDirection: function() {
|
|
var delta = this.positionAbs.left - this.lastPositionAbs.left;
|
|
return delta !== 0 && ( delta > 0 ? "right" : "left" );
|
|
},
|
|
|
|
refresh: function( event ) {
|
|
this._refreshItems( event );
|
|
this._setHandleClassName();
|
|
this.refreshPositions();
|
|
return this;
|
|
},
|
|
|
|
_connectWith: function() {
|
|
var options = this.options;
|
|
return options.connectWith.constructor === String ?
|
|
[ options.connectWith ] :
|
|
options.connectWith;
|
|
},
|
|
|
|
_getItemsAsjQuery: function( connected ) {
|
|
|
|
var i, j, cur, inst,
|
|
items = [],
|
|
queries = [],
|
|
connectWith = this._connectWith();
|
|
|
|
if ( connectWith && connected ) {
|
|
for ( i = connectWith.length - 1; i >= 0; i-- ) {
|
|
cur = $( connectWith[ i ], this.document[ 0 ] );
|
|
for ( j = cur.length - 1; j >= 0; j-- ) {
|
|
inst = $.data( cur[ j ], this.widgetFullName );
|
|
if ( inst && inst !== this && !inst.options.disabled ) {
|
|
queries.push( [ typeof inst.options.items === "function" ?
|
|
inst.options.items.call( inst.element ) :
|
|
$( inst.options.items, inst.element )
|
|
.not( ".ui-sortable-helper" )
|
|
.not( ".ui-sortable-placeholder" ), inst ] );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
queries.push( [ typeof this.options.items === "function" ?
|
|
this.options.items
|
|
.call( this.element, null, { options: this.options, item: this.currentItem } ) :
|
|
$( this.options.items, this.element )
|
|
.not( ".ui-sortable-helper" )
|
|
.not( ".ui-sortable-placeholder" ), this ] );
|
|
|
|
function addItems() {
|
|
items.push( this );
|
|
}
|
|
for ( i = queries.length - 1; i >= 0; i-- ) {
|
|
queries[ i ][ 0 ].each( addItems );
|
|
}
|
|
|
|
return $( items );
|
|
|
|
},
|
|
|
|
_removeCurrentsFromItems: function() {
|
|
|
|
var list = this.currentItem.find( ":data(" + this.widgetName + "-item)" );
|
|
|
|
this.items = $.grep( this.items, function( item ) {
|
|
for ( var j = 0; j < list.length; j++ ) {
|
|
if ( list[ j ] === item.item[ 0 ] ) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
} );
|
|
|
|
},
|
|
|
|
_refreshItems: function( event ) {
|
|
|
|
this.items = [];
|
|
this.containers = [ this ];
|
|
|
|
var i, j, cur, inst, targetData, _queries, item, queriesLength,
|
|
items = this.items,
|
|
queries = [ [ typeof this.options.items === "function" ?
|
|
this.options.items.call( this.element[ 0 ], event, { item: this.currentItem } ) :
|
|
$( this.options.items, this.element ), this ] ],
|
|
connectWith = this._connectWith();
|
|
|
|
//Shouldn't be run the first time through due to massive slow-down
|
|
if ( connectWith && this.ready ) {
|
|
for ( i = connectWith.length - 1; i >= 0; i-- ) {
|
|
cur = $( connectWith[ i ], this.document[ 0 ] );
|
|
for ( j = cur.length - 1; j >= 0; j-- ) {
|
|
inst = $.data( cur[ j ], this.widgetFullName );
|
|
if ( inst && inst !== this && !inst.options.disabled ) {
|
|
queries.push( [ typeof inst.options.items === "function" ?
|
|
inst.options.items
|
|
.call( inst.element[ 0 ], event, { item: this.currentItem } ) :
|
|
$( inst.options.items, inst.element ), inst ] );
|
|
this.containers.push( inst );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for ( i = queries.length - 1; i >= 0; i-- ) {
|
|
targetData = queries[ i ][ 1 ];
|
|
_queries = queries[ i ][ 0 ];
|
|
|
|
for ( j = 0, queriesLength = _queries.length; j < queriesLength; j++ ) {
|
|
item = $( _queries[ j ] );
|
|
|
|
// Data for target checking (mouse manager)
|
|
item.data( this.widgetName + "-item", targetData );
|
|
|
|
items.push( {
|
|
item: item,
|
|
instance: targetData,
|
|
width: 0, height: 0,
|
|
left: 0, top: 0
|
|
} );
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
_refreshItemPositions: function( fast ) {
|
|
var i, item, t, p;
|
|
|
|
for ( i = this.items.length - 1; i >= 0; i-- ) {
|
|
item = this.items[ i ];
|
|
|
|
//We ignore calculating positions of all connected containers when we're not over them
|
|
if ( this.currentContainer && item.instance !== this.currentContainer &&
|
|
item.item[ 0 ] !== this.currentItem[ 0 ] ) {
|
|
continue;
|
|
}
|
|
|
|
t = this.options.toleranceElement ?
|
|
$( this.options.toleranceElement, item.item ) :
|
|
item.item;
|
|
|
|
if ( !fast ) {
|
|
item.width = t.outerWidth();
|
|
item.height = t.outerHeight();
|
|
}
|
|
|
|
p = t.offset();
|
|
item.left = p.left;
|
|
item.top = p.top;
|
|
}
|
|
},
|
|
|
|
refreshPositions: function( fast ) {
|
|
|
|
// Determine whether items are being displayed horizontally
|
|
this.floating = this.items.length ?
|
|
this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) :
|
|
false;
|
|
|
|
// This has to be redone because due to the item being moved out/into the offsetParent,
|
|
// the offsetParent's position will change
|
|
if ( this.offsetParent && this.helper ) {
|
|
this.offset.parent = this._getParentOffset();
|
|
}
|
|
|
|
this._refreshItemPositions( fast );
|
|
|
|
var i, p;
|
|
|
|
if ( this.options.custom && this.options.custom.refreshContainers ) {
|
|
this.options.custom.refreshContainers.call( this );
|
|
} else {
|
|
for ( i = this.containers.length - 1; i >= 0; i-- ) {
|
|
p = this.containers[ i ].element.offset();
|
|
this.containers[ i ].containerCache.left = p.left;
|
|
this.containers[ i ].containerCache.top = p.top;
|
|
this.containers[ i ].containerCache.width =
|
|
this.containers[ i ].element.outerWidth();
|
|
this.containers[ i ].containerCache.height =
|
|
this.containers[ i ].element.outerHeight();
|
|
}
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
_createPlaceholder: function( that ) {
|
|
that = that || this;
|
|
var className, nodeName,
|
|
o = that.options;
|
|
|
|
if ( !o.placeholder || o.placeholder.constructor === String ) {
|
|
className = o.placeholder;
|
|
nodeName = that.currentItem[ 0 ].nodeName.toLowerCase();
|
|
o.placeholder = {
|
|
element: function() {
|
|
|
|
var element = $( "<" + nodeName + ">", that.document[ 0 ] );
|
|
|
|
that._addClass( element, "ui-sortable-placeholder",
|
|
className || that.currentItem[ 0 ].className )
|
|
._removeClass( element, "ui-sortable-helper" );
|
|
|
|
if ( nodeName === "tbody" ) {
|
|
that._createTrPlaceholder(
|
|
that.currentItem.find( "tr" ).eq( 0 ),
|
|
$( "<tr>", that.document[ 0 ] ).appendTo( element )
|
|
);
|
|
} else if ( nodeName === "tr" ) {
|
|
that._createTrPlaceholder( that.currentItem, element );
|
|
} else if ( nodeName === "img" ) {
|
|
element.attr( "src", that.currentItem.attr( "src" ) );
|
|
}
|
|
|
|
if ( !className ) {
|
|
element.css( "visibility", "hidden" );
|
|
}
|
|
|
|
return element;
|
|
},
|
|
update: function( container, p ) {
|
|
|
|
// 1. If a className is set as 'placeholder option, we don't force sizes -
|
|
// the class is responsible for that
|
|
// 2. The option 'forcePlaceholderSize can be enabled to force it even if a
|
|
// class name is specified
|
|
if ( className && !o.forcePlaceholderSize ) {
|
|
return;
|
|
}
|
|
|
|
// If the element doesn't have a actual height or width by itself (without
|
|
// styles coming from a stylesheet), it receives the inline height and width
|
|
// from the dragged item. Or, if it's a tbody or tr, it's going to have a height
|
|
// anyway since we're populating them with <td>s above, but they're unlikely to
|
|
// be the correct height on their own if the row heights are dynamic, so we'll
|
|
// always assign the height of the dragged item given forcePlaceholderSize
|
|
// is true.
|
|
if ( !p.height() || ( o.forcePlaceholderSize &&
|
|
( nodeName === "tbody" || nodeName === "tr" ) ) ) {
|
|
p.height(
|
|
that.currentItem.innerHeight() -
|
|
parseInt( that.currentItem.css( "paddingTop" ) || 0, 10 ) -
|
|
parseInt( that.currentItem.css( "paddingBottom" ) || 0, 10 ) );
|
|
}
|
|
if ( !p.width() ) {
|
|
p.width(
|
|
that.currentItem.innerWidth() -
|
|
parseInt( that.currentItem.css( "paddingLeft" ) || 0, 10 ) -
|
|
parseInt( that.currentItem.css( "paddingRight" ) || 0, 10 ) );
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
//Create the placeholder
|
|
that.placeholder = $( o.placeholder.element.call( that.element, that.currentItem ) );
|
|
|
|
//Append it after the actual current item
|
|
that.currentItem.after( that.placeholder );
|
|
|
|
//Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
|
|
o.placeholder.update( that, that.placeholder );
|
|
|
|
},
|
|
|
|
_createTrPlaceholder: function( sourceTr, targetTr ) {
|
|
var that = this;
|
|
|
|
sourceTr.children().each( function() {
|
|
$( "<td> </td>", that.document[ 0 ] )
|
|
.attr( "colspan", $( this ).attr( "colspan" ) || 1 )
|
|
.appendTo( targetTr );
|
|
} );
|
|
},
|
|
|
|
_contactContainers: function( event ) {
|
|
var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, cur, nearBottom,
|
|
floating, axis,
|
|
innermostContainer = null,
|
|
innermostIndex = null;
|
|
|
|
// Get innermost container that intersects with item
|
|
for ( i = this.containers.length - 1; i >= 0; i-- ) {
|
|
|
|
// Never consider a container that's located within the item itself
|
|
if ( $.contains( this.currentItem[ 0 ], this.containers[ i ].element[ 0 ] ) ) {
|
|
continue;
|
|
}
|
|
|
|
if ( this._intersectsWith( this.containers[ i ].containerCache ) ) {
|
|
|
|
// If we've already found a container and it's more "inner" than this, then continue
|
|
if ( innermostContainer &&
|
|
$.contains(
|
|
this.containers[ i ].element[ 0 ],
|
|
innermostContainer.element[ 0 ] ) ) {
|
|
continue;
|
|
}
|
|
|
|
innermostContainer = this.containers[ i ];
|
|
innermostIndex = i;
|
|
|
|
} else {
|
|
|
|
// container doesn't intersect. trigger "out" event if necessary
|
|
if ( this.containers[ i ].containerCache.over ) {
|
|
this.containers[ i ]._trigger( "out", event, this._uiHash( this ) );
|
|
this.containers[ i ].containerCache.over = 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// If no intersecting containers found, return
|
|
if ( !innermostContainer ) {
|
|
return;
|
|
}
|
|
|
|
// Move the item into the container if it's not there already
|
|
if ( this.containers.length === 1 ) {
|
|
if ( !this.containers[ innermostIndex ].containerCache.over ) {
|
|
this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) );
|
|
this.containers[ innermostIndex ].containerCache.over = 1;
|
|
}
|
|
} else {
|
|
|
|
// When entering a new container, we will find the item with the least distance and
|
|
// append our item near it
|
|
dist = 10000;
|
|
itemWithLeastDistance = null;
|
|
floating = innermostContainer.floating || this._isFloating( this.currentItem );
|
|
posProperty = floating ? "left" : "top";
|
|
sizeProperty = floating ? "width" : "height";
|
|
axis = floating ? "pageX" : "pageY";
|
|
|
|
for ( j = this.items.length - 1; j >= 0; j-- ) {
|
|
if ( !$.contains(
|
|
this.containers[ innermostIndex ].element[ 0 ], this.items[ j ].item[ 0 ] )
|
|
) {
|
|
continue;
|
|
}
|
|
if ( this.items[ j ].item[ 0 ] === this.currentItem[ 0 ] ) {
|
|
continue;
|
|
}
|
|
|
|
cur = this.items[ j ].item.offset()[ posProperty ];
|
|
nearBottom = false;
|
|
if ( event[ axis ] - cur > this.items[ j ][ sizeProperty ] / 2 ) {
|
|
nearBottom = true;
|
|
}
|
|
|
|
if ( Math.abs( event[ axis ] - cur ) < dist ) {
|
|
dist = Math.abs( event[ axis ] - cur );
|
|
itemWithLeastDistance = this.items[ j ];
|
|
this.direction = nearBottom ? "up" : "down";
|
|
}
|
|
}
|
|
|
|
//Check if dropOnEmpty is enabled
|
|
if ( !itemWithLeastDistance && !this.options.dropOnEmpty ) {
|
|
return;
|
|
}
|
|
|
|
if ( this.currentContainer === this.containers[ innermostIndex ] ) {
|
|
if ( !this.currentContainer.containerCache.over ) {
|
|
this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash() );
|
|
this.currentContainer.containerCache.over = 1;
|
|
}
|
|
return;
|
|
}
|
|
|
|
if ( itemWithLeastDistance ) {
|
|
this._rearrange( event, itemWithLeastDistance, null, true );
|
|
} else {
|
|
this._rearrange( event, null, this.containers[ innermostIndex ].element, true );
|
|
}
|
|
this._trigger( "change", event, this._uiHash() );
|
|
this.containers[ innermostIndex ]._trigger( "change", event, this._uiHash( this ) );
|
|
this.currentContainer = this.containers[ innermostIndex ];
|
|
|
|
//Update the placeholder
|
|
this.options.placeholder.update( this.currentContainer, this.placeholder );
|
|
|
|
//Update scrollParent
|
|
this.scrollParent = this.placeholder.scrollParent();
|
|
|
|
//Update overflowOffset
|
|
if ( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
|
|
this.scrollParent[ 0 ].tagName !== "HTML" ) {
|
|
this.overflowOffset = this.scrollParent.offset();
|
|
}
|
|
|
|
this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) );
|
|
this.containers[ innermostIndex ].containerCache.over = 1;
|
|
}
|
|
|
|
},
|
|
|
|
_createHelper: function( event ) {
|
|
|
|
var o = this.options,
|
|
helper = typeof o.helper === "function" ?
|
|
$( o.helper.apply( this.element[ 0 ], [ event, this.currentItem ] ) ) :
|
|
( o.helper === "clone" ? this.currentItem.clone() : this.currentItem );
|
|
|
|
//Add the helper to the DOM if that didn't happen already
|
|
if ( !helper.parents( "body" ).length ) {
|
|
this.appendTo[ 0 ].appendChild( helper[ 0 ] );
|
|
}
|
|
|
|
if ( helper[ 0 ] === this.currentItem[ 0 ] ) {
|
|
this._storedCSS = {
|
|
width: this.currentItem[ 0 ].style.width,
|
|
height: this.currentItem[ 0 ].style.height,
|
|
position: this.currentItem.css( "position" ),
|
|
top: this.currentItem.css( "top" ),
|
|
left: this.currentItem.css( "left" )
|
|
};
|
|
}
|
|
|
|
if ( !helper[ 0 ].style.width || o.forceHelperSize ) {
|
|
helper.width( this.currentItem.width() );
|
|
}
|
|
if ( !helper[ 0 ].style.height || o.forceHelperSize ) {
|
|
helper.height( this.currentItem.height() );
|
|
}
|
|
|
|
return helper;
|
|
|
|
},
|
|
|
|
_adjustOffsetFromHelper: function( obj ) {
|
|
if ( typeof obj === "string" ) {
|
|
obj = obj.split( " " );
|
|
}
|
|
if ( Array.isArray( obj ) ) {
|
|
obj = { left: +obj[ 0 ], top: +obj[ 1 ] || 0 };
|
|
}
|
|
if ( "left" in obj ) {
|
|
this.offset.click.left = obj.left + this.margins.left;
|
|
}
|
|
if ( "right" in obj ) {
|
|
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
|
|
}
|
|
if ( "top" in obj ) {
|
|
this.offset.click.top = obj.top + this.margins.top;
|
|
}
|
|
if ( "bottom" in obj ) {
|
|
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
|
|
}
|
|
},
|
|
|
|
_getParentOffset: function() {
|
|
|
|
//Get the offsetParent and cache its position
|
|
this.offsetParent = this.helper.offsetParent();
|
|
var po = this.offsetParent.offset();
|
|
|
|
// This is a special case where we need to modify a offset calculated on start, since the
|
|
// following happened:
|
|
// 1. The position of the helper is absolute, so it's position is calculated based on the
|
|
// next positioned parent
|
|
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't
|
|
// the document, which means that the scroll is included in the initial calculation of the
|
|
// offset of the parent, and never recalculated upon drag
|
|
if ( this.cssPosition === "absolute" && this.scrollParent[ 0 ] !== this.document[ 0 ] &&
|
|
$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) {
|
|
po.left += this.scrollParent.scrollLeft();
|
|
po.top += this.scrollParent.scrollTop();
|
|
}
|
|
|
|
// This needs to be actually done for all browsers, since pageX/pageY includes this
|
|
// information with an ugly IE fix
|
|
if ( this.offsetParent[ 0 ] === this.document[ 0 ].body ||
|
|
( this.offsetParent[ 0 ].tagName &&
|
|
this.offsetParent[ 0 ].tagName.toLowerCase() === "html" && $.ui.ie ) ) {
|
|
po = { top: 0, left: 0 };
|
|
}
|
|
|
|
return {
|
|
top: po.top + ( parseInt( this.offsetParent.css( "borderTopWidth" ), 10 ) || 0 ),
|
|
left: po.left + ( parseInt( this.offsetParent.css( "borderLeftWidth" ), 10 ) || 0 )
|
|
};
|
|
|
|
},
|
|
|
|
_getRelativeOffset: function() {
|
|
|
|
if ( this.cssPosition === "relative" ) {
|
|
var p = this.currentItem.position();
|
|
return {
|
|
top: p.top - ( parseInt( this.helper.css( "top" ), 10 ) || 0 ) +
|
|
this.scrollParent.scrollTop(),
|
|
left: p.left - ( parseInt( this.helper.css( "left" ), 10 ) || 0 ) +
|
|
this.scrollParent.scrollLeft()
|
|
};
|
|
} else {
|
|
return { top: 0, left: 0 };
|
|
}
|
|
|
|
},
|
|
|
|
_cacheMargins: function() {
|
|
this.margins = {
|
|
left: ( parseInt( this.currentItem.css( "marginLeft" ), 10 ) || 0 ),
|
|
top: ( parseInt( this.currentItem.css( "marginTop" ), 10 ) || 0 )
|
|
};
|
|
},
|
|
|
|
_cacheHelperProportions: function() {
|
|
this.helperProportions = {
|
|
width: this.helper.outerWidth(),
|
|
height: this.helper.outerHeight()
|
|
};
|
|
},
|
|
|
|
_setContainment: function() {
|
|
|
|
var ce, co, over,
|
|
o = this.options;
|
|
if ( o.containment === "parent" ) {
|
|
o.containment = this.helper[ 0 ].parentNode;
|
|
}
|
|
if ( o.containment === "document" || o.containment === "window" ) {
|
|
this.containment = [
|
|
0 - this.offset.relative.left - this.offset.parent.left,
|
|
0 - this.offset.relative.top - this.offset.parent.top,
|
|
o.containment === "document" ?
|
|
this.document.width() :
|
|
this.window.width() - this.helperProportions.width - this.margins.left,
|
|
( o.containment === "document" ?
|
|
( this.document.height() || document.body.parentNode.scrollHeight ) :
|
|
this.window.height() || this.document[ 0 ].body.parentNode.scrollHeight
|
|
) - this.helperProportions.height - this.margins.top
|
|
];
|
|
}
|
|
|
|
if ( !( /^(document|window|parent)$/ ).test( o.containment ) ) {
|
|
ce = $( o.containment )[ 0 ];
|
|
co = $( o.containment ).offset();
|
|
over = ( $( ce ).css( "overflow" ) !== "hidden" );
|
|
|
|
this.containment = [
|
|
co.left + ( parseInt( $( ce ).css( "borderLeftWidth" ), 10 ) || 0 ) +
|
|
( parseInt( $( ce ).css( "paddingLeft" ), 10 ) || 0 ) - this.margins.left,
|
|
co.top + ( parseInt( $( ce ).css( "borderTopWidth" ), 10 ) || 0 ) +
|
|
( parseInt( $( ce ).css( "paddingTop" ), 10 ) || 0 ) - this.margins.top,
|
|
co.left + ( over ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) -
|
|
( parseInt( $( ce ).css( "borderLeftWidth" ), 10 ) || 0 ) -
|
|
( parseInt( $( ce ).css( "paddingRight" ), 10 ) || 0 ) -
|
|
this.helperProportions.width - this.margins.left,
|
|
co.top + ( over ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) -
|
|
( parseInt( $( ce ).css( "borderTopWidth" ), 10 ) || 0 ) -
|
|
( parseInt( $( ce ).css( "paddingBottom" ), 10 ) || 0 ) -
|
|
this.helperProportions.height - this.margins.top
|
|
];
|
|
}
|
|
|
|
},
|
|
|
|
_convertPositionTo: function( d, pos ) {
|
|
|
|
if ( !pos ) {
|
|
pos = this.position;
|
|
}
|
|
var mod = d === "absolute" ? 1 : -1,
|
|
scroll = this.cssPosition === "absolute" &&
|
|
!( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
|
|
$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ?
|
|
this.offsetParent :
|
|
this.scrollParent,
|
|
scrollIsRootNode = ( /(html|body)/i ).test( scroll[ 0 ].tagName );
|
|
|
|
return {
|
|
top: (
|
|
|
|
// The absolute mouse position
|
|
pos.top +
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.top * mod +
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.top * mod -
|
|
( ( this.cssPosition === "fixed" ?
|
|
-this.scrollParent.scrollTop() :
|
|
( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod )
|
|
),
|
|
left: (
|
|
|
|
// The absolute mouse position
|
|
pos.left +
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.left * mod +
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.left * mod -
|
|
( ( this.cssPosition === "fixed" ?
|
|
-this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 :
|
|
scroll.scrollLeft() ) * mod )
|
|
)
|
|
};
|
|
|
|
},
|
|
|
|
_generatePosition: function( event ) {
|
|
|
|
var top, left,
|
|
o = this.options,
|
|
pageX = event.pageX,
|
|
pageY = event.pageY,
|
|
scroll = this.cssPosition === "absolute" &&
|
|
!( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
|
|
$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ?
|
|
this.offsetParent :
|
|
this.scrollParent,
|
|
scrollIsRootNode = ( /(html|body)/i ).test( scroll[ 0 ].tagName );
|
|
|
|
// This is another very weird special case that only happens for relative elements:
|
|
// 1. If the css position is relative
|
|
// 2. and the scroll parent is the document or similar to the offset parent
|
|
// we have to refresh the relative offset during the scroll so there are no jumps
|
|
if ( this.cssPosition === "relative" && !( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
|
|
this.scrollParent[ 0 ] !== this.offsetParent[ 0 ] ) ) {
|
|
this.offset.relative = this._getRelativeOffset();
|
|
}
|
|
|
|
/*
|
|
* - Position constraining -
|
|
* Constrain the position to a mix of grid, containment.
|
|
*/
|
|
|
|
if ( this.originalPosition ) { //If we are not dragging yet, we won't check for options
|
|
|
|
if ( this.containment ) {
|
|
if ( event.pageX - this.offset.click.left < this.containment[ 0 ] ) {
|
|
pageX = this.containment[ 0 ] + this.offset.click.left;
|
|
}
|
|
if ( event.pageY - this.offset.click.top < this.containment[ 1 ] ) {
|
|
pageY = this.containment[ 1 ] + this.offset.click.top;
|
|
}
|
|
if ( event.pageX - this.offset.click.left > this.containment[ 2 ] ) {
|
|
pageX = this.containment[ 2 ] + this.offset.click.left;
|
|
}
|
|
if ( event.pageY - this.offset.click.top > this.containment[ 3 ] ) {
|
|
pageY = this.containment[ 3 ] + this.offset.click.top;
|
|
}
|
|
}
|
|
|
|
if ( o.grid ) {
|
|
top = this.originalPageY + Math.round( ( pageY - this.originalPageY ) /
|
|
o.grid[ 1 ] ) * o.grid[ 1 ];
|
|
pageY = this.containment ?
|
|
( ( top - this.offset.click.top >= this.containment[ 1 ] &&
|
|
top - this.offset.click.top <= this.containment[ 3 ] ) ?
|
|
top :
|
|
( ( top - this.offset.click.top >= this.containment[ 1 ] ) ?
|
|
top - o.grid[ 1 ] : top + o.grid[ 1 ] ) ) :
|
|
top;
|
|
|
|
left = this.originalPageX + Math.round( ( pageX - this.originalPageX ) /
|
|
o.grid[ 0 ] ) * o.grid[ 0 ];
|
|
pageX = this.containment ?
|
|
( ( left - this.offset.click.left >= this.containment[ 0 ] &&
|
|
left - this.offset.click.left <= this.containment[ 2 ] ) ?
|
|
left :
|
|
( ( left - this.offset.click.left >= this.containment[ 0 ] ) ?
|
|
left - o.grid[ 0 ] : left + o.grid[ 0 ] ) ) :
|
|
left;
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
top: (
|
|
|
|
// The absolute mouse position
|
|
pageY -
|
|
|
|
// Click offset (relative to the element)
|
|
this.offset.click.top -
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.top -
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.top +
|
|
( ( this.cssPosition === "fixed" ?
|
|
-this.scrollParent.scrollTop() :
|
|
( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) )
|
|
),
|
|
left: (
|
|
|
|
// The absolute mouse position
|
|
pageX -
|
|
|
|
// Click offset (relative to the element)
|
|
this.offset.click.left -
|
|
|
|
// Only for relative positioned nodes: Relative offset from element to offset parent
|
|
this.offset.relative.left -
|
|
|
|
// The offsetParent's offset without borders (offset + border)
|
|
this.offset.parent.left +
|
|
( ( this.cssPosition === "fixed" ?
|
|
-this.scrollParent.scrollLeft() :
|
|
scrollIsRootNode ? 0 : scroll.scrollLeft() ) )
|
|
)
|
|
};
|
|
|
|
},
|
|
|
|
_rearrange: function( event, i, a, hardRefresh ) {
|
|
|
|
if ( a ) {
|
|
a[ 0 ].appendChild( this.placeholder[ 0 ] );
|
|
} else {
|
|
i.item[ 0 ].parentNode.insertBefore( this.placeholder[ 0 ],
|
|
( this.direction === "down" ? i.item[ 0 ] : i.item[ 0 ].nextSibling ) );
|
|
}
|
|
|
|
//Various things done here to improve the performance:
|
|
// 1. we create a setTimeout, that calls refreshPositions
|
|
// 2. on the instance, we have a counter variable, that get's higher after every append
|
|
// 3. on the local scope, we copy the counter variable, and check in the timeout,
|
|
// if it's still the same
|
|
// 4. this lets only the last addition to the timeout stack through
|
|
this.counter = this.counter ? ++this.counter : 1;
|
|
var counter = this.counter;
|
|
|
|
this._delay( function() {
|
|
if ( counter === this.counter ) {
|
|
|
|
//Precompute after each DOM insertion, NOT on mousemove
|
|
this.refreshPositions( !hardRefresh );
|
|
}
|
|
} );
|
|
|
|
},
|
|
|
|
_clear: function( event, noPropagation ) {
|
|
|
|
this.reverting = false;
|
|
|
|
// We delay all events that have to be triggered to after the point where the placeholder
|
|
// has been removed and everything else normalized again
|
|
var i,
|
|
delayedTriggers = [];
|
|
|
|
// We first have to update the dom position of the actual currentItem
|
|
// Note: don't do it if the current item is already removed (by a user), or it gets
|
|
// reappended (see #4088)
|
|
if ( !this._noFinalSort && this.currentItem.parent().length ) {
|
|
this.placeholder.before( this.currentItem );
|
|
}
|
|
this._noFinalSort = null;
|
|
|
|
if ( this.helper[ 0 ] === this.currentItem[ 0 ] ) {
|
|
for ( i in this._storedCSS ) {
|
|
if ( this._storedCSS[ i ] === "auto" || this._storedCSS[ i ] === "static" ) {
|
|
this._storedCSS[ i ] = "";
|
|
}
|
|
}
|
|
this.currentItem.css( this._storedCSS );
|
|
this._removeClass( this.currentItem, "ui-sortable-helper" );
|
|
} else {
|
|
this.currentItem.show();
|
|
}
|
|
|
|
if ( this.fromOutside && !noPropagation ) {
|
|
delayedTriggers.push( function( event ) {
|
|
this._trigger( "receive", event, this._uiHash( this.fromOutside ) );
|
|
} );
|
|
}
|
|
if ( ( this.fromOutside ||
|
|
this.domPosition.prev !==
|
|
this.currentItem.prev().not( ".ui-sortable-helper" )[ 0 ] ||
|
|
this.domPosition.parent !== this.currentItem.parent()[ 0 ] ) && !noPropagation ) {
|
|
|
|
// Trigger update callback if the DOM position has changed
|
|
delayedTriggers.push( function( event ) {
|
|
this._trigger( "update", event, this._uiHash() );
|
|
} );
|
|
}
|
|
|
|
// Check if the items Container has Changed and trigger appropriate
|
|
// events.
|
|
if ( this !== this.currentContainer ) {
|
|
if ( !noPropagation ) {
|
|
delayedTriggers.push( function( event ) {
|
|
this._trigger( "remove", event, this._uiHash() );
|
|
} );
|
|
delayedTriggers.push( ( function( c ) {
|
|
return function( event ) {
|
|
c._trigger( "receive", event, this._uiHash( this ) );
|
|
};
|
|
} ).call( this, this.currentContainer ) );
|
|
delayedTriggers.push( ( function( c ) {
|
|
return function( event ) {
|
|
c._trigger( "update", event, this._uiHash( this ) );
|
|
};
|
|
} ).call( this, this.currentContainer ) );
|
|
}
|
|
}
|
|
|
|
//Post events to containers
|
|
function delayEvent( type, instance, container ) {
|
|
return function( event ) {
|
|
container._trigger( type, event, instance._uiHash( instance ) );
|
|
};
|
|
}
|
|
for ( i = this.containers.length - 1; i >= 0; i-- ) {
|
|
if ( !noPropagation ) {
|
|
delayedTriggers.push( delayEvent( "deactivate", this, this.containers[ i ] ) );
|
|
}
|
|
if ( this.containers[ i ].containerCache.over ) {
|
|
delayedTriggers.push( delayEvent( "out", this, this.containers[ i ] ) );
|
|
this.containers[ i ].containerCache.over = 0;
|
|
}
|
|
}
|
|
|
|
//Do what was originally in plugins
|
|
if ( this.storedCursor ) {
|
|
this.document.find( "body" ).css( "cursor", this.storedCursor );
|
|
this.storedStylesheet.remove();
|
|
}
|
|
if ( this._storedOpacity ) {
|
|
this.helper.css( "opacity", this._storedOpacity );
|
|
}
|
|
if ( this._storedZIndex ) {
|
|
this.helper.css( "zIndex", this._storedZIndex === "auto" ? "" : this._storedZIndex );
|
|
}
|
|
|
|
this.dragging = false;
|
|
|
|
if ( !noPropagation ) {
|
|
this._trigger( "beforeStop", event, this._uiHash() );
|
|
}
|
|
|
|
//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately,
|
|
// it unbinds ALL events from the original node!
|
|
this.placeholder[ 0 ].parentNode.removeChild( this.placeholder[ 0 ] );
|
|
|
|
if ( !this.cancelHelperRemoval ) {
|
|
if ( this.helper[ 0 ] !== this.currentItem[ 0 ] ) {
|
|
this.helper.remove();
|
|
}
|
|
this.helper = null;
|
|
}
|
|
|
|
if ( !noPropagation ) {
|
|
for ( i = 0; i < delayedTriggers.length; i++ ) {
|
|
|
|
// Trigger all delayed events
|
|
delayedTriggers[ i ].call( this, event );
|
|
}
|
|
this._trigger( "stop", event, this._uiHash() );
|
|
}
|
|
|
|
this.fromOutside = false;
|
|
return !this.cancelHelperRemoval;
|
|
|
|
},
|
|
|
|
_trigger: function() {
|
|
if ( $.Widget.prototype._trigger.apply( this, arguments ) === false ) {
|
|
this.cancel();
|
|
}
|
|
},
|
|
|
|
_uiHash: function( _inst ) {
|
|
var inst = _inst || this;
|
|
return {
|
|
helper: inst.helper,
|
|
placeholder: inst.placeholder || $( [] ),
|
|
position: inst.position,
|
|
originalPosition: inst.originalPosition,
|
|
offset: inst.positionAbs,
|
|
item: inst.currentItem,
|
|
sender: _inst ? _inst.element : null
|
|
};
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
/*!
|
|
* jQuery UI Controlgroup 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Controlgroup
|
|
//>>group: Widgets
|
|
//>>description: Visually groups form control widgets
|
|
//>>docs: http://api.jqueryui.com/controlgroup/
|
|
//>>demos: http://jqueryui.com/controlgroup/
|
|
//>>css.structure: ../../themes/base/core.css
|
|
//>>css.structure: ../../themes/base/controlgroup.css
|
|
//>>css.theme: ../../themes/base/theme.css
|
|
|
|
|
|
var controlgroupCornerRegex = /ui-corner-([a-z]){2,6}/g;
|
|
|
|
var widgetsControlgroup = $.widget( "ui.controlgroup", {
|
|
version: "1.13.1",
|
|
defaultElement: "<div>",
|
|
options: {
|
|
direction: "horizontal",
|
|
disabled: null,
|
|
onlyVisible: true,
|
|
items: {
|
|
"button": "input[type=button], input[type=submit], input[type=reset], button, a",
|
|
"controlgroupLabel": ".ui-controlgroup-label",
|
|
"checkboxradio": "input[type='checkbox'], input[type='radio']",
|
|
"selectmenu": "select",
|
|
"spinner": ".ui-spinner-input"
|
|
}
|
|
},
|
|
|
|
_create: function() {
|
|
this._enhance();
|
|
},
|
|
|
|
// To support the enhanced option in jQuery Mobile, we isolate DOM manipulation
|
|
_enhance: function() {
|
|
this.element.attr( "role", "toolbar" );
|
|
this.refresh();
|
|
},
|
|
|
|
_destroy: function() {
|
|
this._callChildMethod( "destroy" );
|
|
this.childWidgets.removeData( "ui-controlgroup-data" );
|
|
this.element.removeAttr( "role" );
|
|
if ( this.options.items.controlgroupLabel ) {
|
|
this.element
|
|
.find( this.options.items.controlgroupLabel )
|
|
.find( ".ui-controlgroup-label-contents" )
|
|
.contents().unwrap();
|
|
}
|
|
},
|
|
|
|
_initWidgets: function() {
|
|
var that = this,
|
|
childWidgets = [];
|
|
|
|
// First we iterate over each of the items options
|
|
$.each( this.options.items, function( widget, selector ) {
|
|
var labels;
|
|
var options = {};
|
|
|
|
// Make sure the widget has a selector set
|
|
if ( !selector ) {
|
|
return;
|
|
}
|
|
|
|
if ( widget === "controlgroupLabel" ) {
|
|
labels = that.element.find( selector );
|
|
labels.each( function() {
|
|
var element = $( this );
|
|
|
|
if ( element.children( ".ui-controlgroup-label-contents" ).length ) {
|
|
return;
|
|
}
|
|
element.contents()
|
|
.wrapAll( "<span class='ui-controlgroup-label-contents'></span>" );
|
|
} );
|
|
that._addClass( labels, null, "ui-widget ui-widget-content ui-state-default" );
|
|
childWidgets = childWidgets.concat( labels.get() );
|
|
return;
|
|
}
|
|
|
|
// Make sure the widget actually exists
|
|
if ( !$.fn[ widget ] ) {
|
|
return;
|
|
}
|
|
|
|
// We assume everything is in the middle to start because we can't determine
|
|
// first / last elements until all enhancments are done.
|
|
if ( that[ "_" + widget + "Options" ] ) {
|
|
options = that[ "_" + widget + "Options" ]( "middle" );
|
|
} else {
|
|
options = { classes: {} };
|
|
}
|
|
|
|
// Find instances of this widget inside controlgroup and init them
|
|
that.element
|
|
.find( selector )
|
|
.each( function() {
|
|
var element = $( this );
|
|
var instance = element[ widget ]( "instance" );
|
|
|
|
// We need to clone the default options for this type of widget to avoid
|
|
// polluting the variable options which has a wider scope than a single widget.
|
|
var instanceOptions = $.widget.extend( {}, options );
|
|
|
|
// If the button is the child of a spinner ignore it
|
|
// TODO: Find a more generic solution
|
|
if ( widget === "button" && element.parent( ".ui-spinner" ).length ) {
|
|
return;
|
|
}
|
|
|
|
// Create the widget if it doesn't exist
|
|
if ( !instance ) {
|
|
instance = element[ widget ]()[ widget ]( "instance" );
|
|
}
|
|
if ( instance ) {
|
|
instanceOptions.classes =
|
|
that._resolveClassesValues( instanceOptions.classes, instance );
|
|
}
|
|
element[ widget ]( instanceOptions );
|
|
|
|
// Store an instance of the controlgroup to be able to reference
|
|
// from the outermost element for changing options and refresh
|
|
var widgetElement = element[ widget ]( "widget" );
|
|
$.data( widgetElement[ 0 ], "ui-controlgroup-data",
|
|
instance ? instance : element[ widget ]( "instance" ) );
|
|
|
|
childWidgets.push( widgetElement[ 0 ] );
|
|
} );
|
|
} );
|
|
|
|
this.childWidgets = $( $.uniqueSort( childWidgets ) );
|
|
this._addClass( this.childWidgets, "ui-controlgroup-item" );
|
|
},
|
|
|
|
_callChildMethod: function( method ) {
|
|
this.childWidgets.each( function() {
|
|
var element = $( this ),
|
|
data = element.data( "ui-controlgroup-data" );
|
|
if ( data && data[ method ] ) {
|
|
data[ method ]();
|
|
}
|
|
} );
|
|
},
|
|
|
|
_updateCornerClass: function( element, position ) {
|
|
var remove = "ui-corner-top ui-corner-bottom ui-corner-left ui-corner-right ui-corner-all";
|
|
var add = this._buildSimpleOptions( position, "label" ).classes.label;
|
|
|
|
this._removeClass( element, null, remove );
|
|
this._addClass( element, null, add );
|
|
},
|
|
|
|
_buildSimpleOptions: function( position, key ) {
|
|
var direction = this.options.direction === "vertical";
|
|
var result = {
|
|
classes: {}
|
|
};
|
|
result.classes[ key ] = {
|
|
"middle": "",
|
|
"first": "ui-corner-" + ( direction ? "top" : "left" ),
|
|
"last": "ui-corner-" + ( direction ? "bottom" : "right" ),
|
|
"only": "ui-corner-all"
|
|
}[ position ];
|
|
|
|
return result;
|
|
},
|
|
|
|
_spinnerOptions: function( position ) {
|
|
var options = this._buildSimpleOptions( position, "ui-spinner" );
|
|
|
|
options.classes[ "ui-spinner-up" ] = "";
|
|
options.classes[ "ui-spinner-down" ] = "";
|
|
|
|
return options;
|
|
},
|
|
|
|
_buttonOptions: function( position ) {
|
|
return this._buildSimpleOptions( position, "ui-button" );
|
|
},
|
|
|
|
_checkboxradioOptions: function( position ) {
|
|
return this._buildSimpleOptions( position, "ui-checkboxradio-label" );
|
|
},
|
|
|
|
_selectmenuOptions: function( position ) {
|
|
var direction = this.options.direction === "vertical";
|
|
return {
|
|
width: direction ? "auto" : false,
|
|
classes: {
|
|
middle: {
|
|
"ui-selectmenu-button-open": "",
|
|
"ui-selectmenu-button-closed": ""
|
|
},
|
|
first: {
|
|
"ui-selectmenu-button-open": "ui-corner-" + ( direction ? "top" : "tl" ),
|
|
"ui-selectmenu-button-closed": "ui-corner-" + ( direction ? "top" : "left" )
|
|
},
|
|
last: {
|
|
"ui-selectmenu-button-open": direction ? "" : "ui-corner-tr",
|
|
"ui-selectmenu-button-closed": "ui-corner-" + ( direction ? "bottom" : "right" )
|
|
},
|
|
only: {
|
|
"ui-selectmenu-button-open": "ui-corner-top",
|
|
"ui-selectmenu-button-closed": "ui-corner-all"
|
|
}
|
|
|
|
}[ position ]
|
|
};
|
|
},
|
|
|
|
_resolveClassesValues: function( classes, instance ) {
|
|
var result = {};
|
|
$.each( classes, function( key ) {
|
|
var current = instance.options.classes[ key ] || "";
|
|
current = String.prototype.trim.call( current.replace( controlgroupCornerRegex, "" ) );
|
|
result[ key ] = ( current + " " + classes[ key ] ).replace( /\s+/g, " " );
|
|
} );
|
|
return result;
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
if ( key === "direction" ) {
|
|
this._removeClass( "ui-controlgroup-" + this.options.direction );
|
|
}
|
|
|
|
this._super( key, value );
|
|
if ( key === "disabled" ) {
|
|
this._callChildMethod( value ? "disable" : "enable" );
|
|
return;
|
|
}
|
|
|
|
this.refresh();
|
|
},
|
|
|
|
refresh: function() {
|
|
var children,
|
|
that = this;
|
|
|
|
this._addClass( "ui-controlgroup ui-controlgroup-" + this.options.direction );
|
|
|
|
if ( this.options.direction === "horizontal" ) {
|
|
this._addClass( null, "ui-helper-clearfix" );
|
|
}
|
|
this._initWidgets();
|
|
|
|
children = this.childWidgets;
|
|
|
|
// We filter here because we need to track all childWidgets not just the visible ones
|
|
if ( this.options.onlyVisible ) {
|
|
children = children.filter( ":visible" );
|
|
}
|
|
|
|
if ( children.length ) {
|
|
|
|
// We do this last because we need to make sure all enhancment is done
|
|
// before determining first and last
|
|
$.each( [ "first", "last" ], function( index, value ) {
|
|
var instance = children[ value ]().data( "ui-controlgroup-data" );
|
|
|
|
if ( instance && that[ "_" + instance.widgetName + "Options" ] ) {
|
|
var options = that[ "_" + instance.widgetName + "Options" ](
|
|
children.length === 1 ? "only" : value
|
|
);
|
|
options.classes = that._resolveClassesValues( options.classes, instance );
|
|
instance.element[ instance.widgetName ]( options );
|
|
} else {
|
|
that._updateCornerClass( children[ value ](), value );
|
|
}
|
|
} );
|
|
|
|
// Finally call the refresh method on each of the child widgets.
|
|
this._callChildMethod( "refresh" );
|
|
}
|
|
}
|
|
} );
|
|
|
|
/*!
|
|
* jQuery UI Checkboxradio 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Checkboxradio
|
|
//>>group: Widgets
|
|
//>>description: Enhances a form with multiple themeable checkboxes or radio buttons.
|
|
//>>docs: http://api.jqueryui.com/checkboxradio/
|
|
//>>demos: http://jqueryui.com/checkboxradio/
|
|
//>>css.structure: ../../themes/base/core.css
|
|
//>>css.structure: ../../themes/base/button.css
|
|
//>>css.structure: ../../themes/base/checkboxradio.css
|
|
//>>css.theme: ../../themes/base/theme.css
|
|
|
|
|
|
$.widget( "ui.checkboxradio", [ $.ui.formResetMixin, {
|
|
version: "1.13.1",
|
|
options: {
|
|
disabled: null,
|
|
label: null,
|
|
icon: true,
|
|
classes: {
|
|
"ui-checkboxradio-label": "ui-corner-all",
|
|
"ui-checkboxradio-icon": "ui-corner-all"
|
|
}
|
|
},
|
|
|
|
_getCreateOptions: function() {
|
|
var disabled, labels;
|
|
var that = this;
|
|
var options = this._super() || {};
|
|
|
|
// We read the type here, because it makes more sense to throw a element type error first,
|
|
// rather then the error for lack of a label. Often if its the wrong type, it
|
|
// won't have a label (e.g. calling on a div, btn, etc)
|
|
this._readType();
|
|
|
|
labels = this.element.labels();
|
|
|
|
// If there are multiple labels, use the last one
|
|
this.label = $( labels[ labels.length - 1 ] );
|
|
if ( !this.label.length ) {
|
|
$.error( "No label found for checkboxradio widget" );
|
|
}
|
|
|
|
this.originalLabel = "";
|
|
|
|
// We need to get the label text but this may also need to make sure it does not contain the
|
|
// input itself.
|
|
this.label.contents().not( this.element[ 0 ] ).each( function() {
|
|
|
|
// The label contents could be text, html, or a mix. We concat each element to get a
|
|
// string representation of the label, without the input as part of it.
|
|
that.originalLabel += this.nodeType === 3 ? $( this ).text() : this.outerHTML;
|
|
} );
|
|
|
|
// Set the label option if we found label text
|
|
if ( this.originalLabel ) {
|
|
options.label = this.originalLabel;
|
|
}
|
|
|
|
disabled = this.element[ 0 ].disabled;
|
|
if ( disabled != null ) {
|
|
options.disabled = disabled;
|
|
}
|
|
return options;
|
|
},
|
|
|
|
_create: function() {
|
|
var checked = this.element[ 0 ].checked;
|
|
|
|
this._bindFormResetHandler();
|
|
|
|
if ( this.options.disabled == null ) {
|
|
this.options.disabled = this.element[ 0 ].disabled;
|
|
}
|
|
|
|
this._setOption( "disabled", this.options.disabled );
|
|
this._addClass( "ui-checkboxradio", "ui-helper-hidden-accessible" );
|
|
this._addClass( this.label, "ui-checkboxradio-label", "ui-button ui-widget" );
|
|
|
|
if ( this.type === "radio" ) {
|
|
this._addClass( this.label, "ui-checkboxradio-radio-label" );
|
|
}
|
|
|
|
if ( this.options.label && this.options.label !== this.originalLabel ) {
|
|
this._updateLabel();
|
|
} else if ( this.originalLabel ) {
|
|
this.options.label = this.originalLabel;
|
|
}
|
|
|
|
this._enhance();
|
|
|
|
if ( checked ) {
|
|
this._addClass( this.label, "ui-checkboxradio-checked", "ui-state-active" );
|
|
}
|
|
|
|
this._on( {
|
|
change: "_toggleClasses",
|
|
focus: function() {
|
|
this._addClass( this.label, null, "ui-state-focus ui-visual-focus" );
|
|
},
|
|
blur: function() {
|
|
this._removeClass( this.label, null, "ui-state-focus ui-visual-focus" );
|
|
}
|
|
} );
|
|
},
|
|
|
|
_readType: function() {
|
|
var nodeName = this.element[ 0 ].nodeName.toLowerCase();
|
|
this.type = this.element[ 0 ].type;
|
|
if ( nodeName !== "input" || !/radio|checkbox/.test( this.type ) ) {
|
|
$.error( "Can't create checkboxradio on element.nodeName=" + nodeName +
|
|
" and element.type=" + this.type );
|
|
}
|
|
},
|
|
|
|
// Support jQuery Mobile enhanced option
|
|
_enhance: function() {
|
|
this._updateIcon( this.element[ 0 ].checked );
|
|
},
|
|
|
|
widget: function() {
|
|
return this.label;
|
|
},
|
|
|
|
_getRadioGroup: function() {
|
|
var group;
|
|
var name = this.element[ 0 ].name;
|
|
var nameSelector = "input[name='" + $.escapeSelector( name ) + "']";
|
|
|
|
if ( !name ) {
|
|
return $( [] );
|
|
}
|
|
|
|
if ( this.form.length ) {
|
|
group = $( this.form[ 0 ].elements ).filter( nameSelector );
|
|
} else {
|
|
|
|
// Not inside a form, check all inputs that also are not inside a form
|
|
group = $( nameSelector ).filter( function() {
|
|
return $( this )._form().length === 0;
|
|
} );
|
|
}
|
|
|
|
return group.not( this.element );
|
|
},
|
|
|
|
_toggleClasses: function() {
|
|
var checked = this.element[ 0 ].checked;
|
|
this._toggleClass( this.label, "ui-checkboxradio-checked", "ui-state-active", checked );
|
|
|
|
if ( this.options.icon && this.type === "checkbox" ) {
|
|
this._toggleClass( this.icon, null, "ui-icon-check ui-state-checked", checked )
|
|
._toggleClass( this.icon, null, "ui-icon-blank", !checked );
|
|
}
|
|
|
|
if ( this.type === "radio" ) {
|
|
this._getRadioGroup()
|
|
.each( function() {
|
|
var instance = $( this ).checkboxradio( "instance" );
|
|
|
|
if ( instance ) {
|
|
instance._removeClass( instance.label,
|
|
"ui-checkboxradio-checked", "ui-state-active" );
|
|
}
|
|
} );
|
|
}
|
|
},
|
|
|
|
_destroy: function() {
|
|
this._unbindFormResetHandler();
|
|
|
|
if ( this.icon ) {
|
|
this.icon.remove();
|
|
this.iconSpace.remove();
|
|
}
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
|
|
// We don't allow the value to be set to nothing
|
|
if ( key === "label" && !value ) {
|
|
return;
|
|
}
|
|
|
|
this._super( key, value );
|
|
|
|
if ( key === "disabled" ) {
|
|
this._toggleClass( this.label, null, "ui-state-disabled", value );
|
|
this.element[ 0 ].disabled = value;
|
|
|
|
// Don't refresh when setting disabled
|
|
return;
|
|
}
|
|
this.refresh();
|
|
},
|
|
|
|
_updateIcon: function( checked ) {
|
|
var toAdd = "ui-icon ui-icon-background ";
|
|
|
|
if ( this.options.icon ) {
|
|
if ( !this.icon ) {
|
|
this.icon = $( "<span>" );
|
|
this.iconSpace = $( "<span> </span>" );
|
|
this._addClass( this.iconSpace, "ui-checkboxradio-icon-space" );
|
|
}
|
|
|
|
if ( this.type === "checkbox" ) {
|
|
toAdd += checked ? "ui-icon-check ui-state-checked" : "ui-icon-blank";
|
|
this._removeClass( this.icon, null, checked ? "ui-icon-blank" : "ui-icon-check" );
|
|
} else {
|
|
toAdd += "ui-icon-blank";
|
|
}
|
|
this._addClass( this.icon, "ui-checkboxradio-icon", toAdd );
|
|
if ( !checked ) {
|
|
this._removeClass( this.icon, null, "ui-icon-check ui-state-checked" );
|
|
}
|
|
this.icon.prependTo( this.label ).after( this.iconSpace );
|
|
} else if ( this.icon !== undefined ) {
|
|
this.icon.remove();
|
|
this.iconSpace.remove();
|
|
delete this.icon;
|
|
}
|
|
},
|
|
|
|
_updateLabel: function() {
|
|
|
|
// Remove the contents of the label ( minus the icon, icon space, and input )
|
|
var contents = this.label.contents().not( this.element[ 0 ] );
|
|
if ( this.icon ) {
|
|
contents = contents.not( this.icon[ 0 ] );
|
|
}
|
|
if ( this.iconSpace ) {
|
|
contents = contents.not( this.iconSpace[ 0 ] );
|
|
}
|
|
contents.remove();
|
|
|
|
this.label.append( this.options.label );
|
|
},
|
|
|
|
refresh: function() {
|
|
var checked = this.element[ 0 ].checked,
|
|
isDisabled = this.element[ 0 ].disabled;
|
|
|
|
this._updateIcon( checked );
|
|
this._toggleClass( this.label, "ui-checkboxradio-checked", "ui-state-active", checked );
|
|
if ( this.options.label !== null ) {
|
|
this._updateLabel();
|
|
}
|
|
|
|
if ( isDisabled !== this.options.disabled ) {
|
|
this._setOptions( { "disabled": isDisabled } );
|
|
}
|
|
}
|
|
|
|
} ] );
|
|
|
|
var widgetsCheckboxradio = $.ui.checkboxradio;
|
|
|
|
|
|
/*!
|
|
* jQuery UI Button 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Button
|
|
//>>group: Widgets
|
|
//>>description: Enhances a form with themeable buttons.
|
|
//>>docs: http://api.jqueryui.com/button/
|
|
//>>demos: http://jqueryui.com/button/
|
|
//>>css.structure: ../../themes/base/core.css
|
|
//>>css.structure: ../../themes/base/button.css
|
|
//>>css.theme: ../../themes/base/theme.css
|
|
|
|
|
|
$.widget( "ui.button", {
|
|
version: "1.13.1",
|
|
defaultElement: "<button>",
|
|
options: {
|
|
classes: {
|
|
"ui-button": "ui-corner-all"
|
|
},
|
|
disabled: null,
|
|
icon: null,
|
|
iconPosition: "beginning",
|
|
label: null,
|
|
showLabel: true
|
|
},
|
|
|
|
_getCreateOptions: function() {
|
|
var disabled,
|
|
|
|
// This is to support cases like in jQuery Mobile where the base widget does have
|
|
// an implementation of _getCreateOptions
|
|
options = this._super() || {};
|
|
|
|
this.isInput = this.element.is( "input" );
|
|
|
|
disabled = this.element[ 0 ].disabled;
|
|
if ( disabled != null ) {
|
|
options.disabled = disabled;
|
|
}
|
|
|
|
this.originalLabel = this.isInput ? this.element.val() : this.element.html();
|
|
if ( this.originalLabel ) {
|
|
options.label = this.originalLabel;
|
|
}
|
|
|
|
return options;
|
|
},
|
|
|
|
_create: function() {
|
|
if ( !this.option.showLabel & !this.options.icon ) {
|
|
this.options.showLabel = true;
|
|
}
|
|
|
|
// We have to check the option again here even though we did in _getCreateOptions,
|
|
// because null may have been passed on init which would override what was set in
|
|
// _getCreateOptions
|
|
if ( this.options.disabled == null ) {
|
|
this.options.disabled = this.element[ 0 ].disabled || false;
|
|
}
|
|
|
|
this.hasTitle = !!this.element.attr( "title" );
|
|
|
|
// Check to see if the label needs to be set or if its already correct
|
|
if ( this.options.label && this.options.label !== this.originalLabel ) {
|
|
if ( this.isInput ) {
|
|
this.element.val( this.options.label );
|
|
} else {
|
|
this.element.html( this.options.label );
|
|
}
|
|
}
|
|
this._addClass( "ui-button", "ui-widget" );
|
|
this._setOption( "disabled", this.options.disabled );
|
|
this._enhance();
|
|
|
|
if ( this.element.is( "a" ) ) {
|
|
this._on( {
|
|
"keyup": function( event ) {
|
|
if ( event.keyCode === $.ui.keyCode.SPACE ) {
|
|
event.preventDefault();
|
|
|
|
// Support: PhantomJS <= 1.9, IE 8 Only
|
|
// If a native click is available use it so we actually cause navigation
|
|
// otherwise just trigger a click event
|
|
if ( this.element[ 0 ].click ) {
|
|
this.element[ 0 ].click();
|
|
} else {
|
|
this.element.trigger( "click" );
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
},
|
|
|
|
_enhance: function() {
|
|
if ( !this.element.is( "button" ) ) {
|
|
this.element.attr( "role", "button" );
|
|
}
|
|
|
|
if ( this.options.icon ) {
|
|
this._updateIcon( "icon", this.options.icon );
|
|
this._updateTooltip();
|
|
}
|
|
},
|
|
|
|
_updateTooltip: function() {
|
|
this.title = this.element.attr( "title" );
|
|
|
|
if ( !this.options.showLabel && !this.title ) {
|
|
this.element.attr( "title", this.options.label );
|
|
}
|
|
},
|
|
|
|
_updateIcon: function( option, value ) {
|
|
var icon = option !== "iconPosition",
|
|
position = icon ? this.options.iconPosition : value,
|
|
displayBlock = position === "top" || position === "bottom";
|
|
|
|
// Create icon
|
|
if ( !this.icon ) {
|
|
this.icon = $( "<span>" );
|
|
|
|
this._addClass( this.icon, "ui-button-icon", "ui-icon" );
|
|
|
|
if ( !this.options.showLabel ) {
|
|
this._addClass( "ui-button-icon-only" );
|
|
}
|
|
} else if ( icon ) {
|
|
|
|
// If we are updating the icon remove the old icon class
|
|
this._removeClass( this.icon, null, this.options.icon );
|
|
}
|
|
|
|
// If we are updating the icon add the new icon class
|
|
if ( icon ) {
|
|
this._addClass( this.icon, null, value );
|
|
}
|
|
|
|
this._attachIcon( position );
|
|
|
|
// If the icon is on top or bottom we need to add the ui-widget-icon-block class and remove
|
|
// the iconSpace if there is one.
|
|
if ( displayBlock ) {
|
|
this._addClass( this.icon, null, "ui-widget-icon-block" );
|
|
if ( this.iconSpace ) {
|
|
this.iconSpace.remove();
|
|
}
|
|
} else {
|
|
|
|
// Position is beginning or end so remove the ui-widget-icon-block class and add the
|
|
// space if it does not exist
|
|
if ( !this.iconSpace ) {
|
|
this.iconSpace = $( "<span> </span>" );
|
|
this._addClass( this.iconSpace, "ui-button-icon-space" );
|
|
}
|
|
this._removeClass( this.icon, null, "ui-wiget-icon-block" );
|
|
this._attachIconSpace( position );
|
|
}
|
|
},
|
|
|
|
_destroy: function() {
|
|
this.element.removeAttr( "role" );
|
|
|
|
if ( this.icon ) {
|
|
this.icon.remove();
|
|
}
|
|
if ( this.iconSpace ) {
|
|
this.iconSpace.remove();
|
|
}
|
|
if ( !this.hasTitle ) {
|
|
this.element.removeAttr( "title" );
|
|
}
|
|
},
|
|
|
|
_attachIconSpace: function( iconPosition ) {
|
|
this.icon[ /^(?:end|bottom)/.test( iconPosition ) ? "before" : "after" ]( this.iconSpace );
|
|
},
|
|
|
|
_attachIcon: function( iconPosition ) {
|
|
this.element[ /^(?:end|bottom)/.test( iconPosition ) ? "append" : "prepend" ]( this.icon );
|
|
},
|
|
|
|
_setOptions: function( options ) {
|
|
var newShowLabel = options.showLabel === undefined ?
|
|
this.options.showLabel :
|
|
options.showLabel,
|
|
newIcon = options.icon === undefined ? this.options.icon : options.icon;
|
|
|
|
if ( !newShowLabel && !newIcon ) {
|
|
options.showLabel = true;
|
|
}
|
|
this._super( options );
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
if ( key === "icon" ) {
|
|
if ( value ) {
|
|
this._updateIcon( key, value );
|
|
} else if ( this.icon ) {
|
|
this.icon.remove();
|
|
if ( this.iconSpace ) {
|
|
this.iconSpace.remove();
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( key === "iconPosition" ) {
|
|
this._updateIcon( key, value );
|
|
}
|
|
|
|
// Make sure we can't end up with a button that has neither text nor icon
|
|
if ( key === "showLabel" ) {
|
|
this._toggleClass( "ui-button-icon-only", null, !value );
|
|
this._updateTooltip();
|
|
}
|
|
|
|
if ( key === "label" ) {
|
|
if ( this.isInput ) {
|
|
this.element.val( value );
|
|
} else {
|
|
|
|
// If there is an icon, append it, else nothing then append the value
|
|
// this avoids removal of the icon when setting label text
|
|
this.element.html( value );
|
|
if ( this.icon ) {
|
|
this._attachIcon( this.options.iconPosition );
|
|
this._attachIconSpace( this.options.iconPosition );
|
|
}
|
|
}
|
|
}
|
|
|
|
this._super( key, value );
|
|
|
|
if ( key === "disabled" ) {
|
|
this._toggleClass( null, "ui-state-disabled", value );
|
|
this.element[ 0 ].disabled = value;
|
|
if ( value ) {
|
|
this.element.trigger( "blur" );
|
|
}
|
|
}
|
|
},
|
|
|
|
refresh: function() {
|
|
|
|
// Make sure to only check disabled if its an element that supports this otherwise
|
|
// check for the disabled class to determine state
|
|
var isDisabled = this.element.is( "input, button" ) ?
|
|
this.element[ 0 ].disabled : this.element.hasClass( "ui-button-disabled" );
|
|
|
|
if ( isDisabled !== this.options.disabled ) {
|
|
this._setOptions( { disabled: isDisabled } );
|
|
}
|
|
|
|
this._updateTooltip();
|
|
}
|
|
} );
|
|
|
|
// DEPRECATED
|
|
if ( $.uiBackCompat !== false ) {
|
|
|
|
// Text and Icons options
|
|
$.widget( "ui.button", $.ui.button, {
|
|
options: {
|
|
text: true,
|
|
icons: {
|
|
primary: null,
|
|
secondary: null
|
|
}
|
|
},
|
|
|
|
_create: function() {
|
|
if ( this.options.showLabel && !this.options.text ) {
|
|
this.options.showLabel = this.options.text;
|
|
}
|
|
if ( !this.options.showLabel && this.options.text ) {
|
|
this.options.text = this.options.showLabel;
|
|
}
|
|
if ( !this.options.icon && ( this.options.icons.primary ||
|
|
this.options.icons.secondary ) ) {
|
|
if ( this.options.icons.primary ) {
|
|
this.options.icon = this.options.icons.primary;
|
|
} else {
|
|
this.options.icon = this.options.icons.secondary;
|
|
this.options.iconPosition = "end";
|
|
}
|
|
} else if ( this.options.icon ) {
|
|
this.options.icons.primary = this.options.icon;
|
|
}
|
|
this._super();
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
if ( key === "text" ) {
|
|
this._super( "showLabel", value );
|
|
return;
|
|
}
|
|
if ( key === "showLabel" ) {
|
|
this.options.text = value;
|
|
}
|
|
if ( key === "icon" ) {
|
|
this.options.icons.primary = value;
|
|
}
|
|
if ( key === "icons" ) {
|
|
if ( value.primary ) {
|
|
this._super( "icon", value.primary );
|
|
this._super( "iconPosition", "beginning" );
|
|
} else if ( value.secondary ) {
|
|
this._super( "icon", value.secondary );
|
|
this._super( "iconPosition", "end" );
|
|
}
|
|
}
|
|
this._superApply( arguments );
|
|
}
|
|
} );
|
|
|
|
$.fn.button = ( function( orig ) {
|
|
return function( options ) {
|
|
var isMethodCall = typeof options === "string";
|
|
var args = Array.prototype.slice.call( arguments, 1 );
|
|
var returnValue = this;
|
|
|
|
if ( isMethodCall ) {
|
|
|
|
// If this is an empty collection, we need to have the instance method
|
|
// return undefined instead of the jQuery instance
|
|
if ( !this.length && options === "instance" ) {
|
|
returnValue = undefined;
|
|
} else {
|
|
this.each( function() {
|
|
var methodValue;
|
|
var type = $( this ).attr( "type" );
|
|
var name = type !== "checkbox" && type !== "radio" ?
|
|
"button" :
|
|
"checkboxradio";
|
|
var instance = $.data( this, "ui-" + name );
|
|
|
|
if ( options === "instance" ) {
|
|
returnValue = instance;
|
|
return false;
|
|
}
|
|
|
|
if ( !instance ) {
|
|
return $.error( "cannot call methods on button" +
|
|
" prior to initialization; " +
|
|
"attempted to call method '" + options + "'" );
|
|
}
|
|
|
|
if ( typeof instance[ options ] !== "function" ||
|
|
options.charAt( 0 ) === "_" ) {
|
|
return $.error( "no such method '" + options + "' for button" +
|
|
" widget instance" );
|
|
}
|
|
|
|
methodValue = instance[ options ].apply( instance, args );
|
|
|
|
if ( methodValue !== instance && methodValue !== undefined ) {
|
|
returnValue = methodValue && methodValue.jquery ?
|
|
returnValue.pushStack( methodValue.get() ) :
|
|
methodValue;
|
|
return false;
|
|
}
|
|
} );
|
|
}
|
|
} else {
|
|
|
|
// Allow multiple hashes to be passed on init
|
|
if ( args.length ) {
|
|
options = $.widget.extend.apply( null, [ options ].concat( args ) );
|
|
}
|
|
|
|
this.each( function() {
|
|
var type = $( this ).attr( "type" );
|
|
var name = type !== "checkbox" && type !== "radio" ? "button" : "checkboxradio";
|
|
var instance = $.data( this, "ui-" + name );
|
|
|
|
if ( instance ) {
|
|
instance.option( options || {} );
|
|
if ( instance._init ) {
|
|
instance._init();
|
|
}
|
|
} else {
|
|
if ( name === "button" ) {
|
|
orig.call( $( this ), options );
|
|
return;
|
|
}
|
|
|
|
$( this ).checkboxradio( $.extend( { icon: false }, options ) );
|
|
}
|
|
} );
|
|
}
|
|
|
|
return returnValue;
|
|
};
|
|
} )( $.fn.button );
|
|
|
|
$.fn.buttonset = function() {
|
|
if ( !$.ui.controlgroup ) {
|
|
$.error( "Controlgroup widget missing" );
|
|
}
|
|
if ( arguments[ 0 ] === "option" && arguments[ 1 ] === "items" && arguments[ 2 ] ) {
|
|
return this.controlgroup.apply( this,
|
|
[ arguments[ 0 ], "items.button", arguments[ 2 ] ] );
|
|
}
|
|
if ( arguments[ 0 ] === "option" && arguments[ 1 ] === "items" ) {
|
|
return this.controlgroup.apply( this, [ arguments[ 0 ], "items.button" ] );
|
|
}
|
|
if ( typeof arguments[ 0 ] === "object" && arguments[ 0 ].items ) {
|
|
arguments[ 0 ].items = {
|
|
button: arguments[ 0 ].items
|
|
};
|
|
}
|
|
return this.controlgroup.apply( this, arguments );
|
|
};
|
|
}
|
|
|
|
var widgetsButton = $.ui.button;
|
|
|
|
|
|
/*!
|
|
* jQuery UI Spinner 1.13.1
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: Spinner
|
|
//>>group: Widgets
|
|
//>>description: Displays buttons to easily input numbers via the keyboard or mouse.
|
|
//>>docs: http://api.jqueryui.com/spinner/
|
|
//>>demos: http://jqueryui.com/spinner/
|
|
//>>css.structure: ../../themes/base/core.css
|
|
//>>css.structure: ../../themes/base/spinner.css
|
|
//>>css.theme: ../../themes/base/theme.css
|
|
|
|
|
|
function spinnerModifier( fn ) {
|
|
return function() {
|
|
var previous = this.element.val();
|
|
fn.apply( this, arguments );
|
|
this._refresh();
|
|
if ( previous !== this.element.val() ) {
|
|
this._trigger( "change" );
|
|
}
|
|
};
|
|
}
|
|
|
|
$.widget( "ui.spinner", {
|
|
version: "1.13.1",
|
|
defaultElement: "<input>",
|
|
widgetEventPrefix: "spin",
|
|
options: {
|
|
classes: {
|
|
"ui-spinner": "ui-corner-all",
|
|
"ui-spinner-down": "ui-corner-br",
|
|
"ui-spinner-up": "ui-corner-tr"
|
|
},
|
|
culture: null,
|
|
icons: {
|
|
down: "ui-icon-triangle-1-s",
|
|
up: "ui-icon-triangle-1-n"
|
|
},
|
|
incremental: true,
|
|
max: null,
|
|
min: null,
|
|
numberFormat: null,
|
|
page: 10,
|
|
step: 1,
|
|
|
|
change: null,
|
|
spin: null,
|
|
start: null,
|
|
stop: null
|
|
},
|
|
|
|
_create: function() {
|
|
|
|
// handle string values that need to be parsed
|
|
this._setOption( "max", this.options.max );
|
|
this._setOption( "min", this.options.min );
|
|
this._setOption( "step", this.options.step );
|
|
|
|
// Only format if there is a value, prevents the field from being marked
|
|
// as invalid in Firefox, see #9573.
|
|
if ( this.value() !== "" ) {
|
|
|
|
// Format the value, but don't constrain.
|
|
this._value( this.element.val(), true );
|
|
}
|
|
|
|
this._draw();
|
|
this._on( this._events );
|
|
this._refresh();
|
|
|
|
// Turning off autocomplete prevents the browser from remembering the
|
|
// value when navigating through history, so we re-enable autocomplete
|
|
// if the page is unloaded before the widget is destroyed. #7790
|
|
this._on( this.window, {
|
|
beforeunload: function() {
|
|
this.element.removeAttr( "autocomplete" );
|
|
}
|
|
} );
|
|
},
|
|
|
|
_getCreateOptions: function() {
|
|
var options = this._super();
|
|
var element = this.element;
|
|
|
|
$.each( [ "min", "max", "step" ], function( i, option ) {
|
|
var value = element.attr( option );
|
|
if ( value != null && value.length ) {
|
|
options[ option ] = value;
|
|
}
|
|
} );
|
|
|
|
return options;
|
|
},
|
|
|
|
_events: {
|
|
keydown: function( event ) {
|
|
if ( this._start( event ) && this._keydown( event ) ) {
|
|
event.preventDefault();
|
|
}
|
|
},
|
|
keyup: "_stop",
|
|
focus: function() {
|
|
this.previous = this.element.val();
|
|
},
|
|
blur: function( event ) {
|
|
if ( this.cancelBlur ) {
|
|
delete this.cancelBlur;
|
|
return;
|
|
}
|
|
|
|
this._stop();
|
|
this._refresh();
|
|
if ( this.previous !== this.element.val() ) {
|
|
this._trigger( "change", event );
|
|
}
|
|
},
|
|
mousewheel: function( event, delta ) {
|
|
var activeElement = $.ui.safeActiveElement( this.document[ 0 ] );
|
|
var isActive = this.element[ 0 ] === activeElement;
|
|
|
|
if ( !isActive || !delta ) {
|
|
return;
|
|
}
|
|
|
|
if ( !this.spinning && !this._start( event ) ) {
|
|
return false;
|
|
}
|
|
|
|
this._spin( ( delta > 0 ? 1 : -1 ) * this.options.step, event );
|
|
clearTimeout( this.mousewheelTimer );
|
|
this.mousewheelTimer = this._delay( function() {
|
|
if ( this.spinning ) {
|
|
this._stop( event );
|
|
}
|
|
}, 100 );
|
|
event.preventDefault();
|
|
},
|
|
"mousedown .ui-spinner-button": function( event ) {
|
|
var previous;
|
|
|
|
// We never want the buttons to have focus; whenever the user is
|
|
// interacting with the spinner, the focus should be on the input.
|
|
// If the input is focused then this.previous is properly set from
|
|
// when the input first received focus. If the input is not focused
|
|
// then we need to set this.previous based on the value before spinning.
|
|
previous = this.element[ 0 ] === $.ui.safeActiveElement( this.document[ 0 ] ) ?
|
|
this.previous : this.element.val();
|
|
function checkFocus() {
|
|
var isActive = this.element[ 0 ] === $.ui.safeActiveElement( this.document[ 0 ] );
|
|
if ( !isActive ) {
|
|
this.element.trigger( "focus" );
|
|
this.previous = previous;
|
|
|
|
// support: IE
|
|
// IE sets focus asynchronously, so we need to check if focus
|
|
// moved off of the input because the user clicked on the button.
|
|
this._delay( function() {
|
|
this.previous = previous;
|
|
} );
|
|
}
|
|
}
|
|
|
|
// Ensure focus is on (or stays on) the text field
|
|
event.preventDefault();
|
|
checkFocus.call( this );
|
|
|
|
// Support: IE
|
|
// IE doesn't prevent moving focus even with event.preventDefault()
|
|
// so we set a flag to know when we should ignore the blur event
|
|
// and check (again) if focus moved off of the input.
|
|
this.cancelBlur = true;
|
|
this._delay( function() {
|
|
delete this.cancelBlur;
|
|
checkFocus.call( this );
|
|
} );
|
|
|
|
if ( this._start( event ) === false ) {
|
|
return;
|
|
}
|
|
|
|
this._repeat( null, $( event.currentTarget )
|
|
.hasClass( "ui-spinner-up" ) ? 1 : -1, event );
|
|
},
|
|
"mouseup .ui-spinner-button": "_stop",
|
|
"mouseenter .ui-spinner-button": function( event ) {
|
|
|
|
// button will add ui-state-active if mouse was down while mouseleave and kept down
|
|
if ( !$( event.currentTarget ).hasClass( "ui-state-active" ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( this._start( event ) === false ) {
|
|
return false;
|
|
}
|
|
this._repeat( null, $( event.currentTarget )
|
|
.hasClass( "ui-spinner-up" ) ? 1 : -1, event );
|
|
},
|
|
|
|
// TODO: do we really want to consider this a stop?
|
|
// shouldn't we just stop the repeater and wait until mouseup before
|
|
// we trigger the stop event?
|
|
"mouseleave .ui-spinner-button": "_stop"
|
|
},
|
|
|
|
// Support mobile enhanced option and make backcompat more sane
|
|
_enhance: function() {
|
|
this.uiSpinner = this.element
|
|
.attr( "autocomplete", "off" )
|
|
.wrap( "<span>" )
|
|
.parent()
|
|
|
|
// Add buttons
|
|
.append(
|
|
"<a></a><a></a>"
|
|
);
|
|
},
|
|
|
|
_draw: function() {
|
|
this._enhance();
|
|
|
|
this._addClass( this.uiSpinner, "ui-spinner", "ui-widget ui-widget-content" );
|
|
this._addClass( "ui-spinner-input" );
|
|
|
|
this.element.attr( "role", "spinbutton" );
|
|
|
|
// Button bindings
|
|
this.buttons = this.uiSpinner.children( "a" )
|
|
.attr( "tabIndex", -1 )
|
|
.attr( "aria-hidden", true )
|
|
.button( {
|
|
classes: {
|
|
"ui-button": ""
|
|
}
|
|
} );
|
|
|
|
// TODO: Right now button does not support classes this is already updated in button PR
|
|
this._removeClass( this.buttons, "ui-corner-all" );
|
|
|
|
this._addClass( this.buttons.first(), "ui-spinner-button ui-spinner-up" );
|
|
this._addClass( this.buttons.last(), "ui-spinner-button ui-spinner-down" );
|
|
this.buttons.first().button( {
|
|
"icon": this.options.icons.up,
|
|
"showLabel": false
|
|
} );
|
|
this.buttons.last().button( {
|
|
"icon": this.options.icons.down,
|
|
"showLabel": false
|
|
} );
|
|
|
|
// IE 6 doesn't understand height: 50% for the buttons
|
|
// unless the wrapper has an explicit height
|
|
if ( this.buttons.height() > Math.ceil( this.uiSpinner.height() * 0.5 ) &&
|
|
this.uiSpinner.height() > 0 ) {
|
|
this.uiSpinner.height( this.uiSpinner.height() );
|
|
}
|
|
},
|
|
|
|
_keydown: function( event ) {
|
|
var options = this.options,
|
|
keyCode = $.ui.keyCode;
|
|
|
|
switch ( event.keyCode ) {
|
|
case keyCode.UP:
|
|
this._repeat( null, 1, event );
|
|
return true;
|
|
case keyCode.DOWN:
|
|
this._repeat( null, -1, event );
|
|
return true;
|
|
case keyCode.PAGE_UP:
|
|
this._repeat( null, options.page, event );
|
|
return true;
|
|
case keyCode.PAGE_DOWN:
|
|
this._repeat( null, -options.page, event );
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
},
|
|
|
|
_start: function( event ) {
|
|
if ( !this.spinning && this._trigger( "start", event ) === false ) {
|
|
return false;
|
|
}
|
|
|
|
if ( !this.counter ) {
|
|
this.counter = 1;
|
|
}
|
|
this.spinning = true;
|
|
return true;
|
|
},
|
|
|
|
_repeat: function( i, steps, event ) {
|
|
i = i || 500;
|
|
|
|
clearTimeout( this.timer );
|
|
this.timer = this._delay( function() {
|
|
this._repeat( 40, steps, event );
|
|
}, i );
|
|
|
|
this._spin( steps * this.options.step, event );
|
|
},
|
|
|
|
_spin: function( step, event ) {
|
|
var value = this.value() || 0;
|
|
|
|
if ( !this.counter ) {
|
|
this.counter = 1;
|
|
}
|
|
|
|
value = this._adjustValue( value + step * this._increment( this.counter ) );
|
|
|
|
if ( !this.spinning || this._trigger( "spin", event, { value: value } ) !== false ) {
|
|
this._value( value );
|
|
this.counter++;
|
|
}
|
|
},
|
|
|
|
_increment: function( i ) {
|
|
var incremental = this.options.incremental;
|
|
|
|
if ( incremental ) {
|
|
return typeof incremental === "function" ?
|
|
incremental( i ) :
|
|
Math.floor( i * i * i / 50000 - i * i / 500 + 17 * i / 200 + 1 );
|
|
}
|
|
|
|
return 1;
|
|
},
|
|
|
|
_precision: function() {
|
|
var precision = this._precisionOf( this.options.step );
|
|
if ( this.options.min !== null ) {
|
|
precision = Math.max( precision, this._precisionOf( this.options.min ) );
|
|
}
|
|
return precision;
|
|
},
|
|
|
|
_precisionOf: function( num ) {
|
|
var str = num.toString(),
|
|
decimal = str.indexOf( "." );
|
|
return decimal === -1 ? 0 : str.length - decimal - 1;
|
|
},
|
|
|
|
_adjustValue: function( value ) {
|
|
var base, aboveMin,
|
|
options = this.options;
|
|
|
|
// Make sure we're at a valid step
|
|
// - find out where we are relative to the base (min or 0)
|
|
base = options.min !== null ? options.min : 0;
|
|
aboveMin = value - base;
|
|
|
|
// - round to the nearest step
|
|
aboveMin = Math.round( aboveMin / options.step ) * options.step;
|
|
|
|
// - rounding is based on 0, so adjust back to our base
|
|
value = base + aboveMin;
|
|
|
|
// Fix precision from bad JS floating point math
|
|
value = parseFloat( value.toFixed( this._precision() ) );
|
|
|
|
// Clamp the value
|
|
if ( options.max !== null && value > options.max ) {
|
|
return options.max;
|
|
}
|
|
if ( options.min !== null && value < options.min ) {
|
|
return options.min;
|
|
}
|
|
|
|
return value;
|
|
},
|
|
|
|
_stop: function( event ) {
|
|
if ( !this.spinning ) {
|
|
return;
|
|
}
|
|
|
|
clearTimeout( this.timer );
|
|
clearTimeout( this.mousewheelTimer );
|
|
this.counter = 0;
|
|
this.spinning = false;
|
|
this._trigger( "stop", event );
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
var prevValue, first, last;
|
|
|
|
if ( key === "culture" || key === "numberFormat" ) {
|
|
prevValue = this._parse( this.element.val() );
|
|
this.options[ key ] = value;
|
|
this.element.val( this._format( prevValue ) );
|
|
return;
|
|
}
|
|
|
|
if ( key === "max" || key === "min" || key === "step" ) {
|
|
if ( typeof value === "string" ) {
|
|
value = this._parse( value );
|
|
}
|
|
}
|
|
if ( key === "icons" ) {
|
|
first = this.buttons.first().find( ".ui-icon" );
|
|
this._removeClass( first, null, this.options.icons.up );
|
|
this._addClass( first, null, value.up );
|
|
last = this.buttons.last().find( ".ui-icon" );
|
|
this._removeClass( last, null, this.options.icons.down );
|
|
this._addClass( last, null, value.down );
|
|
}
|
|
|
|
this._super( key, value );
|
|
},
|
|
|
|
_setOptionDisabled: function( value ) {
|
|
this._super( value );
|
|
|
|
this._toggleClass( this.uiSpinner, null, "ui-state-disabled", !!value );
|
|
this.element.prop( "disabled", !!value );
|
|
this.buttons.button( value ? "disable" : "enable" );
|
|
},
|
|
|
|
_setOptions: spinnerModifier( function( options ) {
|
|
this._super( options );
|
|
} ),
|
|
|
|
_parse: function( val ) {
|
|
if ( typeof val === "string" && val !== "" ) {
|
|
val = window.Globalize && this.options.numberFormat ?
|
|
Globalize.parseFloat( val, 10, this.options.culture ) : +val;
|
|
}
|
|
return val === "" || isNaN( val ) ? null : val;
|
|
},
|
|
|
|
_format: function( value ) {
|
|
if ( value === "" ) {
|
|
return "";
|
|
}
|
|
return window.Globalize && this.options.numberFormat ?
|
|
Globalize.format( value, this.options.numberFormat, this.options.culture ) :
|
|
value;
|
|
},
|
|
|
|
_refresh: function() {
|
|
this.element.attr( {
|
|
"aria-valuemin": this.options.min,
|
|
"aria-valuemax": this.options.max,
|
|
|
|
// TODO: what should we do with values that can't be parsed?
|
|
"aria-valuenow": this._parse( this.element.val() )
|
|
} );
|
|
},
|
|
|
|
isValid: function() {
|
|
var value = this.value();
|
|
|
|
// Null is invalid
|
|
if ( value === null ) {
|
|
return false;
|
|
}
|
|
|
|
// If value gets adjusted, it's invalid
|
|
return value === this._adjustValue( value );
|
|
},
|
|
|
|
// Update the value without triggering change
|
|
_value: function( value, allowAny ) {
|
|
var parsed;
|
|
if ( value !== "" ) {
|
|
parsed = this._parse( value );
|
|
if ( parsed !== null ) {
|
|
if ( !allowAny ) {
|
|
parsed = this._adjustValue( parsed );
|
|
}
|
|
value = this._format( parsed );
|
|
}
|
|
}
|
|
this.element.val( value );
|
|
this._refresh();
|
|
},
|
|
|
|
_destroy: function() {
|
|
this.element
|
|
.prop( "disabled", false )
|
|
.removeAttr( "autocomplete role aria-valuemin aria-valuemax aria-valuenow" );
|
|
|
|
this.uiSpinner.replaceWith( this.element );
|
|
},
|
|
|
|
stepUp: spinnerModifier( function( steps ) {
|
|
this._stepUp( steps );
|
|
} ),
|
|
_stepUp: function( steps ) {
|
|
if ( this._start() ) {
|
|
this._spin( ( steps || 1 ) * this.options.step );
|
|
this._stop();
|
|
}
|
|
},
|
|
|
|
stepDown: spinnerModifier( function( steps ) {
|
|
this._stepDown( steps );
|
|
} ),
|
|
_stepDown: function( steps ) {
|
|
if ( this._start() ) {
|
|
this._spin( ( steps || 1 ) * -this.options.step );
|
|
this._stop();
|
|
}
|
|
},
|
|
|
|
pageUp: spinnerModifier( function( pages ) {
|
|
this._stepUp( ( pages || 1 ) * this.options.page );
|
|
} ),
|
|
|
|
pageDown: spinnerModifier( function( pages ) {
|
|
this._stepDown( ( pages || 1 ) * this.options.page );
|
|
} ),
|
|
|
|
value: function( newVal ) {
|
|
if ( !arguments.length ) {
|
|
return this._parse( this.element.val() );
|
|
}
|
|
spinnerModifier( this._value ).call( this, newVal );
|
|
},
|
|
|
|
widget: function() {
|
|
return this.uiSpinner;
|
|
}
|
|
} );
|
|
|
|
// DEPRECATED
|
|
// TODO: switch return back to widget declaration at top of file when this is removed
|
|
if ( $.uiBackCompat !== false ) {
|
|
|
|
// Backcompat for spinner html extension points
|
|
$.widget( "ui.spinner", $.ui.spinner, {
|
|
_enhance: function() {
|
|
this.uiSpinner = this.element
|
|
.attr( "autocomplete", "off" )
|
|
.wrap( this._uiSpinnerHtml() )
|
|
.parent()
|
|
|
|
// Add buttons
|
|
.append( this._buttonHtml() );
|
|
},
|
|
_uiSpinnerHtml: function() {
|
|
return "<span>";
|
|
},
|
|
|
|
_buttonHtml: function() {
|
|
return "<a></a><a></a>";
|
|
}
|
|
} );
|
|
}
|
|
|
|
var widgetsSpinner = $.ui.spinner;
|
|
|
|
|
|
|
|
|
|
} ); |