summaryrefslogtreecommitdiff
path: root/lib/scripts/jquery/jquery-ui.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2013-03-24 10:17:24 +0100
committerAndreas Gohr <andi@splitbrain.org>2013-03-24 10:18:51 +0100
commit64a19076f0888270102a3ae01cfa2bc5824ce03e (patch)
tree079267df9907c0e5a3495a6281e8a7e1d1076204 /lib/scripts/jquery/jquery-ui.js
parent2ab296805f9b647d3fe46cad4a7f275c45f171a8 (diff)
downloadrpg-64a19076f0888270102a3ae01cfa2bc5824ce03e.tar.gz
rpg-64a19076f0888270102a3ae01cfa2bc5824ce03e.tar.bz2
upgrade jQuery scripts
jQuery 1.9.0 had a bug in replaceWith() that got fixed in 1.9.1 - to ensure compatibility I upgraded the whole suite to their current releases.
Diffstat (limited to 'lib/scripts/jquery/jquery-ui.js')
-rw-r--r--lib/scripts/jquery/jquery-ui.js7655
1 files changed, 3865 insertions, 3790 deletions
diff --git a/lib/scripts/jquery/jquery-ui.js b/lib/scripts/jquery/jquery-ui.js
index 2f83e5a2a..6eccbfec3 100644
--- a/lib/scripts/jquery/jquery-ui.js
+++ b/lib/scripts/jquery/jquery-ui.js
@@ -1,23 +1,17 @@
-/*! jQuery UI - v1.9.2 - 2012-11-23
+/*! jQuery UI - v1.10.2 - 2013-03-14
* http://jqueryui.com
* Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js, jquery.ui.effect.js, jquery.ui.accordion.js, jquery.ui.autocomplete.js, jquery.ui.button.js, jquery.ui.datepicker.js, jquery.ui.dialog.js, jquery.ui.effect-blind.js, jquery.ui.effect-bounce.js, jquery.ui.effect-clip.js, jquery.ui.effect-drop.js, jquery.ui.effect-explode.js, jquery.ui.effect-fade.js, jquery.ui.effect-fold.js, jquery.ui.effect-highlight.js, jquery.ui.effect-pulsate.js, jquery.ui.effect-scale.js, jquery.ui.effect-shake.js, jquery.ui.effect-slide.js, jquery.ui.effect-transfer.js, jquery.ui.menu.js, jquery.ui.position.js, jquery.ui.progressbar.js, jquery.ui.slider.js, jquery.ui.spinner.js, jquery.ui.tabs.js, jquery.ui.tooltip.js
-* Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */
-
+* Copyright 2013 jQuery Foundation and other contributors; Licensed MIT */
(function( $, undefined ) {
var uuid = 0,
runiqueId = /^ui-id-\d+$/;
-// prevent duplicate loading
-// this is only a problem because we proxy existing functions
-// and we don't want to double proxy them
+// $.ui might exist from components with no dependencies, e.g., $.ui.position
$.ui = $.ui || {};
-if ( $.ui.version ) {
- return;
-}
$.extend( $.ui, {
- version: "1.9.2",
+ version: "1.10.2",
keyCode: {
BACKSPACE: 8,
@@ -47,34 +41,35 @@ $.extend( $.ui, {
// plugins
$.fn.extend({
- _focus: $.fn.focus,
- focus: function( delay, fn ) {
- return typeof delay === "number" ?
- this.each(function() {
- var elem = this;
- setTimeout(function() {
- $( elem ).focus();
- if ( fn ) {
- fn.call( elem );
- }
- }, delay );
- }) :
- this._focus.apply( this, arguments );
- },
+ focus: (function( orig ) {
+ return function( delay, fn ) {
+ return typeof delay === "number" ?
+ this.each(function() {
+ var elem = this;
+ setTimeout(function() {
+ $( elem ).focus();
+ if ( fn ) {
+ fn.call( elem );
+ }
+ }, delay );
+ }) :
+ orig.apply( this, arguments );
+ };
+ })( $.fn.focus ),
scrollParent: function() {
var scrollParent;
- if (($.ui.ie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
+ if (($.ui.ie && (/(static|relative)/).test(this.css("position"))) || (/absolute/).test(this.css("position"))) {
scrollParent = this.parents().filter(function() {
- return (/(relative|absolute|fixed)/).test($.css(this,'position')) && (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
+ return (/(relative|absolute|fixed)/).test($.css(this,"position")) && (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
}).eq(0);
} else {
scrollParent = this.parents().filter(function() {
- return (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
+ return (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
}).eq(0);
}
- return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
+ return (/fixed/).test(this.css("position")) || !scrollParent.length ? $(document) : scrollParent;
},
zIndex: function( zIndex ) {
@@ -147,7 +142,7 @@ function focusable( element, isTabIndexNotNaN ) {
function visible( element ) {
return $.expr.filters.visible( element ) &&
- !$( element ).parents().andSelf().filter(function() {
+ !$( element ).parents().addBack().filter(function() {
return $.css( this, "visibility" ) === "hidden";
}).length;
}
@@ -175,31 +170,6 @@ $.extend( $.expr[ ":" ], {
}
});
-// support
-$(function() {
- var body = document.body,
- div = body.appendChild( div = document.createElement( "div" ) );
-
- // access offsetHeight before setting the style to prevent a layout bug
- // in IE 9 which causes the element to continue to take up space even
- // after it is removed from the DOM (#8026)
- div.offsetHeight;
-
- $.extend( div.style, {
- minHeight: "100px",
- height: "auto",
- padding: 0,
- borderWidth: 0
- });
-
- $.support.minHeight = div.offsetHeight === 100;
- $.support.selectstart = "onselectstart" in div;
-
- // set display to none to avoid a layout bug in IE
- // http://dev.jquery.com/ticket/4014
- body.removeChild( div ).style.display = "none";
-});
-
// support: jQuery <1.8
if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
$.each( [ "Width", "Height" ], function( i, name ) {
@@ -247,6 +217,15 @@ if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
});
}
+// support: jQuery <1.8
+if ( !$.fn.addBack ) {
+ $.fn.addBack = function( selector ) {
+ return this.add( selector == null ?
+ this.prevObject : this.prevObject.filter( selector )
+ );
+ };
+}
+
// support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
$.fn.removeData = (function( removeData ) {
@@ -265,13 +244,9 @@ if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
// deprecated
+$.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
-(function() {
- var uaMatch = /msie ([\w.]+)/.exec( navigator.userAgent.toLowerCase() ) || [];
- $.ui.ie = uaMatch.length ? true : false;
- $.ui.ie6 = parseFloat( uaMatch[ 1 ], 10 ) === 6;
-})();
-
+$.support.selectstart = "onselectstart" in document.createElement( "div" );
$.fn.extend({
disableSelection: function() {
return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
@@ -311,8 +286,6 @@ $.extend( $.ui, {
}
},
- contains: $.contains,
-
// only used by resizable
hasScroll: function( el, a ) {
@@ -335,16 +308,6 @@ $.extend( $.ui, {
has = ( el[ scroll ] > 0 );
el[ scroll ] = 0;
return has;
- },
-
- // these are odd functions, fix the API or move into individual plugins
- isOverAxis: function( x, reference, size ) {
- //Determines when x coordinate is over "b" element axis
- return ( x > reference ) && ( x < ( reference + size ) );
- },
- isOver: function( y, x, top, left, height, width ) {
- //Determines when x, y coordinates is over "b" element
- return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
}
});
@@ -367,6 +330,9 @@ $.cleanData = function( elems ) {
$.widget = function( name, base, prototype ) {
var fullName, existingConstructor, constructor, basePrototype,
+ // proxiedPrototype allows the provided prototype to remain unmodified
+ // so that it can be used as a mixin for multiple widgets (#8876)
+ proxiedPrototype = {},
namespace = name.split( "." )[ 0 ];
name = name.split( "." )[ 1 ];
@@ -413,43 +379,43 @@ $.widget = function( name, base, prototype ) {
// inheriting from
basePrototype.options = $.widget.extend( {}, basePrototype.options );
$.each( prototype, function( prop, value ) {
- if ( $.isFunction( value ) ) {
- prototype[ prop ] = (function() {
- var _super = function() {
- return base.prototype[ prop ].apply( this, arguments );
- },
- _superApply = function( args ) {
- return base.prototype[ prop ].apply( this, args );
- };
- return function() {
- var __super = this._super,
- __superApply = this._superApply,
- returnValue;
+ if ( !$.isFunction( value ) ) {
+ proxiedPrototype[ prop ] = value;
+ return;
+ }
+ proxiedPrototype[ prop ] = (function() {
+ var _super = function() {
+ return base.prototype[ prop ].apply( this, arguments );
+ },
+ _superApply = function( args ) {
+ return base.prototype[ prop ].apply( this, args );
+ };
+ return function() {
+ var __super = this._super,
+ __superApply = this._superApply,
+ returnValue;
- this._super = _super;
- this._superApply = _superApply;
+ this._super = _super;
+ this._superApply = _superApply;
- returnValue = value.apply( this, arguments );
+ returnValue = value.apply( this, arguments );
- this._super = __super;
- this._superApply = __superApply;
+ this._super = __super;
+ this._superApply = __superApply;
- return returnValue;
- };
- })();
- }
+ 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
- }, prototype, {
+ }, proxiedPrototype, {
constructor: constructor,
namespace: namespace,
widgetName: name,
- // TODO remove widgetBaseClass, see #8155
- widgetBaseClass: fullName,
widgetFullName: fullName
});
@@ -575,9 +541,6 @@ $.Widget.prototype = {
this.focusable = $();
if ( element !== this ) {
- // 1.9 BC for #7810
- // TODO remove dual storage
- $.data( element, this.widgetName, this );
$.data( element, this.widgetFullName, this );
this._on( true, this.element, {
remove: function( event ) {
@@ -844,7 +807,7 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
if ( options.delay ) {
element.delay( options.delay );
}
- if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
+ if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
element[ method ]( options );
} else if ( effectName !== method && element[ effectName ] ) {
element[ effectName ]( options.duration, options.easing, callback );
@@ -860,26 +823,19 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
};
});
-// DEPRECATED
-if ( $.uiBackCompat !== false ) {
- $.Widget.prototype._getCreateOptions = function() {
- return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
- };
-}
-
})( jQuery );
(function( $, undefined ) {
var mouseHandled = false;
-$( document ).mouseup( function( e ) {
+$( document ).mouseup( function() {
mouseHandled = false;
});
$.widget("ui.mouse", {
- version: "1.9.2",
+ version: "1.10.2",
options: {
- cancel: 'input,textarea,button,select,option',
+ cancel: "input,textarea,button,select,option",
distance: 1,
delay: 0
},
@@ -887,12 +843,12 @@ $.widget("ui.mouse", {
var that = this;
this.element
- .bind('mousedown.'+this.widgetName, function(event) {
+ .bind("mousedown."+this.widgetName, function(event) {
return that._mouseDown(event);
})
- .bind('click.'+this.widgetName, function(event) {
- if (true === $.data(event.target, that.widgetName + '.preventClickEvent')) {
- $.removeData(event.target, that.widgetName + '.preventClickEvent');
+ .bind("click."+this.widgetName, function(event) {
+ if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
+ $.removeData(event.target, that.widgetName + ".preventClickEvent");
event.stopImmediatePropagation();
return false;
}
@@ -904,11 +860,11 @@ $.widget("ui.mouse", {
// TODO: make sure destroying one instance of mouse doesn't mess with
// other instances of mouse
_mouseDestroy: function() {
- this.element.unbind('.'+this.widgetName);
+ this.element.unbind("."+this.widgetName);
if ( this._mouseMoveDelegate ) {
$(document)
- .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
- .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
+ .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
+ .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
}
},
@@ -946,8 +902,8 @@ $.widget("ui.mouse", {
}
// Click event may never have fired (Gecko & Opera)
- if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
- $.removeData(event.target, this.widgetName + '.preventClickEvent');
+ if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
+ $.removeData(event.target, this.widgetName + ".preventClickEvent");
}
// these delegates are required to keep context
@@ -958,8 +914,8 @@ $.widget("ui.mouse", {
return that._mouseUp(event);
};
$(document)
- .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
- .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
+ .bind("mousemove."+this.widgetName, this._mouseMoveDelegate)
+ .bind("mouseup."+this.widgetName, this._mouseUpDelegate);
event.preventDefault();
@@ -969,7 +925,7 @@ $.widget("ui.mouse", {
_mouseMove: function(event) {
// IE mouseup check - mouseup happened when mouse was out of window
- if ($.ui.ie && !(document.documentMode >= 9) && !event.button) {
+ if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
return this._mouseUp(event);
}
@@ -989,14 +945,14 @@ $.widget("ui.mouse", {
_mouseUp: function(event) {
$(document)
- .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
- .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
+ .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
+ .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
if (this._mouseStarted) {
this._mouseStarted = false;
if (event.target === this._mouseDownEvent.target) {
- $.data(event.target, this.widgetName + '.preventClickEvent', true);
+ $.data(event.target, this.widgetName + ".preventClickEvent", true);
}
this._mouseStop(event);
@@ -1013,15 +969,15 @@ $.widget("ui.mouse", {
);
},
- _mouseDelayMet: function(event) {
+ _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; }
+ _mouseStart: function(/* event */) {},
+ _mouseDrag: function(/* event */) {},
+ _mouseStop: function(/* event */) {},
+ _mouseCapture: function(/* event */) { return true; }
});
})(jQuery);
@@ -1029,7 +985,7 @@ $.widget("ui.mouse", {
(function( $, undefined ) {
$.widget("ui.draggable", $.ui.mouse, {
- version: "1.9.2",
+ version: "1.10.2",
widgetEventPrefix: "drag",
options: {
addClasses: true,
@@ -1055,15 +1011,24 @@ $.widget("ui.draggable", $.ui.mouse, {
snapMode: "both",
snapTolerance: 20,
stack: false,
- zIndex: false
+ zIndex: false,
+
+ // callbacks
+ drag: null,
+ start: null,
+ stop: null
},
_create: function() {
- if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
- this.element[0].style.position = 'relative';
-
- (this.options.addClasses && this.element.addClass("ui-draggable"));
- (this.options.disabled && this.element.addClass("ui-draggable-disabled"));
+ if (this.options.helper === "original" && !(/^(?:r|a|f)/).test(this.element.css("position"))) {
+ this.element[0].style.position = "relative";
+ }
+ if (this.options.addClasses){
+ this.element.addClass("ui-draggable");
+ }
+ if (this.options.disabled){
+ this.element.addClass("ui-draggable-disabled");
+ }
this._mouseInit();
@@ -1079,16 +1044,18 @@ $.widget("ui.draggable", $.ui.mouse, {
var o = this.options;
// among others, prevent a drag on a resizable-handle
- if (this.helper || o.disabled || $(event.target).is('.ui-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)
+ if (!this.handle) {
return false;
+ }
$(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
- $('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
+ $("<div class='ui-draggable-iframeFix' style='background: #fff;'></div>")
.css({
width: this.offsetWidth+"px", height: this.offsetHeight+"px",
position: "absolute", opacity: "0.001", zIndex: 1000
@@ -1114,8 +1081,9 @@ $.widget("ui.draggable", $.ui.mouse, {
this._cacheHelperProportions();
//If ddmanager is used for droppables, set the global draggable
- if($.ui.ddmanager)
+ if($.ui.ddmanager) {
$.ui.ddmanager.current = this;
+ }
/*
* - Position generation -
@@ -1150,12 +1118,13 @@ $.widget("ui.draggable", $.ui.mouse, {
this.originalPageX = event.pageX;
this.originalPageY = event.pageY;
- //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
+ //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
//Set a containment if given in the options
- if(o.containment)
+ if(o.containment) {
this._setContainment();
+ }
//Trigger event + callbacks
if(this._trigger("start", event) === false) {
@@ -1167,14 +1136,17 @@ $.widget("ui.draggable", $.ui.mouse, {
this._cacheHelperProportions();
//Prepare the droppable offsets
- if ($.ui.ddmanager && !o.dropBehaviour)
+ if ($.ui.ddmanager && !o.dropBehaviour) {
$.ui.ddmanager.prepareOffsets(this, event);
+ }
this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
//If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
- if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event);
+ if ( $.ui.ddmanager ) {
+ $.ui.ddmanager.dragStart(this, event);
+ }
return true;
},
@@ -1188,16 +1160,22 @@ $.widget("ui.draggable", $.ui.mouse, {
//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) {
+ if(this._trigger("drag", event, ui) === false) {
this._mouseUp({});
return false;
}
this.position = ui.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';
- if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
+ 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";
+ }
+ if($.ui.ddmanager) {
+ $.ui.ddmanager.drag(this, event);
+ }
return false;
},
@@ -1205,9 +1183,13 @@ $.widget("ui.draggable", $.ui.mouse, {
_mouseStop: function(event) {
//If we are using droppables, inform the manager about the drop
- var dropped = false;
- if ($.ui.ddmanager && !this.options.dropBehaviour)
+ var element,
+ that = this,
+ elementInDom = false,
+ 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) {
@@ -1216,17 +1198,17 @@ $.widget("ui.draggable", $.ui.mouse, {
}
//if the original element is no longer in the DOM don't bother to continue (see #8269)
- var element = this.element[0], elementInDom = false;
+ element = this.element[0];
while ( element && (element = element.parentNode) ) {
- if (element == document ) {
+ if (element === document ) {
elementInDom = true;
}
}
- if ( !elementInDom && this.options.helper === "original" )
+ if ( !elementInDom && this.options.helper === "original" ) {
return false;
+ }
- if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
- var that = this;
+ if((this.options.revert === "invalid" && !dropped) || (this.options.revert === "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && 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();
@@ -1248,7 +1230,9 @@ $.widget("ui.draggable", $.ui.mouse, {
});
//If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
- if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event);
+ if( $.ui.ddmanager ) {
+ $.ui.ddmanager.dragStop(this, event);
+ }
return $.ui.mouse.prototype._mouseUp.call(this, event);
},
@@ -1266,51 +1250,45 @@ $.widget("ui.draggable", $.ui.mouse, {
},
_getHandle: function(event) {
-
- var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
- $(this.options.handle, this.element)
- .find("*")
- .andSelf()
- .each(function() {
- if(this == event.target) handle = true;
- });
-
- return handle;
-
+ return this.options.handle ?
+ !!$( event.target ).closest( this.element.find( this.options.handle ) ).length :
+ true;
},
_createHelper: function(event) {
- var o = this.options;
- var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element);
+ var o = this.options,
+ helper = $.isFunction(o.helper) ? $(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));
+ if(!helper.parents("body").length) {
+ helper.appendTo((o.appendTo === "parent" ? this.element[0].parentNode : o.appendTo));
+ }
- if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
+ if(helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) {
helper.css("position", "absolute");
+ }
return helper;
},
_adjustOffsetFromHelper: function(obj) {
- if (typeof obj == 'string') {
- obj = obj.split(' ');
+ if (typeof obj === "string") {
+ obj = obj.split(" ");
}
if ($.isArray(obj)) {
obj = {left: +obj[0], top: +obj[1] || 0};
}
- if ('left' in obj) {
+ if ("left" in obj) {
this.offset.click.left = obj.left + this.margins.left;
}
- if ('right' in obj) {
+ if ("right" in obj) {
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
}
- if ('top' in obj) {
+ if ("top" in obj) {
this.offset.click.top = obj.top + this.margins.top;
}
- if ('bottom' in obj) {
+ if ("bottom" in obj) {
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
}
},
@@ -1325,14 +1303,17 @@ $.widget("ui.draggable", $.ui.mouse, {
// 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])) {
+ 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.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
- || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) //Ugly IE fix
+ //This needs to be actually done for all browsers, since pageX/pageY includes this information
+ //Ugly IE fix
+ if((this.offsetParent[0] === document.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),
@@ -1343,7 +1324,7 @@ $.widget("ui.draggable", $.ui.mouse, {
_getRelativeOffset: function() {
- if(this.cssPosition == "relative") {
+ if(this.cssPosition === "relative") {
var p = this.element.position();
return {
top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
@@ -1373,30 +1354,40 @@ $.widget("ui.draggable", $.ui.mouse, {
_setContainment: function() {
- var o = this.options;
- if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
- if(o.containment == 'document' || o.containment == 'window') this.containment = [
- o.containment == 'document' ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
- o.containment == 'document' ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
- (o.containment == 'document' ? 0 : $(window).scrollLeft()) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
- (o.containment == 'document' ? 0 : $(window).scrollTop()) + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
- ];
+ var over, c, ce,
+ o = this.options;
+
+ if(o.containment === "parent") {
+ o.containment = this.helper[0].parentNode;
+ }
+ if(o.containment === "document" || o.containment === "window") {
+ this.containment = [
+ o.containment === "document" ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
+ o.containment === "document" ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
+ (o.containment === "document" ? 0 : $(window).scrollLeft()) + $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
+ (o.containment === "document" ? 0 : $(window).scrollTop()) + ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
+ ];
+ }
- if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) {
- var c = $(o.containment);
- var ce = c[0]; if(!ce) return;
- var co = c.offset();
- var over = ($(ce).css("overflow") != 'hidden');
+ if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor !== Array) {
+ c = $(o.containment);
+ ce = c[0];
+
+ if(!ce) {
+ return;
+ }
+
+ over = ($(ce).css("overflow") !== "hidden");
this.containment = [
(parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
(parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
- (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 - this.margins.right,
- (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 - this.margins.bottom
+ (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderRightWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,
+ (over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderBottomWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom
];
this.relative_container = c;
- } else if(o.containment.constructor == Array) {
+ } else if(o.containment.constructor === Array) {
this.containment = o.containment;
}
@@ -1404,22 +1395,25 @@ $.widget("ui.draggable", $.ui.mouse, {
_convertPositionTo: function(d, pos) {
- if(!pos) pos = this.position;
- var mod = d == "absolute" ? 1 : -1;
- var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+ if(!pos) {
+ pos = this.position;
+ }
+
+ var mod = d === "absolute" ? 1 : -1,
+ scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
return {
top: (
- pos.top // The absolute mouse position
- + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
- + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
- - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
+ pos.top + // The absolute mouse position
+ this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
),
left: (
- pos.left // The absolute mouse position
- + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
- + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
- - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
+ pos.left + // The absolute mouse position
+ this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
)
};
@@ -1427,9 +1421,12 @@ $.widget("ui.draggable", $.ui.mouse, {
_generatePosition: function(event) {
- var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
- var pageX = event.pageX;
- var pageY = event.pageY;
+ var containment, co, top, left,
+ o = this.options,
+ scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
+ scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName),
+ pageX = event.pageX,
+ pageY = event.pageY;
/*
* - Position constraining -
@@ -1437,10 +1434,9 @@ $.widget("ui.draggable", $.ui.mouse, {
*/
if(this.originalPosition) { //If we are not dragging yet, we won't check for options
- var containment;
if(this.containment) {
if (this.relative_container){
- var co = this.relative_container.offset();
+ co = this.relative_container.offset();
containment = [ this.containment[0] + co.left,
this.containment[1] + co.top,
this.containment[2] + co.left,
@@ -1450,37 +1446,45 @@ $.widget("ui.draggable", $.ui.mouse, {
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(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)
- var 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;
+ 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;
- var 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;
+ 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;
}
}
return {
top: (
- pageY // The absolute mouse position
- - this.offset.click.top // Click offset (relative to the element)
- - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
- - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
- + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
+ pageY - // The absolute mouse position
+ this.offset.click.top - // Click offset (relative to the element)
+ this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
),
left: (
- pageX // The absolute mouse position
- - this.offset.click.left // Click offset (relative to the element)
- - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
- - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
- + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
+ pageX - // The absolute mouse position
+ this.offset.click.left - // Click offset (relative to the element)
+ this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
)
};
@@ -1488,8 +1492,9 @@ $.widget("ui.draggable", $.ui.mouse, {
_clear: function() {
this.helper.removeClass("ui-draggable-dragging");
- if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();
- //if($.ui.ddmanager) $.ui.ddmanager.current = null;
+ if(this.helper[0] !== this.element[0] && !this.cancelHelperRemoval) {
+ this.helper.remove();
+ }
this.helper = null;
this.cancelHelperRemoval = false;
},
@@ -1499,13 +1504,16 @@ $.widget("ui.draggable", $.ui.mouse, {
_trigger: function(type, event, ui) {
ui = ui || this._uiHash();
$.ui.plugin.call(this, type, [event, ui]);
- if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
+ //The absolute position has to be recalculated after plugins
+ if(type === "drag") {
+ this.positionAbs = this._convertPositionTo("absolute");
+ }
return $.Widget.prototype._trigger.call(this, type, event, ui);
},
plugins: {},
- _uiHash: function(event) {
+ _uiHash: function() {
return {
helper: this.helper,
position: this.position,
@@ -1519,11 +1527,11 @@ $.widget("ui.draggable", $.ui.mouse, {
$.ui.plugin.add("draggable", "connectToSortable", {
start: function(event, ui) {
- var inst = $(this).data("draggable"), o = inst.options,
+ var inst = $(this).data("ui-draggable"), o = inst.options,
uiSortable = $.extend({}, ui, { item: inst.element });
inst.sortables = [];
$(o.connectToSortable).each(function() {
- var sortable = $.data(this, 'sortable');
+ var sortable = $.data(this, "ui-sortable");
if (sortable && !sortable.options.disabled) {
inst.sortables.push({
instance: sortable,
@@ -1538,7 +1546,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
stop: function(event, ui) {
//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
- var inst = $(this).data("draggable"),
+ var inst = $(this).data("ui-draggable"),
uiSortable = $.extend({}, ui, { item: inst.element });
$.each(inst.sortables, function() {
@@ -1549,8 +1557,10 @@ $.ui.plugin.add("draggable", "connectToSortable", {
inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
- //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
- if(this.shouldRevert) this.instance.options.revert = true;
+ //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: "valid/invalid"
+ if(this.shouldRevert) {
+ this.instance.options.revert = this.shouldRevert;
+ }
//Trigger the stop of the sortable
this.instance._mouseStop(event);
@@ -1558,8 +1568,9 @@ $.ui.plugin.add("draggable", "connectToSortable", {
this.instance.options.helper = this.instance.options._helper;
//If the helper has been the original item, restore properties in the sortable
- if(inst.options.helper == 'original')
- this.instance.currentItem.css({ top: 'auto', left: 'auto' });
+ if(inst.options.helper === "original") {
+ this.instance.currentItem.css({ top: "auto", left: "auto" });
+ }
} else {
this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
@@ -1571,21 +1582,13 @@ $.ui.plugin.add("draggable", "connectToSortable", {
},
drag: function(event, ui) {
- var inst = $(this).data("draggable"), that = this;
-
- var checkPos = function(o) {
- var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
- var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
- var itemHeight = o.height, itemWidth = o.width;
- var itemTop = o.top, itemLeft = o.left;
+ var inst = $(this).data("ui-draggable"), that = this;
- return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
- };
+ $.each(inst.sortables, function() {
- $.each(inst.sortables, function(i) {
+ var innermostIntersecting = false,
+ thisSortable = this;
- var innermostIntersecting = false;
- var thisSortable = this;
//Copy over some variables to allow calling the sortable's native _intersectsWith
this.instance.positionAbs = inst.positionAbs;
this.instance.helperProportions = inst.helperProportions;
@@ -1597,11 +1600,13 @@ $.ui.plugin.add("draggable", "connectToSortable", {
this.instance.positionAbs = inst.positionAbs;
this.instance.helperProportions = inst.helperProportions;
this.instance.offset.click = inst.offset.click;
- if (this != thisSortable
- && this.instance._intersectsWith(this.instance.containerCache)
- && $.ui.contains(thisSortable.instance.element[0], this.instance.element[0]))
+ if (this !== thisSortable &&
+ this.instance._intersectsWith(this.instance.containerCache) &&
+ $.contains(thisSortable.instance.element[0], this.instance.element[0])
+ ) {
innermostIntersecting = false;
- return innermostIntersecting;
+ }
+ return innermostIntersecting;
});
}
@@ -1614,7 +1619,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
//Now we fake the start of dragging for the sortable instance,
//by cloning the list group item, appending it to the sortable and using it as inst.currentItem
//We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
- this.instance.currentItem = $(that).clone().removeAttr('id').appendTo(this.instance.element).data("sortable-item", true);
+ this.instance.currentItem = $(that).clone().removeAttr("id").appendTo(this.instance.element).data("ui-sortable-item", true);
this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
this.instance.options.helper = function() { return ui.helper[0]; };
@@ -1637,7 +1642,9 @@ $.ui.plugin.add("draggable", "connectToSortable", {
}
//Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
- if(this.instance.currentItem) this.instance._mouseDrag(event);
+ if(this.instance.currentItem) {
+ this.instance._mouseDrag(event);
+ }
} else {
@@ -1652,20 +1659,22 @@ $.ui.plugin.add("draggable", "connectToSortable", {
this.instance.options.revert = false;
// The out event needs to be triggered independently
- this.instance._trigger('out', event, this.instance._uiHash(this.instance));
+ this.instance._trigger("out", event, this.instance._uiHash(this.instance));
this.instance._mouseStop(event, true);
this.instance.options.helper = this.instance.options._helper;
//Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
this.instance.currentItem.remove();
- if(this.instance.placeholder) this.instance.placeholder.remove();
+ if(this.instance.placeholder) {
+ this.instance.placeholder.remove();
+ }
inst._trigger("fromSortable", event);
inst.dropped = false; //draggable revert needs that
}
- };
+ }
});
@@ -1673,176 +1682,220 @@ $.ui.plugin.add("draggable", "connectToSortable", {
});
$.ui.plugin.add("draggable", "cursor", {
- start: function(event, ui) {
- var t = $('body'), o = $(this).data('draggable').options;
- if (t.css("cursor")) o._cursor = t.css("cursor");
+ start: function() {
+ var t = $("body"), o = $(this).data("ui-draggable").options;
+ if (t.css("cursor")) {
+ o._cursor = t.css("cursor");
+ }
t.css("cursor", o.cursor);
},
- stop: function(event, ui) {
- var o = $(this).data('draggable').options;
- if (o._cursor) $('body').css("cursor", o._cursor);
+ stop: function() {
+ var o = $(this).data("ui-draggable").options;
+ if (o._cursor) {
+ $("body").css("cursor", o._cursor);
+ }
}
});
$.ui.plugin.add("draggable", "opacity", {
start: function(event, ui) {
- var t = $(ui.helper), o = $(this).data('draggable').options;
- if(t.css("opacity")) o._opacity = t.css("opacity");
- t.css('opacity', o.opacity);
+ var t = $(ui.helper), o = $(this).data("ui-draggable").options;
+ if(t.css("opacity")) {
+ o._opacity = t.css("opacity");
+ }
+ t.css("opacity", o.opacity);
},
stop: function(event, ui) {
- var o = $(this).data('draggable').options;
- if(o._opacity) $(ui.helper).css('opacity', o._opacity);
+ var o = $(this).data("ui-draggable").options;
+ if(o._opacity) {
+ $(ui.helper).css("opacity", o._opacity);
+ }
}
});
$.ui.plugin.add("draggable", "scroll", {
- start: function(event, ui) {
- var i = $(this).data("draggable");
- if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
+ start: function() {
+ var i = $(this).data("ui-draggable");
+ if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
+ i.overflowOffset = i.scrollParent.offset();
+ }
},
- drag: function(event, ui) {
+ drag: function( event ) {
- var i = $(this).data("draggable"), o = i.options, scrolled = false;
+ var i = $(this).data("ui-draggable"), o = i.options, scrolled = false;
- if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
+ if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
- if(!o.axis || o.axis != 'x') {
- if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
+ if(!o.axis || o.axis !== "x") {
+ if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
- else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity)
+ } else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) {
i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
+ }
}
- if(!o.axis || o.axis != 'y') {
- if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
+ if(!o.axis || o.axis !== "y") {
+ if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
- else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity)
+ } else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) {
i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
+ }
}
} else {
- if(!o.axis || o.axis != 'x') {
- if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
+ 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)
+ } 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)
+ 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)
+ } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
+ }
}
}
- if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
+ if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
$.ui.ddmanager.prepareOffsets(i, event);
+ }
}
});
$.ui.plugin.add("draggable", "snap", {
- start: function(event, ui) {
+ start: function() {
+
+ var i = $(this).data("ui-draggable"),
+ o = i.options;
- var i = $(this).data("draggable"), o = i.options;
i.snapElements = [];
- $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() {
- var $t = $(this); var $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
- });
+ $(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) {
- var inst = $(this).data("draggable"), o = inst.options;
- var d = o.snapTolerance;
-
- var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
+ var ts, bs, ls, rs, l, r, t, b, i, first,
+ inst = $(this).data("ui-draggable"),
+ 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 (var i = inst.snapElements.length - 1; i >= 0; i--){
+ for (i = inst.snapElements.length - 1; i >= 0; i--){
- var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,
- t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
+ l = inst.snapElements[i].left;
+ r = l + inst.snapElements[i].width;
+ t = inst.snapElements[i].top;
+ b = t + inst.snapElements[i].height;
//Yes, I know, this is insane ;)
if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
- if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
+ if(inst.snapElements[i].snapping) {
+ (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') {
- var ts = Math.abs(t - y2) <= d;
- var bs = Math.abs(b - y1) <= d;
- var ls = Math.abs(l - x2) <= d;
- var rs = Math.abs(r - x1) <= d;
- if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
- if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
- if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
- if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
+ 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 - inst.margins.top;
+ }
+ if(bs) {
+ ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
+ }
+ if(ls) {
+ ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
+ }
+ if(rs) {
+ ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
+ }
}
- var first = (ts || bs || ls || rs);
+ first = (ts || bs || ls || rs);
- if(o.snapMode != 'outer') {
- var ts = Math.abs(t - y1) <= d;
- var bs = Math.abs(b - y2) <= d;
- var ls = Math.abs(l - x1) <= d;
- var rs = Math.abs(r - x2) <= d;
- if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
- if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
- if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
- if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
+ 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 - inst.margins.top;
+ }
+ if(bs) {
+ ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
+ }
+ if(ls) {
+ ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
+ }
+ if(rs) {
+ ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
+ }
}
- if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first))
+ if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) {
(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) {
-
- var o = $(this).data("draggable").options;
+ start: function() {
+ var min,
+ o = this.data("ui-draggable").options,
+ group = $.makeArray($(o.stack)).sort(function(a,b) {
+ return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
+ });
- var 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; }
- var min = parseInt(group[0].style.zIndex) || 0;
+ min = parseInt($(group[0]).css("zIndex"), 10) || 0;
$(group).each(function(i) {
- this.style.zIndex = min + i;
+ $(this).css("zIndex", min + i);
});
-
- this[0].style.zIndex = min + group.length;
-
+ this.css("zIndex", (min + group.length));
}
});
$.ui.plugin.add("draggable", "zIndex", {
start: function(event, ui) {
- var t = $(ui.helper), o = $(this).data("draggable").options;
- if(t.css("zIndex")) o._zIndex = t.css("zIndex");
- t.css('zIndex', o.zIndex);
+ var t = $(ui.helper), o = $(this).data("ui-draggable").options;
+ if(t.css("zIndex")) {
+ o._zIndex = t.css("zIndex");
+ }
+ t.css("zIndex", o.zIndex);
},
stop: function(event, ui) {
- var o = $(this).data("draggable").options;
- if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex);
+ var o = $(this).data("ui-draggable").options;
+ if(o._zIndex) {
+ $(ui.helper).css("zIndex", o._zIndex);
+ }
}
});
@@ -1850,22 +1903,36 @@ $.ui.plugin.add("draggable", "zIndex", {
(function( $, undefined ) {
+function isOverAxis( x, reference, size ) {
+ return ( x > reference ) && ( x < ( reference + size ) );
+}
+
$.widget("ui.droppable", {
- version: "1.9.2",
+ version: "1.10.2",
widgetEventPrefix: "drop",
options: {
- accept: '*',
+ accept: "*",
activeClass: false,
addClasses: true,
greedy: false,
hoverClass: false,
- scope: 'default',
- tolerance: 'intersect'
+ scope: "default",
+ tolerance: "intersect",
+
+ // callbacks
+ activate: null,
+ deactivate: null,
+ drop: null,
+ out: null,
+ over: null
},
_create: function() {
- var o = this.options, accept = o.accept;
- this.isover = 0; this.isout = 1;
+ var o = this.options,
+ accept = o.accept;
+
+ this.isover = false;
+ this.isout = true;
this.accept = $.isFunction(accept) ? accept : function(d) {
return d.is(accept);
@@ -1883,17 +1950,21 @@ $.widget("ui.droppable", {
},
_destroy: function() {
- var drop = $.ui.ddmanager.droppables[this.options.scope];
- for ( var i = 0; i < drop.length; i++ )
- if ( drop[i] == this )
+ var i = 0,
+ drop = $.ui.ddmanager.droppables[this.options.scope];
+
+ for ( ; i < drop.length; i++ ) {
+ if ( drop[i] === this ) {
drop.splice(i, 1);
+ }
+ }
this.element.removeClass("ui-droppable ui-droppable-disabled");
},
_setOption: function(key, value) {
- if(key == 'accept') {
+ if(key === "accept") {
this.accept = $.isFunction(value) ? value : function(d) {
return d.is(value);
};
@@ -1903,24 +1974,38 @@ $.widget("ui.droppable", {
_activate: function(event) {
var draggable = $.ui.ddmanager.current;
- if(this.options.activeClass) this.element.addClass(this.options.activeClass);
- (draggable && this._trigger('activate', event, this.ui(draggable)));
+ if(this.options.activeClass) {
+ this.element.addClass(this.options.activeClass);
+ }
+ if(draggable){
+ this._trigger("activate", event, this.ui(draggable));
+ }
},
_deactivate: function(event) {
var draggable = $.ui.ddmanager.current;
- if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
- (draggable && this._trigger('deactivate', event, this.ui(draggable)));
+ if(this.options.activeClass) {
+ this.element.removeClass(this.options.activeClass);
+ }
+ if(draggable){
+ this._trigger("deactivate", event, this.ui(draggable));
+ }
},
_over: function(event) {
var draggable = $.ui.ddmanager.current;
- if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
+
+ // 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))) {
- if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
- this._trigger('over', event, this.ui(draggable));
+ if(this.options.hoverClass) {
+ this.element.addClass(this.options.hoverClass);
+ }
+ this._trigger("over", event, this.ui(draggable));
}
},
@@ -1928,37 +2013,53 @@ $.widget("ui.droppable", {
_out: function(event) {
var draggable = $.ui.ddmanager.current;
- if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
+
+ // 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))) {
- if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
- this._trigger('out', event, this.ui(draggable));
+ if(this.options.hoverClass) {
+ this.element.removeClass(this.options.hoverClass);
+ }
+ this._trigger("out", event, this.ui(draggable));
}
},
_drop: function(event,custom) {
- var draggable = custom || $.ui.ddmanager.current;
- if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
+ 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;
+ }
- var childrenIntersection = false;
- this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
- var inst = $.data(this, 'droppable');
+ this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() {
+ var inst = $.data(this, "ui-droppable");
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)
+ 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)
) { childrenIntersection = true; return false; }
});
- if(childrenIntersection) return false;
+ if(childrenIntersection) {
+ return false;
+ }
if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
- if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
- if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
- this._trigger('drop', event, this.ui(draggable));
+ if(this.options.activeClass) {
+ this.element.removeClass(this.options.activeClass);
+ }
+ if(this.options.hoverClass) {
+ this.element.removeClass(this.options.hoverClass);
+ }
+ this._trigger("drop", event, this.ui(draggable));
return this.element;
}
@@ -1979,44 +2080,40 @@ $.widget("ui.droppable", {
$.ui.intersect = function(draggable, droppable, toleranceMode) {
- if (!droppable.offset) return false;
+ if (!droppable.offset) {
+ return false;
+ }
- var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
- y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
- var l = droppable.offset.left, r = l + droppable.proportions.width,
+ var draggableLeft, draggableTop,
+ x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
+ y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height,
+ l = droppable.offset.left, r = l + droppable.proportions.width,
t = droppable.offset.top, b = t + droppable.proportions.height;
switch (toleranceMode) {
- case 'fit':
- return (l <= x1 && x2 <= r
- && t <= y1 && y2 <= b);
- break;
- 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
- break;
- case 'pointer':
- var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left),
- draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top),
- isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
- return isOver;
- break;
- case 'touch':
+ 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":
+ draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left);
+ draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top);
+ return isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, 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
- );
- break;
+ (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;
- break;
}
};
@@ -2026,20 +2123,38 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) {
*/
$.ui.ddmanager = {
current: null,
- droppables: { 'default': [] },
+ droppables: { "default": [] },
prepareOffsets: function(t, event) {
- var m = $.ui.ddmanager.droppables[t.options.scope] || [];
- var type = event ? event.type : null; // workaround for #2317
- var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
+ 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 (var i = 0; i < m.length; i++) {
+ droppablesLoop: for (i = 0; i < m.length; i++) {
- if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted
- for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item
- m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
+ //No disabled and non-accepted
+ if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) {
+ continue;
+ }
- if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
+ // 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 };
@@ -2050,14 +2165,19 @@ $.ui.ddmanager = {
drop: function(draggable, event) {
var dropped = false;
- $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
+ // 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))
+ if(!this.options) {
+ return;
+ }
+ if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) {
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 = 1; this.isover = 0;
+ this.isout = true;
+ this.isover = false;
this._deactivate.call(this, event);
}
@@ -2068,51 +2188,60 @@ $.ui.ddmanager = {
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" ).bind( "scroll.droppable", function() {
- if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
+ 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);
+ 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 intersects = $.ui.intersect(draggable, this, this.options.tolerance);
+ if(this.options.disabled || this.greedyChild || !this.visible) {
+ return;
+ }
- var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
- if(!c) return;
+ var parentInstance, scope, parent,
+ intersects = $.ui.intersect(draggable, this, this.options.tolerance),
+ c = !intersects && this.isover ? "isout" : (intersects && !this.isover ? "isover" : null);
+ if(!c) {
+ return;
+ }
- var parentInstance;
if (this.options.greedy) {
// find droppable parents with same scope
- var scope = this.options.scope;
- var parent = this.element.parents(':data(droppable)').filter(function () {
- return $.data(this, 'droppable').options.scope === scope;
+ scope = this.options.scope;
+ parent = this.element.parents(":data(ui-droppable)").filter(function () {
+ return $.data(this, "ui-droppable").options.scope === scope;
});
if (parent.length) {
- parentInstance = $.data(parent[0], 'droppable');
- parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
+ parentInstance = $.data(parent[0], "ui-droppable");
+ parentInstance.greedyChild = (c === "isover");
}
}
// we just moved into a greedy child
- if (parentInstance && c == 'isover') {
- parentInstance['isover'] = 0;
- parentInstance['isout'] = 1;
+ if (parentInstance && c === "isover") {
+ parentInstance.isover = false;
+ parentInstance.isout = true;
parentInstance._out.call(parentInstance, event);
}
- this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
- this[c == "isover" ? "_over" : "_out"].call(this, 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'] = 0;
- parentInstance['isover'] = 1;
+ if (parentInstance && c === "isout") {
+ parentInstance.isout = false;
+ parentInstance.isover = true;
parentInstance._over.call(parentInstance, event);
}
});
@@ -2121,7 +2250,9 @@ $.ui.ddmanager = {
dragStop: function( draggable, event ) {
draggable.element.parentsUntil( "body" ).unbind( "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 );
+ if( !draggable.options.refreshPositions ) {
+ $.ui.ddmanager.prepareOffsets( draggable, event );
+ }
}
};
@@ -2129,8 +2260,16 @@ $.ui.ddmanager = {
(function( $, undefined ) {
+function num(v) {
+ return parseInt(v, 10) || 0;
+}
+
+function isNumber(value) {
+ return !isNaN(parseInt(value, 10));
+}
+
$.widget("ui.resizable", $.ui.mouse, {
- version: "1.9.2",
+ version: "1.10.2",
widgetEventPrefix: "resize",
options: {
alsoResize: false,
@@ -2148,11 +2287,19 @@ $.widget("ui.resizable", $.ui.mouse, {
maxWidth: null,
minHeight: 10,
minWidth: 10,
- zIndex: 1000
+ // See #7960
+ zIndex: 90,
+
+ // callbacks
+ resize: null,
+ start: null,
+ stop: null
},
_create: function() {
- var that = this, o = this.options;
+ var n, i, handle, axis, hname,
+ that = this,
+ o = this.options;
this.element.addClass("ui-resizable");
$.extend(this, {
@@ -2160,7 +2307,7 @@ $.widget("ui.resizable", $.ui.mouse, {
aspectRatio: o.aspectRatio,
originalElement: this.element,
_proportionallyResizeElements: [],
- _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null
+ _helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null
});
//Wrap the element if it cannot hold child nodes
@@ -2168,18 +2315,18 @@ $.widget("ui.resizable", $.ui.mouse, {
//Create a wrapper element and set the wrapper to the new current internal element
this.element.wrap(
- $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({
- position: this.element.css('position'),
+ $("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({
+ position: this.element.css("position"),
width: this.element.outerWidth(),
height: this.element.outerHeight(),
- top: this.element.css('top'),
- left: this.element.css('left')
+ top: this.element.css("top"),
+ left: this.element.css("left")
})
);
//Overwrite the original this.element
this.element = this.element.parent().data(
- "resizable", this.element.data('resizable')
+ "ui-resizable", this.element.data("ui-resizable")
);
this.elementIsWrapper = true;
@@ -2189,41 +2336,46 @@ $.widget("ui.resizable", $.ui.mouse, {
this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
//Prevent Safari textarea resize
- this.originalResizeStyle = this.originalElement.css('resize');
- this.originalElement.css('resize', 'none');
+ this.originalResizeStyle = this.originalElement.css("resize");
+ this.originalElement.css("resize", "none");
//Push the actual element to our proportionallyResize internal array
- this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' }));
+ this._proportionallyResizeElements.push(this.originalElement.css({ position: "static", zoom: 1, display: "block" }));
// avoid IE jump (hard set the margin)
- this.originalElement.css({ margin: this.originalElement.css('margin') });
+ this.originalElement.css({ margin: this.originalElement.css("margin") });
// fix handlers offset
this._proportionallyResize();
}
- this.handles = o.handles || (!$('.ui-resizable-handle', this.element).length ? "e,s,se" : { n: '.ui-resizable-n', e: '.ui-resizable-e', s: '.ui-resizable-s', w: '.ui-resizable-w', se: '.ui-resizable-se', sw: '.ui-resizable-sw', ne: '.ui-resizable-ne', nw: '.ui-resizable-nw' });
- if(this.handles.constructor == String) {
+ this.handles = o.handles || (!$(".ui-resizable-handle", this.element).length ? "e,s,se" : { n: ".ui-resizable-n", e: ".ui-resizable-e", s: ".ui-resizable-s", w: ".ui-resizable-w", se: ".ui-resizable-se", sw: ".ui-resizable-sw", ne: ".ui-resizable-ne", nw: ".ui-resizable-nw" });
+ if(this.handles.constructor === String) {
+
+ if ( this.handles === "all") {
+ this.handles = "n,e,s,w,se,sw,ne,nw";
+ }
- if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw';
- var n = this.handles.split(","); this.handles = {};
+ n = this.handles.split(",");
+ this.handles = {};
- for(var i = 0; i < n.length; i++) {
+ for(i = 0; i < n.length; i++) {
- var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle;
- var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>');
+ handle = $.trim(n[i]);
+ hname = "ui-resizable-"+handle;
+ axis = $("<div class='ui-resizable-handle " + hname + "'></div>");
// Apply zIndex to all handles - see #7960
axis.css({ zIndex: o.zIndex });
//TODO : What's going on here?
- if ('se' == handle) {
- axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se');
- };
+ if ("se" === handle) {
+ axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se");
+ }
//Insert into internal handles object and append to element
- this.handles[handle] = '.ui-resizable-'+handle;
+ this.handles[handle] = ".ui-resizable-"+handle;
this.element.append(axis);
}
@@ -2231,26 +2383,29 @@ $.widget("ui.resizable", $.ui.mouse, {
this._renderAxis = function(target) {
+ var i, axis, padPos, padWrapper;
+
target = target || this.element;
- for(var i in this.handles) {
+ for(i in this.handles) {
- if(this.handles[i].constructor == String)
+ if(this.handles[i].constructor === String) {
this.handles[i] = $(this.handles[i], this.element).show();
+ }
//Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
- var axis = $(this.handles[i], this.element), padWrapper = 0;
+ axis = $(this.handles[i], this.element);
//Checking the correct pad and border
padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
//The padding type i have to apply...
- var padPos = [ 'padding',
- /ne|nw|n/.test(i) ? 'Top' :
- /se|sw|s/.test(i) ? 'Bottom' :
- /^e$/.test(i) ? 'Right' : 'Left' ].join("");
+ padPos = [ "padding",
+ /ne|nw|n/.test(i) ? "Top" :
+ /se|sw|s/.test(i) ? "Bottom" :
+ /^e$/.test(i) ? "Right" : "Left" ].join("");
target.css(padPos, padWrapper);
@@ -2259,25 +2414,26 @@ $.widget("ui.resizable", $.ui.mouse, {
}
//TODO: What's that good for? There's not anything to be executed left
- if(!$(this.handles[i]).length)
+ if(!$(this.handles[i]).length) {
continue;
-
+ }
}
};
//TODO: make renderAxis a prototype function
this._renderAxis(this.element);
- this._handles = $('.ui-resizable-handle', this.element)
+ this._handles = $(".ui-resizable-handle", this.element)
.disableSelection();
//Matching axis name
this._handles.mouseover(function() {
if (!that.resizing) {
- if (this.className)
- var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
+ if (this.className) {
+ axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
+ }
//Axis, default = se
- that.axis = axis && axis[1] ? axis[1] : 'se';
+ that.axis = axis && axis[1] ? axis[1] : "se";
}
});
@@ -2287,12 +2443,16 @@ $.widget("ui.resizable", $.ui.mouse, {
$(this.element)
.addClass("ui-resizable-autohide")
.mouseenter(function() {
- if (o.disabled) return;
+ if (o.disabled) {
+ return;
+ }
$(this).removeClass("ui-resizable-autohide");
that._handles.show();
})
.mouseleave(function(){
- if (o.disabled) return;
+ if (o.disabled) {
+ return;
+ }
if (!that.resizing) {
$(this).addClass("ui-resizable-autohide");
that._handles.hide();
@@ -2309,57 +2469,66 @@ $.widget("ui.resizable", $.ui.mouse, {
this._mouseDestroy();
- var _destroy = function(exp) {
- $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
- .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
- };
+ var wrapper,
+ _destroy = function(exp) {
+ $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
+ .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove();
+ };
//TODO: Unwrap at same DOM position
if (this.elementIsWrapper) {
_destroy(this.element);
- var wrapper = this.element;
+ wrapper = this.element;
this.originalElement.css({
- position: wrapper.css('position'),
+ position: wrapper.css("position"),
width: wrapper.outerWidth(),
height: wrapper.outerHeight(),
- top: wrapper.css('top'),
- left: wrapper.css('left')
+ top: wrapper.css("top"),
+ left: wrapper.css("left")
}).insertAfter( wrapper );
wrapper.remove();
}
- this.originalElement.css('resize', this.originalResizeStyle);
+ this.originalElement.css("resize", this.originalResizeStyle);
_destroy(this.originalElement);
return this;
},
_mouseCapture: function(event) {
- var handle = false;
- for (var i in this.handles) {
- if ($(this.handles[i])[0] == event.target) {
- handle = true;
+ var i, handle,
+ capture = false;
+
+ for (i in this.handles) {
+ handle = $(this.handles[i])[0];
+ if (handle === event.target || $.contains(handle, event.target)) {
+ capture = true;
}
}
- return !this.options.disabled && handle;
+ return !this.options.disabled && capture;
},
_mouseStart: function(event) {
- var o = this.options, iniPos = this.element.position(), el = this.element;
+ var curleft, curtop, cursor,
+ o = this.options,
+ iniPos = this.element.position(),
+ el = this.element;
this.resizing = true;
- this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
// bugfix for http://dev.jquery.com/ticket/1749
- if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
- el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
+ if ( (/absolute/).test( el.css("position") ) ) {
+ el.css({ position: "absolute", top: el.css("top"), left: el.css("left") });
+ } else if (el.is(".ui-draggable")) {
+ el.css({ position: "absolute", top: iniPos.top, left: iniPos.left });
}
this._renderProxy();
- var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top'));
+ curleft = num(this.helper.css("left"));
+ curtop = num(this.helper.css("top"));
if (o.containment) {
curleft += $(o.containment).scrollLeft() || 0;
@@ -2376,10 +2545,10 @@ $.widget("ui.resizable", $.ui.mouse, {
this.originalMousePosition = { left: event.pageX, top: event.pageY };
//Aspect Ratio
- this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
+ this.aspectRatio = (typeof o.aspectRatio === "number") ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
- var cursor = $('.ui-resizable-' + this.axis).css('cursor');
- $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor);
+ cursor = $(".ui-resizable-" + this.axis).css("cursor");
+ $("body").css("cursor", cursor === "auto" ? this.axis + "-resize" : cursor);
el.addClass("ui-resizable-resizing");
this._propagate("start", event);
@@ -2389,38 +2558,60 @@ $.widget("ui.resizable", $.ui.mouse, {
_mouseDrag: function(event) {
//Increase performance, avoid regex
- var el = this.helper, o = this.options, props = {},
- that = this, smp = this.originalMousePosition, a = this.axis;
-
- var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
- var trigger = this._change[a];
- if (!trigger) return false;
+ var data,
+ el = this.helper, props = {},
+ smp = this.originalMousePosition,
+ a = this.axis,
+ prevTop = this.position.top,
+ prevLeft = this.position.left,
+ prevWidth = this.size.width,
+ prevHeight = this.size.height,
+ dx = (event.pageX-smp.left)||0,
+ dy = (event.pageY-smp.top)||0,
+ trigger = this._change[a];
+
+ if (!trigger) {
+ return false;
+ }
// Calculate the attrs that will be change
- var data = trigger.apply(this, [event, dx, dy]);
+ data = trigger.apply(this, [event, dx, dy]);
// Put this in the mouseDrag handler since the user can start pressing shift while resizing
this._updateVirtualBoundaries(event.shiftKey);
- if (this._aspectRatio || event.shiftKey)
+ if (this._aspectRatio || event.shiftKey) {
data = this._updateRatio(data, event);
+ }
data = this._respectSize(data, event);
+ this._updateCache(data);
+
// plugins callbacks need to be called first
this._propagate("resize", event);
- el.css({
- top: this.position.top + "px", left: this.position.left + "px",
- width: this.size.width + "px", height: this.size.height + "px"
- });
+ if (this.position.top !== prevTop) {
+ props.top = this.position.top + "px";
+ }
+ if (this.position.left !== prevLeft) {
+ props.left = this.position.left + "px";
+ }
+ if (this.size.width !== prevWidth) {
+ props.width = this.size.width + "px";
+ }
+ if (this.size.height !== prevHeight) {
+ props.height = this.size.height + "px";
+ }
+ el.css(props);
- if (!this._helper && this._proportionallyResizeElements.length)
+ if (!this._helper && this._proportionallyResizeElements.length) {
this._proportionallyResize();
+ }
- this._updateCache(data);
-
- // calling the user callback at the end
- this._trigger('resize', event, this.ui());
+ // Call the user callback if the element was resized
+ if ( ! $.isEmptyObject(props) ) {
+ this._trigger("resize", event, this.ui());
+ }
return false;
},
@@ -2428,39 +2619,49 @@ $.widget("ui.resizable", $.ui.mouse, {
_mouseStop: function(event) {
this.resizing = false;
- var o = this.options, that = this;
+ var pr, ista, soffseth, soffsetw, s, left, top,
+ o = this.options, that = this;
if(this._helper) {
- var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
- soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
- soffsetw = ista ? 0 : that.sizeDiff.width;
- var s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) },
- left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
- top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
+ pr = this._proportionallyResizeElements;
+ ista = pr.length && (/textarea/i).test(pr[0].nodeName);
+ soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height;
+ soffsetw = ista ? 0 : that.sizeDiff.width;
- if (!o.animate)
+ s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) };
+ left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null;
+ top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
+
+ if (!o.animate) {
this.element.css($.extend(s, { top: top, left: left }));
+ }
that.helper.height(that.size.height);
that.helper.width(that.size.width);
- if (this._helper && !o.animate) this._proportionallyResize();
+ if (this._helper && !o.animate) {
+ this._proportionallyResize();
+ }
}
- $('body').css('cursor', 'auto');
+ $("body").css("cursor", "auto");
this.element.removeClass("ui-resizable-resizing");
this._propagate("stop", event);
- if (this._helper) this.helper.remove();
+ if (this._helper) {
+ this.helper.remove();
+ }
+
return false;
},
_updateVirtualBoundaries: function(forceAspectRatio) {
- var o = this.options, pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b;
+ var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,
+ o = this.options;
b = {
minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
@@ -2477,35 +2678,55 @@ $.widget("ui.resizable", $.ui.mouse, {
pMaxWidth = b.maxHeight * this.aspectRatio;
pMaxHeight = b.maxWidth / this.aspectRatio;
- if(pMinWidth > b.minWidth) b.minWidth = pMinWidth;
- if(pMinHeight > b.minHeight) b.minHeight = pMinHeight;
- if(pMaxWidth < b.maxWidth) b.maxWidth = pMaxWidth;
- if(pMaxHeight < b.maxHeight) b.maxHeight = pMaxHeight;
+ if(pMinWidth > b.minWidth) {
+ b.minWidth = pMinWidth;
+ }
+ if(pMinHeight > b.minHeight) {
+ b.minHeight = pMinHeight;
+ }
+ if(pMaxWidth < b.maxWidth) {
+ b.maxWidth = pMaxWidth;
+ }
+ if(pMaxHeight < b.maxHeight) {
+ b.maxHeight = pMaxHeight;
+ }
}
this._vBoundaries = b;
},
_updateCache: function(data) {
- var o = this.options;
this.offset = this.helper.offset();
- if (isNumber(data.left)) this.position.left = data.left;
- if (isNumber(data.top)) this.position.top = data.top;
- if (isNumber(data.height)) this.size.height = data.height;
- if (isNumber(data.width)) this.size.width = data.width;
+ if (isNumber(data.left)) {
+ this.position.left = data.left;
+ }
+ if (isNumber(data.top)) {
+ this.position.top = data.top;
+ }
+ if (isNumber(data.height)) {
+ this.size.height = data.height;
+ }
+ if (isNumber(data.width)) {
+ this.size.width = data.width;
+ }
},
- _updateRatio: function(data, event) {
+ _updateRatio: function( data ) {
- var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
+ var cpos = this.position,
+ csize = this.size,
+ a = this.axis;
- if (isNumber(data.height)) data.width = (data.height * this.aspectRatio);
- else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio);
+ if (isNumber(data.height)) {
+ data.width = (data.height * this.aspectRatio);
+ } else if (isNumber(data.width)) {
+ data.height = (data.width / this.aspectRatio);
+ }
- if (a == 'sw') {
+ if (a === "sw") {
data.left = cpos.left + (csize.width - data.width);
data.top = null;
}
- if (a == 'nw') {
+ if (a === "nw") {
data.top = cpos.top + (csize.height - data.height);
data.left = cpos.left + (csize.width - data.width);
}
@@ -2513,51 +2734,72 @@ $.widget("ui.resizable", $.ui.mouse, {
return data;
},
- _respectSize: function(data, event) {
+ _respectSize: function( data ) {
- var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
- ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
- isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
-
- if (isminw) data.width = o.minWidth;
- if (isminh) data.height = o.minHeight;
- if (ismaxw) data.width = o.maxWidth;
- if (ismaxh) data.height = o.maxHeight;
-
- var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height;
- var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
+ var o = this._vBoundaries,
+ a = this.axis,
+ ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
+ isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height),
+ dw = this.originalPosition.left + this.originalSize.width,
+ dh = this.position.top + this.size.height,
+ cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
+ if (isminw) {
+ data.width = o.minWidth;
+ }
+ if (isminh) {
+ data.height = o.minHeight;
+ }
+ if (ismaxw) {
+ data.width = o.maxWidth;
+ }
+ if (ismaxh) {
+ data.height = o.maxHeight;
+ }
- if (isminw && cw) data.left = dw - o.minWidth;
- if (ismaxw && cw) data.left = dw - o.maxWidth;
- if (isminh && ch) data.top = dh - o.minHeight;
- if (ismaxh && ch) data.top = dh - o.maxHeight;
+ if (isminw && cw) {
+ data.left = dw - o.minWidth;
+ }
+ if (ismaxw && cw) {
+ data.left = dw - o.maxWidth;
+ }
+ if (isminh && ch) {
+ data.top = dh - o.minHeight;
+ }
+ if (ismaxh && ch) {
+ data.top = dh - o.maxHeight;
+ }
// fixing jump error on top/left - bug #2330
- var isNotwh = !data.width && !data.height;
- if (isNotwh && !data.left && data.top) data.top = null;
- else if (isNotwh && !data.top && data.left) data.left = null;
+ if (!data.width && !data.height && !data.left && data.top) {
+ data.top = null;
+ } else if (!data.width && !data.height && !data.top && data.left) {
+ data.left = null;
+ }
return data;
},
_proportionallyResize: function() {
- var o = this.options;
- if (!this._proportionallyResizeElements.length) return;
- var element = this.helper || this.element;
+ if (!this._proportionallyResizeElements.length) {
+ return;
+ }
- for (var i=0; i < this._proportionallyResizeElements.length; i++) {
+ var i, j, borders, paddings, prel,
+ element = this.helper || this.element;
- var prel = this._proportionallyResizeElements[i];
+ for ( i=0; i < this._proportionallyResizeElements.length; i++) {
+
+ prel = this._proportionallyResizeElements[i];
if (!this.borderDif) {
- var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')],
- p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')];
+ this.borderDif = [];
+ borders = [prel.css("borderTopWidth"), prel.css("borderRightWidth"), prel.css("borderBottomWidth"), prel.css("borderLeftWidth")];
+ paddings = [prel.css("paddingTop"), prel.css("paddingRight"), prel.css("paddingBottom"), prel.css("paddingLeft")];
- this.borderDif = $.map(b, function(v, i) {
- var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0;
- return border + padding;
- });
+ for ( j = 0; j < borders.length; j++ ) {
+ this.borderDif[ j ] = ( parseInt( borders[ j ], 10 ) || 0 ) + ( parseInt( paddings[ j ], 10 ) || 0 );
+ }
}
prel.css({
@@ -2565,7 +2807,7 @@ $.widget("ui.resizable", $.ui.mouse, {
width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
});
- };
+ }
},
@@ -2576,18 +2818,14 @@ $.widget("ui.resizable", $.ui.mouse, {
if(this._helper) {
- this.helper = this.helper || $('<div style="overflow:hidden;"></div>');
-
- // fix ie6 offset TODO: This seems broken
- var ie6offset = ($.ui.ie6 ? 1 : 0),
- pxyoffset = ( $.ui.ie6 ? 2 : -1 );
+ this.helper = this.helper || $("<div style='overflow:hidden;'></div>");
this.helper.addClass(this._helper).css({
- width: this.element.outerWidth() + pxyoffset,
- height: this.element.outerHeight() + pxyoffset,
- position: 'absolute',
- left: this.elementOffset.left - ie6offset +'px',
- top: this.elementOffset.top - ie6offset +'px',
+ width: this.element.outerWidth() - 1,
+ height: this.element.outerHeight() - 1,
+ position: "absolute",
+ left: this.elementOffset.left +"px",
+ top: this.elementOffset.top +"px",
zIndex: ++o.zIndex //TODO: Don't modify option
});
@@ -2602,15 +2840,15 @@ $.widget("ui.resizable", $.ui.mouse, {
},
_change: {
- e: function(event, dx, dy) {
+ e: function(event, dx) {
return { width: this.originalSize.width + dx };
},
- w: function(event, dx, dy) {
- var o = this.options, cs = this.originalSize, sp = this.originalPosition;
+ w: function(event, dx) {
+ var cs = this.originalSize, sp = this.originalPosition;
return { left: sp.left + dx, width: cs.width - dx };
},
n: function(event, dx, dy) {
- var o = this.options, cs = this.originalSize, sp = this.originalPosition;
+ var cs = this.originalSize, sp = this.originalPosition;
return { top: sp.top + dy, height: cs.height - dy };
},
s: function(event, dx, dy) {
@@ -2632,7 +2870,7 @@ $.widget("ui.resizable", $.ui.mouse, {
_propagate: function(n, event) {
$.ui.plugin.call(this, n, [event, this.ui()]);
- (n != "resize" && this._trigger(n, event, this.ui()));
+ (n !== "resize" && this._trigger(n, event, this.ui()));
},
plugins: {},
@@ -2655,76 +2893,18 @@ $.widget("ui.resizable", $.ui.mouse, {
* Resizable Extensions
*/
-$.ui.plugin.add("resizable", "alsoResize", {
-
- start: function (event, ui) {
- var that = $(this).data("resizable"), o = that.options;
-
- var _store = function (exp) {
- $(exp).each(function() {
- var el = $(this);
- el.data("resizable-alsoresize", {
- width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
- left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10)
- });
- });
- };
-
- if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
- if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
- else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
- }else{
- _store(o.alsoResize);
- }
- },
-
- resize: function (event, ui) {
- var that = $(this).data("resizable"), o = that.options, os = that.originalSize, op = that.originalPosition;
-
- var delta = {
- height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
- top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
- },
-
- _alsoResize = function (exp, c) {
- $(exp).each(function() {
- var el = $(this), start = $(this).data("resizable-alsoresize"), style = {},
- css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left'];
-
- $.each(css, function (i, prop) {
- var sum = (start[prop]||0) + (delta[prop]||0);
- if (sum && sum >= 0)
- style[prop] = sum || null;
- });
-
- el.css(style);
- });
- };
-
- if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
- $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
- }else{
- _alsoResize(o.alsoResize);
- }
- },
-
- stop: function (event, ui) {
- $(this).removeData("resizable-alsoresize");
- }
-});
-
$.ui.plugin.add("resizable", "animate", {
- stop: function(event, ui) {
- var that = $(this).data("resizable"), o = that.options;
-
- var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
- soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
- soffsetw = ista ? 0 : that.sizeDiff.width;
-
- var style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
- left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
- top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
+ stop: function( event ) {
+ var that = $(this).data("ui-resizable"),
+ o = that.options,
+ pr = that._proportionallyResizeElements,
+ ista = pr.length && (/textarea/i).test(pr[0].nodeName),
+ soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height,
+ soffsetw = ista ? 0 : that.sizeDiff.width,
+ style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
+ left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null,
+ top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
that.element.animate(
$.extend(style, top && left ? { top: top, left: left } : {}), {
@@ -2733,13 +2913,15 @@ $.ui.plugin.add("resizable", "animate", {
step: function() {
var data = {
- width: parseInt(that.element.css('width'), 10),
- height: parseInt(that.element.css('height'), 10),
- top: parseInt(that.element.css('top'), 10),
- left: parseInt(that.element.css('left'), 10)
+ width: parseInt(that.element.css("width"), 10),
+ height: parseInt(that.element.css("height"), 10),
+ top: parseInt(that.element.css("top"), 10),
+ left: parseInt(that.element.css("left"), 10)
};
- if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });
+ if (pr && pr.length) {
+ $(pr[0]).css({ width: data.width, height: data.height });
+ }
// propagating resize, and updating values for each animation step
that._updateCache(data);
@@ -2754,14 +2936,21 @@ $.ui.plugin.add("resizable", "animate", {
$.ui.plugin.add("resizable", "containment", {
- start: function(event, ui) {
- var that = $(this).data("resizable"), o = that.options, el = that.element;
- var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
- if (!ce) return;
+ start: function() {
+ var element, p, co, ch, cw, width, height,
+ that = $(this).data("ui-resizable"),
+ o = that.options,
+ el = that.element,
+ oc = o.containment,
+ ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
+
+ if (!ce) {
+ return;
+ }
that.containerElement = $(ce);
- if (/document/.test(oc) || oc == document) {
+ if (/document/.test(oc) || oc === document) {
that.containerOffset = { left: 0, top: 0 };
that.containerPosition = { left: 0, top: 0 };
@@ -2773,15 +2962,19 @@ $.ui.plugin.add("resizable", "containment", {
// i'm a node, so compute top, left, right, bottom
else {
- var element = $(ce), p = [];
+ element = $(ce);
+ p = [];
$([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
that.containerOffset = element.offset();
that.containerPosition = element.position();
that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
- var co = that.containerOffset, ch = that.containerSize.height, cw = that.containerSize.width,
- width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
+ co = that.containerOffset;
+ ch = that.containerSize.height;
+ cw = that.containerSize.width;
+ width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw );
+ height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
that.parentData = {
element: ce, left: co.left, top: co.top, width: width, height: height
@@ -2789,114 +2982,227 @@ $.ui.plugin.add("resizable", "containment", {
}
},
- resize: function(event, ui) {
- var that = $(this).data("resizable"), o = that.options,
- ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position,
- pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement;
+ resize: function( event ) {
+ var woset, hoset, isParent, isOffsetRelative,
+ that = $(this).data("ui-resizable"),
+ o = that.options,
+ co = that.containerOffset, cp = that.position,
+ pRatio = that._aspectRatio || event.shiftKey,
+ cop = { top:0, left:0 }, ce = that.containerElement;
- if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;
+ if (ce[0] !== document && (/static/).test(ce.css("position"))) {
+ cop = co;
+ }
if (cp.left < (that._helper ? co.left : 0)) {
that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
- if (pRatio) that.size.height = that.size.width / that.aspectRatio;
+ if (pRatio) {
+ that.size.height = that.size.width / that.aspectRatio;
+ }
that.position.left = o.helper ? co.left : 0;
}
if (cp.top < (that._helper ? co.top : 0)) {
that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
- if (pRatio) that.size.width = that.size.height * that.aspectRatio;
+ if (pRatio) {
+ that.size.width = that.size.height * that.aspectRatio;
+ }
that.position.top = that._helper ? co.top : 0;
}
that.offset.left = that.parentData.left+that.position.left;
that.offset.top = that.parentData.top+that.position.top;
- var woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width ),
- hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
+ woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width );
+ hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
- var isParent = that.containerElement.get(0) == that.element.parent().get(0),
- isOffsetRelative = /relative|absolute/.test(that.containerElement.css('position'));
+ isParent = that.containerElement.get(0) === that.element.parent().get(0);
+ isOffsetRelative = /relative|absolute/.test(that.containerElement.css("position"));
- if(isParent && isOffsetRelative) woset -= that.parentData.left;
+ if(isParent && isOffsetRelative) {
+ woset -= that.parentData.left;
+ }
if (woset + that.size.width >= that.parentData.width) {
that.size.width = that.parentData.width - woset;
- if (pRatio) that.size.height = that.size.width / that.aspectRatio;
+ if (pRatio) {
+ that.size.height = that.size.width / that.aspectRatio;
+ }
}
if (hoset + that.size.height >= that.parentData.height) {
that.size.height = that.parentData.height - hoset;
- if (pRatio) that.size.width = that.size.height * that.aspectRatio;
+ if (pRatio) {
+ that.size.width = that.size.height * that.aspectRatio;
+ }
}
},
- stop: function(event, ui){
- var that = $(this).data("resizable"), o = that.options, cp = that.position,
- co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement;
+ stop: function(){
+ var that = $(this).data("ui-resizable"),
+ o = that.options,
+ co = that.containerOffset,
+ cop = that.containerPosition,
+ ce = that.containerElement,
+ helper = $(that.helper),
+ ho = helper.offset(),
+ w = helper.outerWidth() - that.sizeDiff.width,
+ h = helper.outerHeight() - that.sizeDiff.height;
- var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height;
-
- if (that._helper && !o.animate && (/relative/).test(ce.css('position')))
+ if (that._helper && !o.animate && (/relative/).test(ce.css("position"))) {
$(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
+ }
- if (that._helper && !o.animate && (/static/).test(ce.css('position')))
+ if (that._helper && !o.animate && (/static/).test(ce.css("position"))) {
$(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
+ }
+
+ }
+});
+
+$.ui.plugin.add("resizable", "alsoResize", {
+
+ start: function () {
+ var that = $(this).data("ui-resizable"),
+ o = that.options,
+ _store = function (exp) {
+ $(exp).each(function() {
+ var el = $(this);
+ el.data("ui-resizable-alsoresize", {
+ width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
+ left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
+ });
+ });
+ };
+
+ if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) {
+ if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
+ else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
+ }else{
+ _store(o.alsoResize);
+ }
+ },
+
+ resize: function (event, ui) {
+ var that = $(this).data("ui-resizable"),
+ o = that.options,
+ os = that.originalSize,
+ op = that.originalPosition,
+ delta = {
+ height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
+ top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
+ },
+
+ _alsoResize = function (exp, c) {
+ $(exp).each(function() {
+ var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
+ css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ["width", "height"] : ["width", "height", "top", "left"];
+
+ $.each(css, function (i, prop) {
+ var sum = (start[prop]||0) + (delta[prop]||0);
+ if (sum && sum >= 0) {
+ style[prop] = sum || null;
+ }
+ });
+
+ el.css(style);
+ });
+ };
+
+ if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
+ $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
+ }else{
+ _alsoResize(o.alsoResize);
+ }
+ },
+ stop: function () {
+ $(this).removeData("resizable-alsoresize");
}
});
$.ui.plugin.add("resizable", "ghost", {
- start: function(event, ui) {
+ start: function() {
- var that = $(this).data("resizable"), o = that.options, cs = that.size;
+ var that = $(this).data("ui-resizable"), o = that.options, cs = that.size;
that.ghost = that.originalElement.clone();
that.ghost
- .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
- .addClass('ui-resizable-ghost')
- .addClass(typeof o.ghost == 'string' ? o.ghost : '');
+ .css({ opacity: 0.25, display: "block", position: "relative", height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
+ .addClass("ui-resizable-ghost")
+ .addClass(typeof o.ghost === "string" ? o.ghost : "");
that.ghost.appendTo(that.helper);
},
- resize: function(event, ui){
- var that = $(this).data("resizable"), o = that.options;
- if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width });
+ resize: function(){
+ var that = $(this).data("ui-resizable");
+ if (that.ghost) {
+ that.ghost.css({ position: "relative", height: that.size.height, width: that.size.width });
+ }
},
- stop: function(event, ui){
- var that = $(this).data("resizable"), o = that.options;
- if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0));
+ stop: function() {
+ var that = $(this).data("ui-resizable");
+ if (that.ghost && that.helper) {
+ that.helper.get(0).removeChild(that.ghost.get(0));
+ }
}
});
$.ui.plugin.add("resizable", "grid", {
- resize: function(event, ui) {
- var that = $(this).data("resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis, ratio = o._aspectRatio || event.shiftKey;
- o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid;
- var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1);
+ resize: function() {
+ var that = $(this).data("ui-resizable"),
+ o = that.options,
+ cs = that.size,
+ os = that.originalSize,
+ op = that.originalPosition,
+ a = that.axis,
+ grid = typeof o.grid === "number" ? [o.grid, o.grid] : o.grid,
+ gridX = (grid[0]||1),
+ gridY = (grid[1]||1),
+ ox = Math.round((cs.width - os.width) / gridX) * gridX,
+ oy = Math.round((cs.height - os.height) / gridY) * gridY,
+ newWidth = os.width + ox,
+ newHeight = os.height + oy,
+ isMaxWidth = o.maxWidth && (o.maxWidth < newWidth),
+ isMaxHeight = o.maxHeight && (o.maxHeight < newHeight),
+ isMinWidth = o.minWidth && (o.minWidth > newWidth),
+ isMinHeight = o.minHeight && (o.minHeight > newHeight);
+
+ o.grid = grid;
+
+ if (isMinWidth) {
+ newWidth = newWidth + gridX;
+ }
+ if (isMinHeight) {
+ newHeight = newHeight + gridY;
+ }
+ if (isMaxWidth) {
+ newWidth = newWidth - gridX;
+ }
+ if (isMaxHeight) {
+ newHeight = newHeight - gridY;
+ }
if (/^(se|s|e)$/.test(a)) {
- that.size.width = os.width + ox;
- that.size.height = os.height + oy;
- }
- else if (/^(ne)$/.test(a)) {
- that.size.width = os.width + ox;
- that.size.height = os.height + oy;
+ that.size.width = newWidth;
+ that.size.height = newHeight;
+ } else if (/^(ne)$/.test(a)) {
+ that.size.width = newWidth;
+ that.size.height = newHeight;
that.position.top = op.top - oy;
- }
- else if (/^(sw)$/.test(a)) {
- that.size.width = os.width + ox;
- that.size.height = os.height + oy;
+ } else if (/^(sw)$/.test(a)) {
+ that.size.width = newWidth;
+ that.size.height = newHeight;
that.position.left = op.left - ox;
- }
- else {
- that.size.width = os.width + ox;
- that.size.height = os.height + oy;
+ } else {
+ that.size.width = newWidth;
+ that.size.height = newHeight;
that.position.top = op.top - oy;
that.position.left = op.left - ox;
}
@@ -2904,42 +3210,42 @@ $.ui.plugin.add("resizable", "grid", {
});
-var num = function(v) {
- return parseInt(v, 10) || 0;
-};
-
-var isNumber = function(value) {
- return !isNaN(parseInt(value, 10));
-};
-
})(jQuery);
(function( $, undefined ) {
$.widget("ui.selectable", $.ui.mouse, {
- version: "1.9.2",
+ version: "1.10.2",
options: {
- appendTo: 'body',
+ appendTo: "body",
autoRefresh: true,
distance: 0,
- filter: '*',
- tolerance: 'touch'
+ filter: "*",
+ tolerance: "touch",
+
+ // callbacks
+ selected: null,
+ selecting: null,
+ start: null,
+ stop: null,
+ unselected: null,
+ unselecting: null
},
_create: function() {
- var that = this;
+ var selectees,
+ that = this;
this.element.addClass("ui-selectable");
this.dragged = false;
// cache selectee children based on filter
- var selectees;
this.refresh = function() {
selectees = $(that.options.filter, that.element[0]);
selectees.addClass("ui-selectee");
selectees.each(function() {
- var $this = $(this);
- var pos = $this.offset();
+ var $this = $(this),
+ pos = $this.offset();
$.data(this, "selectable-item", {
element: this,
$element: $this,
@@ -2948,9 +3254,9 @@ $.widget("ui.selectable", $.ui.mouse, {
right: pos.left + $this.outerWidth(),
bottom: pos.top + $this.outerHeight(),
startselected: false,
- selected: $this.hasClass('ui-selected'),
- selecting: $this.hasClass('ui-selecting'),
- unselecting: $this.hasClass('ui-unselecting')
+ selected: $this.hasClass("ui-selected"),
+ selecting: $this.hasClass("ui-selecting"),
+ unselecting: $this.hasClass("ui-unselecting")
});
});
};
@@ -2973,14 +3279,14 @@ $.widget("ui.selectable", $.ui.mouse, {
},
_mouseStart: function(event) {
- var that = this;
+ var that = this,
+ options = this.options;
this.opos = [event.pageX, event.pageY];
- if (this.options.disabled)
+ if (this.options.disabled) {
return;
-
- var options = this.options;
+ }
this.selectees = $(options.filter, this.element[0]);
@@ -2989,8 +3295,8 @@ $.widget("ui.selectable", $.ui.mouse, {
$(options.appendTo).append(this.helper);
// position helper (lasso)
this.helper.css({
- "left": event.clientX,
- "top": event.clientY,
+ "left": event.pageX,
+ "top": event.pageY,
"width": 0,
"height": 0
});
@@ -2999,13 +3305,13 @@ $.widget("ui.selectable", $.ui.mouse, {
this.refresh();
}
- this.selectees.filter('.ui-selected').each(function() {
+ this.selectees.filter(".ui-selected").each(function() {
var selectee = $.data(this, "selectable-item");
selectee.startselected = true;
if (!event.metaKey && !event.ctrlKey) {
- selectee.$element.removeClass('ui-selected');
+ selectee.$element.removeClass("ui-selected");
selectee.selected = false;
- selectee.$element.addClass('ui-unselecting');
+ selectee.$element.addClass("ui-unselecting");
selectee.unselecting = true;
// selectable UNSELECTING callback
that._trigger("unselecting", event, {
@@ -3014,10 +3320,11 @@ $.widget("ui.selectable", $.ui.mouse, {
}
});
- $(event.target).parents().andSelf().each(function() {
- var selectee = $.data(this, "selectable-item");
+ $(event.target).parents().addBack().each(function() {
+ var doSelect,
+ selectee = $.data(this, "selectable-item");
if (selectee) {
- var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
+ doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass("ui-selected");
selectee.$element
.removeClass(doSelect ? "ui-unselecting" : "ui-selected")
.addClass(doSelect ? "ui-selecting" : "ui-unselecting");
@@ -3041,43 +3348,52 @@ $.widget("ui.selectable", $.ui.mouse, {
},
_mouseDrag: function(event) {
- var that = this;
+
this.dragged = true;
- if (this.options.disabled)
+ if (this.options.disabled) {
return;
+ }
- var options = this.options;
+ var tmp,
+ that = this,
+ options = this.options,
+ x1 = this.opos[0],
+ y1 = this.opos[1],
+ x2 = event.pageX,
+ y2 = event.pageY;
- var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
- if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
- if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
+ if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; }
+ if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; }
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
this.selectees.each(function() {
- var selectee = $.data(this, "selectable-item");
+ var selectee = $.data(this, "selectable-item"),
+ hit = false;
+
//prevent helper from being selected if appendTo: selectable
- if (!selectee || selectee.element == that.element[0])
+ if (!selectee || selectee.element === that.element[0]) {
return;
- var hit = false;
- if (options.tolerance == 'touch') {
+ }
+
+ if (options.tolerance === "touch") {
hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
- } else if (options.tolerance == 'fit') {
+ } else if (options.tolerance === "fit") {
hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
}
if (hit) {
// SELECT
if (selectee.selected) {
- selectee.$element.removeClass('ui-selected');
+ selectee.$element.removeClass("ui-selected");
selectee.selected = false;
}
if (selectee.unselecting) {
- selectee.$element.removeClass('ui-unselecting');
+ selectee.$element.removeClass("ui-unselecting");
selectee.unselecting = false;
}
if (!selectee.selecting) {
- selectee.$element.addClass('ui-selecting');
+ selectee.$element.addClass("ui-selecting");
selectee.selecting = true;
// selectable SELECTING callback
that._trigger("selecting", event, {
@@ -3088,15 +3404,15 @@ $.widget("ui.selectable", $.ui.mouse, {
// UNSELECT
if (selectee.selecting) {
if ((event.metaKey || event.ctrlKey) && selectee.startselected) {
- selectee.$element.removeClass('ui-selecting');
+ selectee.$element.removeClass("ui-selecting");
selectee.selecting = false;
- selectee.$element.addClass('ui-selected');
+ selectee.$element.addClass("ui-selected");
selectee.selected = true;
} else {
- selectee.$element.removeClass('ui-selecting');
+ selectee.$element.removeClass("ui-selecting");
selectee.selecting = false;
if (selectee.startselected) {
- selectee.$element.addClass('ui-unselecting');
+ selectee.$element.addClass("ui-unselecting");
selectee.unselecting = true;
}
// selectable UNSELECTING callback
@@ -3107,10 +3423,10 @@ $.widget("ui.selectable", $.ui.mouse, {
}
if (selectee.selected) {
if (!event.metaKey && !event.ctrlKey && !selectee.startselected) {
- selectee.$element.removeClass('ui-selected');
+ selectee.$element.removeClass("ui-selected");
selectee.selected = false;
- selectee.$element.addClass('ui-unselecting');
+ selectee.$element.addClass("ui-unselecting");
selectee.unselecting = true;
// selectable UNSELECTING callback
that._trigger("unselecting", event, {
@@ -3129,20 +3445,18 @@ $.widget("ui.selectable", $.ui.mouse, {
this.dragged = false;
- var options = this.options;
-
- $('.ui-unselecting', this.element[0]).each(function() {
+ $(".ui-unselecting", this.element[0]).each(function() {
var selectee = $.data(this, "selectable-item");
- selectee.$element.removeClass('ui-unselecting');
+ selectee.$element.removeClass("ui-unselecting");
selectee.unselecting = false;
selectee.startselected = false;
that._trigger("unselected", event, {
unselected: selectee.element
});
});
- $('.ui-selecting', this.element[0]).each(function() {
+ $(".ui-selecting", this.element[0]).each(function() {
var selectee = $.data(this, "selectable-item");
- selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
+ selectee.$element.removeClass("ui-selecting").addClass("ui-selected");
selectee.selecting = false;
selectee.selected = true;
selectee.startselected = true;
@@ -3163,8 +3477,18 @@ $.widget("ui.selectable", $.ui.mouse, {
(function( $, undefined ) {
+/*jshint loopfunc: true */
+
+function isOverAxis( x, reference, size ) {
+ return ( x > reference ) && ( x < ( reference + size ) );
+}
+
+function isFloating(item) {
+ return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
+}
+
$.widget("ui.sortable", $.ui.mouse, {
- version: "1.9.2",
+ version: "1.10.2",
widgetEventPrefix: "sort",
ready: false,
options: {
@@ -3172,7 +3496,7 @@ $.widget("ui.sortable", $.ui.mouse, {
axis: false,
connectWith: false,
containment: false,
- cursor: 'auto',
+ cursor: "auto",
cursorAt: false,
dropOnEmpty: true,
forcePlaceholderSize: false,
@@ -3180,7 +3504,7 @@ $.widget("ui.sortable", $.ui.mouse, {
grid: false,
handle: false,
helper: "original",
- items: '> *',
+ items: "> *",
opacity: false,
placeholder: false,
revert: false,
@@ -3189,7 +3513,21 @@ $.widget("ui.sortable", $.ui.mouse, {
scrollSpeed: 20,
scope: "default",
tolerance: "intersect",
- zIndex: 1000
+ 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
},
_create: function() {
@@ -3201,7 +3539,7 @@ $.widget("ui.sortable", $.ui.mouse, {
this.refresh();
//Let's determine if the items are being displayed horizontally
- this.floating = this.items.length ? o.axis === 'x' || (/left|right/).test(this.items[0].item.css('float')) || (/inline|table-cell/).test(this.items[0].item.css('display')) : false;
+ this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false;
//Let's determine the parent's offset
this.offset = this.element.offset();
@@ -3210,7 +3548,7 @@ $.widget("ui.sortable", $.ui.mouse, {
this._mouseInit();
//We're ready to go
- this.ready = true
+ this.ready = true;
},
@@ -3219,8 +3557,9 @@ $.widget("ui.sortable", $.ui.mouse, {
.removeClass("ui-sortable ui-sortable-disabled");
this._mouseDestroy();
- for ( var i = this.items.length - 1; i >= 0; i-- )
+ for ( var i = this.items.length - 1; i >= 0; i-- ) {
this.items[i].item.removeData(this.widgetName + "-item");
+ }
return this;
},
@@ -3237,32 +3576,44 @@ $.widget("ui.sortable", $.ui.mouse, {
},
_mouseCapture: function(event, overrideHandle) {
- var that = this;
+ var currentItem = null,
+ validHandle = false,
+ that = this;
if (this.reverting) {
return false;
}
- if(this.options.disabled || this.options.type == 'static') 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
- var currentItem = null, nodes = $(event.target).parents().each(function() {
- if($.data(this, that.widgetName + '-item') == that) {
+ $(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($.data(event.target, that.widgetName + "-item") === that) {
+ currentItem = $(event.target);
+ }
- if(!currentItem) return false;
+ if(!currentItem) {
+ return false;
+ }
if(this.options.handle && !overrideHandle) {
- var validHandle = false;
-
- $(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; });
- if(!validHandle) return false;
+ $(this.options.handle, currentItem).find("*").addBack().each(function() {
+ if(this === event.target) {
+ validHandle = true;
+ }
+ });
+ if(!validHandle) {
+ return false;
+ }
}
this.currentItem = currentItem;
@@ -3273,7 +3624,9 @@ $.widget("ui.sortable", $.ui.mouse, {
_mouseStart: function(event, overrideHandle, noActivation) {
- var o = this.options;
+ var i, body,
+ o = this.options;
+
this.currentContainer = this;
//We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
@@ -3322,14 +3675,14 @@ $.widget("ui.sortable", $.ui.mouse, {
this.originalPageX = event.pageX;
this.originalPageY = event.pageY;
- //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
+ //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
(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]) {
+ if(this.helper[0] !== this.currentItem[0]) {
this.currentItem.hide();
}
@@ -3337,47 +3690,63 @@ $.widget("ui.sortable", $.ui.mouse, {
this._createPlaceholder();
//Set a containment if given in the options
- if(o.containment)
+ 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 );
- if(o.cursor) { // cursor option
- if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor");
- $('body').css("cursor", o.cursor);
+ this.storedStylesheet = $( "<style>*{ cursor: "+o.cursor+" !important; }</style>" ).appendTo( body );
}
if(o.opacity) { // opacity option
- if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity");
+ if (this.helper.css("opacity")) {
+ this._storedOpacity = this.helper.css("opacity");
+ }
this.helper.css("opacity", o.opacity);
}
if(o.zIndex) { // zIndex option
- if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex");
+ if (this.helper.css("zIndex")) {
+ this._storedZIndex = this.helper.css("zIndex");
+ }
this.helper.css("zIndex", o.zIndex);
}
//Prepare scrolling
- if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML')
+ if(this.scrollParent[0] !== document && 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)
+ if(!this._preserveHelperProportions) {
this._cacheHelperProportions();
+ }
- //Post 'activate' events to possible containers
- if(!noActivation) {
- for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); }
+ //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)
+ if($.ui.ddmanager) {
$.ui.ddmanager.current = this;
+ }
- if ($.ui.ddmanager && !o.dropBehaviour)
+ if ($.ui.ddmanager && !o.dropBehaviour) {
$.ui.ddmanager.prepareOffsets(this, event);
+ }
this.dragging = true;
@@ -3388,6 +3757,9 @@ $.widget("ui.sortable", $.ui.mouse, {
},
_mouseDrag: function(event) {
+ var i, item, itemElement, intersection,
+ o = this.options,
+ scrolled = false;
//Compute the helpers position
this.position = this._generatePosition(event);
@@ -3399,50 +3771,62 @@ $.widget("ui.sortable", $.ui.mouse, {
//Do scrolling
if(this.options.scroll) {
- var o = this.options, scrolled = false;
- if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
+ if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
- if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
+ 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)
+ } 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)
+ 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)
+ } else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
+ }
} else {
- if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
+ if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
- else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
+ } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
+ }
- if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
+ if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
- else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
+ } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
+ }
}
- if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
+ if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
$.ui.ddmanager.prepareOffsets(this, event);
+ }
}
//Regenerate the absolute position used for position checks
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';
+ 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";
+ }
//Rearrange
- for (var i = this.items.length - 1; i >= 0; i--) {
+ for (i = this.items.length - 1; i >= 0; i--) {
//Cache variables and intersection, continue if no intersection
- var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
- if (!intersection) continue;
+ 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 form other containers. This works because when moving
@@ -3451,18 +3835,22 @@ $.widget("ui.sortable", $.ui.mouse, {
//
// Without this moving items in "sub-sortables" can cause the placeholder to jitter
// beetween the outer and inner container.
- if (item.instance !== this.currentContainer) continue;
+ if (item.instance !== this.currentContainer) {
+ continue;
+ }
- if (itemElement != this.currentItem[0] //cannot intersect with itself
- && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
- && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
- && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
- //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
+ // 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";
+ this.direction = intersection === 1 ? "down" : "up";
- if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
+ if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
this._rearrange(event, item);
} else {
break;
@@ -3477,10 +3865,12 @@ $.widget("ui.sortable", $.ui.mouse, {
this._contactContainers(event);
//Interconnect with droppables
- if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
+ if($.ui.ddmanager) {
+ $.ui.ddmanager.drag(this, event);
+ }
//Call callbacks
- this._trigger('sort', event, this._uiHash());
+ this._trigger("sort", event, this._uiHash());
this.lastPositionAbs = this.positionAbs;
return false;
@@ -3489,22 +3879,29 @@ $.widget("ui.sortable", $.ui.mouse, {
_mouseStop: function(event, noPropagation) {
- if(!event) return;
+ if(!event) {
+ return;
+ }
//If we are using droppables, inform the manager about the drop
- if ($.ui.ddmanager && !this.options.dropBehaviour)
+ if ($.ui.ddmanager && !this.options.dropBehaviour) {
$.ui.ddmanager.drop(this, event);
+ }
if(this.options.revert) {
- var that = this;
- var cur = this.placeholder.offset();
+ 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] === document.body ? 0 : this.offsetParent[0].scrollLeft);
+ }
+ if ( !axis || axis === "y" ) {
+ animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollTop);
+ }
this.reverting = true;
-
- $(this.helper).animate({
- left: cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft),
- top: cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop)
- }, parseInt(this.options.revert, 10) || 500, function() {
+ $(this.helper).animate( animation, parseInt(this.options.revert, 10) || 500, function() {
that._clear(event);
});
} else {
@@ -3521,10 +3918,11 @@ $.widget("ui.sortable", $.ui.mouse, {
this._mouseUp({ target: null });
- if(this.options.helper == "original")
+ if(this.options.helper === "original") {
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
- else
+ } else {
this.currentItem.show();
+ }
//Post deactivating events to containers
for (var i = this.containers.length - 1; i >= 0; i--){
@@ -3539,8 +3937,12 @@ $.widget("ui.sortable", $.ui.mouse, {
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();
+ 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,
@@ -3562,28 +3964,33 @@ $.widget("ui.sortable", $.ui.mouse, {
serialize: function(o) {
- var items = this._getItemsAsjQuery(o && o.connected);
- var str = []; o = 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]));
+ 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 + '=');
+ str.push(o.key + "=");
}
- return str.join('&');
+ return str.join("&");
},
toArray: function(o) {
- var items = this._getItemsAsjQuery(o && o.connected);
- var ret = []; o = o || {};
+ var items = this._getItemsAsjQuery(o && o.connected),
+ ret = [];
- items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); });
+ o = o || {};
+
+ items.each(function() { ret.push($(o.item || this).attr(o.attribute || "id") || ""); });
return ret;
},
@@ -3594,73 +4001,71 @@ $.widget("ui.sortable", $.ui.mouse, {
var x1 = this.positionAbs.left,
x2 = x1 + this.helperProportions.width,
y1 = this.positionAbs.top,
- y2 = y1 + this.helperProportions.height;
-
- var l = item.left,
+ y2 = y1 + this.helperProportions.height,
+ l = item.left,
r = l + item.width,
t = item.top,
- b = t + item.height;
-
- var dyClick = this.offset.click.top,
- dxClick = this.offset.click.left;
-
- var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
-
- if( this.options.tolerance == "pointer"
- || this.options.forcePointerForContainers
- || (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])
+ b = t + item.height,
+ dyClick = this.offset.click.top,
+ dxClick = this.offset.click.left,
+ isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
+
+ 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
+ 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 isOverElementHeight = (this.options.axis === 'x') || $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
- isOverElementWidth = (this.options.axis === 'y') || $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
+ var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
+ isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
isOverElement = isOverElementHeight && isOverElementWidth,
verticalDirection = this._getDragVerticalDirection(),
horizontalDirection = this._getDragHorizontalDirection();
- if (!isOverElement)
+ if (!isOverElement) {
return false;
+ }
return this.floating ?
- ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
- : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) );
+ ( ((horizontalDirection && horizontalDirection === "right") || verticalDirection === "down") ? 2 : 1 )
+ : ( verticalDirection && (verticalDirection === "down" ? 2 : 1) );
},
_intersectsWithSides: function(item) {
- var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
- isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
+ var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
+ isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
verticalDirection = this._getDragVerticalDirection(),
horizontalDirection = this._getDragHorizontalDirection();
if (this.floating && horizontalDirection) {
- return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
+ return ((horizontalDirection === "right" && isOverRightHalf) || (horizontalDirection === "left" && !isOverRightHalf));
} else {
- return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf));
+ 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");
+ return delta !== 0 && (delta > 0 ? "down" : "up");
},
_getDragHorizontalDirection: function() {
var delta = this.positionAbs.left - this.lastPositionAbs.left;
- return delta != 0 && (delta > 0 ? "right" : "left");
+ return delta !== 0 && (delta > 0 ? "right" : "left");
},
refresh: function(event) {
@@ -3671,36 +4076,35 @@ $.widget("ui.sortable", $.ui.mouse, {
_connectWith: function() {
var options = this.options;
- return options.connectWith.constructor == String
- ? [options.connectWith]
- : options.connectWith;
+ return options.connectWith.constructor === String ? [options.connectWith] : options.connectWith;
},
_getItemsAsjQuery: function(connected) {
- var items = [];
- var queries = [];
- var connectWith = this._connectWith();
+ var i, j, cur, inst,
+ items = [],
+ queries = [],
+ connectWith = this._connectWith();
if(connectWith && connected) {
- for (var i = connectWith.length - 1; i >= 0; i--){
- var cur = $(connectWith[i]);
- for (var j = cur.length - 1; j >= 0; j--){
- var inst = $.data(cur[j], this.widgetName);
- if(inst && inst != this && !inst.options.disabled) {
- queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]);
+ for (i = connectWith.length - 1; i >= 0; i--){
+ cur = $(connectWith[i]);
+ for ( j = cur.length - 1; j >= 0; j--){
+ inst = $.data(cur[j], this.widgetFullName);
+ if(inst && inst !== this && !inst.options.disabled) {
+ queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), inst]);
}
- };
- };
+ }
+ }
}
- queries.push([$.isFunction(this.options.items) ? 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]);
+ queries.push([$.isFunction(this.options.items) ? 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]);
- for (var i = queries.length - 1; i >= 0; i--){
+ for (i = queries.length - 1; i >= 0; i--){
queries[i][0].each(function() {
items.push(this);
});
- };
+ }
return $(items);
@@ -3712,9 +4116,10 @@ $.widget("ui.sortable", $.ui.mouse, {
this.items = $.grep(this.items, function (item) {
for (var j=0; j < list.length; j++) {
- if(list[j] == item.item[0])
+ if(list[j] === item.item[0]) {
return false;
- };
+ }
+ }
return true;
});
@@ -3724,31 +4129,33 @@ $.widget("ui.sortable", $.ui.mouse, {
this.items = [];
this.containers = [this];
- var items = this.items;
- var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]];
- var connectWith = this._connectWith();
+
+ var i, j, cur, inst, targetData, _queries, item, queriesLength,
+ items = this.items,
+ queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]],
+ connectWith = this._connectWith();
if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
- for (var i = connectWith.length - 1; i >= 0; i--){
- var cur = $(connectWith[i]);
- for (var j = cur.length - 1; j >= 0; j--){
- var inst = $.data(cur[j], this.widgetName);
- if(inst && inst != this && !inst.options.disabled) {
+ for (i = connectWith.length - 1; i >= 0; i--){
+ cur = $(connectWith[i]);
+ for (j = cur.length - 1; j >= 0; j--){
+ inst = $.data(cur[j], this.widgetFullName);
+ if(inst && inst !== this && !inst.options.disabled) {
queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
this.containers.push(inst);
}
- };
- };
+ }
+ }
}
- for (var i = queries.length - 1; i >= 0; i--) {
- var targetData = queries[i][1];
- var _queries = queries[i][0];
+ for (i = queries.length - 1; i >= 0; i--) {
+ targetData = queries[i][1];
+ _queries = queries[i][0];
- for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) {
- var item = $(_queries[j]);
+ for (j=0, queriesLength = _queries.length; j < queriesLength; j++) {
+ item = $(_queries[j]);
- item.data(this.widgetName + '-item', targetData); // Data for target checking (mouse manager)
+ item.data(this.widgetName + "-item", targetData); // Data for target checking (mouse manager)
items.push({
item: item,
@@ -3756,8 +4163,8 @@ $.widget("ui.sortable", $.ui.mouse, {
width: 0, height: 0,
left: 0, top: 0
});
- };
- };
+ }
+ }
},
@@ -3768,35 +4175,38 @@ $.widget("ui.sortable", $.ui.mouse, {
this.offset.parent = this._getParentOffset();
}
- for (var i = this.items.length - 1; i >= 0; i--){
- var item = this.items[i];
+ 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(item.instance != this.currentContainer && this.currentContainer && item.item[0] != this.currentItem[0])
+ if(item.instance !== this.currentContainer && this.currentContainer && item.item[0] !== this.currentItem[0]) {
continue;
+ }
- var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
+ t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
if (!fast) {
item.width = t.outerWidth();
item.height = t.outerHeight();
}
- var p = t.offset();
+ p = t.offset();
item.left = p.left;
item.top = p.top;
- };
+ }
if(this.options.custom && this.options.custom.refreshContainers) {
this.options.custom.refreshContainers.call(this);
} else {
- for (var i = this.containers.length - 1; i >= 0; i--){
- var p = this.containers[i].element.offset();
+ 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;
@@ -3804,31 +4214,45 @@ $.widget("ui.sortable", $.ui.mouse, {
_createPlaceholder: function(that) {
that = that || this;
- var o = that.options;
+ var className,
+ o = that.options;
- if(!o.placeholder || o.placeholder.constructor == String) {
- var className = o.placeholder;
+ if(!o.placeholder || o.placeholder.constructor === String) {
+ className = o.placeholder;
o.placeholder = {
element: function() {
- var el = $(document.createElement(that.currentItem[0].nodeName))
- .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
- .removeClass("ui-sortable-helper")[0];
+ var nodeName = that.currentItem[0].nodeName.toLowerCase(),
+ element = $( that.document[0].createElement( nodeName ) )
+ .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
+ .removeClass("ui-sortable-helper");
+
+ if ( nodeName === "tr" ) {
+ // Use a high colspan to force the td to expand the full
+ // width of the table (browsers are smart enough to
+ // handle this properly)
+ element.append( "<td colspan='99'>&#160;</td>" );
+ } else if ( nodeName === "img" ) {
+ element.attr( "src", that.currentItem.attr( "src" ) );
+ }
- if(!className)
- el.style.visibility = "hidden";
+ if ( !className ) {
+ element.css( "visibility", "hidden" );
+ }
- return el;
+ 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(className && !o.forcePlaceholderSize) {
+ return;
+ }
//If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
- if(!p.height()) { 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)); };
+ if(!p.height()) { 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)); }
}
};
}
@@ -3845,22 +4269,24 @@ $.widget("ui.sortable", $.ui.mouse, {
},
_contactContainers: function(event) {
+ var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating,
+ innermostContainer = null,
+ innermostIndex = null;
// get innermost container that intersects with item
- var innermostContainer = null, innermostIndex = null;
-
-
- for (var i = this.containers.length - 1; i >= 0; i--){
+ 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]))
+ 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]))
+ if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0])) {
continue;
+ }
innermostContainer = this.containers[i];
innermostIndex = i;
@@ -3876,24 +4302,37 @@ $.widget("ui.sortable", $.ui.mouse, {
}
// if no intersecting containers found, return
- if(!innermostContainer) return;
+ if(!innermostContainer) {
+ return;
+ }
// move the item into the container if it's not there already
if(this.containers.length === 1) {
- this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
- this.containers[innermostIndex].containerCache.over = 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
- var dist = 10000; var itemWithLeastDistance = null;
- var posProperty = this.containers[innermostIndex].floating ? 'left' : 'top';
- var sizeProperty = this.containers[innermostIndex].floating ? 'width' : 'height';
- var base = this.positionAbs[posProperty] + this.offset.click[posProperty];
- for (var 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;
- var cur = this.items[j].item.offset()[posProperty];
- var nearBottom = false;
+ dist = 10000;
+ itemWithLeastDistance = null;
+ floating = innermostContainer.floating || isFloating(this.currentItem);
+ posProperty = floating ? "left" : "top";
+ sizeProperty = floating ? "width" : "height";
+ base = this.positionAbs[posProperty] + this.offset.click[posProperty];
+ 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;
+ }
+ if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
+ continue;
+ }
+ cur = this.items[j].item.offset()[posProperty];
+ nearBottom = false;
if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
nearBottom = true;
cur += this.items[j][sizeProperty];
@@ -3905,13 +4344,19 @@ $.widget("ui.sortable", $.ui.mouse, {
}
}
- if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
+ //Check if dropOnEmpty is enabled
+ if(!itemWithLeastDistance && !this.options.dropOnEmpty) {
return;
+ }
+
+ if(this.currentContainer === this.containers[innermostIndex]) {
+ return;
+ }
- this.currentContainer = this.containers[innermostIndex];
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : 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);
@@ -3925,39 +4370,46 @@ $.widget("ui.sortable", $.ui.mouse, {
_createHelper: function(event) {
- var o = this.options;
- var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem);
+ var o = this.options,
+ helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper === "clone" ? this.currentItem.clone() : this.currentItem);
- if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already
- $(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
+ //Add the helper to the DOM if that didn't happen already
+ if(!helper.parents("body").length) {
+ $(o.appendTo !== "parent" ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
+ }
- if(helper[0] == this.currentItem[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());
+ 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 (typeof obj === "string") {
+ obj = obj.split(" ");
}
if ($.isArray(obj)) {
obj = {left: +obj[0], top: +obj[1] || 0};
}
- if ('left' in obj) {
+ if ("left" in obj) {
this.offset.click.left = obj.left + this.margins.left;
}
- if ('right' in obj) {
+ if ("right" in obj) {
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
}
- if ('top' in obj) {
+ if ("top" in obj) {
this.offset.click.top = obj.top + this.margins.top;
}
- if ('bottom' in obj) {
+ if ("bottom" in obj) {
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
}
},
@@ -3973,14 +4425,16 @@ $.widget("ui.sortable", $.ui.mouse, {
// 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])) {
+ 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.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
- || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) //Ugly IE fix
+ // This needs to be actually done for all browsers, since pageX/pageY includes this information
+ // with an ugly IE fix
+ if( this.offsetParent[0] === document.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),
@@ -3991,7 +4445,7 @@ $.widget("ui.sortable", $.ui.mouse, {
_getRelativeOffset: function() {
- if(this.cssPosition == "relative") {
+ if(this.cssPosition === "relative") {
var p = this.currentItem.position();
return {
top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
@@ -4019,19 +4473,24 @@ $.widget("ui.sortable", $.ui.mouse, {
_setContainment: function() {
- var 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' ? document : window).width() - this.helperProportions.width - this.margins.left,
- ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
- ];
+ 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" ? document : window).width() - this.helperProportions.width - this.margins.left,
+ ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
+ ];
+ }
if(!(/^(document|window|parent)$/).test(o.containment)) {
- var ce = $(o.containment)[0];
- var co = $(o.containment).offset();
- var over = ($(ce).css("overflow") != 'hidden');
+ 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,
@@ -4045,22 +4504,25 @@ $.widget("ui.sortable", $.ui.mouse, {
_convertPositionTo: function(d, pos) {
- if(!pos) pos = this.position;
- var mod = d == "absolute" ? 1 : -1;
- var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+ if(!pos) {
+ pos = this.position;
+ }
+ var mod = d === "absolute" ? 1 : -1,
+ scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
+ scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
return {
top: (
- pos.top // The absolute mouse position
- + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
- + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
- - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
+ pos.top + // The absolute mouse position
+ this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
),
left: (
- pos.left // The absolute mouse position
- + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
- + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
- - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
+ pos.left + // The absolute mouse position
+ this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
)
};
@@ -4068,19 +4530,20 @@ $.widget("ui.sortable", $.ui.mouse, {
_generatePosition: function(event) {
- var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+ var top, left,
+ o = this.options,
+ pageX = event.pageX,
+ pageY = event.pageY,
+ scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.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] != document && this.scrollParent[0] != this.offsetParent[0])) {
+ if(this.cssPosition === "relative" && !(this.scrollParent[0] !== document && this.scrollParent[0] !== this.offsetParent[0])) {
this.offset.relative = this._getRelativeOffset();
}
- var pageX = event.pageX;
- var pageY = event.pageY;
-
/*
* - Position constraining -
* Constrain the position to a mix of grid, containment.
@@ -4089,36 +4552,44 @@ $.widget("ui.sortable", $.ui.mouse, {
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(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) {
- var 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;
+ 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;
- var 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;
+ 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: (
- pageY // The absolute mouse position
- - this.offset.click.top // Click offset (relative to the element)
- - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
- - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
- + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
+ pageY - // The absolute mouse position
+ this.offset.click.top - // Click offset (relative to the element)
+ this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
),
left: (
- pageX // The absolute mouse position
- - this.offset.click.left // Click offset (relative to the element)
- - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
- - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
- + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
+ pageX - // The absolute mouse position
+ this.offset.click.left - // Click offset (relative to the element)
+ this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
+ this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
)
};
@@ -4126,7 +4597,7 @@ $.widget("ui.sortable", $.ui.mouse, {
_rearrange: function(event, i, a, hardRefresh) {
- a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction == 'down' ? i.item[0] : i.item[0].nextSibling));
+ a ? a[0].appendChild(this.placeholder[0]) : 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
@@ -4137,7 +4608,9 @@ $.widget("ui.sortable", $.ui.mouse, {
var counter = this.counter;
this._delay(function() {
- if(counter == this.counter) this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
+ if(counter === this.counter) {
+ this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
+ }
});
},
@@ -4147,24 +4620,33 @@ $.widget("ui.sortable", $.ui.mouse, {
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 delayedTriggers = [];
+ 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);
+ if(!this._noFinalSort && this.currentItem.parent().length) {
+ this.placeholder.before(this.currentItem);
+ }
this._noFinalSort = null;
- if(this.helper[0] == this.currentItem[0]) {
- for(var i in this._storedCSS) {
- if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = '';
+ 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).removeClass("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) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
+ 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) {
+ delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
+ }
// Check if the items Container has Changed and trigger appropriate
// events.
@@ -4178,8 +4660,10 @@ $.widget("ui.sortable", $.ui.mouse, {
//Post events to containers
- for (var i = this.containers.length - 1; i >= 0; i--){
- if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
+ for (i = this.containers.length - 1; i >= 0; i--){
+ if(!noPropagation) {
+ delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
+ }
if(this.containers[i].containerCache.over) {
delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
this.containers[i].containerCache.over = 0;
@@ -4187,15 +4671,24 @@ $.widget("ui.sortable", $.ui.mouse, {
}
//Do what was originally in plugins
- if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor
- if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset opacity
- if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index
+ 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(this.cancelHelperRemoval) {
if(!noPropagation) {
this._trigger("beforeStop", event, this._uiHash());
- for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
+ for (i=0; i < delayedTriggers.length; i++) {
+ delayedTriggers[i].call(this, event);
+ } //Trigger all delayed events
this._trigger("stop", event, this._uiHash());
}
@@ -4203,15 +4696,22 @@ $.widget("ui.sortable", $.ui.mouse, {
return false;
}
- if(!noPropagation) this._trigger("beforeStop", event, this._uiHash());
+ 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.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null;
+ if(this.helper[0] !== this.currentItem[0]) {
+ this.helper.remove();
+ }
+ this.helper = null;
if(!noPropagation) {
- for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
+ for (i=0; i < delayedTriggers.length; i++) {
+ delayedTriggers[i].call(this, event);
+ } //Trigger all delayed events
this._trigger("stop", event, this._uiHash());
}
@@ -4243,35 +4743,33 @@ $.widget("ui.sortable", $.ui.mouse, {
})(jQuery);
-;(jQuery.effects || (function($, undefined) {
+(function($, undefined) {
-var backCompat = $.uiBackCompat !== false,
- // prefix used for storing data on .data()
- dataSpace = "ui-effects-";
+var dataSpace = "ui-effects-";
$.effects = {
effect: {}
};
/*!
- * jQuery Color Animations v2.0.0
- * http://jquery.com/
+ * jQuery Color Animations v2.1.2
+ * https://github.com/jquery/jquery-color
*
- * Copyright 2012 jQuery Foundation and other contributors
+ * Copyright 2013 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
- * Date: Mon Aug 13 13:41:02 2012 -0500
+ * Date: Wed Jan 16 08:47:09 2013 -0600
*/
(function( jQuery, undefined ) {
- var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor".split(" "),
+ var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
// plusequals test for += 100 -= 100
rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
// a set of RE's that can match strings and generate color tuples.
stringParsers = [{
- re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
+ re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
parse: function( execResult ) {
return [
execResult[ 1 ],
@@ -4281,7 +4779,7 @@ $.effects = {
];
}
}, {
- re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
+ re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
parse: function( execResult ) {
return [
execResult[ 1 ] * 2.55,
@@ -4311,7 +4809,7 @@ $.effects = {
];
}
}, {
- re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
+ re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
space: "hsla",
parse: function( execResult ) {
return [
@@ -4528,7 +5026,7 @@ color.fn = jQuery.extend( color.prototype, {
});
// everything defined but alpha?
- if ( inst[ cache ] && $.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
+ if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
// use the default of 1
inst[ cache ][ 3 ] = 1;
if ( space.from ) {
@@ -4716,8 +5214,10 @@ spaces.hsla.to = function ( rgba ) {
h = ( 60 * ( r - g ) / diff ) + 240;
}
- if ( l === 0 || l === 1 ) {
- s = l;
+ // chroma (diff) == 0 means greyscale which, by definition, saturation = 0%
+ // otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)
+ if ( diff === 0 ) {
+ s = 0;
} else if ( l <= 0.5 ) {
s = diff / add;
} else {
@@ -4821,51 +5321,58 @@ each( spaces, function( spaceName, space ) {
});
});
-// add .fx.step functions
-each( stepHooks, function( i, hook ) {
- jQuery.cssHooks[ hook ] = {
- set: function( elem, value ) {
- var parsed, curElem,
- backgroundColor = "";
-
- if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
- value = color( parsed || value );
- if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
- curElem = hook === "backgroundColor" ? elem.parentNode : elem;
- while (
- (backgroundColor === "" || backgroundColor === "transparent") &&
- curElem && curElem.style
- ) {
- try {
- backgroundColor = jQuery.css( curElem, "backgroundColor" );
- curElem = curElem.parentNode;
- } catch ( e ) {
+// add cssHook and .fx.step function for each named hook.
+// accept a space separated string of properties
+color.hook = function( hook ) {
+ var hooks = hook.split( " " );
+ each( hooks, function( i, hook ) {
+ jQuery.cssHooks[ hook ] = {
+ set: function( elem, value ) {
+ var parsed, curElem,
+ backgroundColor = "";
+
+ if ( value !== "transparent" && ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) {
+ value = color( parsed || value );
+ if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
+ curElem = hook === "backgroundColor" ? elem.parentNode : elem;
+ while (
+ (backgroundColor === "" || backgroundColor === "transparent") &&
+ curElem && curElem.style
+ ) {
+ try {
+ backgroundColor = jQuery.css( curElem, "backgroundColor" );
+ curElem = curElem.parentNode;
+ } catch ( e ) {
+ }
}
+
+ value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
+ backgroundColor :
+ "_default" );
}
- value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
- backgroundColor :
- "_default" );
+ value = value.toRgbaString();
+ }
+ try {
+ elem.style[ hook ] = value;
+ } catch( e ) {
+ // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
}
-
- value = value.toRgbaString();
}
- try {
- elem.style[ hook ] = value;
- } catch( error ) {
- // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
+ };
+ jQuery.fx.step[ hook ] = function( fx ) {
+ if ( !fx.colorInit ) {
+ fx.start = color( fx.elem, hook );
+ fx.end = color( fx.end );
+ fx.colorInit = true;
}
- }
- };
- jQuery.fx.step[ hook ] = function( fx ) {
- if ( !fx.colorInit ) {
- fx.start = color( fx.elem, hook );
- fx.end = color( fx.end );
- fx.colorInit = true;
- }
- jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
- };
-});
+ jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
+ };
+ });
+
+};
+
+color.hook( stepHooks );
jQuery.cssHooks.borderColor = {
expand: function( value ) {
@@ -4909,7 +5416,6 @@ colors = jQuery.Color.names = {
})( jQuery );
-
/******************************************************************************/
/****************************** CLASS ANIMATIONS ******************************/
/******************************************************************************/
@@ -4937,32 +5443,31 @@ $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopS
};
});
-function getElementStyles() {
- var style = this.ownerDocument.defaultView ?
- this.ownerDocument.defaultView.getComputedStyle( this, null ) :
- this.currentStyle,
- newStyle = {},
- key,
- len;
+function getElementStyles( elem ) {
+ var key, len,
+ style = elem.ownerDocument.defaultView ?
+ elem.ownerDocument.defaultView.getComputedStyle( elem, null ) :
+ elem.currentStyle,
+ styles = {};
- // webkit enumerates style porperties
if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
len = style.length;
while ( len-- ) {
key = style[ len ];
if ( typeof style[ key ] === "string" ) {
- newStyle[ $.camelCase( key ) ] = style[ key ];
+ styles[ $.camelCase( key ) ] = style[ key ];
}
}
+ // support: Opera, IE <9
} else {
for ( key in style ) {
if ( typeof style[ key ] === "string" ) {
- newStyle[ key ] = style[ key ];
+ styles[ key ] = style[ key ];
}
}
}
- return newStyle;
+ return styles;
}
@@ -4984,6 +5489,15 @@ function styleDifference( oldStyle, newStyle ) {
return diff;
}
+// support: jQuery <1.8
+if ( !$.fn.addBack ) {
+ $.fn.addBack = function( selector ) {
+ return this.add( selector == null ?
+ this.prevObject : this.prevObject.filter( selector )
+ );
+ };
+}
+
$.effects.animateClass = function( value, duration, easing, callback ) {
var o = $.speed( duration, easing, callback );
@@ -4991,14 +5505,14 @@ $.effects.animateClass = function( value, duration, easing, callback ) {
var animated = $( this ),
baseClass = animated.attr( "class" ) || "",
applyClassChange,
- allAnimations = o.children ? animated.find( "*" ).andSelf() : animated;
+ allAnimations = o.children ? animated.find( "*" ).addBack() : animated;
// map the animated objects to store the original styles.
allAnimations = allAnimations.map(function() {
var el = $( this );
return {
el: el,
- start: getElementStyles.call( this )
+ start: getElementStyles( this )
};
});
@@ -5014,7 +5528,7 @@ $.effects.animateClass = function( value, duration, easing, callback ) {
// map all animated objects again - calculate new styles and diff
allAnimations = allAnimations.map(function() {
- this.end = getElementStyles.call( this.el[ 0 ] );
+ this.end = getElementStyles( this.el[ 0 ] );
this.diff = styleDifference( this.start, this.end );
return this;
});
@@ -5026,7 +5540,7 @@ $.effects.animateClass = function( value, duration, easing, callback ) {
allAnimations = allAnimations.map(function() {
var styleInfo = this,
dfd = $.Deferred(),
- opts = jQuery.extend({}, o, {
+ opts = $.extend({}, o, {
queue: false,
complete: function() {
dfd.resolve( styleInfo );
@@ -5048,7 +5562,7 @@ $.effects.animateClass = function( value, duration, easing, callback ) {
$.each( arguments, function() {
var el = this.el;
$.each( this.diff, function(key) {
- el.css( key, '' );
+ el.css( key, "" );
});
});
@@ -5060,39 +5574,42 @@ $.effects.animateClass = function( value, duration, easing, callback ) {
};
$.fn.extend({
- _addClass: $.fn.addClass,
- addClass: function( classNames, speed, easing, callback ) {
- return speed ?
- $.effects.animateClass.call( this,
- { add: classNames }, speed, easing, callback ) :
- this._addClass( classNames );
- },
-
- _removeClass: $.fn.removeClass,
- removeClass: function( classNames, speed, easing, callback ) {
- return speed ?
- $.effects.animateClass.call( this,
- { remove: classNames }, speed, easing, callback ) :
- this._removeClass( classNames );
- },
-
- _toggleClass: $.fn.toggleClass,
- toggleClass: function( classNames, force, speed, easing, callback ) {
- if ( typeof force === "boolean" || force === undefined ) {
- if ( !speed ) {
- // without speed parameter
- return this._toggleClass( classNames, force );
+ addClass: (function( orig ) {
+ return function( classNames, speed, easing, callback ) {
+ return speed ?
+ $.effects.animateClass.call( this,
+ { add: classNames }, speed, easing, callback ) :
+ orig.apply( this, arguments );
+ };
+ })( $.fn.addClass ),
+
+ removeClass: (function( orig ) {
+ return function( classNames, speed, easing, callback ) {
+ return arguments.length > 1 ?
+ $.effects.animateClass.call( this,
+ { remove: classNames }, speed, easing, callback ) :
+ orig.apply( this, arguments );
+ };
+ })( $.fn.removeClass ),
+
+ toggleClass: (function( orig ) {
+ return function( classNames, force, speed, easing, callback ) {
+ if ( typeof force === "boolean" || force === undefined ) {
+ if ( !speed ) {
+ // without speed parameter
+ return orig.apply( this, arguments );
+ } else {
+ return $.effects.animateClass.call( this,
+ (force ? { add: classNames } : { remove: classNames }),
+ speed, easing, callback );
+ }
} else {
+ // without force parameter
return $.effects.animateClass.call( this,
- (force ? { add: classNames } : { remove: classNames }),
- speed, easing, callback );
+ { toggle: classNames }, force, speed, easing );
}
- } else {
- // without force parameter
- return $.effects.animateClass.call( this,
- { toggle: classNames }, force, speed, easing );
- }
- },
+ };
+ })( $.fn.toggleClass ),
switchClass: function( remove, add, speed, easing, callback) {
return $.effects.animateClass.call( this, {
@@ -5111,7 +5628,7 @@ $.fn.extend({
(function() {
$.extend( $.effects, {
- version: "1.9.2",
+ version: "1.10.2",
// Saves a set of properties in a data storage
save: function( element, set ) {
@@ -5327,21 +5844,28 @@ function _normalizeArguments( effect, options, speed, callback ) {
return effect;
}
-function standardSpeed( speed ) {
- // valid standard speeds
- if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
+function standardAnimationOption( option ) {
+ // Valid standard speeds (nothing, number, named speed)
+ if ( !option || typeof option === "number" || $.fx.speeds[ option ] ) {
return true;
}
- // invalid strings - treat as "normal" speed
- if ( typeof speed === "string" && !$.effects.effect[ speed ] ) {
- // TODO: remove in 2.0 (#7115)
- if ( backCompat && $.effects[ speed ] ) {
- return false;
- }
+ // Invalid strings - treat as "normal" speed
+ if ( typeof option === "string" && !$.effects.effect[ option ] ) {
+ return true;
+ }
+
+ // Complete callback
+ if ( $.isFunction( option ) ) {
+ return true;
+ }
+
+ // Options hash (but not naming an effect)
+ if ( typeof option === "object" && !option.effect ) {
return true;
}
+ // Didn't match any standard API
return false;
}
@@ -5350,12 +5874,9 @@ $.fn.extend({
var args = _normalizeArguments.apply( this, arguments ),
mode = args.mode,
queue = args.queue,
- effectMethod = $.effects.effect[ args.effect ],
+ effectMethod = $.effects.effect[ args.effect ];
- // DEPRECATED: remove in 2.0 (#7115)
- oldEffectMethod = !effectMethod && backCompat && $.effects[ args.effect ];
-
- if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) {
+ if ( $.fx.off || !effectMethod ) {
// delegate to the original method (e.g., .show()) if possible
if ( mode ) {
return this[ mode ]( args.duration, args.complete );
@@ -5382,62 +5903,54 @@ $.fn.extend({
}
}
- // if the element is hiddden and mode is hide,
- // or element is visible and mode is show
+ // If the element already has the correct final state, delegate to
+ // the core methods so the internal tracking of "olddisplay" works.
if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
+ elem[ mode ]();
done();
} else {
effectMethod.call( elem[0], args, done );
}
}
- // TODO: remove this check in 2.0, effectMethod will always be true
- if ( effectMethod ) {
- return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
- } else {
- // DEPRECATED: remove in 2.0 (#7115)
- return oldEffectMethod.call(this, {
- options: args,
- duration: args.duration,
- callback: args.complete,
- mode: args.mode
- });
- }
+ return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
},
- _show: $.fn.show,
- show: function( speed ) {
- if ( standardSpeed( speed ) ) {
- return this._show.apply( this, arguments );
- } else {
- var args = _normalizeArguments.apply( this, arguments );
- args.mode = "show";
- return this.effect.call( this, args );
- }
- },
+ show: (function( orig ) {
+ return function( option ) {
+ if ( standardAnimationOption( option ) ) {
+ return orig.apply( this, arguments );
+ } else {
+ var args = _normalizeArguments.apply( this, arguments );
+ args.mode = "show";
+ return this.effect.call( this, args );
+ }
+ };
+ })( $.fn.show ),
- _hide: $.fn.hide,
- hide: function( speed ) {
- if ( standardSpeed( speed ) ) {
- return this._hide.apply( this, arguments );
- } else {
- var args = _normalizeArguments.apply( this, arguments );
- args.mode = "hide";
- return this.effect.call( this, args );
- }
- },
+ hide: (function( orig ) {
+ return function( option ) {
+ if ( standardAnimationOption( option ) ) {
+ return orig.apply( this, arguments );
+ } else {
+ var args = _normalizeArguments.apply( this, arguments );
+ args.mode = "hide";
+ return this.effect.call( this, args );
+ }
+ };
+ })( $.fn.hide ),
- // jQuery core overloads toggle and creates _toggle
- __toggle: $.fn.toggle,
- toggle: function( speed ) {
- if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) {
- return this.__toggle.apply( this, arguments );
- } else {
- var args = _normalizeArguments.apply( this, arguments );
- args.mode = "toggle";
- return this.effect.call( this, args );
- }
- },
+ toggle: (function( orig ) {
+ return function( option ) {
+ if ( standardAnimationOption( option ) || typeof option === "boolean" ) {
+ return orig.apply( this, arguments );
+ } else {
+ var args = _normalizeArguments.apply( this, arguments );
+ args.mode = "toggle";
+ return this.effect.call( this, args );
+ }
+ };
+ })( $.fn.toggle ),
// helper functions
cssUnit: function(key) {
@@ -5508,7 +6021,7 @@ $.each( baseEasings, function( name, easeIn ) {
})();
-})(jQuery));
+})(jQuery);
(function( $, undefined ) {
@@ -5522,7 +6035,7 @@ showProps.height = showProps.paddingTop = showProps.paddingBottom =
showProps.borderTopWidth = showProps.borderBottomWidth = "show";
$.widget( "ui.accordion", {
- version: "1.9.2",
+ version: "1.10.2",
options: {
active: 0,
animate: {},
@@ -5541,100 +6054,29 @@ $.widget( "ui.accordion", {
},
_create: function() {
- var accordionId = this.accordionId = "ui-accordion-" +
- (this.element.attr( "id" ) || ++uid),
- options = this.options;
-
+ var options = this.options;
this.prevShow = this.prevHide = $();
- this.element.addClass( "ui-accordion ui-widget ui-helper-reset" );
-
- this.headers = this.element.find( options.header )
- .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" );
- this._hoverable( this.headers );
- this._focusable( this.headers );
-
- this.headers.next()
- .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" )
- .hide();
+ this.element.addClass( "ui-accordion ui-widget ui-helper-reset" )
+ // ARIA
+ .attr( "role", "tablist" );
// don't allow collapsible: false and active: false / null
if ( !options.collapsible && (options.active === false || options.active == null) ) {
options.active = 0;
}
+
+ this._processPanels();
// handle negative values
if ( options.active < 0 ) {
options.active += this.headers.length;
}
- this.active = this._findActive( options.active )
- .addClass( "ui-accordion-header-active ui-state-active" )
- .toggleClass( "ui-corner-all ui-corner-top" );
- this.active.next()
- .addClass( "ui-accordion-content-active" )
- .show();
-
- this._createIcons();
- this.refresh();
-
- // ARIA
- this.element.attr( "role", "tablist" );
-
- this.headers
- .attr( "role", "tab" )
- .each(function( i ) {
- var header = $( this ),
- headerId = header.attr( "id" ),
- panel = header.next(),
- panelId = panel.attr( "id" );
- if ( !headerId ) {
- headerId = accordionId + "-header-" + i;
- header.attr( "id", headerId );
- }
- if ( !panelId ) {
- panelId = accordionId + "-panel-" + i;
- panel.attr( "id", panelId );
- }
- header.attr( "aria-controls", panelId );
- panel.attr( "aria-labelledby", headerId );
- })
- .next()
- .attr( "role", "tabpanel" );
-
- this.headers
- .not( this.active )
- .attr({
- "aria-selected": "false",
- tabIndex: -1
- })
- .next()
- .attr({
- "aria-expanded": "false",
- "aria-hidden": "true"
- })
- .hide();
-
- // make sure at least one header is in the tab order
- if ( !this.active.length ) {
- this.headers.eq( 0 ).attr( "tabIndex", 0 );
- } else {
- this.active.attr({
- "aria-selected": "true",
- tabIndex: 0
- })
- .next()
- .attr({
- "aria-expanded": "true",
- "aria-hidden": "false"
- });
- }
-
- this._on( this.headers, { keydown: "_keydown" });
- this._on( this.headers.next(), { keydown: "_panelKeyDown" });
- this._setupEvents( options.event );
+ this._refresh();
},
_getCreateEventData: function() {
return {
header: this.active,
+ panel: !this.active.length ? $() : this.active.next(),
content: !this.active.length ? $() : this.active.next()
};
},
@@ -5736,6 +6178,7 @@ $.widget( "ui.accordion", {
},
_keydown: function( event ) {
+ /*jshint maxcomplexity:15*/
if ( event.altKey || event.ctrlKey ) {
return;
}
@@ -5781,20 +6224,116 @@ $.widget( "ui.accordion", {
},
refresh: function() {
- var maxHeight, overflow,
- heightStyle = this.options.heightStyle,
- parent = this.element.parent();
+ var options = this.options;
+ this._processPanels();
+
+ // was collapsed or no panel
+ if ( ( options.active === false && options.collapsible === true ) || !this.headers.length ) {
+ options.active = false;
+ this.active = $();
+ // active false only when collapsible is true
+ } if ( options.active === false ) {
+ this._activate( 0 );
+ // was active, but active panel is gone
+ } else if ( this.active.length && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
+ // all remaining panel are disabled
+ if ( this.headers.length === this.headers.find(".ui-state-disabled").length ) {
+ options.active = false;
+ this.active = $();
+ // activate previous panel
+ } else {
+ this._activate( Math.max( 0, options.active - 1 ) );
+ }
+ // was active, active panel still exists
+ } else {
+ // make sure active index is correct
+ options.active = this.headers.index( this.active );
+ }
+
+ this._destroyIcons();
+
+ this._refresh();
+ },
+
+ _processPanels: function() {
+ this.headers = this.element.find( this.options.header )
+ .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" );
+
+ this.headers.next()
+ .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" )
+ .filter(":not(.ui-accordion-content-active)")
+ .hide();
+ },
+
+ _refresh: function() {
+ var maxHeight,
+ options = this.options,
+ heightStyle = options.heightStyle,
+ parent = this.element.parent(),
+ accordionId = this.accordionId = "ui-accordion-" +
+ (this.element.attr( "id" ) || ++uid);
+ this.active = this._findActive( options.active )
+ .addClass( "ui-accordion-header-active ui-state-active ui-corner-top" )
+ .removeClass( "ui-corner-all" );
+ this.active.next()
+ .addClass( "ui-accordion-content-active" )
+ .show();
+
+ this.headers
+ .attr( "role", "tab" )
+ .each(function( i ) {
+ var header = $( this ),
+ headerId = header.attr( "id" ),
+ panel = header.next(),
+ panelId = panel.attr( "id" );
+ if ( !headerId ) {
+ headerId = accordionId + "-header-" + i;
+ header.attr( "id", headerId );
+ }
+ if ( !panelId ) {
+ panelId = accordionId + "-panel-" + i;
+ panel.attr( "id", panelId );
+ }
+ header.attr( "aria-controls", panelId );
+ panel.attr( "aria-labelledby", headerId );
+ })
+ .next()
+ .attr( "role", "tabpanel" );
+
+ this.headers
+ .not( this.active )
+ .attr({
+ "aria-selected": "false",
+ tabIndex: -1
+ })
+ .next()
+ .attr({
+ "aria-expanded": "false",
+ "aria-hidden": "true"
+ })
+ .hide();
+
+ // make sure at least one header is in the tab order
+ if ( !this.active.length ) {
+ this.headers.eq( 0 ).attr( "tabIndex", 0 );
+ } else {
+ this.active.attr({
+ "aria-selected": "true",
+ tabIndex: 0
+ })
+ .next()
+ .attr({
+ "aria-expanded": "true",
+ "aria-hidden": "false"
+ });
+ }
+
+ this._createIcons();
+
+ this._setupEvents( options.event );
if ( heightStyle === "fill" ) {
- // IE 6 treats height like minHeight, so we need to turn off overflow
- // in order to get a reliable height
- // we use the minHeight support test because we assume that only
- // browsers that don't support minHeight will treat height as minHeight
- if ( !$.support.minHeight ) {
- overflow = parent.css( "overflow" );
- parent.css( "overflow", "hidden");
- }
maxHeight = parent.height();
this.element.siblings( ":visible" ).each(function() {
var elem = $( this ),
@@ -5805,9 +6344,6 @@ $.widget( "ui.accordion", {
}
maxHeight -= elem.outerHeight( true );
});
- if ( overflow ) {
- parent.css( "overflow", overflow );
- }
this.headers.each(function() {
maxHeight -= $( this ).outerHeight( true );
@@ -5852,14 +6388,20 @@ $.widget( "ui.accordion", {
},
_setupEvents: function( event ) {
- var events = {};
- if ( !event ) {
- return;
+ var events = {
+ keydown: "_keydown"
+ };
+ if ( event ) {
+ $.each( event.split(" "), function( index, eventName ) {
+ events[ eventName ] = "_eventHandler";
+ });
}
- $.each( event.split(" "), function( index, eventName ) {
- events[ eventName ] = "_eventHandler";
- });
+
+ this._off( this.headers.add( this.headers.next() ) );
this._on( this.headers, events );
+ this._on( this.headers.next(), { keydown: "_panelKeyDown" });
+ this._hoverable( this.headers );
+ this._focusable( this.headers );
},
_eventHandler: function( event ) {
@@ -6038,194 +6580,6 @@ $.widget( "ui.accordion", {
}
});
-
-
-// DEPRECATED
-if ( $.uiBackCompat !== false ) {
- // navigation options
- (function( $, prototype ) {
- $.extend( prototype.options, {
- navigation: false,
- navigationFilter: function() {
- return this.href.toLowerCase() === location.href.toLowerCase();
- }
- });
-
- var _create = prototype._create;
- prototype._create = function() {
- if ( this.options.navigation ) {
- var that = this,
- headers = this.element.find( this.options.header ),
- content = headers.next(),
- current = headers.add( content )
- .find( "a" )
- .filter( this.options.navigationFilter )
- [ 0 ];
- if ( current ) {
- headers.add( content ).each( function( index ) {
- if ( $.contains( this, current ) ) {
- that.options.active = Math.floor( index / 2 );
- return false;
- }
- });
- }
- }
- _create.call( this );
- };
- }( jQuery, jQuery.ui.accordion.prototype ) );
-
- // height options
- (function( $, prototype ) {
- $.extend( prototype.options, {
- heightStyle: null, // remove default so we fall back to old values
- autoHeight: true, // use heightStyle: "auto"
- clearStyle: false, // use heightStyle: "content"
- fillSpace: false // use heightStyle: "fill"
- });
-
- var _create = prototype._create,
- _setOption = prototype._setOption;
-
- $.extend( prototype, {
- _create: function() {
- this.options.heightStyle = this.options.heightStyle ||
- this._mergeHeightStyle();
-
- _create.call( this );
- },
-
- _setOption: function( key ) {
- if ( key === "autoHeight" || key === "clearStyle" || key === "fillSpace" ) {
- this.options.heightStyle = this._mergeHeightStyle();
- }
- _setOption.apply( this, arguments );
- },
-
- _mergeHeightStyle: function() {
- var options = this.options;
-
- if ( options.fillSpace ) {
- return "fill";
- }
-
- if ( options.clearStyle ) {
- return "content";
- }
-
- if ( options.autoHeight ) {
- return "auto";
- }
- }
- });
- }( jQuery, jQuery.ui.accordion.prototype ) );
-
- // icon options
- (function( $, prototype ) {
- $.extend( prototype.options.icons, {
- activeHeader: null, // remove default so we fall back to old values
- headerSelected: "ui-icon-triangle-1-s"
- });
-
- var _createIcons = prototype._createIcons;
- prototype._createIcons = function() {
- if ( this.options.icons ) {
- this.options.icons.activeHeader = this.options.icons.activeHeader ||
- this.options.icons.headerSelected;
- }
- _createIcons.call( this );
- };
- }( jQuery, jQuery.ui.accordion.prototype ) );
-
- // expanded active option, activate method
- (function( $, prototype ) {
- prototype.activate = prototype._activate;
-
- var _findActive = prototype._findActive;
- prototype._findActive = function( index ) {
- if ( index === -1 ) {
- index = false;
- }
- if ( index && typeof index !== "number" ) {
- index = this.headers.index( this.headers.filter( index ) );
- if ( index === -1 ) {
- index = false;
- }
- }
- return _findActive.call( this, index );
- };
- }( jQuery, jQuery.ui.accordion.prototype ) );
-
- // resize method
- jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh;
-
- // change events
- (function( $, prototype ) {
- $.extend( prototype.options, {
- change: null,
- changestart: null
- });
-
- var _trigger = prototype._trigger;
- prototype._trigger = function( type, event, data ) {
- var ret = _trigger.apply( this, arguments );
- if ( !ret ) {
- return false;
- }
-
- if ( type === "beforeActivate" ) {
- ret = _trigger.call( this, "changestart", event, {
- oldHeader: data.oldHeader,
- oldContent: data.oldPanel,
- newHeader: data.newHeader,
- newContent: data.newPanel
- });
- } else if ( type === "activate" ) {
- ret = _trigger.call( this, "change", event, {
- oldHeader: data.oldHeader,
- oldContent: data.oldPanel,
- newHeader: data.newHeader,
- newContent: data.newPanel
- });
- }
- return ret;
- };
- }( jQuery, jQuery.ui.accordion.prototype ) );
-
- // animated option
- // NOTE: this only provides support for "slide", "bounceslide", and easings
- // not the full $.ui.accordion.animations API
- (function( $, prototype ) {
- $.extend( prototype.options, {
- animate: null,
- animated: "slide"
- });
-
- var _create = prototype._create;
- prototype._create = function() {
- var options = this.options;
- if ( options.animate === null ) {
- if ( !options.animated ) {
- options.animate = false;
- } else if ( options.animated === "slide" ) {
- options.animate = 300;
- } else if ( options.animated === "bounceslide" ) {
- options.animate = {
- duration: 200,
- down: {
- easing: "easeOutBounce",
- duration: 1000
- }
- };
- } else {
- options.animate = options.animated;
- }
- }
-
- _create.call( this );
- };
- }( jQuery, jQuery.ui.accordion.prototype ) );
-}
-
})( jQuery );
(function( $, undefined ) {
@@ -6234,10 +6588,10 @@ if ( $.uiBackCompat !== false ) {
var requestIndex = 0;
$.widget( "ui.autocomplete", {
- version: "1.9.2",
+ version: "1.10.2",
defaultElement: "<input>",
options: {
- appendTo: "body",
+ appendTo: null,
autoFocus: false,
delay: 300,
minLength: 1,
@@ -6268,10 +6622,21 @@ $.widget( "ui.autocomplete", {
// so we use the suppressKeyPressRepeat flag to avoid handling keypress
// events when we know the keydown event was used to modify the
// search term. #7799
- var suppressKeyPress, suppressKeyPressRepeat, suppressInput;
-
- this.isMultiLine = this._isMultiLine();
- this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
+ var suppressKeyPress, suppressKeyPressRepeat, suppressInput,
+ nodeName = this.element[0].nodeName.toLowerCase(),
+ isTextarea = nodeName === "textarea",
+ isInput = nodeName === "input";
+
+ this.isMultiLine =
+ // Textareas are always multi-line
+ isTextarea ? true :
+ // Inputs are always single-line, even if inside a contentEditable element
+ // IE also treats inputs as contentEditable
+ isInput ? false :
+ // All other element types are determined by whether or not they're contentEditable
+ this.element.prop( "isContentEditable" );
+
+ this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
this.isNewMenu = true;
this.element
@@ -6280,6 +6645,7 @@ $.widget( "ui.autocomplete", {
this._on( this.element, {
keydown: function( event ) {
+ /*jshint maxcomplexity:15*/
if ( this.element.prop( "readOnly" ) ) {
suppressKeyPress = true;
suppressInput = true;
@@ -6394,17 +6760,16 @@ $.widget( "ui.autocomplete", {
this._initSource();
this.menu = $( "<ul>" )
- .addClass( "ui-autocomplete" )
- .appendTo( this.document.find( this.options.appendTo || "body" )[ 0 ] )
+ .addClass( "ui-autocomplete ui-front" )
+ .appendTo( this._appendTo() )
.menu({
// custom key handling for now
input: $(),
// disable ARIA support, the live region takes care of that
role: null
})
- .zIndex( this.element.zIndex() + 1 )
.hide()
- .data( "menu" );
+ .data( "ui-menu" );
this._on( this.menu.element, {
mousedown: function( event ) {
@@ -6437,7 +6802,8 @@ $.widget( "ui.autocomplete", {
}
},
menufocus: function( event, ui ) {
- // #7024 - Prevent accidental activation of menu items in Firefox
+ // support: Firefox
+ // Prevent accidental activation of menu items in Firefox (#7024 #9118)
if ( this.isNewMenu ) {
this.isNewMenu = false;
if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {
@@ -6451,9 +6817,7 @@ $.widget( "ui.autocomplete", {
}
}
- // back compat for _renderItem using item.autocomplete, via #7810
- // TODO remove the fallback, see #8156
- var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" );
+ var item = ui.item.data( "ui-autocomplete-item" );
if ( false !== this._trigger( "focus", event, { item: item } ) ) {
// use value to match what will end up in the input, if it was a key event
if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
@@ -6469,9 +6833,7 @@ $.widget( "ui.autocomplete", {
}
},
menuselect: function( event, ui ) {
- // back compat for _renderItem using item.autocomplete, via #7810
- // TODO remove the fallback, see #8156
- var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" ),
+ var item = ui.item.data( "ui-autocomplete-item" ),
previous = this.previous;
// only trigger when focus was lost (click on menu)
@@ -6506,10 +6868,6 @@ $.widget( "ui.autocomplete", {
.addClass( "ui-helper-hidden-accessible" )
.insertAfter( this.element );
- if ( $.fn.bgiframe ) {
- this.menu.element.bgiframe();
- }
-
// 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
@@ -6535,25 +6893,31 @@ $.widget( "ui.autocomplete", {
this._initSource();
}
if ( key === "appendTo" ) {
- this.menu.element.appendTo( this.document.find( value || "body" )[0] );
+ this.menu.element.appendTo( this._appendTo() );
}
if ( key === "disabled" && value && this.xhr ) {
this.xhr.abort();
}
},
- _isMultiLine: function() {
- // Textareas are always multi-line
- if ( this.element.is( "textarea" ) ) {
- return true;
+ _appendTo: function() {
+ var element = this.options.appendTo;
+
+ if ( element ) {
+ element = element.jquery || element.nodeType ?
+ $( element ) :
+ this.document.find( element ).eq( 0 );
}
- // Inputs are always single-line, even if inside a contentEditable element
- // IE also treats inputs as contentEditable
- if ( this.element.is( "input" ) ) {
- return false;
+
+ if ( !element ) {
+ element = this.element.closest( ".ui-front" );
+ }
+
+ if ( !element.length ) {
+ element = this.document[0].body;
}
- // All other element types are determined by whether or not they're contentEditable
- return this.element.prop( "isContentEditable" );
+
+ return element;
},
_initSource: function() {
@@ -6693,10 +7057,9 @@ $.widget( "ui.autocomplete", {
},
_suggest: function( items ) {
- var ul = this.menu.element
- .empty()
- .zIndex( this.element.zIndex() + 1 );
+ var ul = this.menu.element.empty();
this._renderMenu( ul, items );
+ this.isNewMenu = true;
this.menu.refresh();
// size and position menu
@@ -6812,7 +7175,6 @@ $.widget( "ui.autocomplete", $.ui.autocomplete, {
}
});
-
}( jQuery ));
(function( $, undefined ) {
@@ -6832,6 +7194,7 @@ var lastActive, startXPos, startYPos, clickDragged,
form = radio.form,
radios = $( [] );
if ( name ) {
+ name = name.replace( /'/g, "\\'" );
if ( form ) {
radios = $( form ).find( "[name='" + name + "']" );
} else {
@@ -6845,7 +7208,7 @@ var lastActive, startXPos, startYPos, clickDragged,
};
$.widget( "ui.button", {
- version: "1.9.2",
+ version: "1.10.2",
defaultElement: "<button>",
options: {
disabled: null,
@@ -6949,8 +7312,6 @@ $.widget( "ui.button", {
if ( options.disabled || clickDragged ) {
return false;
}
- $( this ).toggleClass( "ui-state-active" );
- that.buttonElement.attr( "aria-pressed", that.element[0].checked );
});
} else if ( this.type === "radio" ) {
this.buttonElement.bind( "click" + this.eventNamespace, function() {
@@ -6995,7 +7356,9 @@ $.widget( "ui.button", {
$( this ).addClass( "ui-state-active" );
}
})
- .bind( "keyup" + this.eventNamespace, function() {
+ // see #8559, we bind to blur here in case the button element loses
+ // focus between keydown and keyup, it would be left in an "active" state
+ .bind( "keyup" + this.eventNamespace + " blur" + this.eventNamespace, function() {
$( this ).removeClass( "ui-state-active" );
});
@@ -7162,9 +7525,9 @@ $.widget( "ui.button", {
});
$.widget( "ui.buttonset", {
- version: "1.9.2",
+ version: "1.10.2",
options: {
- items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(button)"
+ items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(ui-button)"
},
_create: function() {
@@ -7222,11 +7585,11 @@ $.widget( "ui.buttonset", {
(function( $, undefined ) {
-$.extend($.ui, { datepicker: { version: "1.9.2" } });
+$.extend($.ui, { datepicker: { version: "1.10.2" } });
-var PROP_NAME = 'datepicker';
-var dpuuid = new Date().getTime();
-var instActive;
+var PROP_NAME = "datepicker",
+ dpuuid = new Date().getTime(),
+ instActive;
/* Date picker manager.
Use the singleton instance of this class, $.datepicker, to interact with the date picker.
@@ -7234,50 +7597,49 @@ var instActive;
allowing multiple different settings on the same page. */
function Datepicker() {
- this.debug = false; // Change this to true to start debugging
this._curInst = null; // The current instance in use
this._keyEvent = false; // If the last event was a key event
this._disabledInputs = []; // List of date picker inputs that have been disabled
this._datepickerShowing = false; // True if the popup picker is showing , false if not
this._inDialog = false; // True if showing within a "dialog", false if not
- this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
- this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
- this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
- this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
- this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
- this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
- this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
- this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
- this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
+ this._mainDivId = "ui-datepicker-div"; // The ID of the main datepicker division
+ this._inlineClass = "ui-datepicker-inline"; // The name of the inline marker class
+ this._appendClass = "ui-datepicker-append"; // The name of the append marker class
+ this._triggerClass = "ui-datepicker-trigger"; // The name of the trigger marker class
+ this._dialogClass = "ui-datepicker-dialog"; // The name of the dialog marker class
+ this._disableClass = "ui-datepicker-disabled"; // The name of the disabled covering marker class
+ this._unselectableClass = "ui-datepicker-unselectable"; // The name of the unselectable cell marker class
+ this._currentClass = "ui-datepicker-current-day"; // The name of the current day marker class
+ this._dayOverClass = "ui-datepicker-days-cell-over"; // The name of the day hover marker class
this.regional = []; // Available regional settings, indexed by language code
- this.regional[''] = { // Default regional settings
- closeText: 'Done', // Display text for close link
- prevText: 'Prev', // Display text for previous month link
- nextText: 'Next', // Display text for next month link
- currentText: 'Today', // Display text for current month link
- monthNames: ['January','February','March','April','May','June',
- 'July','August','September','October','November','December'], // Names of months for drop-down and formatting
- monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
- dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
- dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
- dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
- weekHeader: 'Wk', // Column header for week of the year
- dateFormat: 'mm/dd/yy', // See format options on parseDate
+ this.regional[""] = { // Default regional settings
+ closeText: "Done", // Display text for close link
+ prevText: "Prev", // Display text for previous month link
+ nextText: "Next", // Display text for next month link
+ currentText: "Today", // Display text for current month link
+ monthNames: ["January","February","March","April","May","June",
+ "July","August","September","October","November","December"], // Names of months for drop-down and formatting
+ monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], // For formatting
+ dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], // For formatting
+ dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], // For formatting
+ dayNamesMin: ["Su","Mo","Tu","We","Th","Fr","Sa"], // Column headings for days starting at Sunday
+ weekHeader: "Wk", // Column header for week of the year
+ dateFormat: "mm/dd/yy", // See format options on parseDate
firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
isRTL: false, // True if right-to-left language, false if left-to-right
showMonthAfterYear: false, // True if the year select precedes month, false for month then year
- yearSuffix: '' // Additional text to append to the year in the month headers
+ yearSuffix: "" // Additional text to append to the year in the month headers
};
this._defaults = { // Global defaults for all the date picker instances
- showOn: 'focus', // 'focus' for popup on focus,
- // 'button' for trigger button, or 'both' for either
- showAnim: 'fadeIn', // Name of jQuery animation for popup
+ showOn: "focus", // "focus" for popup on focus,
+ // "button" for trigger button, or "both" for either
+ showAnim: "fadeIn", // Name of jQuery animation for popup
showOptions: {}, // Options for enhanced animations
defaultDate: null, // Used when field is blank: actual date,
// +/-number for offset from today, null for today
- appendText: '', // Display text following the input box, e.g. showing the format
- buttonText: '...', // Text for trigger button
- buttonImage: '', // URL for trigger button image
+ appendText: "", // Display text following the input box, e.g. showing the format
+ buttonText: "...", // Text for trigger button
+ buttonImage: "", // URL for trigger button image
buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
hideIfNoPrevNext: false, // True to hide next/previous month links
// if not applicable, false to just disable them
@@ -7285,7 +7647,7 @@ function Datepicker() {
gotoCurrent: false, // True if today link goes back to current selection instead
changeMonth: false, // True if month can be selected directly, false if only prev/next
changeYear: false, // True if year can be selected directly, false if only prev/next
- yearRange: 'c-10:c+10', // Range of years to display in drop-down,
+ yearRange: "c-10:c+10", // Range of years to display in drop-down,
// either relative to today's year (-nn:+nn), relative to currently displayed year
// (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
showOtherMonths: false, // True to show dates in other months, false to leave blank
@@ -7293,14 +7655,14 @@ function Datepicker() {
showWeek: false, // True to show week of the year, false to not show it
calculateWeek: this.iso8601Week, // How to calculate the week of the year,
// takes a Date and returns the number of the week for it
- shortYearCutoff: '+10', // Short year values < this are in the current century,
+ shortYearCutoff: "+10", // Short year values < this are in the current century,
// > this are in the previous century,
- // string value starting with '+' for current year + value
+ // string value starting with "+" for current year + value
minDate: null, // The earliest selectable date, or null for no limit
maxDate: null, // The latest selectable date, or null for no limit
- duration: 'fast', // Duration of display/closure
+ duration: "fast", // Duration of display/closure
beforeShowDay: null, // Function that takes a date and returns an array with
- // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
+ // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or "",
// [2] = cell title (optional), e.g. $.datepicker.noWeekends
beforeShow: null, // Function that takes an input field and
// returns a set of custom settings for the date picker
@@ -7311,69 +7673,53 @@ function Datepicker() {
showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
stepMonths: 1, // Number of months to step back/forward
stepBigMonths: 12, // Number of months to step back/forward for the big links
- altField: '', // Selector for an alternate field to store selected dates into
- altFormat: '', // The date format to use for the alternate field
+ altField: "", // Selector for an alternate field to store selected dates into
+ altFormat: "", // The date format to use for the alternate field
constrainInput: true, // The input is constrained by the current date format
showButtonPanel: false, // True to show button panel, false to not show it
autoSize: false, // True to size the input for the date format, false to leave as is
disabled: false // The initial disabled state
};
- $.extend(this._defaults, this.regional['']);
- this.dpDiv = bindHover($('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'));
+ $.extend(this._defaults, this.regional[""]);
+ this.dpDiv = bindHover($("<div id='" + this._mainDivId + "' class='ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>"));
}
$.extend(Datepicker.prototype, {
/* Class name added to elements to indicate already configured with a date picker. */
- markerClassName: 'hasDatepicker',
+ markerClassName: "hasDatepicker",
//Keep track of the maximum number of rows displayed (see #7043)
maxRows: 4,
- /* Debug logging (if enabled). */
- log: function () {
- if (this.debug)
- console.log.apply('', arguments);
- },
-
// TODO rename to "widget" when switching to widget factory
_widgetDatepicker: function() {
return this.dpDiv;
},
/* Override the default settings for all instances of the date picker.
- @param settings object - the new settings to use as defaults (anonymous object)
- @return the manager object */
+ * @param settings object - the new settings to use as defaults (anonymous object)
+ * @return the manager object
+ */
setDefaults: function(settings) {
extendRemove(this._defaults, settings || {});
return this;
},
/* Attach the date picker to a jQuery selection.
- @param target element - the target input field or division or span
- @param settings object - the new settings to use for this date picker instance (anonymous) */
+ * @param target element - the target input field or division or span
+ * @param settings object - the new settings to use for this date picker instance (anonymous)
+ */
_attachDatepicker: function(target, settings) {
- // check for settings on the control itself - in namespace 'date:'
- var inlineSettings = null;
- for (var attrName in this._defaults) {
- var attrValue = target.getAttribute('date:' + attrName);
- if (attrValue) {
- inlineSettings = inlineSettings || {};
- try {
- inlineSettings[attrName] = eval(attrValue);
- } catch (err) {
- inlineSettings[attrName] = attrValue;
- }
- }
- }
- var nodeName = target.nodeName.toLowerCase();
- var inline = (nodeName == 'div' || nodeName == 'span');
+ var nodeName, inline, inst;
+ nodeName = target.nodeName.toLowerCase();
+ inline = (nodeName === "div" || nodeName === "span");
if (!target.id) {
this.uuid += 1;
- target.id = 'dp' + this.uuid;
+ target.id = "dp" + this.uuid;
}
- var inst = this._newInst($(target), inline);
- inst.settings = $.extend({}, settings || {}, inlineSettings || {});
- if (nodeName == 'input') {
+ inst = this._newInst($(target), inline);
+ inst.settings = $.extend({}, settings || {});
+ if (nodeName === "input") {
this._connectDatepicker(target, inst);
} else if (inline) {
this._inlineDatepicker(target, inst);
@@ -7382,13 +7728,13 @@ $.extend(Datepicker.prototype, {
/* Create a new instance object. */
_newInst: function(target, inline) {
- var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); // escape jQuery meta chars
+ var id = target[0].id.replace(/([^A-Za-z0-9_\-])/g, "\\\\$1"); // escape jQuery meta chars
return {id: id, input: target, // associated target
selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
drawMonth: 0, drawYear: 0, // month being drawn
inline: inline, // is datepicker inline or not
dpDiv: (!inline ? this.dpDiv : // presentation div
- bindHover($('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>')))};
+ bindHover($("<div class='" + this._inlineClass + " ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>")))};
},
/* Attach the date picker to an input field. */
@@ -7396,16 +7742,12 @@ $.extend(Datepicker.prototype, {
var input = $(target);
inst.append = $([]);
inst.trigger = $([]);
- if (input.hasClass(this.markerClassName))
+ if (input.hasClass(this.markerClassName)) {
return;
+ }
this._attachments(input, inst);
input.addClass(this.markerClassName).keydown(this._doKeyDown).
- keypress(this._doKeyPress).keyup(this._doKeyUp).
- bind("setData.datepicker", function(event, key, value) {
- inst.settings[key] = value;
- }).bind("getData.datepicker", function(event, key) {
- return this._get(inst, key);
- });
+ keypress(this._doKeyPress).keyup(this._doKeyUp);
this._autoSize(inst);
$.data(target, PROP_NAME, inst);
//If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)
@@ -7416,38 +7758,47 @@ $.extend(Datepicker.prototype, {
/* Make attachments based on settings. */
_attachments: function(input, inst) {
- var appendText = this._get(inst, 'appendText');
- var isRTL = this._get(inst, 'isRTL');
- if (inst.append)
+ var showOn, buttonText, buttonImage,
+ appendText = this._get(inst, "appendText"),
+ isRTL = this._get(inst, "isRTL");
+
+ if (inst.append) {
inst.append.remove();
+ }
if (appendText) {
- inst.append = $('<span class="' + this._appendClass + '">' + appendText + '</span>');
- input[isRTL ? 'before' : 'after'](inst.append);
+ inst.append = $("<span class='" + this._appendClass + "'>" + appendText + "</span>");
+ input[isRTL ? "before" : "after"](inst.append);
}
- input.unbind('focus', this._showDatepicker);
- if (inst.trigger)
+
+ input.unbind("focus", this._showDatepicker);
+
+ if (inst.trigger) {
inst.trigger.remove();
- var showOn = this._get(inst, 'showOn');
- if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
+ }
+
+ showOn = this._get(inst, "showOn");
+ if (showOn === "focus" || showOn === "both") { // pop-up date picker when in the marked field
input.focus(this._showDatepicker);
- if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
- var buttonText = this._get(inst, 'buttonText');
- var buttonImage = this._get(inst, 'buttonImage');
- inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
- $('<img/>').addClass(this._triggerClass).
+ }
+ if (showOn === "button" || showOn === "both") { // pop-up date picker when button clicked
+ buttonText = this._get(inst, "buttonText");
+ buttonImage = this._get(inst, "buttonImage");
+ inst.trigger = $(this._get(inst, "buttonImageOnly") ?
+ $("<img/>").addClass(this._triggerClass).
attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
- $('<button type="button"></button>').addClass(this._triggerClass).
- html(buttonImage == '' ? buttonText : $('<img/>').attr(
+ $("<button type='button'></button>").addClass(this._triggerClass).
+ html(!buttonImage ? buttonText : $("<img/>").attr(
{ src:buttonImage, alt:buttonText, title:buttonText })));
- input[isRTL ? 'before' : 'after'](inst.trigger);
+ input[isRTL ? "before" : "after"](inst.trigger);
inst.trigger.click(function() {
- if ($.datepicker._datepickerShowing && $.datepicker._lastInput == input[0])
+ if ($.datepicker._datepickerShowing && $.datepicker._lastInput === input[0]) {
$.datepicker._hideDatepicker();
- else if ($.datepicker._datepickerShowing && $.datepicker._lastInput != input[0]) {
+ } else if ($.datepicker._datepickerShowing && $.datepicker._lastInput !== input[0]) {
$.datepicker._hideDatepicker();
$.datepicker._showDatepicker(input[0]);
- } else
+ } else {
$.datepicker._showDatepicker(input[0]);
+ }
return false;
});
}
@@ -7455,14 +7806,16 @@ $.extend(Datepicker.prototype, {
/* Apply the maximum length for the date format. */
_autoSize: function(inst) {
- if (this._get(inst, 'autoSize') && !inst.inline) {
- var date = new Date(2009, 12 - 1, 20); // Ensure double digits
- var dateFormat = this._get(inst, 'dateFormat');
+ if (this._get(inst, "autoSize") && !inst.inline) {
+ var findMax, max, maxI, i,
+ date = new Date(2009, 12 - 1, 20), // Ensure double digits
+ dateFormat = this._get(inst, "dateFormat");
+
if (dateFormat.match(/[DM]/)) {
- var findMax = function(names) {
- var max = 0;
- var maxI = 0;
- for (var i = 0; i < names.length; i++) {
+ findMax = function(names) {
+ max = 0;
+ maxI = 0;
+ for (i = 0; i < names.length; i++) {
if (names[i].length > max) {
max = names[i].length;
maxI = i;
@@ -7471,25 +7824,21 @@ $.extend(Datepicker.prototype, {
return maxI;
};
date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
- 'monthNames' : 'monthNamesShort'))));
+ "monthNames" : "monthNamesShort"))));
date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
- 'dayNames' : 'dayNamesShort'))) + 20 - date.getDay());
+ "dayNames" : "dayNamesShort"))) + 20 - date.getDay());
}
- inst.input.attr('size', this._formatDate(inst, date).length);
+ inst.input.attr("size", this._formatDate(inst, date).length);
}
},
/* Attach an inline date picker to a div. */
_inlineDatepicker: function(target, inst) {
var divSpan = $(target);
- if (divSpan.hasClass(this.markerClassName))
+ if (divSpan.hasClass(this.markerClassName)) {
return;
- divSpan.addClass(this.markerClassName).append(inst.dpDiv).
- bind("setData.datepicker", function(event, key, value){
- inst.settings[key] = value;
- }).bind("getData.datepicker", function(event, key){
- return this._get(inst, key);
- });
+ }
+ divSpan.addClass(this.markerClassName).append(inst.dpDiv);
$.data(target, PROP_NAME, inst);
this._setDate(inst, this._getDefaultDate(inst), true);
this._updateDatepicker(inst);
@@ -7504,186 +7853,219 @@ $.extend(Datepicker.prototype, {
},
/* Pop-up the date picker in a "dialog" box.
- @param input element - ignored
- @param date string or Date - the initial date to display
- @param onSelect function - the function to call when a date is selected
- @param settings object - update the dialog date picker instance's settings (anonymous object)
- @param pos int[2] - coordinates for the dialog's position within the screen or
- event - with x/y coordinates or
- leave empty for default (screen centre)
- @return the manager object */
+ * @param input element - ignored
+ * @param date string or Date - the initial date to display
+ * @param onSelect function - the function to call when a date is selected
+ * @param settings object - update the dialog date picker instance's settings (anonymous object)
+ * @param pos int[2] - coordinates for the dialog's position within the screen or
+ * event - with x/y coordinates or
+ * leave empty for default (screen centre)
+ * @return the manager object
+ */
_dialogDatepicker: function(input, date, onSelect, settings, pos) {
- var inst = this._dialogInst; // internal instance
+ var id, browserWidth, browserHeight, scrollX, scrollY,
+ inst = this._dialogInst; // internal instance
+
if (!inst) {
this.uuid += 1;
- var id = 'dp' + this.uuid;
- this._dialogInput = $('<input type="text" id="' + id +
- '" style="position: absolute; top: -100px; width: 0px;"/>');
+ id = "dp" + this.uuid;
+ this._dialogInput = $("<input type='text' id='" + id +
+ "' style='position: absolute; top: -100px; width: 0px;'/>");
this._dialogInput.keydown(this._doKeyDown);
- $('body').append(this._dialogInput);
+ $("body").append(this._dialogInput);
inst = this._dialogInst = this._newInst(this._dialogInput, false);
inst.settings = {};
$.data(this._dialogInput[0], PROP_NAME, inst);
}
extendRemove(inst.settings, settings || {});
- date = (date && date.constructor == Date ? this._formatDate(inst, date) : date);
+ date = (date && date.constructor === Date ? this._formatDate(inst, date) : date);
this._dialogInput.val(date);
this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
if (!this._pos) {
- var browserWidth = document.documentElement.clientWidth;
- var browserHeight = document.documentElement.clientHeight;
- var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
- var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
+ browserWidth = document.documentElement.clientWidth;
+ browserHeight = document.documentElement.clientHeight;
+ scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
+ scrollY = document.documentElement.scrollTop || document.body.scrollTop;
this._pos = // should use actual width/height below
[(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
}
// move input on screen for focus, but hidden behind dialog
- this._dialogInput.css('left', (this._pos[0] + 20) + 'px').css('top', this._pos[1] + 'px');
+ this._dialogInput.css("left", (this._pos[0] + 20) + "px").css("top", this._pos[1] + "px");
inst.settings.onSelect = onSelect;
this._inDialog = true;
this.dpDiv.addClass(this._dialogClass);
this._showDatepicker(this._dialogInput[0]);
- if ($.blockUI)
+ if ($.blockUI) {
$.blockUI(this.dpDiv);
+ }
$.data(this._dialogInput[0], PROP_NAME, inst);
return this;
},
/* Detach a datepicker from its control.
- @param target element - the target input field or division or span */
+ * @param target element - the target input field or division or span
+ */
_destroyDatepicker: function(target) {
- var $target = $(target);
- var inst = $.data(target, PROP_NAME);
+ var nodeName,
+ $target = $(target),
+ inst = $.data(target, PROP_NAME);
+
if (!$target.hasClass(this.markerClassName)) {
return;
}
- var nodeName = target.nodeName.toLowerCase();
+
+ nodeName = target.nodeName.toLowerCase();
$.removeData(target, PROP_NAME);
- if (nodeName == 'input') {
+ if (nodeName === "input") {
inst.append.remove();
inst.trigger.remove();
$target.removeClass(this.markerClassName).
- unbind('focus', this._showDatepicker).
- unbind('keydown', this._doKeyDown).
- unbind('keypress', this._doKeyPress).
- unbind('keyup', this._doKeyUp);
- } else if (nodeName == 'div' || nodeName == 'span')
+ unbind("focus", this._showDatepicker).
+ unbind("keydown", this._doKeyDown).
+ unbind("keypress", this._doKeyPress).
+ unbind("keyup", this._doKeyUp);
+ } else if (nodeName === "div" || nodeName === "span") {
$target.removeClass(this.markerClassName).empty();
+ }
},
/* Enable the date picker to a jQuery selection.
- @param target element - the target input field or division or span */
+ * @param target element - the target input field or division or span
+ */
_enableDatepicker: function(target) {
- var $target = $(target);
- var inst = $.data(target, PROP_NAME);
+ var nodeName, inline,
+ $target = $(target),
+ inst = $.data(target, PROP_NAME);
+
if (!$target.hasClass(this.markerClassName)) {
return;
}
- var nodeName = target.nodeName.toLowerCase();
- if (nodeName == 'input') {
+
+ nodeName = target.nodeName.toLowerCase();
+ if (nodeName === "input") {
target.disabled = false;
- inst.trigger.filter('button').
+ inst.trigger.filter("button").
each(function() { this.disabled = false; }).end().
- filter('img').css({opacity: '1.0', cursor: ''});
- }
- else if (nodeName == 'div' || nodeName == 'span') {
- var inline = $target.children('.' + this._inlineClass);
- inline.children().removeClass('ui-state-disabled');
+ filter("img").css({opacity: "1.0", cursor: ""});
+ } else if (nodeName === "div" || nodeName === "span") {
+ inline = $target.children("." + this._inlineClass);
+ inline.children().removeClass("ui-state-disabled");
inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
prop("disabled", false);
}
this._disabledInputs = $.map(this._disabledInputs,
- function(value) { return (value == target ? null : value); }); // delete entry
+ function(value) { return (value === target ? null : value); }); // delete entry
},
/* Disable the date picker to a jQuery selection.
- @param target element - the target input field or division or span */
+ * @param target element - the target input field or division or span
+ */
_disableDatepicker: function(target) {
- var $target = $(target);
- var inst = $.data(target, PROP_NAME);
+ var nodeName, inline,
+ $target = $(target),
+ inst = $.data(target, PROP_NAME);
+
if (!$target.hasClass(this.markerClassName)) {
return;
}
- var nodeName = target.nodeName.toLowerCase();
- if (nodeName == 'input') {
+
+ nodeName = target.nodeName.toLowerCase();
+ if (nodeName === "input") {
target.disabled = true;
- inst.trigger.filter('button').
+ inst.trigger.filter("button").
each(function() { this.disabled = true; }).end().
- filter('img').css({opacity: '0.5', cursor: 'default'});
- }
- else if (nodeName == 'div' || nodeName == 'span') {
- var inline = $target.children('.' + this._inlineClass);
- inline.children().addClass('ui-state-disabled');
+ filter("img").css({opacity: "0.5", cursor: "default"});
+ } else if (nodeName === "div" || nodeName === "span") {
+ inline = $target.children("." + this._inlineClass);
+ inline.children().addClass("ui-state-disabled");
inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
prop("disabled", true);
}
this._disabledInputs = $.map(this._disabledInputs,
- function(value) { return (value == target ? null : value); }); // delete entry
+ function(value) { return (value === target ? null : value); }); // delete entry
this._disabledInputs[this._disabledInputs.length] = target;
},
/* Is the first field in a jQuery collection disabled as a datepicker?
- @param target element - the target input field or division or span
- @return boolean - true if disabled, false if enabled */
+ * @param target element - the target input field or division or span
+ * @return boolean - true if disabled, false if enabled
+ */
_isDisabledDatepicker: function(target) {
if (!target) {
return false;
}
for (var i = 0; i < this._disabledInputs.length; i++) {
- if (this._disabledInputs[i] == target)
+ if (this._disabledInputs[i] === target) {
return true;
+ }
}
return false;
},
/* Retrieve the instance data for the target control.
- @param target element - the target input field or division or span
- @return object - the associated instance data
- @throws error if a jQuery problem getting data */
+ * @param target element - the target input field or division or span
+ * @return object - the associated instance data
+ * @throws error if a jQuery problem getting data
+ */
_getInst: function(target) {
try {
return $.data(target, PROP_NAME);
}
catch (err) {
- throw 'Missing instance data for this datepicker';
+ throw "Missing instance data for this datepicker";
}
},
/* Update or retrieve the settings for a date picker attached to an input field or division.
- @param target element - the target input field or division or span
- @param name object - the new settings to update or
- string - the name of the setting to change or retrieve,
- when retrieving also 'all' for all instance settings or
- 'defaults' for all global defaults
- @param value any - the new value for the setting
- (omit if above is an object or to retrieve a value) */
+ * @param target element - the target input field or division or span
+ * @param name object - the new settings to update or
+ * string - the name of the setting to change or retrieve,
+ * when retrieving also "all" for all instance settings or
+ * "defaults" for all global defaults
+ * @param value any - the new value for the setting
+ * (omit if above is an object or to retrieve a value)
+ */
_optionDatepicker: function(target, name, value) {
- var inst = this._getInst(target);
- if (arguments.length == 2 && typeof name == 'string') {
- return (name == 'defaults' ? $.extend({}, $.datepicker._defaults) :
- (inst ? (name == 'all' ? $.extend({}, inst.settings) :
+ var settings, date, minDate, maxDate,
+ inst = this._getInst(target);
+
+ if (arguments.length === 2 && typeof name === "string") {
+ return (name === "defaults" ? $.extend({}, $.datepicker._defaults) :
+ (inst ? (name === "all" ? $.extend({}, inst.settings) :
this._get(inst, name)) : null));
}
- var settings = name || {};
- if (typeof name == 'string') {
+
+ settings = name || {};
+ if (typeof name === "string") {
settings = {};
settings[name] = value;
}
+
if (inst) {
- if (this._curInst == inst) {
+ if (this._curInst === inst) {
this._hideDatepicker();
}
- var date = this._getDateDatepicker(target, true);
- var minDate = this._getMinMaxDate(inst, 'min');
- var maxDate = this._getMinMaxDate(inst, 'max');
+
+ date = this._getDateDatepicker(target, true);
+ minDate = this._getMinMaxDate(inst, "min");
+ maxDate = this._getMinMaxDate(inst, "max");
extendRemove(inst.settings, settings);
// reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided
- if (minDate !== null && settings['dateFormat'] !== undefined && settings['minDate'] === undefined)
+ if (minDate !== null && settings.dateFormat !== undefined && settings.minDate === undefined) {
inst.settings.minDate = this._formatDate(inst, minDate);
- if (maxDate !== null && settings['dateFormat'] !== undefined && settings['maxDate'] === undefined)
+ }
+ if (maxDate !== null && settings.dateFormat !== undefined && settings.maxDate === undefined) {
inst.settings.maxDate = this._formatDate(inst, maxDate);
+ }
+ if ( "disabled" in settings ) {
+ if ( settings.disabled ) {
+ this._disableDatepicker(target);
+ } else {
+ this._enableDatepicker(target);
+ }
+ }
this._attachments($(target), inst);
this._autoSize(inst);
this._setDate(inst, date);
@@ -7698,7 +8080,8 @@ $.extend(Datepicker.prototype, {
},
/* Redraw the date picker attached to an input field or division.
- @param target element - the target input field or division or span */
+ * @param target element - the target input field or division or span
+ */
_refreshDatepicker: function(target) {
var inst = this._getInst(target);
if (inst) {
@@ -7707,8 +8090,9 @@ $.extend(Datepicker.prototype, {
},
/* Set the dates for a jQuery selection.
- @param target element - the target input field or division or span
- @param date Date - the new date */
+ * @param target element - the target input field or division or span
+ * @param date Date - the new date
+ */
_setDateDatepicker: function(target, date) {
var inst = this._getInst(target);
if (inst) {
@@ -7719,87 +8103,110 @@ $.extend(Datepicker.prototype, {
},
/* Get the date(s) for the first entry in a jQuery selection.
- @param target element - the target input field or division or span
- @param noDefault boolean - true if no default date is to be used
- @return Date - the current date */
+ * @param target element - the target input field or division or span
+ * @param noDefault boolean - true if no default date is to be used
+ * @return Date - the current date
+ */
_getDateDatepicker: function(target, noDefault) {
var inst = this._getInst(target);
- if (inst && !inst.inline)
+ if (inst && !inst.inline) {
this._setDateFromField(inst, noDefault);
+ }
return (inst ? this._getDate(inst) : null);
},
/* Handle keystrokes. */
_doKeyDown: function(event) {
- var inst = $.datepicker._getInst(event.target);
- var handled = true;
- var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
+ var onSelect, dateStr, sel,
+ inst = $.datepicker._getInst(event.target),
+ handled = true,
+ isRTL = inst.dpDiv.is(".ui-datepicker-rtl");
+
inst._keyEvent = true;
- if ($.datepicker._datepickerShowing)
+ if ($.datepicker._datepickerShowing) {
switch (event.keyCode) {
case 9: $.datepicker._hideDatepicker();
handled = false;
break; // hide on tab out
- case 13: var sel = $('td.' + $.datepicker._dayOverClass + ':not(.' +
- $.datepicker._currentClass + ')', inst.dpDiv);
- if (sel[0])
+ case 13: sel = $("td." + $.datepicker._dayOverClass + ":not(." +
+ $.datepicker._currentClass + ")", inst.dpDiv);
+ if (sel[0]) {
$.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
- var onSelect = $.datepicker._get(inst, 'onSelect');
- if (onSelect) {
- var dateStr = $.datepicker._formatDate(inst);
+ }
- // trigger custom callback
- onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
- }
- else
+ onSelect = $.datepicker._get(inst, "onSelect");
+ if (onSelect) {
+ dateStr = $.datepicker._formatDate(inst);
+
+ // trigger custom callback
+ onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
+ } else {
$.datepicker._hideDatepicker();
+ }
+
return false; // don't submit the form
- break; // select the value on enter
case 27: $.datepicker._hideDatepicker();
break; // hide on escape
case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
- -$.datepicker._get(inst, 'stepBigMonths') :
- -$.datepicker._get(inst, 'stepMonths')), 'M');
+ -$.datepicker._get(inst, "stepBigMonths") :
+ -$.datepicker._get(inst, "stepMonths")), "M");
break; // previous month/year on page up/+ ctrl
case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
- +$.datepicker._get(inst, 'stepBigMonths') :
- +$.datepicker._get(inst, 'stepMonths')), 'M');
+ +$.datepicker._get(inst, "stepBigMonths") :
+ +$.datepicker._get(inst, "stepMonths")), "M");
break; // next month/year on page down/+ ctrl
- case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
+ case 35: if (event.ctrlKey || event.metaKey) {
+ $.datepicker._clearDate(event.target);
+ }
handled = event.ctrlKey || event.metaKey;
break; // clear on ctrl or command +end
- case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
+ case 36: if (event.ctrlKey || event.metaKey) {
+ $.datepicker._gotoToday(event.target);
+ }
handled = event.ctrlKey || event.metaKey;
break; // current on ctrl or command +home
- case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
+ case 37: if (event.ctrlKey || event.metaKey) {
+ $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), "D");
+ }
handled = event.ctrlKey || event.metaKey;
// -1 day on ctrl or command +left
- if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
- -$.datepicker._get(inst, 'stepBigMonths') :
- -$.datepicker._get(inst, 'stepMonths')), 'M');
+ if (event.originalEvent.altKey) {
+ $.datepicker._adjustDate(event.target, (event.ctrlKey ?
+ -$.datepicker._get(inst, "stepBigMonths") :
+ -$.datepicker._get(inst, "stepMonths")), "M");
+ }
// next month/year on alt +left on Mac
break;
- case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
+ case 38: if (event.ctrlKey || event.metaKey) {
+ $.datepicker._adjustDate(event.target, -7, "D");
+ }
handled = event.ctrlKey || event.metaKey;
break; // -1 week on ctrl or command +up
- case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
+ case 39: if (event.ctrlKey || event.metaKey) {
+ $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), "D");
+ }
handled = event.ctrlKey || event.metaKey;
// +1 day on ctrl or command +right
- if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
- +$.datepicker._get(inst, 'stepBigMonths') :
- +$.datepicker._get(inst, 'stepMonths')), 'M');
+ if (event.originalEvent.altKey) {
+ $.datepicker._adjustDate(event.target, (event.ctrlKey ?
+ +$.datepicker._get(inst, "stepBigMonths") :
+ +$.datepicker._get(inst, "stepMonths")), "M");
+ }
// next month/year on alt +right
break;
- case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
+ case 40: if (event.ctrlKey || event.metaKey) {
+ $.datepicker._adjustDate(event.target, +7, "D");
+ }
handled = event.ctrlKey || event.metaKey;
break; // +1 week on ctrl or command +down
default: handled = false;
}
- else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
+ } else if (event.keyCode === 36 && event.ctrlKey) { // display the date picker on ctrl+home
$.datepicker._showDatepicker(this);
- else {
+ } else {
handled = false;
}
+
if (handled) {
event.preventDefault();
event.stopPropagation();
@@ -7808,22 +8215,27 @@ $.extend(Datepicker.prototype, {
/* Filter entered characters - based on date format. */
_doKeyPress: function(event) {
- var inst = $.datepicker._getInst(event.target);
- if ($.datepicker._get(inst, 'constrainInput')) {
- var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
- var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
- return event.ctrlKey || event.metaKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
+ var chars, chr,
+ inst = $.datepicker._getInst(event.target);
+
+ if ($.datepicker._get(inst, "constrainInput")) {
+ chars = $.datepicker._possibleChars($.datepicker._get(inst, "dateFormat"));
+ chr = String.fromCharCode(event.charCode == null ? event.keyCode : event.charCode);
+ return event.ctrlKey || event.metaKey || (chr < " " || !chars || chars.indexOf(chr) > -1);
}
},
/* Synchronise manual entry and field/alternate field. */
_doKeyUp: function(event) {
- var inst = $.datepicker._getInst(event.target);
- if (inst.input.val() != inst.lastVal) {
+ var date,
+ inst = $.datepicker._getInst(event.target);
+
+ if (inst.input.val() !== inst.lastVal) {
try {
- var date = $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
+ date = $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
(inst.input ? inst.input.val() : null),
$.datepicker._getFormatConfig(inst));
+
if (date) { // only if valid
$.datepicker._setDateFromField(inst);
$.datepicker._updateAlternate(inst);
@@ -7831,86 +8243,91 @@ $.extend(Datepicker.prototype, {
}
}
catch (err) {
- $.datepicker.log(err);
}
}
return true;
},
/* Pop-up the date picker for a given input field.
- If false returned from beforeShow event handler do not show.
- @param input element - the input field attached to the date picker or
- event - if triggered by focus */
+ * If false returned from beforeShow event handler do not show.
+ * @param input element - the input field attached to the date picker or
+ * event - if triggered by focus
+ */
_showDatepicker: function(input) {
input = input.target || input;
- if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
- input = $('input', input.parentNode)[0];
- if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
+ if (input.nodeName.toLowerCase() !== "input") { // find from button/image trigger
+ input = $("input", input.parentNode)[0];
+ }
+
+ if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput === input) { // already here
return;
- var inst = $.datepicker._getInst(input);
- if ($.datepicker._curInst && $.datepicker._curInst != inst) {
+ }
+
+ var inst, beforeShow, beforeShowSettings, isFixed,
+ offset, showAnim, duration;
+
+ inst = $.datepicker._getInst(input);
+ if ($.datepicker._curInst && $.datepicker._curInst !== inst) {
$.datepicker._curInst.dpDiv.stop(true, true);
if ( inst && $.datepicker._datepickerShowing ) {
$.datepicker._hideDatepicker( $.datepicker._curInst.input[0] );
}
}
- var beforeShow = $.datepicker._get(inst, 'beforeShow');
- var beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
+
+ beforeShow = $.datepicker._get(inst, "beforeShow");
+ beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
if(beforeShowSettings === false){
- //false
return;
}
extendRemove(inst.settings, beforeShowSettings);
+
inst.lastVal = null;
$.datepicker._lastInput = input;
$.datepicker._setDateFromField(inst);
- if ($.datepicker._inDialog) // hide cursor
- input.value = '';
+
+ if ($.datepicker._inDialog) { // hide cursor
+ input.value = "";
+ }
if (!$.datepicker._pos) { // position below input
$.datepicker._pos = $.datepicker._findPos(input);
$.datepicker._pos[1] += input.offsetHeight; // add the height
}
- var isFixed = false;
+
+ isFixed = false;
$(input).parents().each(function() {
- isFixed |= $(this).css('position') == 'fixed';
+ isFixed |= $(this).css("position") === "fixed";
return !isFixed;
});
- var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
+
+ offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
$.datepicker._pos = null;
//to avoid flashes on Firefox
inst.dpDiv.empty();
// determine sizing offscreen
- inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
+ inst.dpDiv.css({position: "absolute", display: "block", top: "-1000px"});
$.datepicker._updateDatepicker(inst);
// fix width for dynamic number of date pickers
// and adjust position before showing
offset = $.datepicker._checkOffset(inst, offset, isFixed);
inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
- 'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
- left: offset.left + 'px', top: offset.top + 'px'});
+ "static" : (isFixed ? "fixed" : "absolute")), display: "none",
+ left: offset.left + "px", top: offset.top + "px"});
+
if (!inst.inline) {
- var showAnim = $.datepicker._get(inst, 'showAnim');
- var duration = $.datepicker._get(inst, 'duration');
- var postProcess = function() {
- var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
- if( !! cover.length ){
- var borders = $.datepicker._getBorders(inst.dpDiv);
- cover.css({left: -borders[0], top: -borders[1],
- width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()});
- }
- };
+ showAnim = $.datepicker._get(inst, "showAnim");
+ duration = $.datepicker._get(inst, "duration");
inst.dpDiv.zIndex($(input).zIndex()+1);
$.datepicker._datepickerShowing = true;
- // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
- if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) )
- inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
- else
- inst.dpDiv[showAnim || 'show']((showAnim ? duration : null), postProcess);
- if (!showAnim || !duration)
- postProcess();
- if (inst.input.is(':visible') && !inst.input.is(':disabled'))
+ if ( $.effects && $.effects.effect[ showAnim ] ) {
+ inst.dpDiv.show(showAnim, $.datepicker._get(inst, "showOptions"), duration);
+ } else {
+ inst.dpDiv[showAnim || "show"](showAnim ? duration : null);
+ }
+
+ if (inst.input.is(":visible") && !inst.input.is(":disabled")) {
inst.input.focus();
+ }
$.datepicker._curInst = inst;
}
},
@@ -7918,37 +8335,39 @@ $.extend(Datepicker.prototype, {
/* Generate the date picker content. */
_updateDatepicker: function(inst) {
this.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
- var borders = $.datepicker._getBorders(inst.dpDiv);
instActive = inst; // for delegate hover events
inst.dpDiv.empty().append(this._generateHTML(inst));
this._attachHandlers(inst);
- var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
- if( !!cover.length ){ //avoid call to outerXXXX() when not in IE6
- cover.css({left: -borders[0], top: -borders[1], width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()})
- }
- inst.dpDiv.find('.' + this._dayOverClass + ' a').mouseover();
- var numMonths = this._getNumberOfMonths(inst);
- var cols = numMonths[1];
- var width = 17;
- inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
- if (cols > 1)
- inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
- inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
- 'Class']('ui-datepicker-multi');
- inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
- 'Class']('ui-datepicker-rtl');
- if (inst == $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input &&
- // #6694 - don't focus the input if it's already focused
- // this breaks the change event in IE
- inst.input.is(':visible') && !inst.input.is(':disabled') && inst.input[0] != document.activeElement)
+ inst.dpDiv.find("." + this._dayOverClass + " a").mouseover();
+
+ var origyearshtml,
+ numMonths = this._getNumberOfMonths(inst),
+ cols = numMonths[1],
+ width = 17;
+
+ inst.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width("");
+ if (cols > 1) {
+ inst.dpDiv.addClass("ui-datepicker-multi-" + cols).css("width", (width * cols) + "em");
+ }
+ inst.dpDiv[(numMonths[0] !== 1 || numMonths[1] !== 1 ? "add" : "remove") +
+ "Class"]("ui-datepicker-multi");
+ inst.dpDiv[(this._get(inst, "isRTL") ? "add" : "remove") +
+ "Class"]("ui-datepicker-rtl");
+
+ // #6694 - don't focus the input if it's already focused
+ // this breaks the change event in IE
+ if (inst === $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input &&
+ inst.input.is(":visible") && !inst.input.is(":disabled") && inst.input[0] !== document.activeElement) {
inst.input.focus();
+ }
+
// deffered render of the years select (to avoid flashes on Firefox)
if( inst.yearshtml ){
- var origyearshtml = inst.yearshtml;
+ origyearshtml = inst.yearshtml;
setTimeout(function(){
//assure that inst.yearshtml didn't change.
if( origyearshtml === inst.yearshtml && inst.yearshtml ){
- inst.dpDiv.find('select.ui-datepicker-year:first').replaceWith(inst.yearshtml);
+ inst.dpDiv.find("select.ui-datepicker-year:first").replaceWith(inst.yearshtml);
}
origyearshtml = inst.yearshtml = null;
}, 0);
@@ -7956,28 +8375,29 @@ $.extend(Datepicker.prototype, {
},
/* Retrieve the size of left and top borders for an element.
- @param elem (jQuery object) the element of interest
- @return (number[2]) the left and top borders */
+ * @param elem (jQuery object) the element of interest
+ * @return (number[2]) the left and top borders
+ */
_getBorders: function(elem) {
var convert = function(value) {
return {thin: 1, medium: 2, thick: 3}[value] || value;
};
- return [parseFloat(convert(elem.css('border-left-width'))),
- parseFloat(convert(elem.css('border-top-width')))];
+ return [parseFloat(convert(elem.css("border-left-width"))),
+ parseFloat(convert(elem.css("border-top-width")))];
},
/* Check positioning to remain on screen. */
_checkOffset: function(inst, offset, isFixed) {
- var dpWidth = inst.dpDiv.outerWidth();
- var dpHeight = inst.dpDiv.outerHeight();
- var inputWidth = inst.input ? inst.input.outerWidth() : 0;
- var inputHeight = inst.input ? inst.input.outerHeight() : 0;
- var viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft());
- var viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop());
+ var dpWidth = inst.dpDiv.outerWidth(),
+ dpHeight = inst.dpDiv.outerHeight(),
+ inputWidth = inst.input ? inst.input.outerWidth() : 0,
+ inputHeight = inst.input ? inst.input.outerHeight() : 0,
+ viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft()),
+ viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop());
- offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
- offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
- offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
+ offset.left -= (this._get(inst, "isRTL") ? (dpWidth - inputWidth) : 0);
+ offset.left -= (isFixed && offset.left === inst.input.offset().left) ? $(document).scrollLeft() : 0;
+ offset.top -= (isFixed && offset.top === (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
// now check if datepicker is showing outside window viewport - move to a better place if so.
offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
@@ -7990,47 +8410,60 @@ $.extend(Datepicker.prototype, {
/* Find an object's position on the screen. */
_findPos: function(obj) {
- var inst = this._getInst(obj);
- var isRTL = this._get(inst, 'isRTL');
- while (obj && (obj.type == 'hidden' || obj.nodeType != 1 || $.expr.filters.hidden(obj))) {
- obj = obj[isRTL ? 'previousSibling' : 'nextSibling'];
+ var position,
+ inst = this._getInst(obj),
+ isRTL = this._get(inst, "isRTL");
+
+ while (obj && (obj.type === "hidden" || obj.nodeType !== 1 || $.expr.filters.hidden(obj))) {
+ obj = obj[isRTL ? "previousSibling" : "nextSibling"];
}
- var position = $(obj).offset();
+
+ position = $(obj).offset();
return [position.left, position.top];
},
/* Hide the date picker from view.
- @param input element - the input field attached to the date picker */
+ * @param input element - the input field attached to the date picker
+ */
_hideDatepicker: function(input) {
- var inst = this._curInst;
- if (!inst || (input && inst != $.data(input, PROP_NAME)))
+ var showAnim, duration, postProcess, onClose,
+ inst = this._curInst;
+
+ if (!inst || (input && inst !== $.data(input, PROP_NAME))) {
return;
+ }
+
if (this._datepickerShowing) {
- var showAnim = this._get(inst, 'showAnim');
- var duration = this._get(inst, 'duration');
- var postProcess = function() {
+ showAnim = this._get(inst, "showAnim");
+ duration = this._get(inst, "duration");
+ postProcess = function() {
$.datepicker._tidyDialog(inst);
};
// DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
- if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) )
- inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
- else
- inst.dpDiv[(showAnim == 'slideDown' ? 'slideUp' :
- (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
- if (!showAnim)
+ if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) ) {
+ inst.dpDiv.hide(showAnim, $.datepicker._get(inst, "showOptions"), duration, postProcess);
+ } else {
+ inst.dpDiv[(showAnim === "slideDown" ? "slideUp" :
+ (showAnim === "fadeIn" ? "fadeOut" : "hide"))]((showAnim ? duration : null), postProcess);
+ }
+
+ if (!showAnim) {
postProcess();
+ }
this._datepickerShowing = false;
- var onClose = this._get(inst, 'onClose');
- if (onClose)
- onClose.apply((inst.input ? inst.input[0] : null),
- [(inst.input ? inst.input.val() : ''), inst]);
+
+ onClose = this._get(inst, "onClose");
+ if (onClose) {
+ onClose.apply((inst.input ? inst.input[0] : null), [(inst.input ? inst.input.val() : ""), inst]);
+ }
+
this._lastInput = null;
if (this._inDialog) {
- this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
+ this._dialogInput.css({ position: "absolute", left: "0", top: "-100px" });
if ($.blockUI) {
$.unblockUI();
- $('body').append(this.dpDiv);
+ $("body").append(this.dpDiv);
}
}
this._inDialog = false;
@@ -8039,50 +8472,54 @@ $.extend(Datepicker.prototype, {
/* Tidy up after a dialog display. */
_tidyDialog: function(inst) {
- inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
+ inst.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar");
},
/* Close date picker if clicked elsewhere. */
_checkExternalClick: function(event) {
- if (!$.datepicker._curInst)
+ if (!$.datepicker._curInst) {
return;
+ }
var $target = $(event.target),
inst = $.datepicker._getInst($target[0]);
- if ( ( ( $target[0].id != $.datepicker._mainDivId &&
- $target.parents('#' + $.datepicker._mainDivId).length == 0 &&
+ if ( ( ( $target[0].id !== $.datepicker._mainDivId &&
+ $target.parents("#" + $.datepicker._mainDivId).length === 0 &&
!$target.hasClass($.datepicker.markerClassName) &&
!$target.closest("." + $.datepicker._triggerClass).length &&
$.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) ||
- ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst != inst ) )
- $.datepicker._hideDatepicker();
+ ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst !== inst ) ) {
+ $.datepicker._hideDatepicker();
+ }
},
/* Adjust one of the date sub-fields. */
_adjustDate: function(id, offset, period) {
- var target = $(id);
- var inst = this._getInst(target[0]);
+ var target = $(id),
+ inst = this._getInst(target[0]);
+
if (this._isDisabledDatepicker(target[0])) {
return;
}
this._adjustInstDate(inst, offset +
- (period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
+ (period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning
period);
this._updateDatepicker(inst);
},
/* Action for current link. */
_gotoToday: function(id) {
- var target = $(id);
- var inst = this._getInst(target[0]);
- if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
+ var date,
+ target = $(id),
+ inst = this._getInst(target[0]);
+
+ if (this._get(inst, "gotoCurrent") && inst.currentDay) {
inst.selectedDay = inst.currentDay;
inst.drawMonth = inst.selectedMonth = inst.currentMonth;
inst.drawYear = inst.selectedYear = inst.currentYear;
- }
- else {
- var date = new Date();
+ } else {
+ date = new Date();
inst.selectedDay = date.getDate();
inst.drawMonth = inst.selectedMonth = date.getMonth();
inst.drawYear = inst.selectedYear = date.getFullYear();
@@ -8093,23 +8530,28 @@ $.extend(Datepicker.prototype, {
/* Action for selecting a new month/year. */
_selectMonthYear: function(id, select, period) {
- var target = $(id);
- var inst = this._getInst(target[0]);
- inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
- inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
+ var target = $(id),
+ inst = this._getInst(target[0]);
+
+ inst["selected" + (period === "M" ? "Month" : "Year")] =
+ inst["draw" + (period === "M" ? "Month" : "Year")] =
parseInt(select.options[select.selectedIndex].value,10);
+
this._notifyChange(inst);
this._adjustDate(target);
},
/* Action for selecting a day. */
_selectDay: function(id, month, year, td) {
- var target = $(id);
+ var inst,
+ target = $(id);
+
if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
return;
}
- var inst = this._getInst(target[0]);
- inst.selectedDay = inst.currentDay = $('a', td).html();
+
+ inst = this._getInst(target[0]);
+ inst.selectedDay = inst.currentDay = $("a", td).html();
inst.selectedMonth = inst.currentMonth = month;
inst.selectedYear = inst.currentYear = year;
this._selectDate(id, this._formatDate(inst,
@@ -8119,372 +8561,427 @@ $.extend(Datepicker.prototype, {
/* Erase the input field and hide the date picker. */
_clearDate: function(id) {
var target = $(id);
- var inst = this._getInst(target[0]);
- this._selectDate(target, '');
+ this._selectDate(target, "");
},
/* Update the input field with the selected date. */
_selectDate: function(id, dateStr) {
- var target = $(id);
- var inst = this._getInst(target[0]);
+ var onSelect,
+ target = $(id),
+ inst = this._getInst(target[0]);
+
dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
- if (inst.input)
+ if (inst.input) {
inst.input.val(dateStr);
+ }
this._updateAlternate(inst);
- var onSelect = this._get(inst, 'onSelect');
- if (onSelect)
+
+ onSelect = this._get(inst, "onSelect");
+ if (onSelect) {
onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
- else if (inst.input)
- inst.input.trigger('change'); // fire the change event
- if (inst.inline)
+ } else if (inst.input) {
+ inst.input.trigger("change"); // fire the change event
+ }
+
+ if (inst.inline){
this._updateDatepicker(inst);
- else {
+ } else {
this._hideDatepicker();
this._lastInput = inst.input[0];
- if (typeof(inst.input[0]) != 'object')
+ if (typeof(inst.input[0]) !== "object") {
inst.input.focus(); // restore focus
+ }
this._lastInput = null;
}
},
/* Update any alternate field to synchronise with the main field. */
_updateAlternate: function(inst) {
- var altField = this._get(inst, 'altField');
+ var altFormat, date, dateStr,
+ altField = this._get(inst, "altField");
+
if (altField) { // update alternate field too
- var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
- var date = this._getDate(inst);
- var dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
+ altFormat = this._get(inst, "altFormat") || this._get(inst, "dateFormat");
+ date = this._getDate(inst);
+ dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
$(altField).each(function() { $(this).val(dateStr); });
}
},
/* Set as beforeShowDay function to prevent selection of weekends.
- @param date Date - the date to customise
- @return [boolean, string] - is this date selectable?, what is its CSS class? */
+ * @param date Date - the date to customise
+ * @return [boolean, string] - is this date selectable?, what is its CSS class?
+ */
noWeekends: function(date) {
var day = date.getDay();
- return [(day > 0 && day < 6), ''];
+ return [(day > 0 && day < 6), ""];
},
/* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
- @param date Date - the date to get the week for
- @return number - the number of the week within the year that contains this date */
+ * @param date Date - the date to get the week for
+ * @return number - the number of the week within the year that contains this date
+ */
iso8601Week: function(date) {
- var checkDate = new Date(date.getTime());
+ var time,
+ checkDate = new Date(date.getTime());
+
// Find Thursday of this week starting on Monday
checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
- var time = checkDate.getTime();
+
+ time = checkDate.getTime();
checkDate.setMonth(0); // Compare with Jan 1
checkDate.setDate(1);
return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
},
/* Parse a string value into a date object.
- See formatDate below for the possible formats.
-
- @param format string - the expected format of the date
- @param value string - the date in the above format
- @param settings Object - attributes include:
- shortYearCutoff number - the cutoff year for determining the century (optional)
- dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
- dayNames string[7] - names of the days from Sunday (optional)
- monthNamesShort string[12] - abbreviated names of the months (optional)
- monthNames string[12] - names of the months (optional)
- @return Date - the extracted date value or null if value is blank */
+ * See formatDate below for the possible formats.
+ *
+ * @param format string - the expected format of the date
+ * @param value string - the date in the above format
+ * @param settings Object - attributes include:
+ * shortYearCutoff number - the cutoff year for determining the century (optional)
+ * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
+ * dayNames string[7] - names of the days from Sunday (optional)
+ * monthNamesShort string[12] - abbreviated names of the months (optional)
+ * monthNames string[12] - names of the months (optional)
+ * @return Date - the extracted date value or null if value is blank
+ */
parseDate: function (format, value, settings) {
- if (format == null || value == null)
- throw 'Invalid arguments';
- value = (typeof value == 'object' ? value.toString() : value + '');
- if (value == '')
+ if (format == null || value == null) {
+ throw "Invalid arguments";
+ }
+
+ value = (typeof value === "object" ? value.toString() : value + "");
+ if (value === "") {
return null;
- var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
- shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
- new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
- var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
- var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
- var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
- var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
- var year = -1;
- var month = -1;
- var day = -1;
- var doy = -1;
- var literal = false;
- // Check whether a format character is doubled
- var lookAhead = function(match) {
- var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
- if (matches)
- iFormat++;
- return matches;
- };
- // Extract a number from the string value
- var getNumber = function(match) {
- var isDoubled = lookAhead(match);
- var size = (match == '@' ? 14 : (match == '!' ? 20 :
- (match == 'y' && isDoubled ? 4 : (match == 'o' ? 3 : 2))));
- var digits = new RegExp('^\\d{1,' + size + '}');
- var num = value.substring(iValue).match(digits);
- if (!num)
- throw 'Missing number at position ' + iValue;
- iValue += num[0].length;
- return parseInt(num[0], 10);
- };
- // Extract a name from the string value and convert to an index
- var getName = function(match, shortNames, longNames) {
- var names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
- return [ [k, v] ];
- }).sort(function (a, b) {
- return -(a[1].length - b[1].length);
- });
- var index = -1;
- $.each(names, function (i, pair) {
- var name = pair[1];
- if (value.substr(iValue, name.length).toLowerCase() == name.toLowerCase()) {
- index = pair[0];
- iValue += name.length;
- return false;
+ }
+
+ var iFormat, dim, extra,
+ iValue = 0,
+ shortYearCutoffTemp = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff,
+ shortYearCutoff = (typeof shortYearCutoffTemp !== "string" ? shortYearCutoffTemp :
+ new Date().getFullYear() % 100 + parseInt(shortYearCutoffTemp, 10)),
+ dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort,
+ dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames,
+ monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort,
+ monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames,
+ year = -1,
+ month = -1,
+ day = -1,
+ doy = -1,
+ literal = false,
+ date,
+ // Check whether a format character is doubled
+ lookAhead = function(match) {
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
+ if (matches) {
+ iFormat++;
+ }
+ return matches;
+ },
+ // Extract a number from the string value
+ getNumber = function(match) {
+ var isDoubled = lookAhead(match),
+ size = (match === "@" ? 14 : (match === "!" ? 20 :
+ (match === "y" && isDoubled ? 4 : (match === "o" ? 3 : 2)))),
+ digits = new RegExp("^\\d{1," + size + "}"),
+ num = value.substring(iValue).match(digits);
+ if (!num) {
+ throw "Missing number at position " + iValue;
+ }
+ iValue += num[0].length;
+ return parseInt(num[0], 10);
+ },
+ // Extract a name from the string value and convert to an index
+ getName = function(match, shortNames, longNames) {
+ var index = -1,
+ names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
+ return [ [k, v] ];
+ }).sort(function (a, b) {
+ return -(a[1].length - b[1].length);
+ });
+
+ $.each(names, function (i, pair) {
+ var name = pair[1];
+ if (value.substr(iValue, name.length).toLowerCase() === name.toLowerCase()) {
+ index = pair[0];
+ iValue += name.length;
+ return false;
+ }
+ });
+ if (index !== -1) {
+ return index + 1;
+ } else {
+ throw "Unknown name at position " + iValue;
}
- });
- if (index != -1)
- return index + 1;
- else
- throw 'Unknown name at position ' + iValue;
- };
- // Confirm that a literal character matches the string value
- var checkLiteral = function() {
- if (value.charAt(iValue) != format.charAt(iFormat))
- throw 'Unexpected literal at position ' + iValue;
- iValue++;
- };
- var iValue = 0;
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
- if (literal)
- if (format.charAt(iFormat) == "'" && !lookAhead("'"))
+ },
+ // Confirm that a literal character matches the string value
+ checkLiteral = function() {
+ if (value.charAt(iValue) !== format.charAt(iFormat)) {
+ throw "Unexpected literal at position " + iValue;
+ }
+ iValue++;
+ };
+
+ for (iFormat = 0; iFormat < format.length; iFormat++) {
+ if (literal) {
+ if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
literal = false;
- else
+ } else {
checkLiteral();
- else
+ }
+ } else {
switch (format.charAt(iFormat)) {
- case 'd':
- day = getNumber('d');
+ case "d":
+ day = getNumber("d");
break;
- case 'D':
- getName('D', dayNamesShort, dayNames);
+ case "D":
+ getName("D", dayNamesShort, dayNames);
break;
- case 'o':
- doy = getNumber('o');
+ case "o":
+ doy = getNumber("o");
break;
- case 'm':
- month = getNumber('m');
+ case "m":
+ month = getNumber("m");
break;
- case 'M':
- month = getName('M', monthNamesShort, monthNames);
+ case "M":
+ month = getName("M", monthNamesShort, monthNames);
break;
- case 'y':
- year = getNumber('y');
+ case "y":
+ year = getNumber("y");
break;
- case '@':
- var date = new Date(getNumber('@'));
+ case "@":
+ date = new Date(getNumber("@"));
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate();
break;
- case '!':
- var date = new Date((getNumber('!') - this._ticksTo1970) / 10000);
+ case "!":
+ date = new Date((getNumber("!") - this._ticksTo1970) / 10000);
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate();
break;
case "'":
- if (lookAhead("'"))
+ if (lookAhead("'")){
checkLiteral();
- else
+ } else {
literal = true;
+ }
break;
default:
checkLiteral();
}
+ }
}
+
if (iValue < value.length){
- var extra = value.substr(iValue);
+ extra = value.substr(iValue);
if (!/^\s+/.test(extra)) {
throw "Extra/unparsed characters found in date: " + extra;
}
}
- if (year == -1)
+
+ if (year === -1) {
year = new Date().getFullYear();
- else if (year < 100)
+ } else if (year < 100) {
year += new Date().getFullYear() - new Date().getFullYear() % 100 +
(year <= shortYearCutoff ? 0 : -100);
+ }
+
if (doy > -1) {
month = 1;
day = doy;
do {
- var dim = this._getDaysInMonth(year, month - 1);
- if (day <= dim)
+ dim = this._getDaysInMonth(year, month - 1);
+ if (day <= dim) {
break;
+ }
month++;
day -= dim;
} while (true);
}
- var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
- if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
- throw 'Invalid date'; // E.g. 31/02/00
+
+ date = this._daylightSavingAdjust(new Date(year, month - 1, day));
+ if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
+ throw "Invalid date"; // E.g. 31/02/00
+ }
return date;
},
/* Standard date formats. */
- ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
- COOKIE: 'D, dd M yy',
- ISO_8601: 'yy-mm-dd',
- RFC_822: 'D, d M y',
- RFC_850: 'DD, dd-M-y',
- RFC_1036: 'D, d M y',
- RFC_1123: 'D, d M yy',
- RFC_2822: 'D, d M yy',
- RSS: 'D, d M y', // RFC 822
- TICKS: '!',
- TIMESTAMP: '@',
- W3C: 'yy-mm-dd', // ISO 8601
+ ATOM: "yy-mm-dd", // RFC 3339 (ISO 8601)
+ COOKIE: "D, dd M yy",
+ ISO_8601: "yy-mm-dd",
+ RFC_822: "D, d M y",
+ RFC_850: "DD, dd-M-y",
+ RFC_1036: "D, d M y",
+ RFC_1123: "D, d M yy",
+ RFC_2822: "D, d M yy",
+ RSS: "D, d M y", // RFC 822
+ TICKS: "!",
+ TIMESTAMP: "@",
+ W3C: "yy-mm-dd", // ISO 8601
_ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
/* Format a date object into a string value.
- The format can be combinations of the following:
- d - day of month (no leading zero)
- dd - day of month (two digit)
- o - day of year (no leading zeros)
- oo - day of year (three digit)
- D - day name short
- DD - day name long
- m - month of year (no leading zero)
- mm - month of year (two digit)
- M - month name short
- MM - month name long
- y - year (two digit)
- yy - year (four digit)
- @ - Unix timestamp (ms since 01/01/1970)
- ! - Windows ticks (100ns since 01/01/0001)
- '...' - literal text
- '' - single quote
-
- @param format string - the desired format of the date
- @param date Date - the date value to format
- @param settings Object - attributes include:
- dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
- dayNames string[7] - names of the days from Sunday (optional)
- monthNamesShort string[12] - abbreviated names of the months (optional)
- monthNames string[12] - names of the months (optional)
- @return string - the date in the above format */
+ * The format can be combinations of the following:
+ * d - day of month (no leading zero)
+ * dd - day of month (two digit)
+ * o - day of year (no leading zeros)
+ * oo - day of year (three digit)
+ * D - day name short
+ * DD - day name long
+ * m - month of year (no leading zero)
+ * mm - month of year (two digit)
+ * M - month name short
+ * MM - month name long
+ * y - year (two digit)
+ * yy - year (four digit)
+ * @ - Unix timestamp (ms since 01/01/1970)
+ * ! - Windows ticks (100ns since 01/01/0001)
+ * "..." - literal text
+ * '' - single quote
+ *
+ * @param format string - the desired format of the date
+ * @param date Date - the date value to format
+ * @param settings Object - attributes include:
+ * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
+ * dayNames string[7] - names of the days from Sunday (optional)
+ * monthNamesShort string[12] - abbreviated names of the months (optional)
+ * monthNames string[12] - names of the months (optional)
+ * @return string - the date in the above format
+ */
formatDate: function (format, date, settings) {
- if (!date)
- return '';
- var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
- var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
- var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
- var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
- // Check whether a format character is doubled
- var lookAhead = function(match) {
- var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
- if (matches)
- iFormat++;
- return matches;
- };
- // Format a number, with leading zero if necessary
- var formatNumber = function(match, value, len) {
- var num = '' + value;
- if (lookAhead(match))
- while (num.length < len)
- num = '0' + num;
- return num;
- };
- // Format a name, short or long as requested
- var formatName = function(match, value, shortNames, longNames) {
- return (lookAhead(match) ? longNames[value] : shortNames[value]);
- };
- var output = '';
- var literal = false;
- if (date)
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
- if (literal)
- if (format.charAt(iFormat) == "'" && !lookAhead("'"))
+ if (!date) {
+ return "";
+ }
+
+ var iFormat,
+ dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort,
+ dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames,
+ monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort,
+ monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames,
+ // Check whether a format character is doubled
+ lookAhead = function(match) {
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
+ if (matches) {
+ iFormat++;
+ }
+ return matches;
+ },
+ // Format a number, with leading zero if necessary
+ formatNumber = function(match, value, len) {
+ var num = "" + value;
+ if (lookAhead(match)) {
+ while (num.length < len) {
+ num = "0" + num;
+ }
+ }
+ return num;
+ },
+ // Format a name, short or long as requested
+ formatName = function(match, value, shortNames, longNames) {
+ return (lookAhead(match) ? longNames[value] : shortNames[value]);
+ },
+ output = "",
+ literal = false;
+
+ if (date) {
+ for (iFormat = 0; iFormat < format.length; iFormat++) {
+ if (literal) {
+ if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
literal = false;
- else
+ } else {
output += format.charAt(iFormat);
- else
+ }
+ } else {
switch (format.charAt(iFormat)) {
- case 'd':
- output += formatNumber('d', date.getDate(), 2);
+ case "d":
+ output += formatNumber("d", date.getDate(), 2);
break;
- case 'D':
- output += formatName('D', date.getDay(), dayNamesShort, dayNames);
+ case "D":
+ output += formatName("D", date.getDay(), dayNamesShort, dayNames);
break;
- case 'o':
- output += formatNumber('o',
+ case "o":
+ output += formatNumber("o",
Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
break;
- case 'm':
- output += formatNumber('m', date.getMonth() + 1, 2);
+ case "m":
+ output += formatNumber("m", date.getMonth() + 1, 2);
break;
- case 'M':
- output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
+ case "M":
+ output += formatName("M", date.getMonth(), monthNamesShort, monthNames);
break;
- case 'y':
- output += (lookAhead('y') ? date.getFullYear() :
- (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
+ case "y":
+ output += (lookAhead("y") ? date.getFullYear() :
+ (date.getYear() % 100 < 10 ? "0" : "") + date.getYear() % 100);
break;
- case '@':
+ case "@":
output += date.getTime();
break;
- case '!':
+ case "!":
output += date.getTime() * 10000 + this._ticksTo1970;
break;
case "'":
- if (lookAhead("'"))
+ if (lookAhead("'")) {
output += "'";
- else
+ } else {
literal = true;
+ }
break;
default:
output += format.charAt(iFormat);
}
+ }
}
+ }
return output;
},
/* Extract all possible characters from the date format. */
_possibleChars: function (format) {
- var chars = '';
- var literal = false;
- // Check whether a format character is doubled
- var lookAhead = function(match) {
- var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
- if (matches)
- iFormat++;
- return matches;
- };
- for (var iFormat = 0; iFormat < format.length; iFormat++)
- if (literal)
- if (format.charAt(iFormat) == "'" && !lookAhead("'"))
+ var iFormat,
+ chars = "",
+ literal = false,
+ // Check whether a format character is doubled
+ lookAhead = function(match) {
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
+ if (matches) {
+ iFormat++;
+ }
+ return matches;
+ };
+
+ for (iFormat = 0; iFormat < format.length; iFormat++) {
+ if (literal) {
+ if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
literal = false;
- else
+ } else {
chars += format.charAt(iFormat);
- else
+ }
+ } else {
switch (format.charAt(iFormat)) {
- case 'd': case 'm': case 'y': case '@':
- chars += '0123456789';
+ case "d": case "m": case "y": case "@":
+ chars += "0123456789";
break;
- case 'D': case 'M':
+ case "D": case "M":
return null; // Accept anything
case "'":
- if (lookAhead("'"))
+ if (lookAhead("'")) {
chars += "'";
- else
+ } else {
literal = true;
+ }
break;
default:
chars += format.charAt(iFormat);
}
+ }
+ }
return chars;
},
@@ -8496,19 +8993,20 @@ $.extend(Datepicker.prototype, {
/* Parse existing date and initialise date picker. */
_setDateFromField: function(inst, noDefault) {
- if (inst.input.val() == inst.lastVal) {
+ if (inst.input.val() === inst.lastVal) {
return;
}
- var dateFormat = this._get(inst, 'dateFormat');
- var dates = inst.lastVal = inst.input ? inst.input.val() : null;
- var date, defaultDate;
- date = defaultDate = this._getDefaultDate(inst);
- var settings = this._getFormatConfig(inst);
+
+ var dateFormat = this._get(inst, "dateFormat"),
+ dates = inst.lastVal = inst.input ? inst.input.val() : null,
+ defaultDate = this._getDefaultDate(inst),
+ date = defaultDate,
+ settings = this._getFormatConfig(inst);
+
try {
date = this.parseDate(dateFormat, dates, settings) || defaultDate;
} catch (event) {
- this.log(event);
- dates = (noDefault ? '' : dates);
+ dates = (noDefault ? "" : dates);
}
inst.selectedDay = date.getDate();
inst.drawMonth = inst.selectedMonth = date.getMonth();
@@ -8522,53 +9020,56 @@ $.extend(Datepicker.prototype, {
/* Retrieve the default date shown on opening. */
_getDefaultDate: function(inst) {
return this._restrictMinMax(inst,
- this._determineDate(inst, this._get(inst, 'defaultDate'), new Date()));
+ this._determineDate(inst, this._get(inst, "defaultDate"), new Date()));
},
/* A date may be specified as an exact value or a relative one. */
_determineDate: function(inst, date, defaultDate) {
var offsetNumeric = function(offset) {
- var date = new Date();
- date.setDate(date.getDate() + offset);
- return date;
- };
- var offsetString = function(offset) {
- try {
- return $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
- offset, $.datepicker._getFormatConfig(inst));
- }
- catch (e) {
- // Ignore
- }
- var date = (offset.toLowerCase().match(/^c/) ?
- $.datepicker._getDate(inst) : null) || new Date();
- var year = date.getFullYear();
- var month = date.getMonth();
- var day = date.getDate();
- var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
- var matches = pattern.exec(offset);
- while (matches) {
- switch (matches[2] || 'd') {
- case 'd' : case 'D' :
- day += parseInt(matches[1],10); break;
- case 'w' : case 'W' :
- day += parseInt(matches[1],10) * 7; break;
- case 'm' : case 'M' :
- month += parseInt(matches[1],10);
- day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
- break;
- case 'y': case 'Y' :
- year += parseInt(matches[1],10);
- day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
- break;
+ var date = new Date();
+ date.setDate(date.getDate() + offset);
+ return date;
+ },
+ offsetString = function(offset) {
+ try {
+ return $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
+ offset, $.datepicker._getFormatConfig(inst));
+ }
+ catch (e) {
+ // Ignore
+ }
+
+ var date = (offset.toLowerCase().match(/^c/) ?
+ $.datepicker._getDate(inst) : null) || new Date(),
+ year = date.getFullYear(),
+ month = date.getMonth(),
+ day = date.getDate(),
+ pattern = /([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,
+ matches = pattern.exec(offset);
+
+ while (matches) {
+ switch (matches[2] || "d") {
+ case "d" : case "D" :
+ day += parseInt(matches[1],10); break;
+ case "w" : case "W" :
+ day += parseInt(matches[1],10) * 7; break;
+ case "m" : case "M" :
+ month += parseInt(matches[1],10);
+ day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
+ break;
+ case "y": case "Y" :
+ year += parseInt(matches[1],10);
+ day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
+ break;
+ }
+ matches = pattern.exec(offset);
}
- matches = pattern.exec(offset);
- }
- return new Date(year, month, day);
- };
- var newDate = (date == null || date === '' ? defaultDate : (typeof date == 'string' ? offsetString(date) :
- (typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));
- newDate = (newDate && newDate.toString() == 'Invalid Date' ? defaultDate : newDate);
+ return new Date(year, month, day);
+ },
+ newDate = (date == null || date === "" ? defaultDate : (typeof date === "string" ? offsetString(date) :
+ (typeof date === "number" ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));
+
+ newDate = (newDate && newDate.toString() === "Invalid Date" ? defaultDate : newDate);
if (newDate) {
newDate.setHours(0);
newDate.setMinutes(0);
@@ -8579,37 +9080,42 @@ $.extend(Datepicker.prototype, {
},
/* Handle switch to/from daylight saving.
- Hours may be non-zero on daylight saving cut-over:
- > 12 when midnight changeover, but then cannot generate
- midnight datetime, so jump to 1AM, otherwise reset.
- @param date (Date) the date to check
- @return (Date) the corrected date */
+ * Hours may be non-zero on daylight saving cut-over:
+ * > 12 when midnight changeover, but then cannot generate
+ * midnight datetime, so jump to 1AM, otherwise reset.
+ * @param date (Date) the date to check
+ * @return (Date) the corrected date
+ */
_daylightSavingAdjust: function(date) {
- if (!date) return null;
+ if (!date) {
+ return null;
+ }
date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
return date;
},
/* Set the date(s) directly. */
_setDate: function(inst, date, noChange) {
- var clear = !date;
- var origMonth = inst.selectedMonth;
- var origYear = inst.selectedYear;
- var newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
+ var clear = !date,
+ origMonth = inst.selectedMonth,
+ origYear = inst.selectedYear,
+ newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
+
inst.selectedDay = inst.currentDay = newDate.getDate();
inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();
inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();
- if ((origMonth != inst.selectedMonth || origYear != inst.selectedYear) && !noChange)
+ if ((origMonth !== inst.selectedMonth || origYear !== inst.selectedYear) && !noChange) {
this._notifyChange(inst);
+ }
this._adjustInstDate(inst);
if (inst.input) {
- inst.input.val(clear ? '' : this._formatDate(inst));
+ inst.input.val(clear ? "" : this._formatDate(inst));
}
},
/* Retrieve the date(s) directly. */
_getDate: function(inst) {
- var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null :
+ var startDate = (!inst.currentYear || (inst.input && inst.input.val() === "") ? null :
this._daylightSavingAdjust(new Date(
inst.currentYear, inst.currentMonth, inst.currentDay)));
return startDate;
@@ -8619,64 +9125,71 @@ $.extend(Datepicker.prototype, {
* they work with static code transformers like Caja.
*/
_attachHandlers: function(inst) {
- var stepMonths = this._get(inst, 'stepMonths');
- var id = '#' + inst.id.replace( /\\\\/g, "\\" );
- inst.dpDiv.find('[data-handler]').map(function () {
+ var stepMonths = this._get(inst, "stepMonths"),
+ id = "#" + inst.id.replace( /\\\\/g, "\\" );
+ inst.dpDiv.find("[data-handler]").map(function () {
var handler = {
prev: function () {
- window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, -stepMonths, 'M');
+ window["DP_jQuery_" + dpuuid].datepicker._adjustDate(id, -stepMonths, "M");
},
next: function () {
- window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, +stepMonths, 'M');
+ window["DP_jQuery_" + dpuuid].datepicker._adjustDate(id, +stepMonths, "M");
},
hide: function () {
- window['DP_jQuery_' + dpuuid].datepicker._hideDatepicker();
+ window["DP_jQuery_" + dpuuid].datepicker._hideDatepicker();
},
today: function () {
- window['DP_jQuery_' + dpuuid].datepicker._gotoToday(id);
+ window["DP_jQuery_" + dpuuid].datepicker._gotoToday(id);
},
selectDay: function () {
- window['DP_jQuery_' + dpuuid].datepicker._selectDay(id, +this.getAttribute('data-month'), +this.getAttribute('data-year'), this);
+ window["DP_jQuery_" + dpuuid].datepicker._selectDay(id, +this.getAttribute("data-month"), +this.getAttribute("data-year"), this);
return false;
},
selectMonth: function () {
- window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'M');
+ window["DP_jQuery_" + dpuuid].datepicker._selectMonthYear(id, this, "M");
return false;
},
selectYear: function () {
- window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'Y');
+ window["DP_jQuery_" + dpuuid].datepicker._selectMonthYear(id, this, "Y");
return false;
}
};
- $(this).bind(this.getAttribute('data-event'), handler[this.getAttribute('data-handler')]);
+ $(this).bind(this.getAttribute("data-event"), handler[this.getAttribute("data-handler")]);
});
},
/* Generate the HTML for the current state of the date picker. */
_generateHTML: function(inst) {
- var today = new Date();
- today = this._daylightSavingAdjust(
- new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
- var isRTL = this._get(inst, 'isRTL');
- var showButtonPanel = this._get(inst, 'showButtonPanel');
- var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
- var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
- var numMonths = this._getNumberOfMonths(inst);
- var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
- var stepMonths = this._get(inst, 'stepMonths');
- var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
- var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
- new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
- var minDate = this._getMinMaxDate(inst, 'min');
- var maxDate = this._getMinMaxDate(inst, 'max');
- var drawMonth = inst.drawMonth - showCurrentAtPos;
- var drawYear = inst.drawYear;
+ var maxDraw, prevText, prev, nextText, next, currentText, gotoDate,
+ controls, buttonPanel, firstDay, showWeek, dayNames, dayNamesMin,
+ monthNames, monthNamesShort, beforeShowDay, showOtherMonths,
+ selectOtherMonths, defaultDate, html, dow, row, group, col, selectedDate,
+ cornerClass, calender, thead, day, daysInMonth, leadDays, curRows, numRows,
+ printDate, dRow, tbody, daySettings, otherMonth, unselectable,
+ tempDate = new Date(),
+ today = this._daylightSavingAdjust(
+ new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())), // clear time
+ isRTL = this._get(inst, "isRTL"),
+ showButtonPanel = this._get(inst, "showButtonPanel"),
+ hideIfNoPrevNext = this._get(inst, "hideIfNoPrevNext"),
+ navigationAsDateFormat = this._get(inst, "navigationAsDateFormat"),
+ numMonths = this._getNumberOfMonths(inst),
+ showCurrentAtPos = this._get(inst, "showCurrentAtPos"),
+ stepMonths = this._get(inst, "stepMonths"),
+ isMultiMonth = (numMonths[0] !== 1 || numMonths[1] !== 1),
+ currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
+ new Date(inst.currentYear, inst.currentMonth, inst.currentDay))),
+ minDate = this._getMinMaxDate(inst, "min"),
+ maxDate = this._getMinMaxDate(inst, "max"),
+ drawMonth = inst.drawMonth - showCurrentAtPos,
+ drawYear = inst.drawYear;
+
if (drawMonth < 0) {
drawMonth += 12;
drawYear--;
}
if (maxDate) {
- var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
+ maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
@@ -8689,133 +9202,142 @@ $.extend(Datepicker.prototype, {
}
inst.drawMonth = drawMonth;
inst.drawYear = drawYear;
- var prevText = this._get(inst, 'prevText');
+
+ prevText = this._get(inst, "prevText");
prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
this._getFormatConfig(inst)));
- var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
- '<a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click"' +
- ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
- (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
- var nextText = this._get(inst, 'nextText');
+
+ prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
+ "<a class='ui-datepicker-prev ui-corner-all' data-handler='prev' data-event='click'" +
+ " title='" + prevText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w") + "'>" + prevText + "</span></a>" :
+ (hideIfNoPrevNext ? "" : "<a class='ui-datepicker-prev ui-corner-all ui-state-disabled' title='"+ prevText +"'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w") + "'>" + prevText + "</span></a>"));
+
+ nextText = this._get(inst, "nextText");
nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
this._getFormatConfig(inst)));
- var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
- '<a class="ui-datepicker-next ui-corner-all" data-handler="next" data-event="click"' +
- ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
- (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
- var currentText = this._get(inst, 'currentText');
- var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
+
+ next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
+ "<a class='ui-datepicker-next ui-corner-all' data-handler='next' data-event='click'" +
+ " title='" + nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e") + "'>" + nextText + "</span></a>" :
+ (hideIfNoPrevNext ? "" : "<a class='ui-datepicker-next ui-corner-all ui-state-disabled' title='"+ nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e") + "'>" + nextText + "</span></a>"));
+
+ currentText = this._get(inst, "currentText");
+ gotoDate = (this._get(inst, "gotoCurrent") && inst.currentDay ? currentDate : today);
currentText = (!navigationAsDateFormat ? currentText :
this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
- var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" data-handler="hide" data-event="click">' +
- this._get(inst, 'closeText') + '</button>' : '');
- var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
- (this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" data-handler="today" data-event="click"' +
- '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
- var firstDay = parseInt(this._get(inst, 'firstDay'),10);
+
+ controls = (!inst.inline ? "<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" +
+ this._get(inst, "closeText") + "</button>" : "");
+
+ buttonPanel = (showButtonPanel) ? "<div class='ui-datepicker-buttonpane ui-widget-content'>" + (isRTL ? controls : "") +
+ (this._isInRange(inst, gotoDate) ? "<button type='button' class='ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all' data-handler='today' data-event='click'" +
+ ">" + currentText + "</button>" : "") + (isRTL ? "" : controls) + "</div>" : "";
+
+ firstDay = parseInt(this._get(inst, "firstDay"),10);
firstDay = (isNaN(firstDay) ? 0 : firstDay);
- var showWeek = this._get(inst, 'showWeek');
- var dayNames = this._get(inst, 'dayNames');
- var dayNamesShort = this._get(inst, 'dayNamesShort');
- var dayNamesMin = this._get(inst, 'dayNamesMin');
- var monthNames = this._get(inst, 'monthNames');
- var monthNamesShort = this._get(inst, 'monthNamesShort');
- var beforeShowDay = this._get(inst, 'beforeShowDay');
- var showOtherMonths = this._get(inst, 'showOtherMonths');
- var selectOtherMonths = this._get(inst, 'selectOtherMonths');
- var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
- var defaultDate = this._getDefaultDate(inst);
- var html = '';
- for (var row = 0; row < numMonths[0]; row++) {
- var group = '';
+
+ showWeek = this._get(inst, "showWeek");
+ dayNames = this._get(inst, "dayNames");
+ dayNamesMin = this._get(inst, "dayNamesMin");
+ monthNames = this._get(inst, "monthNames");
+ monthNamesShort = this._get(inst, "monthNamesShort");
+ beforeShowDay = this._get(inst, "beforeShowDay");
+ showOtherMonths = this._get(inst, "showOtherMonths");
+ selectOtherMonths = this._get(inst, "selectOtherMonths");
+ defaultDate = this._getDefaultDate(inst);
+ html = "";
+ dow;
+ for (row = 0; row < numMonths[0]; row++) {
+ group = "";
this.maxRows = 4;
- for (var col = 0; col < numMonths[1]; col++) {
- var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
- var cornerClass = ' ui-corner-all';
- var calender = '';
+ for (col = 0; col < numMonths[1]; col++) {
+ selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
+ cornerClass = " ui-corner-all";
+ calender = "";
if (isMultiMonth) {
- calender += '<div class="ui-datepicker-group';
- if (numMonths[1] > 1)
+ calender += "<div class='ui-datepicker-group";
+ if (numMonths[1] > 1) {
switch (col) {
- case 0: calender += ' ui-datepicker-group-first';
- cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
- case numMonths[1]-1: calender += ' ui-datepicker-group-last';
- cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
- default: calender += ' ui-datepicker-group-middle'; cornerClass = ''; break;
+ case 0: calender += " ui-datepicker-group-first";
+ cornerClass = " ui-corner-" + (isRTL ? "right" : "left"); break;
+ case numMonths[1]-1: calender += " ui-datepicker-group-last";
+ cornerClass = " ui-corner-" + (isRTL ? "left" : "right"); break;
+ default: calender += " ui-datepicker-group-middle"; cornerClass = ""; break;
}
- calender += '">';
+ }
+ calender += "'>";
}
- calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
- (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
- (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
+ calender += "<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix" + cornerClass + "'>" +
+ (/all|left/.test(cornerClass) && row === 0 ? (isRTL ? next : prev) : "") +
+ (/all|right/.test(cornerClass) && row === 0 ? (isRTL ? prev : next) : "") +
this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
- '</div><table class="ui-datepicker-calendar"><thead>' +
- '<tr>';
- var thead = (showWeek ? '<th class="ui-datepicker-week-col">' + this._get(inst, 'weekHeader') + '</th>' : '');
- for (var dow = 0; dow < 7; dow++) { // days of the week
- var day = (dow + firstDay) % 7;
- thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
- '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
- }
- calender += thead + '</tr></thead><tbody>';
- var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
- if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
+ "</div><table class='ui-datepicker-calendar'><thead>" +
+ "<tr>";
+ thead = (showWeek ? "<th class='ui-datepicker-week-col'>" + this._get(inst, "weekHeader") + "</th>" : "");
+ for (dow = 0; dow < 7; dow++) { // days of the week
+ day = (dow + firstDay) % 7;
+ thead += "<th" + ((dow + firstDay + 6) % 7 >= 5 ? " class='ui-datepicker-week-end'" : "") + ">" +
+ "<span title='" + dayNames[day] + "'>" + dayNamesMin[day] + "</span></th>";
+ }
+ calender += thead + "</tr></thead><tbody>";
+ daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
+ if (drawYear === inst.selectedYear && drawMonth === inst.selectedMonth) {
inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
- var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
- var curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
- var numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
+ }
+ leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
+ curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
+ numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
this.maxRows = numRows;
- var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
- for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
- calender += '<tr>';
- var tbody = (!showWeek ? '' : '<td class="ui-datepicker-week-col">' +
- this._get(inst, 'calculateWeek')(printDate) + '</td>');
- for (var dow = 0; dow < 7; dow++) { // create date picker days
- var daySettings = (beforeShowDay ?
- beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
- var otherMonth = (printDate.getMonth() != drawMonth);
- var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
+ printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
+ for (dRow = 0; dRow < numRows; dRow++) { // create date picker rows
+ calender += "<tr>";
+ tbody = (!showWeek ? "" : "<td class='ui-datepicker-week-col'>" +
+ this._get(inst, "calculateWeek")(printDate) + "</td>");
+ for (dow = 0; dow < 7; dow++) { // create date picker days
+ daySettings = (beforeShowDay ?
+ beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, ""]);
+ otherMonth = (printDate.getMonth() !== drawMonth);
+ unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
(minDate && printDate < minDate) || (maxDate && printDate > maxDate);
- tbody += '<td class="' +
- ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
- (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
- ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
- (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
+ tbody += "<td class='" +
+ ((dow + firstDay + 6) % 7 >= 5 ? " ui-datepicker-week-end" : "") + // highlight weekends
+ (otherMonth ? " ui-datepicker-other-month" : "") + // highlight days from other months
+ ((printDate.getTime() === selectedDate.getTime() && drawMonth === inst.selectedMonth && inst._keyEvent) || // user pressed key
+ (defaultDate.getTime() === printDate.getTime() && defaultDate.getTime() === selectedDate.getTime()) ?
// or defaultDate is current printedDate and defaultDate is selectedDate
- ' ' + this._dayOverClass : '') + // highlight selected day
- (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable days
- (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
- (printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
- (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
- ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
- (unselectable ? '' : ' data-handler="selectDay" data-event="click" data-month="' + printDate.getMonth() + '" data-year="' + printDate.getFullYear() + '"') + '>' + // actions
- (otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
- (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
- (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
- (printDate.getTime() == currentDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
- (otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
- '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
+ " " + this._dayOverClass : "") + // highlight selected day
+ (unselectable ? " " + this._unselectableClass + " ui-state-disabled": "") + // highlight unselectable days
+ (otherMonth && !showOtherMonths ? "" : " " + daySettings[1] + // highlight custom dates
+ (printDate.getTime() === currentDate.getTime() ? " " + this._currentClass : "") + // highlight selected day
+ (printDate.getTime() === today.getTime() ? " ui-datepicker-today" : "")) + "'" + // highlight today (if different)
+ ((!otherMonth || showOtherMonths) && daySettings[2] ? " title='" + daySettings[2].replace(/'/g, "&#39;") + "'" : "") + // cell title
+ (unselectable ? "" : " data-handler='selectDay' data-event='click' data-month='" + printDate.getMonth() + "' data-year='" + printDate.getFullYear() + "'") + ">" + // actions
+ (otherMonth && !showOtherMonths ? "&#xa0;" : // display for other months
+ (unselectable ? "<span class='ui-state-default'>" + printDate.getDate() + "</span>" : "<a class='ui-state-default" +
+ (printDate.getTime() === today.getTime() ? " ui-state-highlight" : "") +
+ (printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "") + // highlight selected day
+ (otherMonth ? " ui-priority-secondary" : "") + // distinguish dates from other months
+ "' href='#'>" + printDate.getDate() + "</a>")) + "</td>"; // display selectable date
printDate.setDate(printDate.getDate() + 1);
printDate = this._daylightSavingAdjust(printDate);
}
- calender += tbody + '</tr>';
+ calender += tbody + "</tr>";
}
drawMonth++;
if (drawMonth > 11) {
drawMonth = 0;
drawYear++;
}
- calender += '</tbody></table>' + (isMultiMonth ? '</div>' +
- ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
+ calender += "</tbody></table>" + (isMultiMonth ? "</div>" +
+ ((numMonths[0] > 0 && col === numMonths[1]-1) ? "<div class='ui-datepicker-row-break'></div>" : "") : "");
group += calender;
}
html += group;
}
- html += buttonPanel + ($.ui.ie6 && !inst.inline ?
- '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
+ html += buttonPanel;
inst._keyEvent = false;
return html;
},
@@ -8823,108 +9345,116 @@ $.extend(Datepicker.prototype, {
/* Generate the month and year header. */
_generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
secondary, monthNames, monthNamesShort) {
- var changeMonth = this._get(inst, 'changeMonth');
- var changeYear = this._get(inst, 'changeYear');
- var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
- var html = '<div class="ui-datepicker-title">';
- var monthHtml = '';
+
+ var inMinYear, inMaxYear, month, years, thisYear, determineYear, year, endYear,
+ changeMonth = this._get(inst, "changeMonth"),
+ changeYear = this._get(inst, "changeYear"),
+ showMonthAfterYear = this._get(inst, "showMonthAfterYear"),
+ html = "<div class='ui-datepicker-title'>",
+ monthHtml = "";
+
// month selection
- if (secondary || !changeMonth)
- monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span>';
- else {
- var inMinYear = (minDate && minDate.getFullYear() == drawYear);
- var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
- monthHtml += '<select class="ui-datepicker-month" data-handler="selectMonth" data-event="change">';
- for (var month = 0; month < 12; month++) {
- if ((!inMinYear || month >= minDate.getMonth()) &&
- (!inMaxYear || month <= maxDate.getMonth()))
- monthHtml += '<option value="' + month + '"' +
- (month == drawMonth ? ' selected="selected"' : '') +
- '>' + monthNamesShort[month] + '</option>';
- }
- monthHtml += '</select>';
- }
- if (!showMonthAfterYear)
- html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '');
+ if (secondary || !changeMonth) {
+ monthHtml += "<span class='ui-datepicker-month'>" + monthNames[drawMonth] + "</span>";
+ } else {
+ inMinYear = (minDate && minDate.getFullYear() === drawYear);
+ inMaxYear = (maxDate && maxDate.getFullYear() === drawYear);
+ monthHtml += "<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>";
+ for ( month = 0; month < 12; month++) {
+ if ((!inMinYear || month >= minDate.getMonth()) && (!inMaxYear || month <= maxDate.getMonth())) {
+ monthHtml += "<option value='" + month + "'" +
+ (month === drawMonth ? " selected='selected'" : "") +
+ ">" + monthNamesShort[month] + "</option>";
+ }
+ }
+ monthHtml += "</select>";
+ }
+
+ if (!showMonthAfterYear) {
+ html += monthHtml + (secondary || !(changeMonth && changeYear) ? "&#xa0;" : "");
+ }
+
// year selection
if ( !inst.yearshtml ) {
- inst.yearshtml = '';
- if (secondary || !changeYear)
- html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
- else {
+ inst.yearshtml = "";
+ if (secondary || !changeYear) {
+ html += "<span class='ui-datepicker-year'>" + drawYear + "</span>";
+ } else {
// determine range of years to display
- var years = this._get(inst, 'yearRange').split(':');
- var thisYear = new Date().getFullYear();
- var determineYear = function(value) {
- var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
- (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
+ years = this._get(inst, "yearRange").split(":");
+ thisYear = new Date().getFullYear();
+ determineYear = function(value) {
+ var year = (value.match(/c[+\-].*/) ? drawYear + parseInt(value.substring(1), 10) :
+ (value.match(/[+\-].*/) ? thisYear + parseInt(value, 10) :
parseInt(value, 10)));
return (isNaN(year) ? thisYear : year);
};
- var year = determineYear(years[0]);
- var endYear = Math.max(year, determineYear(years[1] || ''));
+ year = determineYear(years[0]);
+ endYear = Math.max(year, determineYear(years[1] || ""));
year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
- inst.yearshtml += '<select class="ui-datepicker-year" data-handler="selectYear" data-event="change">';
+ inst.yearshtml += "<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>";
for (; year <= endYear; year++) {
- inst.yearshtml += '<option value="' + year + '"' +
- (year == drawYear ? ' selected="selected"' : '') +
- '>' + year + '</option>';
+ inst.yearshtml += "<option value='" + year + "'" +
+ (year === drawYear ? " selected='selected'" : "") +
+ ">" + year + "</option>";
}
- inst.yearshtml += '</select>';
+ inst.yearshtml += "</select>";
html += inst.yearshtml;
inst.yearshtml = null;
}
}
- html += this._get(inst, 'yearSuffix');
- if (showMonthAfterYear)
- html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;
- html += '</div>'; // Close datepicker_header
+
+ html += this._get(inst, "yearSuffix");
+ if (showMonthAfterYear) {
+ html += (secondary || !(changeMonth && changeYear) ? "&#xa0;" : "") + monthHtml;
+ }
+ html += "</div>"; // Close datepicker_header
return html;
},
/* Adjust one of the date sub-fields. */
_adjustInstDate: function(inst, offset, period) {
- var year = inst.drawYear + (period == 'Y' ? offset : 0);
- var month = inst.drawMonth + (period == 'M' ? offset : 0);
- var day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) +
- (period == 'D' ? offset : 0);
- var date = this._restrictMinMax(inst,
- this._daylightSavingAdjust(new Date(year, month, day)));
+ var year = inst.drawYear + (period === "Y" ? offset : 0),
+ month = inst.drawMonth + (period === "M" ? offset : 0),
+ day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) + (period === "D" ? offset : 0),
+ date = this._restrictMinMax(inst, this._daylightSavingAdjust(new Date(year, month, day)));
+
inst.selectedDay = date.getDate();
inst.drawMonth = inst.selectedMonth = date.getMonth();
inst.drawYear = inst.selectedYear = date.getFullYear();
- if (period == 'M' || period == 'Y')
+ if (period === "M" || period === "Y") {
this._notifyChange(inst);
+ }
},
/* Ensure a date is within any min/max bounds. */
_restrictMinMax: function(inst, date) {
- var minDate = this._getMinMaxDate(inst, 'min');
- var maxDate = this._getMinMaxDate(inst, 'max');
- var newDate = (minDate && date < minDate ? minDate : date);
- newDate = (maxDate && newDate > maxDate ? maxDate : newDate);
- return newDate;
+ var minDate = this._getMinMaxDate(inst, "min"),
+ maxDate = this._getMinMaxDate(inst, "max"),
+ newDate = (minDate && date < minDate ? minDate : date);
+ return (maxDate && newDate > maxDate ? maxDate : newDate);
},
/* Notify change of month/year. */
_notifyChange: function(inst) {
- var onChange = this._get(inst, 'onChangeMonthYear');
- if (onChange)
+ var onChange = this._get(inst, "onChangeMonthYear");
+ if (onChange) {
onChange.apply((inst.input ? inst.input[0] : null),
[inst.selectedYear, inst.selectedMonth + 1, inst]);
+ }
},
/* Determine the number of months to show. */
_getNumberOfMonths: function(inst) {
- var numMonths = this._get(inst, 'numberOfMonths');
- return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
+ var numMonths = this._get(inst, "numberOfMonths");
+ return (numMonths == null ? [1, 1] : (typeof numMonths === "number" ? [1, numMonths] : numMonths));
},
/* Determine the current maximum date - ensure no time components are set. */
_getMinMaxDate: function(inst, minMax) {
- return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
+ return this._determineDate(inst, this._get(inst, minMax + "Date"), null);
},
/* Find the number of days in a given month. */
@@ -8939,30 +9469,51 @@ $.extend(Datepicker.prototype, {
/* Determines if we should allow a "next/prev" month display change. */
_canAdjustMonth: function(inst, offset, curYear, curMonth) {
- var numMonths = this._getNumberOfMonths(inst);
- var date = this._daylightSavingAdjust(new Date(curYear,
+ var numMonths = this._getNumberOfMonths(inst),
+ date = this._daylightSavingAdjust(new Date(curYear,
curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
- if (offset < 0)
+
+ if (offset < 0) {
date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
+ }
return this._isInRange(inst, date);
},
/* Is the given date in the accepted range? */
_isInRange: function(inst, date) {
- var minDate = this._getMinMaxDate(inst, 'min');
- var maxDate = this._getMinMaxDate(inst, 'max');
+ var yearSplit, currentYear,
+ minDate = this._getMinMaxDate(inst, "min"),
+ maxDate = this._getMinMaxDate(inst, "max"),
+ minYear = null,
+ maxYear = null,
+ years = this._get(inst, "yearRange");
+ if (years){
+ yearSplit = years.split(":");
+ currentYear = new Date().getFullYear();
+ minYear = parseInt(yearSplit[0], 10);
+ maxYear = parseInt(yearSplit[1], 10);
+ if ( yearSplit[0].match(/[+\-].*/) ) {
+ minYear += currentYear;
+ }
+ if ( yearSplit[1].match(/[+\-].*/) ) {
+ maxYear += currentYear;
+ }
+ }
+
return ((!minDate || date.getTime() >= minDate.getTime()) &&
- (!maxDate || date.getTime() <= maxDate.getTime()));
+ (!maxDate || date.getTime() <= maxDate.getTime()) &&
+ (!minYear || date.getFullYear() >= minYear) &&
+ (!maxYear || date.getFullYear() <= maxYear));
},
/* Provide the configuration settings for formatting/parsing. */
_getFormatConfig: function(inst) {
- var shortYearCutoff = this._get(inst, 'shortYearCutoff');
- shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
+ var shortYearCutoff = this._get(inst, "shortYearCutoff");
+ shortYearCutoff = (typeof shortYearCutoff !== "string" ? shortYearCutoff :
new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
return {shortYearCutoff: shortYearCutoff,
- dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
- monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')};
+ dayNamesShort: this._get(inst, "dayNamesShort"), dayNames: this._get(inst, "dayNames"),
+ monthNamesShort: this._get(inst, "monthNamesShort"), monthNames: this._get(inst, "monthNames")};
},
/* Format the given date for display. */
@@ -8972,10 +9523,10 @@ $.extend(Datepicker.prototype, {
inst.currentMonth = inst.selectedMonth;
inst.currentYear = inst.selectedYear;
}
- var date = (day ? (typeof day == 'object' ? day :
+ var date = (day ? (typeof day === "object" ? day :
this._daylightSavingAdjust(new Date(year, month, day))) :
this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
- return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst));
+ return this.formatDate(this._get(inst, "dateFormat"), date, this._getFormatConfig(inst));
}
});
@@ -8985,18 +9536,26 @@ $.extend(Datepicker.prototype, {
* Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
*/
function bindHover(dpDiv) {
- var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a';
- return dpDiv.delegate(selector, 'mouseout', function() {
- $(this).removeClass('ui-state-hover');
- if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
- if (this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
+ var selector = "button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a";
+ return dpDiv.delegate(selector, "mouseout", function() {
+ $(this).removeClass("ui-state-hover");
+ if (this.className.indexOf("ui-datepicker-prev") !== -1) {
+ $(this).removeClass("ui-datepicker-prev-hover");
+ }
+ if (this.className.indexOf("ui-datepicker-next") !== -1) {
+ $(this).removeClass("ui-datepicker-next-hover");
+ }
})
- .delegate(selector, 'mouseover', function(){
+ .delegate(selector, "mouseover", function(){
if (!$.datepicker._isDisabledDatepicker( instActive.inline ? dpDiv.parent()[0] : instActive.input[0])) {
- $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
- $(this).addClass('ui-state-hover');
- if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
- if (this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
+ $(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");
+ $(this).addClass("ui-state-hover");
+ if (this.className.indexOf("ui-datepicker-prev") !== -1) {
+ $(this).addClass("ui-datepicker-prev-hover");
+ }
+ if (this.className.indexOf("ui-datepicker-next") !== -1) {
+ $(this).addClass("ui-datepicker-next-hover");
+ }
}
});
}
@@ -9004,15 +9563,17 @@ function bindHover(dpDiv) {
/* jQuery extend now ignores nulls! */
function extendRemove(target, props) {
$.extend(target, props);
- for (var name in props)
- if (props[name] == null || props[name] == undefined)
+ for (var name in props) {
+ if (props[name] == null) {
target[name] = props[name];
+ }
+ }
return target;
-};
+}
/* Invoke the datepicker functionality.
@param options string - a command, optionally followed by additional parameters or
- Object - settings for attaching new datepicker functionality
+ Object - settings for attaching new datepicker functionality
@return jQuery object */
$.fn.datepicker = function(options){
@@ -9023,21 +9584,27 @@ $.fn.datepicker = function(options){
/* Initialise the date picker. */
if (!$.datepicker.initialized) {
- $(document).mousedown($.datepicker._checkExternalClick).
- find(document.body).append($.datepicker.dpDiv);
+ $(document).mousedown($.datepicker._checkExternalClick);
$.datepicker.initialized = true;
}
+ /* Append datepicker main container to body if not exist. */
+ if ($("#"+$.datepicker._mainDivId).length === 0) {
+ $("body").append($.datepicker.dpDiv);
+ }
+
var otherArgs = Array.prototype.slice.call(arguments, 1);
- if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget'))
- return $.datepicker['_' + options + 'Datepicker'].
+ if (typeof options === "string" && (options === "isDisabled" || options === "getDate" || options === "widget")) {
+ return $.datepicker["_" + options + "Datepicker"].
apply($.datepicker, [this[0]].concat(otherArgs));
- if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
- return $.datepicker['_' + options + 'Datepicker'].
+ }
+ if (options === "option" && arguments.length === 2 && typeof arguments[1] === "string") {
+ return $.datepicker["_" + options + "Datepicker"].
apply($.datepicker, [this[0]].concat(otherArgs));
+ }
return this.each(function() {
- typeof options == 'string' ?
- $.datepicker['_' + options + 'Datepicker'].
+ typeof options === "string" ?
+ $.datepicker["_" + options + "Datepicker"].
apply($.datepicker, [this].concat(otherArgs)) :
$.datepicker._attachDatepicker(this, options);
});
@@ -9046,18 +9613,17 @@ $.fn.datepicker = function(options){
$.datepicker = new Datepicker(); // singleton instance
$.datepicker.initialized = false;
$.datepicker.uuid = new Date().getTime();
-$.datepicker.version = "1.9.2";
+$.datepicker.version = "1.10.2";
// Workaround for #4055
// Add another global to avoid noConflict issues with inline event handlers
-window['DP_jQuery_' + dpuuid] = $;
+window["DP_jQuery_" + dpuuid] = $;
})(jQuery);
(function( $, undefined ) {
-var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
- sizeRelatedOptions = {
+var sizeRelatedOptions = {
buttons: true,
height: true,
maxHeight: true,
@@ -9073,19 +9639,20 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
minWidth: true
};
-$.widget("ui.dialog", {
- version: "1.9.2",
+$.widget( "ui.dialog", {
+ version: "1.10.2",
options: {
+ appendTo: "body",
autoOpen: true,
- buttons: {},
+ buttons: [],
closeOnEscape: true,
closeText: "close",
dialogClass: "",
draggable: true,
hide: null,
height: "auto",
- maxHeight: false,
- maxWidth: false,
+ maxHeight: null,
+ maxWidth: null,
minHeight: 150,
minWidth: 150,
modal: false,
@@ -9094,7 +9661,7 @@ $.widget("ui.dialog", {
at: "center",
of: window,
collision: "fit",
- // ensure that the titlebar is never outside the document
+ // Ensure the titlebar is always visible
using: function( pos ) {
var topOffset = $( this ).css( pos ).offset().top;
if ( topOffset < 0 ) {
@@ -9104,137 +9671,56 @@ $.widget("ui.dialog", {
},
resizable: true,
show: null,
- stack: true,
- title: "",
+ title: null,
width: 300,
- zIndex: 1000
+
+ // callbacks
+ beforeClose: null,
+ close: null,
+ drag: null,
+ dragStart: null,
+ dragStop: null,
+ focus: null,
+ open: null,
+ resize: null,
+ resizeStart: null,
+ resizeStop: null
},
_create: function() {
- this.originalTitle = this.element.attr( "title" );
- // #5742 - .attr() might return a DOMElement
- if ( typeof this.originalTitle !== "string" ) {
- this.originalTitle = "";
- }
- this.oldPosition = {
+ this.originalCss = {
+ display: this.element[0].style.display,
+ width: this.element[0].style.width,
+ minHeight: this.element[0].style.minHeight,
+ maxHeight: this.element[0].style.maxHeight,
+ height: this.element[0].style.height
+ };
+ this.originalPosition = {
parent: this.element.parent(),
index: this.element.parent().children().index( this.element )
};
+ this.originalTitle = this.element.attr("title");
this.options.title = this.options.title || this.originalTitle;
- var that = this,
- options = this.options,
-
- title = options.title || "&#160;",
- uiDialog,
- uiDialogTitlebar,
- uiDialogTitlebarClose,
- uiDialogTitle,
- uiDialogButtonPane;
-
- uiDialog = ( this.uiDialog = $( "<div>" ) )
- .addClass( uiDialogClasses + options.dialogClass )
- .css({
- display: "none",
- outline: 0, // TODO: move to stylesheet
- zIndex: options.zIndex
- })
- // setting tabIndex makes the div focusable
- .attr( "tabIndex", -1)
- .keydown(function( event ) {
- if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
- event.keyCode === $.ui.keyCode.ESCAPE ) {
- that.close( event );
- event.preventDefault();
- }
- })
- .mousedown(function( event ) {
- that.moveToTop( false, event );
- })
- .appendTo( "body" );
-
- this.element
- .show()
- .removeAttr( "title" )
- .addClass( "ui-dialog-content ui-widget-content" )
- .appendTo( uiDialog );
-
- uiDialogTitlebar = ( this.uiDialogTitlebar = $( "<div>" ) )
- .addClass( "ui-dialog-titlebar ui-widget-header " +
- "ui-corner-all ui-helper-clearfix" )
- .bind( "mousedown", function() {
- // Dialog isn't getting focus when dragging (#8063)
- uiDialog.focus();
- })
- .prependTo( uiDialog );
-
- uiDialogTitlebarClose = $( "<a href='#'></a>" )
- .addClass( "ui-dialog-titlebar-close ui-corner-all" )
- .attr( "role", "button" )
- .click(function( event ) {
- event.preventDefault();
- that.close( event );
- })
- .appendTo( uiDialogTitlebar );
-
- ( this.uiDialogTitlebarCloseText = $( "<span>" ) )
- .addClass( "ui-icon ui-icon-closethick" )
- .text( options.closeText )
- .appendTo( uiDialogTitlebarClose );
-
- uiDialogTitle = $( "<span>" )
- .uniqueId()
- .addClass( "ui-dialog-title" )
- .html( title )
- .prependTo( uiDialogTitlebar );
-
- uiDialogButtonPane = ( this.uiDialogButtonPane = $( "<div>" ) )
- .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" );
- ( this.uiButtonSet = $( "<div>" ) )
- .addClass( "ui-dialog-buttonset" )
- .appendTo( uiDialogButtonPane );
+ this._createWrapper();
- uiDialog.attr({
- role: "dialog",
- "aria-labelledby": uiDialogTitle.attr( "id" )
- });
+ this.element
+ .show()
+ .removeAttr("title")
+ .addClass("ui-dialog-content ui-widget-content")
+ .appendTo( this.uiDialog );
- uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();
- this._hoverable( uiDialogTitlebarClose );
- this._focusable( uiDialogTitlebarClose );
+ this._createTitlebar();
+ this._createButtonPane();
- if ( options.draggable && $.fn.draggable ) {
+ if ( this.options.draggable && $.fn.draggable ) {
this._makeDraggable();
}
- if ( options.resizable && $.fn.resizable ) {
+ if ( this.options.resizable && $.fn.resizable ) {
this._makeResizable();
}
- this._createButtons( options.buttons );
this._isOpen = false;
-
- if ( $.fn.bgiframe ) {
- uiDialog.bgiframe();
- }
-
- // prevent tabbing out of modal dialogs
- this._on( uiDialog, { keydown: function( event ) {
- if ( !options.modal || event.keyCode !== $.ui.keyCode.TAB ) {
- return;
- }
-
- var tabbables = $( ":tabbable", uiDialog ),
- first = tabbables.filter( ":first" ),
- last = tabbables.filter( ":last" );
-
- if ( event.target === last[0] && !event.shiftKey ) {
- first.focus( 1 );
- return false;
- } else if ( event.target === first[0] && event.shiftKey ) {
- last.focus( 1 );
- return false;
- }
- }});
},
_init: function() {
@@ -9243,30 +9729,39 @@ $.widget("ui.dialog", {
}
},
+ _appendTo: function() {
+ var element = this.options.appendTo;
+ if ( element && (element.jquery || element.nodeType) ) {
+ return $( element );
+ }
+ return this.document.find( element || "body" ).eq( 0 );
+ },
+
_destroy: function() {
var next,
- oldPosition = this.oldPosition;
+ originalPosition = this.originalPosition;
+
+ this._destroyOverlay();
- if ( this.overlay ) {
- this.overlay.destroy();
- }
- this.uiDialog.hide();
this.element
- .removeClass( "ui-dialog-content ui-widget-content" )
- .hide()
- .appendTo( "body" );
- this.uiDialog.remove();
+ .removeUniqueId()
+ .removeClass("ui-dialog-content ui-widget-content")
+ .css( this.originalCss )
+ // Without detaching first, the following becomes really slow
+ .detach();
+
+ this.uiDialog.stop( true, true ).remove();
if ( this.originalTitle ) {
this.element.attr( "title", this.originalTitle );
}
- next = oldPosition.parent.children().eq( oldPosition.index );
+ next = originalPosition.parent.children().eq( originalPosition.index );
// Don't try to place the dialog next to itself (#8613)
- if ( next.length && next[ 0 ] !== this.element[ 0 ] ) {
+ if ( next.length && next[0] !== this.element[0] ) {
next.before( this.element );
} else {
- oldPosition.parent.append( this.element );
+ originalPosition.parent.append( this.element );
}
},
@@ -9274,160 +9769,266 @@ $.widget("ui.dialog", {
return this.uiDialog;
},
- close: function( event ) {
- var that = this,
- maxZ, thisZ;
+ disable: $.noop,
+ enable: $.noop,
- if ( !this._isOpen ) {
- return;
- }
+ close: function( event ) {
+ var that = this;
- if ( false === this._trigger( "beforeClose", event ) ) {
+ if ( !this._isOpen || this._trigger( "beforeClose", event ) === false ) {
return;
}
this._isOpen = false;
+ this._destroyOverlay();
- if ( this.overlay ) {
- this.overlay.destroy();
- }
-
- if ( this.options.hide ) {
- this._hide( this.uiDialog, this.options.hide, function() {
- that._trigger( "close", event );
- });
- } else {
- this.uiDialog.hide();
- this._trigger( "close", event );
+ if ( !this.opener.filter(":focusable").focus().length ) {
+ // Hiding a focused element doesn't trigger blur in WebKit
+ // so in case we have nothing to focus on, explicitly blur the active element
+ // https://bugs.webkit.org/show_bug.cgi?id=47182
+ $( this.document[0].activeElement ).blur();
}
- $.ui.dialog.overlay.resize();
-
- // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
- if ( this.options.modal ) {
- maxZ = 0;
- $( ".ui-dialog" ).each(function() {
- if ( this !== that.uiDialog[0] ) {
- thisZ = $( this ).css( "z-index" );
- if ( !isNaN( thisZ ) ) {
- maxZ = Math.max( maxZ, thisZ );
- }
- }
- });
- $.ui.dialog.maxZ = maxZ;
- }
-
- return this;
+ this._hide( this.uiDialog, this.options.hide, function() {
+ that._trigger( "close", event );
+ });
},
isOpen: function() {
return this._isOpen;
},
- // the force parameter allows us to move modal dialogs to their correct
- // position on open
- moveToTop: function( force, event ) {
- var options = this.options,
- saveScroll;
-
- if ( ( options.modal && !force ) ||
- ( !options.stack && !options.modal ) ) {
- return this._trigger( "focus", event );
- }
+ moveToTop: function() {
+ this._moveToTop();
+ },
- if ( options.zIndex > $.ui.dialog.maxZ ) {
- $.ui.dialog.maxZ = options.zIndex;
+ _moveToTop: function( event, silent ) {
+ var moved = !!this.uiDialog.nextAll(":visible").insertBefore( this.uiDialog ).length;
+ if ( moved && !silent ) {
+ this._trigger( "focus", event );
}
- if ( this.overlay ) {
- $.ui.dialog.maxZ += 1;
- $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
- this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ );
- }
-
- // Save and then restore scroll
- // Opera 9.5+ resets when parent z-index is changed.
- // http://bugs.jqueryui.com/ticket/3193
- saveScroll = {
- scrollTop: this.element.scrollTop(),
- scrollLeft: this.element.scrollLeft()
- };
- $.ui.dialog.maxZ += 1;
- this.uiDialog.css( "z-index", $.ui.dialog.maxZ );
- this.element.attr( saveScroll );
- this._trigger( "focus", event );
-
- return this;
+ return moved;
},
open: function() {
+ var that = this;
if ( this._isOpen ) {
+ if ( this._moveToTop() ) {
+ this._focusTabbable();
+ }
return;
}
- var hasFocus,
- options = this.options,
- uiDialog = this.uiDialog;
+ this._isOpen = true;
+ this.opener = $( this.document[0].activeElement );
this._size();
- this._position( options.position );
- uiDialog.show( options.show );
- this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null;
- this.moveToTop( true );
-
- // set focus to the first tabbable element in the content area or the first button
- // if there are no tabbable elements, set focus on the dialog itself
- hasFocus = this.element.find( ":tabbable" );
+ this._position();
+ this._createOverlay();
+ this._moveToTop( null, true );
+ this._show( this.uiDialog, this.options.show, function() {
+ that._focusTabbable();
+ that._trigger("focus");
+ });
+
+ this._trigger("open");
+ },
+
+ _focusTabbable: function() {
+ // Set focus to the first match:
+ // 1. First element inside the dialog matching [autofocus]
+ // 2. Tabbable element inside the content element
+ // 3. Tabbable element inside the buttonpane
+ // 4. The close button
+ // 5. The dialog itself
+ var hasFocus = this.element.find("[autofocus]");
if ( !hasFocus.length ) {
- hasFocus = this.uiDialogButtonPane.find( ":tabbable" );
- if ( !hasFocus.length ) {
- hasFocus = uiDialog;
- }
+ hasFocus = this.element.find(":tabbable");
+ }
+ if ( !hasFocus.length ) {
+ hasFocus = this.uiDialogButtonPane.find(":tabbable");
+ }
+ if ( !hasFocus.length ) {
+ hasFocus = this.uiDialogTitlebarClose.filter(":tabbable");
+ }
+ if ( !hasFocus.length ) {
+ hasFocus = this.uiDialog;
}
hasFocus.eq( 0 ).focus();
+ },
- this._isOpen = true;
- this._trigger( "open" );
+ _keepFocus: function( event ) {
+ function checkFocus() {
+ var activeElement = this.document[0].activeElement,
+ isActive = this.uiDialog[0] === activeElement ||
+ $.contains( this.uiDialog[0], activeElement );
+ if ( !isActive ) {
+ this._focusTabbable();
+ }
+ }
+ event.preventDefault();
+ checkFocus.call( this );
+ // support: IE
+ // IE <= 8 doesn't prevent moving focus even with event.preventDefault()
+ // so we check again later
+ this._delay( checkFocus );
+ },
- return this;
+ _createWrapper: function() {
+ this.uiDialog = $("<div>")
+ .addClass( "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front " +
+ this.options.dialogClass )
+ .hide()
+ .attr({
+ // Setting tabIndex makes the div focusable
+ tabIndex: -1,
+ role: "dialog"
+ })
+ .appendTo( this._appendTo() );
+
+ this._on( this.uiDialog, {
+ keydown: function( event ) {
+ if ( this.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
+ event.keyCode === $.ui.keyCode.ESCAPE ) {
+ event.preventDefault();
+ this.close( event );
+ return;
+ }
+
+ // prevent tabbing out of dialogs
+ if ( event.keyCode !== $.ui.keyCode.TAB ) {
+ return;
+ }
+ var tabbables = this.uiDialog.find(":tabbable"),
+ first = tabbables.filter(":first"),
+ last = tabbables.filter(":last");
+
+ if ( ( event.target === last[0] || event.target === this.uiDialog[0] ) && !event.shiftKey ) {
+ first.focus( 1 );
+ event.preventDefault();
+ } else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) {
+ last.focus( 1 );
+ event.preventDefault();
+ }
+ },
+ mousedown: function( event ) {
+ if ( this._moveToTop( event ) ) {
+ this._focusTabbable();
+ }
+ }
+ });
+
+ // We assume that any existing aria-describedby attribute means
+ // that the dialog content is marked up properly
+ // otherwise we brute force the content as the description
+ if ( !this.element.find("[aria-describedby]").length ) {
+ this.uiDialog.attr({
+ "aria-describedby": this.element.uniqueId().attr("id")
+ });
+ }
+ },
+
+ _createTitlebar: function() {
+ var uiDialogTitle;
+
+ this.uiDialogTitlebar = $("<div>")
+ .addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix")
+ .prependTo( this.uiDialog );
+ this._on( this.uiDialogTitlebar, {
+ mousedown: function( event ) {
+ // Don't prevent click on close button (#8838)
+ // Focusing a dialog that is partially scrolled out of view
+ // causes the browser to scroll it into view, preventing the click event
+ if ( !$( event.target ).closest(".ui-dialog-titlebar-close") ) {
+ // Dialog isn't getting focus when dragging (#8063)
+ this.uiDialog.focus();
+ }
+ }
+ });
+
+ this.uiDialogTitlebarClose = $("<button></button>")
+ .button({
+ label: this.options.closeText,
+ icons: {
+ primary: "ui-icon-closethick"
+ },
+ text: false
+ })
+ .addClass("ui-dialog-titlebar-close")
+ .appendTo( this.uiDialogTitlebar );
+ this._on( this.uiDialogTitlebarClose, {
+ click: function( event ) {
+ event.preventDefault();
+ this.close( event );
+ }
+ });
+
+ uiDialogTitle = $("<span>")
+ .uniqueId()
+ .addClass("ui-dialog-title")
+ .prependTo( this.uiDialogTitlebar );
+ this._title( uiDialogTitle );
+
+ this.uiDialog.attr({
+ "aria-labelledby": uiDialogTitle.attr("id")
+ });
+ },
+
+ _title: function( title ) {
+ if ( !this.options.title ) {
+ title.html("&#160;");
+ }
+ title.text( this.options.title );
},
- _createButtons: function( buttons ) {
+ _createButtonPane: function() {
+ this.uiDialogButtonPane = $("<div>")
+ .addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix");
+
+ this.uiButtonSet = $("<div>")
+ .addClass("ui-dialog-buttonset")
+ .appendTo( this.uiDialogButtonPane );
+
+ this._createButtons();
+ },
+
+ _createButtons: function() {
var that = this,
- hasButtons = false;
+ buttons = this.options.buttons;
// if we already have a button pane, remove it
this.uiDialogButtonPane.remove();
this.uiButtonSet.empty();
- if ( typeof buttons === "object" && buttons !== null ) {
- $.each( buttons, function() {
- return !(hasButtons = true);
- });
- }
- if ( hasButtons ) {
- $.each( buttons, function( name, props ) {
- var button, click;
- props = $.isFunction( props ) ?
- { click: props, text: name } :
- props;
- // Default to a non-submitting button
- props = $.extend( { type: "button" }, props );
- // Change the context for the click callback to be the main element
- click = props.click;
- props.click = function() {
- click.apply( that.element[0], arguments );
- };
- button = $( "<button></button>", props )
- .appendTo( that.uiButtonSet );
- if ( $.fn.button ) {
- button.button();
- }
- });
- this.uiDialog.addClass( "ui-dialog-buttons" );
- this.uiDialogButtonPane.appendTo( this.uiDialog );
- } else {
- this.uiDialog.removeClass( "ui-dialog-buttons" );
+ if ( $.isEmptyObject( buttons ) || ($.isArray( buttons ) && !buttons.length) ) {
+ this.uiDialog.removeClass("ui-dialog-buttons");
+ return;
}
+
+ $.each( buttons, function( name, props ) {
+ var click, buttonOptions;
+ props = $.isFunction( props ) ?
+ { click: props, text: name } :
+ props;
+ // Default to a non-submitting button
+ props = $.extend( { type: "button" }, props );
+ // Change the context for the click callback to be the main element
+ click = props.click;
+ props.click = function() {
+ click.apply( that.element[0], arguments );
+ };
+ buttonOptions = {
+ icons: props.icons,
+ text: props.showText
+ };
+ delete props.icons;
+ delete props.showText;
+ $( "<button></button>", props )
+ .button( buttonOptions )
+ .appendTo( that.uiButtonSet );
+ });
+ this.uiDialog.addClass("ui-dialog-buttons");
+ this.uiDialogButtonPane.appendTo( this.uiDialog );
},
_makeDraggable: function() {
@@ -9446,8 +10047,8 @@ $.widget("ui.dialog", {
handle: ".ui-dialog-titlebar",
containment: "document",
start: function( event, ui ) {
- $( this )
- .addClass( "ui-dialog-dragging" );
+ $( this ).addClass("ui-dialog-dragging");
+ that._blockFrames();
that._trigger( "dragStart", event, filteredUi( ui ) );
},
drag: function( event, ui ) {
@@ -9458,22 +10059,21 @@ $.widget("ui.dialog", {
ui.position.left - that.document.scrollLeft(),
ui.position.top - that.document.scrollTop()
];
- $( this )
- .removeClass( "ui-dialog-dragging" );
+ $( this ).removeClass("ui-dialog-dragging");
+ that._unblockFrames();
that._trigger( "dragStop", event, filteredUi( ui ) );
- $.ui.dialog.overlay.resize();
}
});
},
- _makeResizable: function( handles ) {
- handles = (handles === undefined ? this.options.resizable : handles);
+ _makeResizable: function() {
var that = this,
options = this.options,
+ handles = options.resizable,
// .ui-resizable has position: relative defined in the stylesheet
// but dialogs have to use absolute or fixed positioning
- position = this.uiDialog.css( "position" ),
- resizeHandles = typeof handles === 'string' ?
+ position = this.uiDialog.css("position"),
+ resizeHandles = typeof handles === "string" ?
handles :
"n,e,s,w,se,sw,ne,nw";
@@ -9496,76 +10096,39 @@ $.widget("ui.dialog", {
minHeight: this._minHeight(),
handles: resizeHandles,
start: function( event, ui ) {
- $( this ).addClass( "ui-dialog-resizing" );
+ $( this ).addClass("ui-dialog-resizing");
+ that._blockFrames();
that._trigger( "resizeStart", event, filteredUi( ui ) );
},
resize: function( event, ui ) {
that._trigger( "resize", event, filteredUi( ui ) );
},
stop: function( event, ui ) {
- $( this ).removeClass( "ui-dialog-resizing" );
options.height = $( this ).height();
options.width = $( this ).width();
+ $( this ).removeClass("ui-dialog-resizing");
+ that._unblockFrames();
that._trigger( "resizeStop", event, filteredUi( ui ) );
- $.ui.dialog.overlay.resize();
}
})
- .css( "position", position )
- .find( ".ui-resizable-se" )
- .addClass( "ui-icon ui-icon-grip-diagonal-se" );
+ .css( "position", position );
},
_minHeight: function() {
var options = this.options;
- if ( options.height === "auto" ) {
- return options.minHeight;
- } else {
- return Math.min( options.minHeight, options.height );
- }
+ return options.height === "auto" ?
+ options.minHeight :
+ Math.min( options.minHeight, options.height );
},
- _position: function( position ) {
- var myAt = [],
- offset = [ 0, 0 ],
- isVisible;
-
- if ( position ) {
- // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
- // if (typeof position == 'string' || $.isArray(position)) {
- // myAt = $.isArray(position) ? position : position.split(' ');
-
- if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
- myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ];
- if ( myAt.length === 1 ) {
- myAt[ 1 ] = myAt[ 0 ];
- }
-
- $.each( [ "left", "top" ], function( i, offsetPosition ) {
- if ( +myAt[ i ] === myAt[ i ] ) {
- offset[ i ] = myAt[ i ];
- myAt[ i ] = offsetPosition;
- }
- });
-
- position = {
- my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
- myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
- at: myAt.join( " " )
- };
- }
-
- position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
- } else {
- position = $.ui.dialog.prototype.options.position;
- }
-
- // need to show the dialog to get the actual offset in the position plugin
- isVisible = this.uiDialog.is( ":visible" );
+ _position: function() {
+ // Need to show the dialog to get the actual offset in the position plugin
+ var isVisible = this.uiDialog.is(":visible");
if ( !isVisible ) {
this.uiDialog.show();
}
- this.uiDialog.position( position );
+ this.uiDialog.position( this.options.position );
if ( !isVisible ) {
this.uiDialog.hide();
}
@@ -9573,8 +10136,8 @@ $.widget("ui.dialog", {
_setOptions: function( options ) {
var that = this,
- resizableOptions = {},
- resize = false;
+ resize = false,
+ resizableOptions = {};
$.each( options, function( key, value ) {
that._setOption( key, value );
@@ -9589,88 +10152,94 @@ $.widget("ui.dialog", {
if ( resize ) {
this._size();
+ this._position();
}
- if ( this.uiDialog.is( ":data(resizable)" ) ) {
+ if ( this.uiDialog.is(":data(ui-resizable)") ) {
this.uiDialog.resizable( "option", resizableOptions );
}
},
_setOption: function( key, value ) {
+ /*jshint maxcomplexity:15*/
var isDraggable, isResizable,
uiDialog = this.uiDialog;
- switch ( key ) {
- case "buttons":
- this._createButtons( value );
- break;
- case "closeText":
- // ensure that we always pass a string
- this.uiDialogTitlebarCloseText.text( "" + value );
- break;
- case "dialogClass":
- uiDialog
- .removeClass( this.options.dialogClass )
- .addClass( uiDialogClasses + value );
- break;
- case "disabled":
- if ( value ) {
- uiDialog.addClass( "ui-dialog-disabled" );
- } else {
- uiDialog.removeClass( "ui-dialog-disabled" );
- }
- break;
- case "draggable":
- isDraggable = uiDialog.is( ":data(draggable)" );
- if ( isDraggable && !value ) {
- uiDialog.draggable( "destroy" );
- }
+ if ( key === "dialogClass" ) {
+ uiDialog
+ .removeClass( this.options.dialogClass )
+ .addClass( value );
+ }
- if ( !isDraggable && value ) {
- this._makeDraggable();
- }
- break;
- case "position":
- this._position( value );
- break;
- case "resizable":
- // currently resizable, becoming non-resizable
- isResizable = uiDialog.is( ":data(resizable)" );
- if ( isResizable && !value ) {
- uiDialog.resizable( "destroy" );
- }
+ if ( key === "disabled" ) {
+ return;
+ }
- // currently resizable, changing handles
- if ( isResizable && typeof value === "string" ) {
- uiDialog.resizable( "option", "handles", value );
- }
+ this._super( key, value );
- // currently non-resizable, becoming resizable
- if ( !isResizable && value !== false ) {
- this._makeResizable( value );
- }
- break;
- case "title":
- // convert whatever was passed in o a string, for html() to not throw up
- $( ".ui-dialog-title", this.uiDialogTitlebar )
- .html( "" + ( value || "&#160;" ) );
- break;
+ if ( key === "appendTo" ) {
+ this.uiDialog.appendTo( this._appendTo() );
}
- this._super( key, value );
+ if ( key === "buttons" ) {
+ this._createButtons();
+ }
+
+ if ( key === "closeText" ) {
+ this.uiDialogTitlebarClose.button({
+ // Ensure that we always pass a string
+ label: "" + value
+ });
+ }
+
+ if ( key === "draggable" ) {
+ isDraggable = uiDialog.is(":data(ui-draggable)");
+ if ( isDraggable && !value ) {
+ uiDialog.draggable("destroy");
+ }
+
+ if ( !isDraggable && value ) {
+ this._makeDraggable();
+ }
+ }
+
+ if ( key === "position" ) {
+ this._position();
+ }
+
+ if ( key === "resizable" ) {
+ // currently resizable, becoming non-resizable
+ isResizable = uiDialog.is(":data(ui-resizable)");
+ if ( isResizable && !value ) {
+ uiDialog.resizable("destroy");
+ }
+
+ // currently resizable, changing handles
+ if ( isResizable && typeof value === "string" ) {
+ uiDialog.resizable( "option", "handles", value );
+ }
+
+ // currently non-resizable, becoming resizable
+ if ( !isResizable && value !== false ) {
+ this._makeResizable();
+ }
+ }
+
+ if ( key === "title" ) {
+ this._title( this.uiDialogTitlebar.find(".ui-dialog-title") );
+ }
},
_size: function() {
- /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
- * divs will both have width and height set, so we need to reset them
- */
- var nonContentHeight, minContentHeight, autoHeight,
- options = this.options,
- isVisible = this.uiDialog.is( ":visible" );
+ // If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
+ // divs will both have width and height set, so we need to reset them
+ var nonContentHeight, minContentHeight, maxContentHeight,
+ options = this.options;
- // reset content sizing
+ // Reset content sizing
this.element.show().css({
width: "auto",
minHeight: 0,
+ maxHeight: "none",
height: 0
});
@@ -9686,211 +10255,159 @@ $.widget("ui.dialog", {
})
.outerHeight();
minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
+ maxContentHeight = typeof options.maxHeight === "number" ?
+ Math.max( 0, options.maxHeight - nonContentHeight ) :
+ "none";
if ( options.height === "auto" ) {
- // only needed for IE6 support
- if ( $.support.minHeight ) {
- this.element.css({
- minHeight: minContentHeight,
- height: "auto"
- });
- } else {
- this.uiDialog.show();
- autoHeight = this.element.css( "height", "auto" ).height();
- if ( !isVisible ) {
- this.uiDialog.hide();
- }
- this.element.height( Math.max( autoHeight, minContentHeight ) );
- }
+ this.element.css({
+ minHeight: minContentHeight,
+ maxHeight: maxContentHeight,
+ height: "auto"
+ });
} else {
- this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
+ this.element.height( Math.max( 0, options.height - nonContentHeight ) );
}
- if (this.uiDialog.is( ":data(resizable)" ) ) {
+ if (this.uiDialog.is(":data(ui-resizable)") ) {
this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
}
- }
-});
+ },
-$.extend($.ui.dialog, {
- uuid: 0,
- maxZ: 0,
+ _blockFrames: function() {
+ this.iframeBlocks = this.document.find( "iframe" ).map(function() {
+ var iframe = $( this );
- getTitleId: function($el) {
- var id = $el.attr( "id" );
- if ( !id ) {
- this.uuid += 1;
- id = this.uuid;
+ return $( "<div>" )
+ .css({
+ position: "absolute",
+ width: iframe.outerWidth(),
+ height: iframe.outerHeight()
+ })
+ .appendTo( iframe.parent() )
+ .offset( iframe.offset() )[0];
+ });
+ },
+
+ _unblockFrames: function() {
+ if ( this.iframeBlocks ) {
+ this.iframeBlocks.remove();
+ delete this.iframeBlocks;
}
- return "ui-dialog-title-" + id;
},
- overlay: function( dialog ) {
- this.$el = $.ui.dialog.overlay.create( dialog );
- }
-});
+ _allowInteraction: function( event ) {
+ if ( $( event.target ).closest(".ui-dialog").length ) {
+ return true;
+ }
+
+ // TODO: Remove hack when datepicker implements
+ // the .ui-front logic (#8989)
+ return !!$( event.target ).closest(".ui-datepicker").length;
+ },
+
+ _createOverlay: function() {
+ if ( !this.options.modal ) {
+ return;
+ }
-$.extend( $.ui.dialog.overlay, {
- instances: [],
- // reuse old instances due to IE memory leak with alpha transparency (see #5185)
- oldInstances: [],
- maxZ: 0,
- events: $.map(
- "focus,mousedown,mouseup,keydown,keypress,click".split( "," ),
- function( event ) {
- return event + ".dialog-overlay";
- }
- ).join( " " ),
- create: function( dialog ) {
- if ( this.instances.length === 0 ) {
- // prevent use of anchors and inputs
- // we use a setTimeout in case the overlay is created from an
- // event that we're going to be cancelling (see #2804)
- setTimeout(function() {
- // handle $(el).dialog().dialog('close') (see #4065)
- if ( $.ui.dialog.overlay.instances.length ) {
- $( document ).bind( $.ui.dialog.overlay.events, function( event ) {
- // stop events if the z-index of the target is < the z-index of the overlay
- // we cannot return true when we don't want to cancel the event (#3523)
- if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) {
- return false;
+ var that = this,
+ widgetFullName = this.widgetFullName;
+ if ( !$.ui.dialog.overlayInstances ) {
+ // Prevent use of anchors and inputs.
+ // We use a delay in case the overlay is created from an
+ // event that we're going to be cancelling. (#2804)
+ this._delay(function() {
+ // Handle .dialog().dialog("close") (#4065)
+ if ( $.ui.dialog.overlayInstances ) {
+ this.document.bind( "focusin.dialog", function( event ) {
+ if ( !that._allowInteraction( event ) ) {
+ event.preventDefault();
+ $(".ui-dialog:visible:last .ui-dialog-content")
+ .data( widgetFullName )._focusTabbable();
}
});
}
- }, 1 );
-
- // handle window resize
- $( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize );
+ });
}
- var $el = ( this.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay" ) );
-
- // allow closing by pressing the escape key
- $( document ).bind( "keydown.dialog-overlay", function( event ) {
- var instances = $.ui.dialog.overlay.instances;
- // only react to the event if we're the top overlay
- if ( instances.length !== 0 && instances[ instances.length - 1 ] === $el &&
- dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
- event.keyCode === $.ui.keyCode.ESCAPE ) {
-
- dialog.close( event );
- event.preventDefault();
- }
- });
-
- $el.appendTo( document.body ).css({
- width: this.width(),
- height: this.height()
+ this.overlay = $("<div>")
+ .addClass("ui-widget-overlay ui-front")
+ .appendTo( this._appendTo() );
+ this._on( this.overlay, {
+ mousedown: "_keepFocus"
});
+ $.ui.dialog.overlayInstances++;
+ },
- if ( $.fn.bgiframe ) {
- $el.bgiframe();
+ _destroyOverlay: function() {
+ if ( !this.options.modal ) {
+ return;
}
- this.instances.push( $el );
- return $el;
- },
-
- destroy: function( $el ) {
- var indexOf = $.inArray( $el, this.instances ),
- maxZ = 0;
+ if ( this.overlay ) {
+ $.ui.dialog.overlayInstances--;
- if ( indexOf !== -1 ) {
- this.oldInstances.push( this.instances.splice( indexOf, 1 )[ 0 ] );
+ if ( !$.ui.dialog.overlayInstances ) {
+ this.document.unbind( "focusin.dialog" );
+ }
+ this.overlay.remove();
+ this.overlay = null;
}
+ }
+});
- if ( this.instances.length === 0 ) {
- $( [ document, window ] ).unbind( ".dialog-overlay" );
- }
+$.ui.dialog.overlayInstances = 0;
- $el.height( 0 ).width( 0 ).remove();
+// DEPRECATED
+if ( $.uiBackCompat !== false ) {
+ // position option with array notation
+ // just override with old implementation
+ $.widget( "ui.dialog", $.ui.dialog, {
+ _position: function() {
+ var position = this.options.position,
+ myAt = [],
+ offset = [ 0, 0 ],
+ isVisible;
+
+ if ( position ) {
+ if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
+ myAt = position.split ? position.split(" ") : [ position[0], position[1] ];
+ if ( myAt.length === 1 ) {
+ myAt[1] = myAt[0];
+ }
- // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
- $.each( this.instances, function() {
- maxZ = Math.max( maxZ, this.css( "z-index" ) );
- });
- this.maxZ = maxZ;
- },
+ $.each( [ "left", "top" ], function( i, offsetPosition ) {
+ if ( +myAt[ i ] === myAt[ i ] ) {
+ offset[ i ] = myAt[ i ];
+ myAt[ i ] = offsetPosition;
+ }
+ });
- height: function() {
- var scrollHeight,
- offsetHeight;
- // handle IE
- if ( $.ui.ie ) {
- scrollHeight = Math.max(
- document.documentElement.scrollHeight,
- document.body.scrollHeight
- );
- offsetHeight = Math.max(
- document.documentElement.offsetHeight,
- document.body.offsetHeight
- );
+ position = {
+ my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
+ myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
+ at: myAt.join(" ")
+ };
+ }
- if ( scrollHeight < offsetHeight ) {
- return $( window ).height() + "px";
+ position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
} else {
- return scrollHeight + "px";
+ position = $.ui.dialog.prototype.options.position;
}
- // handle "good" browsers
- } else {
- return $( document ).height() + "px";
- }
- },
-
- width: function() {
- var scrollWidth,
- offsetWidth;
- // handle IE
- if ( $.ui.ie ) {
- scrollWidth = Math.max(
- document.documentElement.scrollWidth,
- document.body.scrollWidth
- );
- offsetWidth = Math.max(
- document.documentElement.offsetWidth,
- document.body.offsetWidth
- );
- if ( scrollWidth < offsetWidth ) {
- return $( window ).width() + "px";
- } else {
- return scrollWidth + "px";
+ // need to show the dialog to get the actual offset in the position plugin
+ isVisible = this.uiDialog.is(":visible");
+ if ( !isVisible ) {
+ this.uiDialog.show();
+ }
+ this.uiDialog.position( position );
+ if ( !isVisible ) {
+ this.uiDialog.hide();
}
- // handle "good" browsers
- } else {
- return $( document ).width() + "px";
}
- },
-
- resize: function() {
- /* If the dialog is draggable and the user drags it past the
- * right edge of the window, the document becomes wider so we
- * need to stretch the overlay. If the user then drags the
- * dialog back to the left, the document will become narrower,
- * so we need to shrink the overlay to the appropriate size.
- * This is handled by shrinking the overlay before setting it
- * to the full document size.
- */
- var $overlays = $( [] );
- $.each( $.ui.dialog.overlay.instances, function() {
- $overlays = $overlays.add( this );
- });
-
- $overlays.css({
- width: 0,
- height: 0
- }).css({
- width: $.ui.dialog.overlay.width(),
- height: $.ui.dialog.overlay.height()
- });
- }
-});
-
-$.extend( $.ui.dialog.overlay.prototype, {
- destroy: function() {
- $.ui.dialog.overlay.destroy( this.$el );
- }
-});
+ });
+}
}( jQuery ) );
@@ -10866,7 +11383,7 @@ $.effects.effect.transfer = function( o, done ) {
width: target.innerWidth()
},
startPosition = elem.offset(),
- transfer = $( '<div class="ui-effects-transfer"></div>' )
+ transfer = $( "<div class='ui-effects-transfer'></div>" )
.appendTo( document.body )
.addClass( o.className )
.css({
@@ -10886,10 +11403,8 @@ $.effects.effect.transfer = function( o, done ) {
(function( $, undefined ) {
-var mouseHandled = false;
-
$.widget( "ui.menu", {
- version: "1.9.2",
+ version: "1.10.2",
defaultElement: "<ul>",
delay: 300,
options: {
@@ -10911,6 +11426,9 @@ $.widget( "ui.menu", {
_create: function() {
this.activeMenu = this.element;
+ // flag used to prevent firing of the click handler
+ // as the event bubbles up through nested menus
+ this.mouseHandled = false;
this.element
.uniqueId()
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
@@ -10944,8 +11462,8 @@ $.widget( "ui.menu", {
},
"click .ui-menu-item:has(a)": function( event ) {
var target = $( event.target ).closest( ".ui-menu-item" );
- if ( !mouseHandled && target.not( ".ui-state-disabled" ).length ) {
- mouseHandled = true;
+ if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
+ this.mouseHandled = true;
this.select( event );
// Open submenu on click
@@ -11001,7 +11519,7 @@ $.widget( "ui.menu", {
}
// Reset the mouseHandled flag
- mouseHandled = false;
+ this.mouseHandled = false;
}
});
},
@@ -11010,7 +11528,7 @@ $.widget( "ui.menu", {
// Destroy (sub)menus
this.element
.removeAttr( "aria-activedescendant" )
- .find( ".ui-menu" ).andSelf()
+ .find( ".ui-menu" ).addBack()
.removeClass( "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" )
.removeAttr( "role" )
.removeAttr( "tabIndex" )
@@ -11044,6 +11562,7 @@ $.widget( "ui.menu", {
},
_keydown: function( event ) {
+ /*jshint maxcomplexity:20*/
var match, prev, character, skip, regex,
preventDefault = true;
@@ -11192,7 +11711,7 @@ $.widget( "ui.menu", {
menus.children( ":not(.ui-menu-item)" ).each(function() {
var item = $( this );
// hyphen, em dash, en dash
- if ( !/[^\-—–\s]/.test( item.text() ) ) {
+ if ( !/[^\-\u2014\u2013\s]/.test( item.text() ) ) {
item.addClass( "ui-widget-content ui-menu-divider" );
}
});
@@ -11213,6 +11732,15 @@ $.widget( "ui.menu", {
}[ this.options.role ];
},
+ _setOption: function( key, value ) {
+ if ( key === "icons" ) {
+ this.element.find( ".ui-menu-icon" )
+ .removeClass( this.options.icons.submenu )
+ .addClass( value.submenu );
+ }
+ this._super( key, value );
+ },
+
focus: function( event, item ) {
var nested, focused;
this.blur( event, event && event.type === "focus" );
@@ -11490,21 +12018,52 @@ var cachedScrollbarWidth,
round = Math.round,
rhorizontal = /left|center|right/,
rvertical = /top|center|bottom/,
- roffset = /[\+\-]\d+%?/,
+ roffset = /[\+\-]\d+(\.[\d]+)?%?/,
rposition = /^\w+/,
rpercent = /%$/,
_position = $.fn.position;
function getOffsets( offsets, width, height ) {
return [
- parseInt( offsets[ 0 ], 10 ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
- parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
+ parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
+ parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
];
}
+
function parseCss( element, property ) {
return parseInt( $.css( element, property ), 10 ) || 0;
}
+function getDimensions( elem ) {
+ var raw = elem[0];
+ if ( raw.nodeType === 9 ) {
+ return {
+ width: elem.width(),
+ height: elem.height(),
+ offset: { top: 0, left: 0 }
+ };
+ }
+ if ( $.isWindow( raw ) ) {
+ return {
+ width: elem.width(),
+ height: elem.height(),
+ offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
+ };
+ }
+ if ( raw.preventDefault ) {
+ return {
+ width: 0,
+ height: 0,
+ offset: { top: raw.pageY, left: raw.pageX }
+ };
+ }
+ return {
+ width: elem.outerWidth(),
+ height: elem.outerHeight(),
+ offset: elem.offset()
+ };
+}
+
$.position = {
scrollbarWidth: function() {
if ( cachedScrollbarWidth !== undefined ) {
@@ -11536,8 +12095,8 @@ $.position = {
hasOverflowY = overflowY === "scroll" ||
( overflowY === "auto" && within.height < within.element[0].scrollHeight );
return {
- width: hasOverflowX ? $.position.scrollbarWidth() : 0,
- height: hasOverflowY ? $.position.scrollbarWidth() : 0
+ width: hasOverflowY ? $.position.scrollbarWidth() : 0,
+ height: hasOverflowX ? $.position.scrollbarWidth() : 0
};
},
getWithinInfo: function( element ) {
@@ -11563,32 +12122,21 @@ $.fn.position = function( options ) {
// make a copy, we don't want to modify arguments
options = $.extend( {}, options );
- var atOffset, targetWidth, targetHeight, targetOffset, basePosition,
+ var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
target = $( options.of ),
within = $.position.getWithinInfo( options.within ),
scrollInfo = $.position.getScrollInfo( within ),
- targetElem = target[0],
collision = ( options.collision || "flip" ).split( " " ),
offsets = {};
- if ( targetElem.nodeType === 9 ) {
- targetWidth = target.width();
- targetHeight = target.height();
- targetOffset = { top: 0, left: 0 };
- } else if ( $.isWindow( targetElem ) ) {
- targetWidth = target.width();
- targetHeight = target.height();
- targetOffset = { top: target.scrollTop(), left: target.scrollLeft() };
- } else if ( targetElem.preventDefault ) {
+ dimensions = getDimensions( target );
+ if ( target[0].preventDefault ) {
// force left top to allow flipping
options.at = "left top";
- targetWidth = targetHeight = 0;
- targetOffset = { top: targetElem.pageY, left: targetElem.pageX };
- } else {
- targetWidth = target.outerWidth();
- targetHeight = target.outerHeight();
- targetOffset = target.offset();
}
+ targetWidth = dimensions.width;
+ targetHeight = dimensions.height;
+ targetOffset = dimensions.offset;
// clone to reuse original targetOffset later
basePosition = $.extend( {}, targetOffset );
@@ -11702,10 +12250,6 @@ $.fn.position = function( options ) {
}
});
- if ( $.fn.bgiframe ) {
- elem.bgiframe();
- }
-
if ( options.using ) {
// adds feedback as second argument to using callback, if present
using = function( props ) {
@@ -11950,69 +12494,38 @@ $.ui.position = {
testElementParent.removeChild( testElement );
})();
-// DEPRECATED
-if ( $.uiBackCompat !== false ) {
- // offset option
- (function( $ ) {
- var _position = $.fn.position;
- $.fn.position = function( options ) {
- if ( !options || !options.offset ) {
- return _position.call( this, options );
- }
- var offset = options.offset.split( " " ),
- at = options.at.split( " " );
- if ( offset.length === 1 ) {
- offset[ 1 ] = offset[ 0 ];
- }
- if ( /^\d/.test( offset[ 0 ] ) ) {
- offset[ 0 ] = "+" + offset[ 0 ];
- }
- if ( /^\d/.test( offset[ 1 ] ) ) {
- offset[ 1 ] = "+" + offset[ 1 ];
- }
- if ( at.length === 1 ) {
- if ( /left|center|right/.test( at[ 0 ] ) ) {
- at[ 1 ] = "center";
- } else {
- at[ 1 ] = at[ 0 ];
- at[ 0 ] = "center";
- }
- }
- return _position.call( this, $.extend( options, {
- at: at[ 0 ] + offset[ 0 ] + " " + at[ 1 ] + offset[ 1 ],
- offset: undefined
- } ) );
- };
- }( jQuery ) );
-}
-
}( jQuery ) );
(function( $, undefined ) {
$.widget( "ui.progressbar", {
- version: "1.9.2",
+ version: "1.10.2",
options: {
+ max: 100,
value: 0,
- max: 100
+
+ change: null,
+ complete: null
},
min: 0,
_create: function() {
+ // Constrain initial value
+ this.oldValue = this.options.value = this._constrainedValue();
+
this.element
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
.attr({
+ // Only set static values, aria-valuenow and aria-valuemax are
+ // set inside _refreshValue()
role: "progressbar",
- "aria-valuemin": this.min,
- "aria-valuemax": this.options.max,
- "aria-valuenow": this._value()
+ "aria-valuemin": this.min
});
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
.appendTo( this.element );
- this.oldValue = this._value();
this._refreshValue();
},
@@ -12029,52 +12542,87 @@ $.widget( "ui.progressbar", {
value: function( newValue ) {
if ( newValue === undefined ) {
- return this._value();
+ return this.options.value;
}
- this._setOption( "value", newValue );
- return this;
+ this.options.value = this._constrainedValue( newValue );
+ this._refreshValue();
},
- _setOption: function( key, value ) {
- if ( key === "value" ) {
- this.options.value = value;
- this._refreshValue();
- if ( this._value() === this.options.max ) {
- this._trigger( "complete" );
- }
+ _constrainedValue: function( newValue ) {
+ if ( newValue === undefined ) {
+ newValue = this.options.value;
}
- this._super( key, value );
+ this.indeterminate = newValue === false;
+
+ // sanitize value
+ if ( typeof newValue !== "number" ) {
+ newValue = 0;
+ }
+
+ return this.indeterminate ? false :
+ Math.min( this.options.max, Math.max( this.min, newValue ) );
},
- _value: function() {
- var val = this.options.value;
- // normalize invalid value
- if ( typeof val !== "number" ) {
- val = 0;
+ _setOptions: function( options ) {
+ // Ensure "value" option is set after other values (like max)
+ var value = options.value;
+ delete options.value;
+
+ this._super( options );
+
+ this.options.value = this._constrainedValue( value );
+ this._refreshValue();
+ },
+
+ _setOption: function( key, value ) {
+ if ( key === "max" ) {
+ // Don't allow a max less than min
+ value = Math.max( this.min, value );
}
- return Math.min( this.options.max, Math.max( this.min, val ) );
+
+ this._super( key, value );
},
_percentage: function() {
- return 100 * this._value() / this.options.max;
+ return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
},
_refreshValue: function() {
- var value = this.value(),
+ var value = this.options.value,
percentage = this._percentage();
+ this.valueDiv
+ .toggle( this.indeterminate || value > this.min )
+ .toggleClass( "ui-corner-right", value === this.options.max )
+ .width( percentage.toFixed(0) + "%" );
+
+ this.element.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
+
+ if ( this.indeterminate ) {
+ this.element.removeAttr( "aria-valuenow" );
+ if ( !this.overlayDiv ) {
+ this.overlayDiv = $( "<div class='ui-progressbar-overlay'></div>" ).appendTo( this.valueDiv );
+ }
+ } else {
+ this.element.attr({
+ "aria-valuemax": this.options.max,
+ "aria-valuenow": value
+ });
+ if ( this.overlayDiv ) {
+ this.overlayDiv.remove();
+ this.overlayDiv = null;
+ }
+ }
+
if ( this.oldValue !== value ) {
this.oldValue = value;
this._trigger( "change" );
}
-
- this.valueDiv
- .toggle( value > this.min )
- .toggleClass( "ui-corner-right", value === this.options.max )
- .width( percentage.toFixed(0) + "%" );
- this.element.attr( "aria-valuenow", value );
+ if ( value === this.options.max ) {
+ this._trigger( "complete" );
+ }
}
});
@@ -12087,7 +12635,7 @@ $.widget( "ui.progressbar", {
var numPages = 5;
$.widget( "ui.slider", $.ui.mouse, {
- version: "1.9.2",
+ version: "1.10.2",
widgetEventPrefix: "slide",
options: {
@@ -12099,16 +12647,16 @@ $.widget( "ui.slider", $.ui.mouse, {
range: false,
step: 1,
value: 0,
- values: null
+ values: null,
+
+ // callbacks
+ change: null,
+ slide: null,
+ start: null,
+ stop: null
},
_create: function() {
- var i, handleCount,
- o = this.options,
- existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
- handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
- handles = [];
-
this._keySliding = false;
this._mouseSliding = false;
this._animateOff = true;
@@ -12121,31 +12669,34 @@ $.widget( "ui.slider", $.ui.mouse, {
" ui-slider-" + this.orientation +
" ui-widget" +
" ui-widget-content" +
- " ui-corner-all" +
- ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) );
+ " ui-corner-all");
- this.range = $([]);
+ this._refresh();
+ this._setOption( "disabled", this.options.disabled );
- if ( o.range ) {
- if ( o.range === true ) {
- if ( !o.values ) {
- o.values = [ this._valueMin(), this._valueMin() ];
- }
- if ( o.values.length && o.values.length !== 2 ) {
- o.values = [ o.values[0], o.values[0] ];
- }
- }
+ this._animateOff = false;
+ },
- this.range = $( "<div></div>" )
- .appendTo( this.element )
- .addClass( "ui-slider-range" +
- // note: this isn't the most fittingly semantic framework class for this element,
- // but worked best visually with a variety of themes
- " ui-widget-header" +
- ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
- }
+ _refresh: function() {
+ this._createRange();
+ this._createHandles();
+ this._setupEvents();
+ this._refreshValue();
+ },
+
+ _createHandles: function() {
+ var i, handleCount,
+ options = this.options,
+ existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
+ handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
+ handles = [];
- handleCount = ( o.values && o.values.length ) || 1;
+ handleCount = ( options.values && options.values.length ) || 1;
+
+ if ( existingHandles.length > handleCount ) {
+ existingHandles.slice( handleCount ).remove();
+ existingHandles = existingHandles.slice( 0, handleCount );
+ }
for ( i = existingHandles.length; i < handleCount; i++ ) {
handles.push( handle );
@@ -12155,113 +12706,56 @@ $.widget( "ui.slider", $.ui.mouse, {
this.handle = this.handles.eq( 0 );
- this.handles.add( this.range ).filter( "a" )
- .click(function( event ) {
- event.preventDefault();
- })
- .mouseenter(function() {
- if ( !o.disabled ) {
- $( this ).addClass( "ui-state-hover" );
- }
- })
- .mouseleave(function() {
- $( this ).removeClass( "ui-state-hover" );
- })
- .focus(function() {
- if ( !o.disabled ) {
- $( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
- $( this ).addClass( "ui-state-focus" );
- } else {
- $( this ).blur();
- }
- })
- .blur(function() {
- $( this ).removeClass( "ui-state-focus" );
- });
-
this.handles.each(function( i ) {
$( this ).data( "ui-slider-handle-index", i );
});
+ },
- this._on( this.handles, {
- keydown: function( event ) {
- var allowed, curVal, newVal, step,
- index = $( event.target ).data( "ui-slider-handle-index" );
-
- switch ( event.keyCode ) {
- case $.ui.keyCode.HOME:
- case $.ui.keyCode.END:
- case $.ui.keyCode.PAGE_UP:
- case $.ui.keyCode.PAGE_DOWN:
- case $.ui.keyCode.UP:
- case $.ui.keyCode.RIGHT:
- case $.ui.keyCode.DOWN:
- case $.ui.keyCode.LEFT:
- event.preventDefault();
- if ( !this._keySliding ) {
- this._keySliding = true;
- $( event.target ).addClass( "ui-state-active" );
- allowed = this._start( event, index );
- if ( allowed === false ) {
- return;
- }
- }
- break;
- }
-
- step = this.options.step;
- if ( this.options.values && this.options.values.length ) {
- curVal = newVal = this.values( index );
- } else {
- curVal = newVal = this.value();
- }
+ _createRange: function() {
+ var options = this.options,
+ classes = "";
- switch ( event.keyCode ) {
- case $.ui.keyCode.HOME:
- newVal = this._valueMin();
- break;
- case $.ui.keyCode.END:
- newVal = this._valueMax();
- break;
- case $.ui.keyCode.PAGE_UP:
- newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
- break;
- case $.ui.keyCode.PAGE_DOWN:
- newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
- break;
- case $.ui.keyCode.UP:
- case $.ui.keyCode.RIGHT:
- if ( curVal === this._valueMax() ) {
- return;
- }
- newVal = this._trimAlignValue( curVal + step );
- break;
- case $.ui.keyCode.DOWN:
- case $.ui.keyCode.LEFT:
- if ( curVal === this._valueMin() ) {
- return;
- }
- newVal = this._trimAlignValue( curVal - step );
- break;
+ if ( options.range ) {
+ if ( options.range === true ) {
+ if ( !options.values ) {
+ options.values = [ this._valueMin(), this._valueMin() ];
+ } else if ( options.values.length && options.values.length !== 2 ) {
+ options.values = [ options.values[0], options.values[0] ];
+ } else if ( $.isArray( options.values ) ) {
+ options.values = options.values.slice(0);
}
+ }
- this._slide( event, index, newVal );
- },
- keyup: function( event ) {
- var index = $( event.target ).data( "ui-slider-handle-index" );
+ if ( !this.range || !this.range.length ) {
+ this.range = $( "<div></div>" )
+ .appendTo( this.element );
- if ( this._keySliding ) {
- this._keySliding = false;
- this._stop( event, index );
- this._change( event, index );
- $( event.target ).removeClass( "ui-state-active" );
- }
+ classes = "ui-slider-range" +
+ // note: this isn't the most fittingly semantic framework class for this element,
+ // but worked best visually with a variety of themes
+ " ui-widget-header ui-corner-all";
+ } else {
+ this.range.removeClass( "ui-slider-range-min ui-slider-range-max" )
+ // Handle range switching from true to min/max
+ .css({
+ "left": "",
+ "bottom": ""
+ });
}
- });
- this._refreshValue();
+ this.range.addClass( classes +
+ ( ( options.range === "min" || options.range === "max" ) ? " ui-slider-range-" + options.range : "" ) );
+ } else {
+ this.range = $([]);
+ }
+ },
- this._animateOff = false;
+ _setupEvents: function() {
+ var elements = this.handles.add( this.range ).filter( "a" );
+ this._off( elements );
+ this._on( elements, this._handleEvents );
+ this._hoverable( elements );
+ this._focusable( elements );
},
_destroy: function() {
@@ -12272,7 +12766,6 @@ $.widget( "ui.slider", $.ui.mouse, {
.removeClass( "ui-slider" +
" ui-slider-horizontal" +
" ui-slider-vertical" +
- " ui-slider-disabled" +
" ui-widget" +
" ui-widget-content" +
" ui-corner-all" );
@@ -12300,21 +12793,15 @@ $.widget( "ui.slider", $.ui.mouse, {
distance = this._valueMax() - this._valueMin() + 1;
this.handles.each(function( i ) {
var thisDistance = Math.abs( normValue - that.values(i) );
- if ( distance > thisDistance ) {
+ if (( distance > thisDistance ) ||
+ ( distance === thisDistance &&
+ (i === that._lastChangedValue || that.values(i) === o.min ))) {
distance = thisDistance;
closestHandle = $( this );
index = i;
}
});
- // workaround for bug #3736 (if both handles of a range are at 0,
- // the first is always used as the one with least distance,
- // and moving it is obviously prevented by preventing negative ranges)
- if( o.range === true && this.values(1) === o.min ) {
- index += 1;
- closestHandle = $( this.handles[index] );
- }
-
allowed = this._start( event, index );
if ( allowed === false ) {
return false;
@@ -12328,7 +12815,7 @@ $.widget( "ui.slider", $.ui.mouse, {
.focus();
offset = closestHandle.offset();
- mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" );
+ mouseOverHandle = !$( event.target ).parents().addBack().is( ".ui-slider-handle" );
this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
top: event.pageY - offset.top -
@@ -12486,6 +12973,9 @@ $.widget( "ui.slider", $.ui.mouse, {
uiHash.values = this.values();
}
+ //store the last changed value index for reference when handles overlap
+ this._lastChangedValue = index;
+
this._trigger( "change", event, uiHash );
}
},
@@ -12538,6 +13028,16 @@ $.widget( "ui.slider", $.ui.mouse, {
var i,
valsLength = 0;
+ if ( key === "range" && this.options.range === true ) {
+ if ( value === "min" ) {
+ this.options.value = this._values( 0 );
+ this.options.values = null;
+ } else if ( value === "max" ) {
+ this.options.value = this._values( this.options.values.length-1 );
+ this.options.values = null;
+ }
+ }
+
if ( $.isArray( this.options.values ) ) {
valsLength = this.options.values.length;
}
@@ -12545,17 +13045,6 @@ $.widget( "ui.slider", $.ui.mouse, {
$.Widget.prototype._setOption.apply( this, arguments );
switch ( key ) {
- case "disabled":
- if ( value ) {
- this.handles.filter( ".ui-state-focus" ).blur();
- this.handles.removeClass( "ui-state-hover" );
- this.handles.prop( "disabled", true );
- this.element.addClass( "ui-disabled" );
- } else {
- this.handles.prop( "disabled", false );
- this.element.removeClass( "ui-disabled" );
- }
- break;
case "orientation":
this._detectOrientation();
this.element
@@ -12583,6 +13072,11 @@ $.widget( "ui.slider", $.ui.mouse, {
this._refreshValue();
this._animateOff = false;
break;
+ case "range":
+ this._animateOff = true;
+ this._refresh();
+ this._animateOff = false;
+ break;
}
},
@@ -12608,7 +13102,7 @@ $.widget( "ui.slider", $.ui.mouse, {
val = this._trimAlignValue( val );
return val;
- } else {
+ } else if ( this.options.values && this.options.values.length ) {
// .slice() creates a copy of the array
// this copy gets trimmed by min and max and then returned
vals = this.options.values.slice();
@@ -12617,6 +13111,8 @@ $.widget( "ui.slider", $.ui.mouse, {
}
return vals;
+ } else {
+ return [];
}
},
@@ -12704,6 +13200,86 @@ $.widget( "ui.slider", $.ui.mouse, {
this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
}
}
+ },
+
+ _handleEvents: {
+ keydown: function( event ) {
+ /*jshint maxcomplexity:25*/
+ var allowed, curVal, newVal, step,
+ index = $( event.target ).data( "ui-slider-handle-index" );
+
+ switch ( event.keyCode ) {
+ case $.ui.keyCode.HOME:
+ case $.ui.keyCode.END:
+ case $.ui.keyCode.PAGE_UP:
+ case $.ui.keyCode.PAGE_DOWN:
+ case $.ui.keyCode.UP:
+ case $.ui.keyCode.RIGHT:
+ case $.ui.keyCode.DOWN:
+ case $.ui.keyCode.LEFT:
+ event.preventDefault();
+ if ( !this._keySliding ) {
+ this._keySliding = true;
+ $( event.target ).addClass( "ui-state-active" );
+ allowed = this._start( event, index );
+ if ( allowed === false ) {
+ return;
+ }
+ }
+ break;
+ }
+
+ step = this.options.step;
+ if ( this.options.values && this.options.values.length ) {
+ curVal = newVal = this.values( index );
+ } else {
+ curVal = newVal = this.value();
+ }
+
+ switch ( event.keyCode ) {
+ case $.ui.keyCode.HOME:
+ newVal = this._valueMin();
+ break;
+ case $.ui.keyCode.END:
+ newVal = this._valueMax();
+ break;
+ case $.ui.keyCode.PAGE_UP:
+ newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
+ break;
+ case $.ui.keyCode.PAGE_DOWN:
+ newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
+ break;
+ case $.ui.keyCode.UP:
+ case $.ui.keyCode.RIGHT:
+ if ( curVal === this._valueMax() ) {
+ return;
+ }
+ newVal = this._trimAlignValue( curVal + step );
+ break;
+ case $.ui.keyCode.DOWN:
+ case $.ui.keyCode.LEFT:
+ if ( curVal === this._valueMin() ) {
+ return;
+ }
+ newVal = this._trimAlignValue( curVal - step );
+ break;
+ }
+
+ this._slide( event, index, newVal );
+ },
+ click: function( event ) {
+ event.preventDefault();
+ },
+ keyup: function( event ) {
+ var index = $( event.target ).data( "ui-slider-handle-index" );
+
+ if ( this._keySliding ) {
+ this._keySliding = false;
+ this._stop( event, index );
+ this._change( event, index );
+ $( event.target ).removeClass( "ui-state-active" );
+ }
+ }
}
});
@@ -12724,7 +13300,7 @@ function modifier( fn ) {
}
$.widget( "ui.spinner", {
- version: "1.9.2",
+ version: "1.10.2",
defaultElement: "<input>",
widgetEventPrefix: "spin",
options: {
@@ -12799,6 +13375,7 @@ $.widget( "ui.spinner", {
return;
}
+ this._stop();
this._refresh();
if ( this.previous !== this.element.val() ) {
this._trigger( "change", event );
@@ -13065,6 +13642,14 @@ $.widget( "ui.spinner", {
value = this._parse( value );
}
}
+ if ( key === "icons" ) {
+ this.buttons.first().find( ".ui-icon" )
+ .removeClass( this.options.icons.up )
+ .addClass( value.up );
+ this.buttons.last().find( ".ui-icon" )
+ .removeClass( this.options.icons.down )
+ .addClass( value.down );
+ }
this._super( key, value );
@@ -13142,14 +13727,20 @@ $.widget( "ui.spinner", {
this._stepUp( steps );
}),
_stepUp: function( steps ) {
- this._spin( (steps || 1) * this.options.step );
+ if ( this._start() ) {
+ this._spin( (steps || 1) * this.options.step );
+ this._stop();
+ }
},
stepDown: modifier(function( steps ) {
this._stepDown( steps );
}),
_stepDown: function( steps ) {
- this._spin( (steps || 1) * -this.options.step );
+ if ( this._start() ) {
+ this._spin( (steps || 1) * -this.options.step );
+ this._stop();
+ }
},
pageUp: modifier(function( pages ) {
@@ -13185,16 +13776,12 @@ function getNextTabId() {
function isLocal( anchor ) {
return anchor.hash.length > 1 &&
- anchor.href.replace( rhash, "" ) ===
- location.href.replace( rhash, "" )
- // support: Safari 5.1
- // Safari 5.1 doesn't encode spaces in window.location
- // but it does encode spaces from anchors (#8777)
- .replace( /\s/g, "%20" );
+ decodeURIComponent( anchor.href.replace( rhash, "" ) ) ===
+ decodeURIComponent( location.href.replace( rhash, "" ) );
}
$.widget( "ui.tabs", {
- version: "1.9.2",
+ version: "1.10.2",
delay: 300,
options: {
active: null,
@@ -13213,9 +13800,7 @@ $.widget( "ui.tabs", {
_create: function() {
var that = this,
- options = this.options,
- active = options.active,
- locationHash = location.hash.substring( 1 );
+ options = this.options;
this.running = false;
@@ -13241,6 +13826,36 @@ $.widget( "ui.tabs", {
});
this._processTabs();
+ options.active = this._initialActive();
+
+ // Take disabling tabs via class attribute from HTML
+ // into account and update option properly.
+ if ( $.isArray( options.disabled ) ) {
+ options.disabled = $.unique( options.disabled.concat(
+ $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
+ return that.tabs.index( li );
+ })
+ ) ).sort();
+ }
+
+ // check for length avoids error when initializing empty list
+ if ( this.options.active !== false && this.anchors.length ) {
+ this.active = this._findActive( options.active );
+ } else {
+ this.active = $();
+ }
+
+ this._refresh();
+
+ if ( this.active.length ) {
+ this.load( options.active );
+ }
+ },
+
+ _initialActive: function() {
+ var active = this.options.active,
+ collapsible = this.options.collapsible,
+ locationHash = location.hash.substring( 1 );
if ( active === null ) {
// check the fragment identifier in the URL
@@ -13268,38 +13883,16 @@ $.widget( "ui.tabs", {
if ( active !== false ) {
active = this.tabs.index( this.tabs.eq( active ) );
if ( active === -1 ) {
- active = options.collapsible ? false : 0;
+ active = collapsible ? false : 0;
}
}
- options.active = active;
// don't allow collapsible: false and active: false
- if ( !options.collapsible && options.active === false && this.anchors.length ) {
- options.active = 0;
- }
-
- // Take disabling tabs via class attribute from HTML
- // into account and update option properly.
- if ( $.isArray( options.disabled ) ) {
- options.disabled = $.unique( options.disabled.concat(
- $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
- return that.tabs.index( li );
- })
- ) ).sort();
- }
-
- // check for length avoids error when initializing empty list
- if ( this.options.active !== false && this.anchors.length ) {
- this.active = this._findActive( this.options.active );
- } else {
- this.active = $();
+ if ( !collapsible && active === false && this.anchors.length ) {
+ active = 0;
}
- this._refresh();
-
- if ( this.active.length ) {
- this.load( options.active );
- }
+ return active;
},
_getCreateEventData: function() {
@@ -13310,6 +13903,7 @@ $.widget( "ui.tabs", {
},
_tabKeydown: function( event ) {
+ /*jshint maxcomplexity:15*/
var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
selectedIndex = this.tabs.index( focusedTab ),
goingForward = true;
@@ -13654,19 +14248,13 @@ $.widget( "ui.tabs", {
},
_setupHeightStyle: function( heightStyle ) {
- var maxHeight, overflow,
+ var maxHeight,
parent = this.element.parent();
if ( heightStyle === "fill" ) {
- // IE 6 treats height like minHeight, so we need to turn off overflow
- // in order to get a reliable height
- // we use the minHeight support test because we assume that only
- // browsers that don't support minHeight will treat height as minHeight
- if ( !$.support.minHeight ) {
- overflow = parent.css( "overflow" );
- parent.css( "overflow", "hidden");
- }
maxHeight = parent.height();
+ maxHeight -= this.element.outerHeight() - this.element.height();
+
this.element.siblings( ":visible" ).each(function() {
var elem = $( this ),
position = elem.css( "position" );
@@ -13676,9 +14264,6 @@ $.widget( "ui.tabs", {
}
maxHeight -= elem.outerHeight( true );
});
- if ( overflow ) {
- parent.css( "overflow", overflow );
- }
this.element.children().not( this.panels ).each(function() {
maxHeight -= $( this ).outerHeight( true );
@@ -13857,8 +14442,6 @@ $.widget( "ui.tabs", {
.removeClass( "ui-tabs-anchor" )
.removeAttr( "role" )
.removeAttr( "tabIndex" )
- .removeData( "href.tabs" )
- .removeData( "load.tabs" )
.removeUniqueId();
this.tabs.add( this.panels ).each(function() {
@@ -13883,7 +14466,9 @@ $.widget( "ui.tabs", {
var li = $( this ),
prev = li.data( "ui-tabs-aria-controls" );
if ( prev ) {
- li.attr( "aria-controls", prev );
+ li
+ .attr( "aria-controls", prev )
+ .removeData( "ui-tabs-aria-controls" );
} else {
li.removeAttr( "aria-controls" );
}
@@ -13994,7 +14579,6 @@ $.widget( "ui.tabs", {
}
},
- // TODO: Remove this function in 1.10 when ajaxOptions is removed
_ajaxSettings: function( anchor, event, eventData ) {
var that = this;
return {
@@ -14012,519 +14596,6 @@ $.widget( "ui.tabs", {
}
});
-// DEPRECATED
-if ( $.uiBackCompat !== false ) {
-
- // helper method for a lot of the back compat extensions
- $.ui.tabs.prototype._ui = function( tab, panel ) {
- return {
- tab: tab,
- panel: panel,
- index: this.anchors.index( tab )
- };
- };
-
- // url method
- $.widget( "ui.tabs", $.ui.tabs, {
- url: function( index, url ) {
- this.anchors.eq( index ).attr( "href", url );
- }
- });
-
- // TODO: Remove _ajaxSettings() method when removing this extension
- // ajaxOptions and cache options
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- ajaxOptions: null,
- cache: false
- },
-
- _create: function() {
- this._super();
-
- var that = this;
-
- this._on({ tabsbeforeload: function( event, ui ) {
- // tab is already cached
- if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) {
- event.preventDefault();
- return;
- }
-
- ui.jqXHR.success(function() {
- if ( that.options.cache ) {
- $.data( ui.tab[ 0 ], "cache.tabs", true );
- }
- });
- }});
- },
-
- _ajaxSettings: function( anchor, event, ui ) {
- var ajaxOptions = this.options.ajaxOptions;
- return $.extend( {}, ajaxOptions, {
- error: function( xhr, status ) {
- try {
- // Passing index avoid a race condition when this method is
- // called after the user has selected another tab.
- // Pass the anchor that initiated this request allows
- // loadError to manipulate the tab content panel via $(a.hash)
- ajaxOptions.error(
- xhr, status, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
- }
- catch ( error ) {}
- }
- }, this._superApply( arguments ) );
- },
-
- _setOption: function( key, value ) {
- // reset cache if switching from cached to not cached
- if ( key === "cache" && value === false ) {
- this.anchors.removeData( "cache.tabs" );
- }
- this._super( key, value );
- },
-
- _destroy: function() {
- this.anchors.removeData( "cache.tabs" );
- this._super();
- },
-
- url: function( index ){
- this.anchors.eq( index ).removeData( "cache.tabs" );
- this._superApply( arguments );
- }
- });
-
- // abort method
- $.widget( "ui.tabs", $.ui.tabs, {
- abort: function() {
- if ( this.xhr ) {
- this.xhr.abort();
- }
- }
- });
-
- // spinner
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- spinner: "<em>Loading&#8230;</em>"
- },
- _create: function() {
- this._super();
- this._on({
- tabsbeforeload: function( event, ui ) {
- // Don't react to nested tabs or tabs that don't use a spinner
- if ( event.target !== this.element[ 0 ] ||
- !this.options.spinner ) {
- return;
- }
-
- var span = ui.tab.find( "span" ),
- html = span.html();
- span.html( this.options.spinner );
- ui.jqXHR.complete(function() {
- span.html( html );
- });
- }
- });
- }
- });
-
- // enable/disable events
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- enable: null,
- disable: null
- },
-
- enable: function( index ) {
- var options = this.options,
- trigger;
-
- if ( index && options.disabled === true ||
- ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) !== -1 ) ) {
- trigger = true;
- }
-
- this._superApply( arguments );
-
- if ( trigger ) {
- this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
- }
- },
-
- disable: function( index ) {
- var options = this.options,
- trigger;
-
- if ( index && options.disabled === false ||
- ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) === -1 ) ) {
- trigger = true;
- }
-
- this._superApply( arguments );
-
- if ( trigger ) {
- this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
- }
- }
- });
-
- // add/remove methods and events
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- add: null,
- remove: null,
- tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
- },
-
- add: function( url, label, index ) {
- if ( index === undefined ) {
- index = this.anchors.length;
- }
-
- var doInsertAfter, panel,
- options = this.options,
- li = $( options.tabTemplate
- .replace( /#\{href\}/g, url )
- .replace( /#\{label\}/g, label ) ),
- id = !url.indexOf( "#" ) ?
- url.replace( "#", "" ) :
- this._tabId( li );
-
- li.addClass( "ui-state-default ui-corner-top" ).data( "ui-tabs-destroy", true );
- li.attr( "aria-controls", id );
-
- doInsertAfter = index >= this.tabs.length;
-
- // try to find an existing element before creating a new one
- panel = this.element.find( "#" + id );
- if ( !panel.length ) {
- panel = this._createPanel( id );
- if ( doInsertAfter ) {
- if ( index > 0 ) {
- panel.insertAfter( this.panels.eq( -1 ) );
- } else {
- panel.appendTo( this.element );
- }
- } else {
- panel.insertBefore( this.panels[ index ] );
- }
- }
- panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide();
-
- if ( doInsertAfter ) {
- li.appendTo( this.tablist );
- } else {
- li.insertBefore( this.tabs[ index ] );
- }
-
- options.disabled = $.map( options.disabled, function( n ) {
- return n >= index ? ++n : n;
- });
-
- this.refresh();
- if ( this.tabs.length === 1 && options.active === false ) {
- this.option( "active", 0 );
- }
-
- this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
- return this;
- },
-
- remove: function( index ) {
- index = this._getIndex( index );
- var options = this.options,
- tab = this.tabs.eq( index ).remove(),
- panel = this._getPanelForTab( tab ).remove();
-
- // If selected tab was removed focus tab to the right or
- // in case the last tab was removed the tab to the left.
- // We check for more than 2 tabs, because if there are only 2,
- // then when we remove this tab, there will only be one tab left
- // so we don't need to detect which tab to activate.
- if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 2 ) {
- this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) );
- }
-
- options.disabled = $.map(
- $.grep( options.disabled, function( n ) {
- return n !== index;
- }),
- function( n ) {
- return n >= index ? --n : n;
- });
-
- this.refresh();
-
- this._trigger( "remove", null, this._ui( tab.find( "a" )[ 0 ], panel[ 0 ] ) );
- return this;
- }
- });
-
- // length method
- $.widget( "ui.tabs", $.ui.tabs, {
- length: function() {
- return this.anchors.length;
- }
- });
-
- // panel ids (idPrefix option + title attribute)
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- idPrefix: "ui-tabs-"
- },
-
- _tabId: function( tab ) {
- var a = tab.is( "li" ) ? tab.find( "a[href]" ) : tab;
- a = a[0];
- return $( a ).closest( "li" ).attr( "aria-controls" ) ||
- a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF\-]/g, "" ) ||
- this.options.idPrefix + getNextTabId();
- }
- });
-
- // _createPanel method
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- panelTemplate: "<div></div>"
- },
-
- _createPanel: function( id ) {
- return $( this.options.panelTemplate )
- .attr( "id", id )
- .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
- .data( "ui-tabs-destroy", true );
- }
- });
-
- // selected option
- $.widget( "ui.tabs", $.ui.tabs, {
- _create: function() {
- var options = this.options;
- if ( options.active === null && options.selected !== undefined ) {
- options.active = options.selected === -1 ? false : options.selected;
- }
- this._super();
- options.selected = options.active;
- if ( options.selected === false ) {
- options.selected = -1;
- }
- },
-
- _setOption: function( key, value ) {
- if ( key !== "selected" ) {
- return this._super( key, value );
- }
-
- var options = this.options;
- this._super( "active", value === -1 ? false : value );
- options.selected = options.active;
- if ( options.selected === false ) {
- options.selected = -1;
- }
- },
-
- _eventHandler: function() {
- this._superApply( arguments );
- this.options.selected = this.options.active;
- if ( this.options.selected === false ) {
- this.options.selected = -1;
- }
- }
- });
-
- // show and select event
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- show: null,
- select: null
- },
- _create: function() {
- this._super();
- if ( this.options.active !== false ) {
- this._trigger( "show", null, this._ui(
- this.active.find( ".ui-tabs-anchor" )[ 0 ],
- this._getPanelForTab( this.active )[ 0 ] ) );
- }
- },
- _trigger: function( type, event, data ) {
- var tab, panel,
- ret = this._superApply( arguments );
-
- if ( !ret ) {
- return false;
- }
-
- if ( type === "beforeActivate" ) {
- tab = data.newTab.length ? data.newTab : data.oldTab;
- panel = data.newPanel.length ? data.newPanel : data.oldPanel;
- ret = this._super( "select", event, {
- tab: tab.find( ".ui-tabs-anchor" )[ 0],
- panel: panel[ 0 ],
- index: tab.closest( "li" ).index()
- });
- } else if ( type === "activate" && data.newTab.length ) {
- ret = this._super( "show", event, {
- tab: data.newTab.find( ".ui-tabs-anchor" )[ 0 ],
- panel: data.newPanel[ 0 ],
- index: data.newTab.closest( "li" ).index()
- });
- }
- return ret;
- }
- });
-
- // select method
- $.widget( "ui.tabs", $.ui.tabs, {
- select: function( index ) {
- index = this._getIndex( index );
- if ( index === -1 ) {
- if ( this.options.collapsible && this.options.selected !== -1 ) {
- index = this.options.selected;
- } else {
- return;
- }
- }
- this.anchors.eq( index ).trigger( this.options.event + this.eventNamespace );
- }
- });
-
- // cookie option
- (function() {
-
- var listId = 0;
-
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
- },
- _create: function() {
- var options = this.options,
- active;
- if ( options.active == null && options.cookie ) {
- active = parseInt( this._cookie(), 10 );
- if ( active === -1 ) {
- active = false;
- }
- options.active = active;
- }
- this._super();
- },
- _cookie: function( active ) {
- var cookie = [ this.cookie ||
- ( this.cookie = this.options.cookie.name || "ui-tabs-" + (++listId) ) ];
- if ( arguments.length ) {
- cookie.push( active === false ? -1 : active );
- cookie.push( this.options.cookie );
- }
- return $.cookie.apply( null, cookie );
- },
- _refresh: function() {
- this._super();
- if ( this.options.cookie ) {
- this._cookie( this.options.active, this.options.cookie );
- }
- },
- _eventHandler: function() {
- this._superApply( arguments );
- if ( this.options.cookie ) {
- this._cookie( this.options.active, this.options.cookie );
- }
- },
- _destroy: function() {
- this._super();
- if ( this.options.cookie ) {
- this._cookie( null, this.options.cookie );
- }
- }
- });
-
- })();
-
- // load event
- $.widget( "ui.tabs", $.ui.tabs, {
- _trigger: function( type, event, data ) {
- var _data = $.extend( {}, data );
- if ( type === "load" ) {
- _data.panel = _data.panel[ 0 ];
- _data.tab = _data.tab.find( ".ui-tabs-anchor" )[ 0 ];
- }
- return this._super( type, event, _data );
- }
- });
-
- // fx option
- // The new animation options (show, hide) conflict with the old show callback.
- // The old fx option wins over show/hide anyway (always favor back-compat).
- // If a user wants to use the new animation API, they must give up the old API.
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- fx: null // e.g. { height: "toggle", opacity: "toggle", duration: 200 }
- },
-
- _getFx: function() {
- var hide, show,
- fx = this.options.fx;
-
- if ( fx ) {
- if ( $.isArray( fx ) ) {
- hide = fx[ 0 ];
- show = fx[ 1 ];
- } else {
- hide = show = fx;
- }
- }
-
- return fx ? { show: show, hide: hide } : null;
- },
-
- _toggle: function( event, eventData ) {
- var that = this,
- toShow = eventData.newPanel,
- toHide = eventData.oldPanel,
- fx = this._getFx();
-
- if ( !fx ) {
- return this._super( event, eventData );
- }
-
- that.running = true;
-
- function complete() {
- that.running = false;
- that._trigger( "activate", event, eventData );
- }
-
- function show() {
- eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
-
- if ( toShow.length && fx.show ) {
- toShow
- .animate( fx.show, fx.show.duration, function() {
- complete();
- });
- } else {
- toShow.show();
- complete();
- }
- }
-
- // start out by hiding, then showing, then completing
- if ( toHide.length && fx.hide ) {
- toHide.animate( fx.hide, fx.hide.duration, function() {
- eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
- show();
- });
- } else {
- eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
- toHide.hide();
- show();
- }
- }
- });
-}
-
})( jQuery );
(function( $ ) {
@@ -14557,10 +14628,14 @@ function removeDescribedBy( elem ) {
}
$.widget( "ui.tooltip", {
- version: "1.9.2",
+ version: "1.10.2",
options: {
content: function() {
- return $( this ).attr( "title" );
+ // support: IE<9, Opera in jQuery <1.7
+ // .text() can't accept undefined, so coerce to a string
+ var title = $( this ).attr( "title" ) || "";
+ // Escape title, since we're going from an attribute to raw HTML
+ return $( "<a>" ).text( title ).html();
},
hide: true,
// Disabled elements have inconsistent behavior across browsers (#8661)
@@ -14625,7 +14700,7 @@ $.widget( "ui.tooltip", {
});
// remove title attributes to prevent native tooltips
- this.element.find( this.options.items ).andSelf().each(function() {
+ this.element.find( this.options.items ).addBack().each(function() {
var element = $( this );
if ( element.is( "[title]" ) ) {
element
@@ -14637,7 +14712,7 @@ $.widget( "ui.tooltip", {
_enable: function() {
// restore title attributes
- this.element.find( this.options.items ).andSelf().each(function() {
+ this.element.find( this.options.items ).addBack().each(function() {
var element = $( this );
if ( element.data( "ui-tooltip-title" ) ) {
element.attr( "title", element.data( "ui-tooltip-title" ) );
@@ -14782,7 +14857,7 @@ $.widget( "ui.tooltip", {
// as the tooltip is visible, position the tooltip using the most recent
// event.
if ( this.options.show && this.options.show.delay ) {
- delayedShow = setInterval(function() {
+ delayedShow = this.delayedShow = setInterval(function() {
if ( tooltip.is( ":visible" ) ) {
position( positionOption.of );
clearInterval( delayedShow );
@@ -14824,6 +14899,9 @@ $.widget( "ui.tooltip", {
return;
}
+ // Clear the interval for delayed tracking tooltips
+ clearInterval( this.delayedShow );
+
// only set title if we had one before (see comment in _open())
if ( target.data( "ui-tooltip-title" ) ) {
target.attr( "title", target.data( "ui-tooltip-title" ) );
@@ -14869,9 +14947,6 @@ $.widget( "ui.tooltip", {
.addClass( "ui-tooltip-content" )
.appendTo( tooltip );
tooltip.appendTo( this.document[0].body );
- if ( $.fn.bgiframe ) {
- tooltip.bgiframe();
- }
this.tooltips[ id ] = element;
return tooltip;
},