5 * Copyright 2012 jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/category/ui-core/
11 (function( $, undefined ) {
14 runiqueId = /^ui-id-\d+$/;
16 // prevent duplicate loading
17 // this is only a problem because we proxy existing functions
18 // and we don't want to double proxy them
56 focus: function( delay, fn ) {
57 return typeof delay === "number" ?
58 this.each(function() {
60 setTimeout(function() {
67 this._focus.apply( this, arguments );
70 scrollParent: function() {
72 if (($.ui.ie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
73 scrollParent = this.parents().filter(function() {
74 return (/(relative|absolute|fixed)/).test($.css(this,'position')) && (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
77 scrollParent = this.parents().filter(function() {
78 return (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
82 return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
85 zIndex: function( zIndex ) {
86 if ( zIndex !== undefined ) {
87 return this.css( "zIndex", zIndex );
91 var elem = $( this[ 0 ] ), position, value;
92 while ( elem.length && elem[ 0 ] !== document ) {
93 // Ignore z-index if position is set to a value where z-index is ignored by the browser
94 // This makes behavior of this function consistent across browsers
95 // WebKit always returns auto if the element is positioned
96 position = elem.css( "position" );
97 if ( position === "absolute" || position === "relative" || position === "fixed" ) {
98 // IE returns 0 when zIndex is not specified
99 // other browsers return a string
100 // we ignore the case of nested elements with an explicit value of 0
101 // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
102 value = parseInt( elem.css( "zIndex" ), 10 );
103 if ( !isNaN( value ) && value !== 0 ) {
107 elem = elem.parent();
114 uniqueId: function() {
115 return this.each(function() {
117 this.id = "ui-id-" + (++uuid);
122 removeUniqueId: function() {
123 return this.each(function() {
124 if ( runiqueId.test( this.id ) ) {
125 $( this ).removeAttr( "id" );
132 function focusable( element, isTabIndexNotNaN ) {
133 var map, mapName, img,
134 nodeName = element.nodeName.toLowerCase();
135 if ( "area" === nodeName ) {
136 map = element.parentNode;
138 if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
141 img = $( "img[usemap=#" + mapName + "]" )[0];
142 return !!img && visible( img );
144 return ( /input|select|textarea|button|object/.test( nodeName ) ?
147 element.href || isTabIndexNotNaN :
149 // the element and all of its ancestors must be visible
153 function visible( element ) {
154 return $.expr.filters.visible( element ) &&
155 !$( element ).parents().andSelf().filter(function() {
156 return $.css( this, "visibility" ) === "hidden";
160 $.extend( $.expr[ ":" ], {
161 data: $.expr.createPseudo ?
162 $.expr.createPseudo(function( dataName ) {
163 return function( elem ) {
164 return !!$.data( elem, dataName );
167 // support: jQuery <1.8
168 function( elem, i, match ) {
169 return !!$.data( elem, match[ 3 ] );
172 focusable: function( element ) {
173 return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
176 tabbable: function( element ) {
177 var tabIndex = $.attr( element, "tabindex" ),
178 isTabIndexNaN = isNaN( tabIndex );
179 return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
185 var body = document.body,
186 div = body.appendChild( div = document.createElement( "div" ) );
188 // access offsetHeight before setting the style to prevent a layout bug
189 // in IE 9 which causes the element to continue to take up space even
190 // after it is removed from the DOM (#8026)
193 $.extend( div.style, {
200 $.support.minHeight = div.offsetHeight === 100;
201 $.support.selectstart = "onselectstart" in div;
203 // set display to none to avoid a layout bug in IE
204 // http://dev.jquery.com/ticket/4014
205 body.removeChild( div ).style.display = "none";
208 // support: jQuery <1.8
209 if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
210 $.each( [ "Width", "Height" ], function( i, name ) {
211 var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
212 type = name.toLowerCase(),
214 innerWidth: $.fn.innerWidth,
215 innerHeight: $.fn.innerHeight,
216 outerWidth: $.fn.outerWidth,
217 outerHeight: $.fn.outerHeight
220 function reduce( elem, size, border, margin ) {
221 $.each( side, function() {
222 size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
224 size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
227 size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
233 $.fn[ "inner" + name ] = function( size ) {
234 if ( size === undefined ) {
235 return orig[ "inner" + name ].call( this );
238 return this.each(function() {
239 $( this ).css( type, reduce( this, size ) + "px" );
243 $.fn[ "outer" + name] = function( size, margin ) {
244 if ( typeof size !== "number" ) {
245 return orig[ "outer" + name ].call( this, size );
248 return this.each(function() {
249 $( this).css( type, reduce( this, size, true, margin ) + "px" );
255 // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
256 if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
257 $.fn.removeData = (function( removeData ) {
258 return function( key ) {
259 if ( arguments.length ) {
260 return removeData.call( this, $.camelCase( key ) );
262 return removeData.call( this );
265 })( $.fn.removeData );
275 var uaMatch = /msie ([\w.]+)/.exec( navigator.userAgent.toLowerCase() ) || [];
276 $.ui.ie = uaMatch.length ? true : false;
277 $.ui.ie6 = parseFloat( uaMatch[ 1 ], 10 ) === 6;
281 disableSelection: function() {
282 return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
283 ".ui-disableSelection", function( event ) {
284 event.preventDefault();
288 enableSelection: function() {
289 return this.unbind( ".ui-disableSelection" );
294 // $.ui.plugin is deprecated. Use the proxy pattern instead.
296 add: function( module, option, set ) {
298 proto = $.ui[ module ].prototype;
300 proto.plugins[ i ] = proto.plugins[ i ] || [];
301 proto.plugins[ i ].push( [ option, set[ i ] ] );
304 call: function( instance, name, args ) {
306 set = instance.plugins[ name ];
307 if ( !set || !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) {
311 for ( i = 0; i < set.length; i++ ) {
312 if ( instance.options[ set[ i ][ 0 ] ] ) {
313 set[ i ][ 1 ].apply( instance.element, args );
319 contains: $.contains,
321 // only used by resizable
322 hasScroll: function( el, a ) {
324 //If overflow is hidden, the element might have extra content, but the user wants to hide it
325 if ( $( el ).css( "overflow" ) === "hidden") {
329 var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
332 if ( el[ scroll ] > 0 ) {
336 // TODO: determine which cases actually cause this to happen
337 // if the element doesn't have the scroll set, see if it's possible to
340 has = ( el[ scroll ] > 0 );
345 // these are odd functions, fix the API or move into individual plugins
346 isOverAxis: function( x, reference, size ) {
347 //Determines when x coordinate is over "b" element axis
348 return ( x > reference ) && ( x < ( reference + size ) );
350 isOver: function( y, x, top, left, height, width ) {
351 //Determines when x, y coordinates is over "b" element
352 return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );