jquery.ui.core.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*!
  2. * jQuery UI 1.8.23
  3. *
  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
  7. *
  8. * http://docs.jquery.com/UI
  9. */
  10. (function( $, undefined ) {
  11. // prevent duplicate loading
  12. // this is only a problem because we proxy existing functions
  13. // and we don't want to double proxy them
  14. $.ui = $.ui || {};
  15. if ( $.ui.version ) {
  16. return;
  17. }
  18. $.extend( $.ui, {
  19. version: "1.8.23",
  20. keyCode: {
  21. ALT: 18,
  22. BACKSPACE: 8,
  23. CAPS_LOCK: 20,
  24. COMMA: 188,
  25. COMMAND: 91,
  26. COMMAND_LEFT: 91, // COMMAND
  27. COMMAND_RIGHT: 93,
  28. CONTROL: 17,
  29. DELETE: 46,
  30. DOWN: 40,
  31. END: 35,
  32. ENTER: 13,
  33. ESCAPE: 27,
  34. HOME: 36,
  35. INSERT: 45,
  36. LEFT: 37,
  37. MENU: 93, // COMMAND_RIGHT
  38. NUMPAD_ADD: 107,
  39. NUMPAD_DECIMAL: 110,
  40. NUMPAD_DIVIDE: 111,
  41. NUMPAD_ENTER: 108,
  42. NUMPAD_MULTIPLY: 106,
  43. NUMPAD_SUBTRACT: 109,
  44. PAGE_DOWN: 34,
  45. PAGE_UP: 33,
  46. PERIOD: 190,
  47. RIGHT: 39,
  48. SHIFT: 16,
  49. SPACE: 32,
  50. TAB: 9,
  51. UP: 38,
  52. WINDOWS: 91 // COMMAND
  53. }
  54. });
  55. // plugins
  56. $.fn.extend({
  57. propAttr: $.fn.prop || $.fn.attr,
  58. _focus: $.fn.focus,
  59. focus: function( delay, fn ) {
  60. return typeof delay === "number" ?
  61. this.each(function() {
  62. var elem = this;
  63. setTimeout(function() {
  64. $( elem ).focus();
  65. if ( fn ) {
  66. fn.call( elem );
  67. }
  68. }, delay );
  69. }) :
  70. this._focus.apply( this, arguments );
  71. },
  72. scrollParent: function() {
  73. var scrollParent;
  74. if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
  75. scrollParent = this.parents().filter(function() {
  76. 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));
  77. }).eq(0);
  78. } else {
  79. scrollParent = this.parents().filter(function() {
  80. return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
  81. }).eq(0);
  82. }
  83. return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
  84. },
  85. zIndex: function( zIndex ) {
  86. if ( zIndex !== undefined ) {
  87. return this.css( "zIndex", zIndex );
  88. }
  89. if ( this.length ) {
  90. var elem = $( this[ 0 ] ), position, value;
  91. while ( elem.length && elem[ 0 ] !== document ) {
  92. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  93. // This makes behavior of this function consistent across browsers
  94. // WebKit always returns auto if the element is positioned
  95. position = elem.css( "position" );
  96. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  97. // IE returns 0 when zIndex is not specified
  98. // other browsers return a string
  99. // we ignore the case of nested elements with an explicit value of 0
  100. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  101. value = parseInt( elem.css( "zIndex" ), 10 );
  102. if ( !isNaN( value ) && value !== 0 ) {
  103. return value;
  104. }
  105. }
  106. elem = elem.parent();
  107. }
  108. }
  109. return 0;
  110. },
  111. disableSelection: function() {
  112. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  113. ".ui-disableSelection", function( event ) {
  114. event.preventDefault();
  115. });
  116. },
  117. enableSelection: function() {
  118. return this.unbind( ".ui-disableSelection" );
  119. }
  120. });
  121. // support: jQuery <1.8
  122. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  123. $.each( [ "Width", "Height" ], function( i, name ) {
  124. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  125. type = name.toLowerCase(),
  126. orig = {
  127. innerWidth: $.fn.innerWidth,
  128. innerHeight: $.fn.innerHeight,
  129. outerWidth: $.fn.outerWidth,
  130. outerHeight: $.fn.outerHeight
  131. };
  132. function reduce( elem, size, border, margin ) {
  133. $.each( side, function() {
  134. size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
  135. if ( border ) {
  136. size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
  137. }
  138. if ( margin ) {
  139. size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
  140. }
  141. });
  142. return size;
  143. }
  144. $.fn[ "inner" + name ] = function( size ) {
  145. if ( size === undefined ) {
  146. return orig[ "inner" + name ].call( this );
  147. }
  148. return this.each(function() {
  149. $( this ).css( type, reduce( this, size ) + "px" );
  150. });
  151. };
  152. $.fn[ "outer" + name] = function( size, margin ) {
  153. if ( typeof size !== "number" ) {
  154. return orig[ "outer" + name ].call( this, size );
  155. }
  156. return this.each(function() {
  157. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  158. });
  159. };
  160. });
  161. }
  162. // selectors
  163. function focusable( element, isTabIndexNotNaN ) {
  164. var nodeName = element.nodeName.toLowerCase();
  165. if ( "area" === nodeName ) {
  166. var map = element.parentNode,
  167. mapName = map.name,
  168. img;
  169. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  170. return false;
  171. }
  172. img = $( "img[usemap=#" + mapName + "]" )[0];
  173. return !!img && visible( img );
  174. }
  175. return ( /input|select|textarea|button|object/.test( nodeName )
  176. ? !element.disabled
  177. : "a" == nodeName
  178. ? element.href || isTabIndexNotNaN
  179. : isTabIndexNotNaN)
  180. // the element and all of its ancestors must be visible
  181. && visible( element );
  182. }
  183. function visible( element ) {
  184. return !$( element ).parents().andSelf().filter(function() {
  185. return $.curCSS( this, "visibility" ) === "hidden" ||
  186. $.expr.filters.hidden( this );
  187. }).length;
  188. }
  189. $.extend( $.expr[ ":" ], {
  190. data: $.expr.createPseudo ?
  191. $.expr.createPseudo(function( dataName ) {
  192. return function( elem ) {
  193. return !!$.data( elem, dataName );
  194. };
  195. }) :
  196. // support: jQuery <1.8
  197. function( elem, i, match ) {
  198. return !!$.data( elem, match[ 3 ] );
  199. },
  200. focusable: function( element ) {
  201. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  202. },
  203. tabbable: function( element ) {
  204. var tabIndex = $.attr( element, "tabindex" ),
  205. isTabIndexNaN = isNaN( tabIndex );
  206. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  207. }
  208. });
  209. // support
  210. $(function() {
  211. var body = document.body,
  212. div = body.appendChild( div = document.createElement( "div" ) );
  213. // access offsetHeight before setting the style to prevent a layout bug
  214. // in IE 9 which causes the elemnt to continue to take up space even
  215. // after it is removed from the DOM (#8026)
  216. div.offsetHeight;
  217. $.extend( div.style, {
  218. minHeight: "100px",
  219. height: "auto",
  220. padding: 0,
  221. borderWidth: 0
  222. });
  223. $.support.minHeight = div.offsetHeight === 100;
  224. $.support.selectstart = "onselectstart" in div;
  225. // set display to none to avoid a layout bug in IE
  226. // http://dev.jquery.com/ticket/4014
  227. body.removeChild( div ).style.display = "none";
  228. });
  229. // jQuery <1.4.3 uses curCSS, in 1.4.3 - 1.7.2 curCSS = css, 1.8+ only has css
  230. if ( !$.curCSS ) {
  231. $.curCSS = $.css;
  232. }
  233. // deprecated
  234. $.extend( $.ui, {
  235. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  236. plugin: {
  237. add: function( module, option, set ) {
  238. var proto = $.ui[ module ].prototype;
  239. for ( var i in set ) {
  240. proto.plugins[ i ] = proto.plugins[ i ] || [];
  241. proto.plugins[ i ].push( [ option, set[ i ] ] );
  242. }
  243. },
  244. call: function( instance, name, args ) {
  245. var set = instance.plugins[ name ];
  246. if ( !set || !instance.element[ 0 ].parentNode ) {
  247. return;
  248. }
  249. for ( var i = 0; i < set.length; i++ ) {
  250. if ( instance.options[ set[ i ][ 0 ] ] ) {
  251. set[ i ][ 1 ].apply( instance.element, args );
  252. }
  253. }
  254. }
  255. },
  256. // will be deprecated when we switch to jQuery 1.4 - use jQuery.contains()
  257. contains: function( a, b ) {
  258. return document.compareDocumentPosition ?
  259. a.compareDocumentPosition( b ) & 16 :
  260. a !== b && a.contains( b );
  261. },
  262. // only used by resizable
  263. hasScroll: function( el, a ) {
  264. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  265. if ( $( el ).css( "overflow" ) === "hidden") {
  266. return false;
  267. }
  268. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  269. has = false;
  270. if ( el[ scroll ] > 0 ) {
  271. return true;
  272. }
  273. // TODO: determine which cases actually cause this to happen
  274. // if the element doesn't have the scroll set, see if it's possible to
  275. // set the scroll
  276. el[ scroll ] = 1;
  277. has = ( el[ scroll ] > 0 );
  278. el[ scroll ] = 0;
  279. return has;
  280. },
  281. // these are odd functions, fix the API or move into individual plugins
  282. isOverAxis: function( x, reference, size ) {
  283. //Determines when x coordinate is over "b" element axis
  284. return ( x > reference ) && ( x < ( reference + size ) );
  285. },
  286. isOver: function( y, x, top, left, height, width ) {
  287. //Determines when x, y coordinates is over "b" element
  288. return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
  289. }
  290. });
  291. })( jQuery );