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 $.each( [ "Width", "Height" ], function( i, name ) {
135 var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
136 type = name.toLowerCase(),
138 innerWidth: $.fn.innerWidth,
139 innerHeight: $.fn.innerHeight,
140 outerWidth: $.fn.outerWidth,
141 outerHeight: $.fn.outerHeight
144 function reduce( elem, size, border, margin ) {
145 $.each( side, function() {
146 size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
148 size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
151 size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
157 $.fn[ "inner" + name ] = function( size ) {
158 if ( size === undefined ) {
159 return orig[ "inner" + name ].call( this );
162 return this.each(function() {
163 $( this ).css( type, reduce( this, size ) + "px" );
167 $.fn[ "outer" + name] = function( size, margin ) {
168 if ( typeof size !== "number" ) {
169 return orig[ "outer" + name ].call( this, size );
172 return this.each(function() {
173 $( this).css( type, reduce( this, size, true, margin ) + "px" );
179 function focusable( element, isTabIndexNotNaN ) {
180 var nodeName = element.nodeName.toLowerCase();
181 if ( "area" === nodeName ) {
182 var map = element.parentNode,
185 if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
188 img = $( "img[usemap=#" + mapName + "]" )[0];
189 return !!img && visible( img );
191 return ( /input|select|textarea|button|object/.test( nodeName )
194 ? element.href || isTabIndexNotNaN
196 // the element and all of its ancestors must be visible
197 && visible( element );
200 function visible( element ) {
201 return !$( element ).parents().andSelf().filter(function() {
202 return $.curCSS( this, "visibility" ) === "hidden" ||
203 $.expr.filters.hidden( this );
207 $.extend( $.expr[ ":" ], {
208 data: function( elem, i, match ) {
209 return !!$.data( elem, match[ 3 ] );
212 focusable: function( element ) {
213 return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
216 tabbable: function( element ) {
217 var tabIndex = $.attr( element, "tabindex" ),
218 isTabIndexNaN = isNaN( tabIndex );
219 return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
225 var body = document.body,
226 div = body.appendChild( div = document.createElement( "div" ) );
228 // access offsetHeight before setting the style to prevent a layout bug
229 // in IE 9 which causes the elemnt to continue to take up space even
230 // after it is removed from the DOM (#8026)
233 $.extend( div.style, {
240 $.support.minHeight = div.offsetHeight === 100;
241 $.support.selectstart = "onselectstart" in div;
243 // set display to none to avoid a layout bug in IE
244 // http://dev.jquery.com/ticket/4014
245 body.removeChild( div ).style.display = "none";
254 // $.ui.plugin is deprecated. Use the proxy pattern instead.
256 add: function( module, option, set ) {
257 var proto = $.ui[ module ].prototype;
258 for ( var i in set ) {
259 proto.plugins[ i ] = proto.plugins[ i ] || [];
260 proto.plugins[ i ].push( [ option, set[ i ] ] );
263 call: function( instance, name, args ) {
264 var set = instance.plugins[ name ];
265 if ( !set || !instance.element[ 0 ].parentNode ) {
269 for ( var i = 0; i < set.length; i++ ) {
270 if ( instance.options[ set[ i ][ 0 ] ] ) {
271 set[ i ][ 1 ].apply( instance.element, args );
277 // will be deprecated when we switch to jQuery 1.4 - use jQuery.contains()
278 contains: function( a, b ) {
279 return document.compareDocumentPosition ?
280 a.compareDocumentPosition( b ) & 16 :
281 a !== b && a.contains( b );
284 // only used by resizable
285 hasScroll: function( el, a ) {
287 //If overflow is hidden, the element might have extra content, but the user wants to hide it
288 if ( $( el ).css( "overflow" ) === "hidden") {
292 var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
295 if ( el[ scroll ] > 0 ) {
299 // TODO: determine which cases actually cause this to happen
300 // if the element doesn't have the scroll set, see if it's possible to
303 has = ( el[ scroll ] > 0 );
308 // these are odd functions, fix the API or move into individual plugins
309 isOverAxis: function( x, reference, size ) {
310 //Determines when x coordinate is over "b" element axis
311 return ( x > reference ) && ( x < ( reference + size ) );
313 isOver: function( y, x, top, left, height, width ) {
314 //Determines when x, y coordinates is over "b" element
315 return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );