You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery.ui.core.js 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*!
  2. * jQuery UI 1.8.20
  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.20",
  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. $.each( [ "Width", "Height" ], function( i, name ) {
  122. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  123. type = name.toLowerCase(),
  124. orig = {
  125. innerWidth: $.fn.innerWidth,
  126. innerHeight: $.fn.innerHeight,
  127. outerWidth: $.fn.outerWidth,
  128. outerHeight: $.fn.outerHeight
  129. };
  130. function reduce( elem, size, border, margin ) {
  131. $.each( side, function() {
  132. size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
  133. if ( border ) {
  134. size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
  135. }
  136. if ( margin ) {
  137. size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
  138. }
  139. });
  140. return size;
  141. }
  142. $.fn[ "inner" + name ] = function( size ) {
  143. if ( size === undefined ) {
  144. return orig[ "inner" + name ].call( this );
  145. }
  146. return this.each(function() {
  147. $( this ).css( type, reduce( this, size ) + "px" );
  148. });
  149. };
  150. $.fn[ "outer" + name] = function( size, margin ) {
  151. if ( typeof size !== "number" ) {
  152. return orig[ "outer" + name ].call( this, size );
  153. }
  154. return this.each(function() {
  155. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  156. });
  157. };
  158. });
  159. // selectors
  160. function focusable( element, isTabIndexNotNaN ) {
  161. var nodeName = element.nodeName.toLowerCase();
  162. if ( "area" === nodeName ) {
  163. var map = element.parentNode,
  164. mapName = map.name,
  165. img;
  166. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  167. return false;
  168. }
  169. img = $( "img[usemap=#" + mapName + "]" )[0];
  170. return !!img && visible( img );
  171. }
  172. return ( /input|select|textarea|button|object/.test( nodeName )
  173. ? !element.disabled
  174. : "a" == nodeName
  175. ? element.href || isTabIndexNotNaN
  176. : isTabIndexNotNaN)
  177. // the element and all of its ancestors must be visible
  178. && visible( element );
  179. }
  180. function visible( element ) {
  181. return !$( element ).parents().andSelf().filter(function() {
  182. return $.curCSS( this, "visibility" ) === "hidden" ||
  183. $.expr.filters.hidden( this );
  184. }).length;
  185. }
  186. $.extend( $.expr[ ":" ], {
  187. data: function( elem, i, match ) {
  188. return !!$.data( elem, match[ 3 ] );
  189. },
  190. focusable: function( element ) {
  191. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  192. },
  193. tabbable: function( element ) {
  194. var tabIndex = $.attr( element, "tabindex" ),
  195. isTabIndexNaN = isNaN( tabIndex );
  196. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  197. }
  198. });
  199. // support
  200. $(function() {
  201. var body = document.body,
  202. div = body.appendChild( div = document.createElement( "div" ) );
  203. // access offsetHeight before setting the style to prevent a layout bug
  204. // in IE 9 which causes the elemnt to continue to take up space even
  205. // after it is removed from the DOM (#8026)
  206. div.offsetHeight;
  207. $.extend( div.style, {
  208. minHeight: "100px",
  209. height: "auto",
  210. padding: 0,
  211. borderWidth: 0
  212. });
  213. $.support.minHeight = div.offsetHeight === 100;
  214. $.support.selectstart = "onselectstart" in div;
  215. // set display to none to avoid a layout bug in IE
  216. // http://dev.jquery.com/ticket/4014
  217. body.removeChild( div ).style.display = "none";
  218. });
  219. // deprecated
  220. $.extend( $.ui, {
  221. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  222. plugin: {
  223. add: function( module, option, set ) {
  224. var proto = $.ui[ module ].prototype;
  225. for ( var i in set ) {
  226. proto.plugins[ i ] = proto.plugins[ i ] || [];
  227. proto.plugins[ i ].push( [ option, set[ i ] ] );
  228. }
  229. },
  230. call: function( instance, name, args ) {
  231. var set = instance.plugins[ name ];
  232. if ( !set || !instance.element[ 0 ].parentNode ) {
  233. return;
  234. }
  235. for ( var i = 0; i < set.length; i++ ) {
  236. if ( instance.options[ set[ i ][ 0 ] ] ) {
  237. set[ i ][ 1 ].apply( instance.element, args );
  238. }
  239. }
  240. }
  241. },
  242. // will be deprecated when we switch to jQuery 1.4 - use jQuery.contains()
  243. contains: function( a, b ) {
  244. return document.compareDocumentPosition ?
  245. a.compareDocumentPosition( b ) & 16 :
  246. a !== b && a.contains( b );
  247. },
  248. // only used by resizable
  249. hasScroll: function( el, a ) {
  250. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  251. if ( $( el ).css( "overflow" ) === "hidden") {
  252. return false;
  253. }
  254. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  255. has = false;
  256. if ( el[ scroll ] > 0 ) {
  257. return true;
  258. }
  259. // TODO: determine which cases actually cause this to happen
  260. // if the element doesn't have the scroll set, see if it's possible to
  261. // set the scroll
  262. el[ scroll ] = 1;
  263. has = ( el[ scroll ] > 0 );
  264. el[ scroll ] = 0;
  265. return has;
  266. },
  267. // these are odd functions, fix the API or move into individual plugins
  268. isOverAxis: function( x, reference, size ) {
  269. //Determines when x coordinate is over "b" element axis
  270. return ( x > reference ) && ( x < ( reference + size ) );
  271. },
  272. isOver: function( y, x, top, left, height, width ) {
  273. //Determines when x, y coordinates is over "b" element
  274. return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
  275. }
  276. });
  277. })( jQuery );