4 * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
8 * http://docs.jquery.com/UI
10 (function( $, undefined ) {
12 // prevent duplicate loading
13 // this is only a problem because we proxy existing functions
14 // and we don't want to double proxy them
29 COMMAND_LEFT: 91, // COMMAND
40 MENU: 93, // COMMAND_RIGHT
55 WINDOWS: 91 // COMMAND
61 propAttr: $.fn.prop || $.fn.attr,
64 focus: function( delay, fn ) {
65 return typeof delay === "number" ?
66 this.each(function() {
68 setTimeout(function() {
75 this._focus.apply( this, arguments );
78 scrollParent: function() {
80 if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
81 scrollParent = this.parents().filter(function() {
82 return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
85 scrollParent = this.parents().filter(function() {
86 return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
90 return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
93 zIndex: function( zIndex ) {
94 if ( zIndex !== undefined ) {
95 return this.css( "zIndex", zIndex );
99 var elem = $( this[ 0 ] ), position, value;
100 while ( elem.length && elem[ 0 ] !== document ) {
101 // Ignore z-index if position is set to a value where z-index is ignored by the browser
102 // This makes behavior of this function consistent across browsers
103 // WebKit always returns auto if the element is positioned
104 position = elem.css( "position" );
105 if ( position === "absolute" || position === "relative" || position === "fixed" ) {
106 // IE returns 0 when zIndex is not specified
107 // other browsers return a string
108 // we ignore the case of nested elements with an explicit value of 0
109 // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
110 value = parseInt( elem.css( "zIndex" ), 10 );
111 if ( !isNaN( value ) && value !== 0 ) {
115 elem = elem.parent();
122 disableSelection: function() {
123 return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
124 ".ui-disableSelection", function( event ) {
125 event.preventDefault();
129 enableSelection: function() {
130 return this.unbind( ".ui-disableSelection" );
134 // support: jQuery <1.8
135 if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
136 $.each( [ "Width", "Height" ], function( i, name ) {
137 var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
138 type = name.toLowerCase(),
140 innerWidth: $.fn.innerWidth,
141 innerHeight: $.fn.innerHeight,
142 outerWidth: $.fn.outerWidth,
143 outerHeight: $.fn.outerHeight
146 function reduce( elem, size, border, margin ) {
147 $.each( side, function() {
148 size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
150 size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
153 size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
159 $.fn[ "inner" + name ] = function( size ) {
160 if ( size === undefined ) {
161 return orig[ "inner" + name ].call( this );
164 return this.each(function() {
165 $( this ).css( type, reduce( this, size ) + "px" );
169 $.fn[ "outer" + name] = function( size, margin ) {
170 if ( typeof size !== "number" ) {
171 return orig[ "outer" + name ].call( this, size );
174 return this.each(function() {
175 $( this).css( type, reduce( this, size, true, margin ) + "px" );
182 function focusable( element, isTabIndexNotNaN ) {
183 var nodeName = element.nodeName.toLowerCase();
184 if ( "area" === nodeName ) {
185 var map = element.parentNode,
188 if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
191 img = $( "img[usemap=#" + mapName + "]" )[0];
192 return !!img && visible( img );
194 return ( /input|select|textarea|button|object/.test( nodeName )
197 ? element.href || isTabIndexNotNaN
199 // the element and all of its ancestors must be visible
200 && visible( element );
203 function visible( element ) {
204 return !$( element ).parents().andSelf().filter(function() {
205 return $.curCSS( this, "visibility" ) === "hidden" ||
206 $.expr.filters.hidden( this );
210 $.extend( $.expr[ ":" ], {
211 data: $.expr.createPseudo ?
212 $.expr.createPseudo(function( dataName ) {
213 return function( elem ) {
214 return !!$.data( elem, dataName );
217 // support: jQuery <1.8
218 function( elem, i, match ) {
219 return !!$.data( elem, match[ 3 ] );
222 focusable: function( element ) {
223 return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
226 tabbable: function( element ) {
227 var tabIndex = $.attr( element, "tabindex" ),
228 isTabIndexNaN = isNaN( tabIndex );
229 return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
235 var body = document.body,
236 div = body.appendChild( div = document.createElement( "div" ) );
238 // access offsetHeight before setting the style to prevent a layout bug
239 // in IE 9 which causes the elemnt to continue to take up space even
240 // after it is removed from the DOM (#8026)
243 $.extend( div.style, {
250 $.support.minHeight = div.offsetHeight === 100;
251 $.support.selectstart = "onselectstart" in div;
253 // set display to none to avoid a layout bug in IE
254 // http://dev.jquery.com/ticket/4014
255 body.removeChild( div ).style.display = "none";
258 // jQuery <1.4.3 uses curCSS, in 1.4.3 - 1.7.2 curCSS = css, 1.8+ only has css
269 // $.ui.plugin is deprecated. Use the proxy pattern instead.
271 add: function( module, option, set ) {
272 var proto = $.ui[ module ].prototype;
273 for ( var i in set ) {
274 proto.plugins[ i ] = proto.plugins[ i ] || [];
275 proto.plugins[ i ].push( [ option, set[ i ] ] );
278 call: function( instance, name, args ) {
279 var set = instance.plugins[ name ];
280 if ( !set || !instance.element[ 0 ].parentNode ) {
284 for ( var i = 0; i < set.length; i++ ) {
285 if ( instance.options[ set[ i ][ 0 ] ] ) {
286 set[ i ][ 1 ].apply( instance.element, args );
292 // will be deprecated when we switch to jQuery 1.4 - use jQuery.contains()
293 contains: function( a, b ) {
294 return document.compareDocumentPosition ?
295 a.compareDocumentPosition( b ) & 16 :
296 a !== b && a.contains( b );
299 // only used by resizable
300 hasScroll: function( el, a ) {
302 //If overflow is hidden, the element might have extra content, but the user wants to hide it
303 if ( $( el ).css( "overflow" ) === "hidden") {
307 var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
310 if ( el[ scroll ] > 0 ) {
314 // TODO: determine which cases actually cause this to happen
315 // if the element doesn't have the scroll set, see if it's possible to
318 has = ( el[ scroll ] > 0 );
323 // these are odd functions, fix the API or move into individual plugins
324 isOverAxis: function( x, reference, size ) {
325 //Determines when x coordinate is over "b" element axis
326 return ( x > reference ) && ( x < ( reference + size ) );
328 isOver: function( y, x, top, left, height, width ) {
329 //Determines when x, y coordinates is over "b" element
330 return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );