4 * Copyright 2011, 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
62 focus: function( delay, fn ) {
63 return typeof delay === "number" ?
64 this.each(function() {
66 setTimeout(function() {
73 this._focus.apply( this, arguments );
76 scrollParent: function() {
78 if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
79 scrollParent = this.parents().filter(function() {
80 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));
83 scrollParent = this.parents().filter(function() {
84 return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
88 return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
91 zIndex: function( zIndex ) {
92 if ( zIndex !== undefined ) {
93 return this.css( "zIndex", zIndex );
97 var elem = $( this[ 0 ] ), position, value;
98 while ( elem.length && elem[ 0 ] !== document ) {
99 // Ignore z-index if position is set to a value where z-index is ignored by the browser
100 // This makes behavior of this function consistent across browsers
101 // WebKit always returns auto if the element is positioned
102 position = elem.css( "position" );
103 if ( position === "absolute" || position === "relative" || position === "fixed" ) {
104 // IE returns 0 when zIndex is not specified
105 // other browsers return a string
106 // we ignore the case of nested elements with an explicit value of 0
107 // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
108 value = parseInt( elem.css( "zIndex" ), 10 );
109 if ( !isNaN( value ) && value !== 0 ) {
113 elem = elem.parent();
120 disableSelection: function() {
121 return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
122 ".ui-disableSelection", function( event ) {
123 event.preventDefault();
127 enableSelection: function() {
128 return this.unbind( ".ui-disableSelection" );
132 $.each( [ "Width", "Height" ], function( i, name ) {
133 var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
134 type = name.toLowerCase(),
136 innerWidth: $.fn.innerWidth,
137 innerHeight: $.fn.innerHeight,
138 outerWidth: $.fn.outerWidth,
139 outerHeight: $.fn.outerHeight
142 function reduce( elem, size, border, margin ) {
143 $.each( side, function() {
144 size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
146 size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
149 size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
155 $.fn[ "inner" + name ] = function( size ) {
156 if ( size === undefined ) {
157 return orig[ "inner" + name ].call( this );
160 return this.each(function() {
161 $( this ).css( type, reduce( this, size ) + "px" );
165 $.fn[ "outer" + name] = function( size, margin ) {
166 if ( typeof size !== "number" ) {
167 return orig[ "outer" + name ].call( this, size );
170 return this.each(function() {
171 $( this).css( type, reduce( this, size, true, margin ) + "px" );
177 function visible( element ) {
178 return !$( element ).parents().andSelf().filter(function() {
179 return $.curCSS( this, "visibility" ) === "hidden" ||
180 $.expr.filters.hidden( this );
184 $.extend( $.expr[ ":" ], {
185 data: function( elem, i, match ) {
186 return !!$.data( elem, match[ 3 ] );
189 focusable: function( element ) {
190 var nodeName = element.nodeName.toLowerCase(),
191 tabIndex = $.attr( element, "tabindex" );
192 if ( "area" === nodeName ) {
193 var map = element.parentNode,
196 if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
199 img = $( "img[usemap=#" + mapName + "]" )[0];
200 return !!img && visible( img );
202 return ( /input|select|textarea|button|object/.test( nodeName )
205 ? element.href || !isNaN( tabIndex )
206 : !isNaN( tabIndex ))
207 // the element and all of its ancestors must be visible
208 && visible( element );
211 tabbable: function( element ) {
212 var tabIndex = $.attr( element, "tabindex" );
213 return ( isNaN( tabIndex ) || tabIndex >= 0 ) && $( element ).is( ":focusable" );
219 var body = document.body,
220 div = body.appendChild( div = document.createElement( "div" ) );
222 $.extend( div.style, {
229 $.support.minHeight = div.offsetHeight === 100;
230 $.support.selectstart = "onselectstart" in div;
232 // set display to none to avoid a layout bug in IE
233 // http://dev.jquery.com/ticket/4014
234 body.removeChild( div ).style.display = "none";
243 // $.ui.plugin is deprecated. Use the proxy pattern instead.
245 add: function( module, option, set ) {
246 var proto = $.ui[ module ].prototype;
247 for ( var i in set ) {
248 proto.plugins[ i ] = proto.plugins[ i ] || [];
249 proto.plugins[ i ].push( [ option, set[ i ] ] );
252 call: function( instance, name, args ) {
253 var set = instance.plugins[ name ];
254 if ( !set || !instance.element[ 0 ].parentNode ) {
258 for ( var i = 0; i < set.length; i++ ) {
259 if ( instance.options[ set[ i ][ 0 ] ] ) {
260 set[ i ][ 1 ].apply( instance.element, args );
266 // will be deprecated when we switch to jQuery 1.4 - use jQuery.contains()
267 contains: function( a, b ) {
268 return document.compareDocumentPosition ?
269 a.compareDocumentPosition( b ) & 16 :
270 a !== b && a.contains( b );
273 // only used by resizable
274 hasScroll: function( el, a ) {
276 //If overflow is hidden, the element might have extra content, but the user wants to hide it
277 if ( $( el ).css( "overflow" ) === "hidden") {
281 var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
284 if ( el[ scroll ] > 0 ) {
288 // TODO: determine which cases actually cause this to happen
289 // if the element doesn't have the scroll set, see if it's possible to
292 has = ( el[ scroll ] > 0 );
297 // these are odd functions, fix the API or move into individual plugins
298 isOverAxis: function( x, reference, size ) {
299 //Determines when x coordinate is over "b" element axis
300 return ( x > reference ) && ( x < ( reference + size ) );
302 isOver: function( y, x, top, left, height, width ) {
303 //Determines when x, y coordinates is over "b" element
304 return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );