jquery.ui.core.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*!
  2. * jQuery UI 1.8.11
  3. *
  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
  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.11",
  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. _focus: $.fn.focus,
  58. focus: function( delay, fn ) {
  59. return typeof delay === "number" ?
  60. this.each(function() {
  61. var elem = this;
  62. setTimeout(function() {
  63. $( elem ).focus();
  64. if ( fn ) {
  65. fn.call( elem );
  66. }
  67. }, delay );
  68. }) :
  69. this._focus.apply( this, arguments );
  70. },
  71. scrollParent: function() {
  72. var scrollParent;
  73. if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
  74. scrollParent = this.parents().filter(function() {
  75. 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));
  76. }).eq(0);
  77. } else {
  78. scrollParent = this.parents().filter(function() {
  79. return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
  80. }).eq(0);
  81. }
  82. return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
  83. },
  84. zIndex: function( zIndex ) {
  85. if ( zIndex !== undefined ) {
  86. return this.css( "zIndex", zIndex );
  87. }
  88. if ( this.length ) {
  89. var elem = $( this[ 0 ] ), position, value;
  90. while ( elem.length && elem[ 0 ] !== document ) {
  91. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  92. // This makes behavior of this function consistent across browsers
  93. // WebKit always returns auto if the element is positioned
  94. position = elem.css( "position" );
  95. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  96. // IE returns 0 when zIndex is not specified
  97. // other browsers return a string
  98. // we ignore the case of nested elements with an explicit value of 0
  99. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  100. value = parseInt( elem.css( "zIndex" ), 10 );
  101. if ( !isNaN( value ) && value !== 0 ) {
  102. return value;
  103. }
  104. }
  105. elem = elem.parent();
  106. }
  107. }
  108. return 0;
  109. },
  110. disableSelection: function() {
  111. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  112. ".ui-disableSelection", function( event ) {
  113. event.preventDefault();
  114. });
  115. },
  116. enableSelection: function() {
  117. return this.unbind( ".ui-disableSelection" );
  118. }
  119. });
  120. $.each( [ "Width", "Height" ], function( i, name ) {
  121. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  122. type = name.toLowerCase(),
  123. orig = {
  124. innerWidth: $.fn.innerWidth,
  125. innerHeight: $.fn.innerHeight,
  126. outerWidth: $.fn.outerWidth,
  127. outerHeight: $.fn.outerHeight
  128. };
  129. function reduce( elem, size, border, margin ) {
  130. $.each( side, function() {
  131. size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
  132. if ( border ) {
  133. size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
  134. }
  135. if ( margin ) {
  136. size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
  137. }
  138. });
  139. return size;
  140. }
  141. $.fn[ "inner" + name ] = function( size ) {
  142. if ( size === undefined ) {
  143. return orig[ "inner" + name ].call( this );
  144. }
  145. return this.each(function() {
  146. $( this ).css( type, reduce( this, size ) + "px" );
  147. });
  148. };
  149. $.fn[ "outer" + name] = function( size, margin ) {
  150. if ( typeof size !== "number" ) {
  151. return orig[ "outer" + name ].call( this, size );
  152. }
  153. return this.each(function() {
  154. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  155. });
  156. };
  157. });
  158. // selectors
  159. function visible( element ) {
  160. return !$( element ).parents().andSelf().filter(function() {
  161. return $.curCSS( this, "visibility" ) === "hidden" ||
  162. $.expr.filters.hidden( this );
  163. }).length;
  164. }
  165. $.extend( $.expr[ ":" ], {
  166. data: function( elem, i, match ) {
  167. return !!$.data( elem, match[ 3 ] );
  168. },
  169. focusable: function( element ) {
  170. var nodeName = element.nodeName.toLowerCase(),
  171. tabIndex = $.attr( element, "tabindex" );
  172. if ( "area" === nodeName ) {
  173. var map = element.parentNode,
  174. mapName = map.name,
  175. img;
  176. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  177. return false;
  178. }
  179. img = $( "img[usemap=#" + mapName + "]" )[0];
  180. return !!img && visible( img );
  181. }
  182. return ( /input|select|textarea|button|object/.test( nodeName )
  183. ? !element.disabled
  184. : "a" == nodeName
  185. ? element.href || !isNaN( tabIndex )
  186. : !isNaN( tabIndex ))
  187. // the element and all of its ancestors must be visible
  188. && visible( element );
  189. },
  190. tabbable: function( element ) {
  191. var tabIndex = $.attr( element, "tabindex" );
  192. return ( isNaN( tabIndex ) || tabIndex >= 0 ) && $( element ).is( ":focusable" );
  193. }
  194. });
  195. // support
  196. $(function() {
  197. var body = document.body,
  198. div = body.appendChild( div = document.createElement( "div" ) );
  199. $.extend( div.style, {
  200. minHeight: "100px",
  201. height: "auto",
  202. padding: 0,
  203. borderWidth: 0
  204. });
  205. $.support.minHeight = div.offsetHeight === 100;
  206. $.support.selectstart = "onselectstart" in div;
  207. // set display to none to avoid a layout bug in IE
  208. // http://dev.jquery.com/ticket/4014
  209. body.removeChild( div ).style.display = "none";
  210. });
  211. // deprecated
  212. $.extend( $.ui, {
  213. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  214. plugin: {
  215. add: function( module, option, set ) {
  216. var proto = $.ui[ module ].prototype;
  217. for ( var i in set ) {
  218. proto.plugins[ i ] = proto.plugins[ i ] || [];
  219. proto.plugins[ i ].push( [ option, set[ i ] ] );
  220. }
  221. },
  222. call: function( instance, name, args ) {
  223. var set = instance.plugins[ name ];
  224. if ( !set || !instance.element[ 0 ].parentNode ) {
  225. return;
  226. }
  227. for ( var i = 0; i < set.length; i++ ) {
  228. if ( instance.options[ set[ i ][ 0 ] ] ) {
  229. set[ i ][ 1 ].apply( instance.element, args );
  230. }
  231. }
  232. }
  233. },
  234. // will be deprecated when we switch to jQuery 1.4 - use jQuery.contains()
  235. contains: function( a, b ) {
  236. return document.compareDocumentPosition ?
  237. a.compareDocumentPosition( b ) & 16 :
  238. a !== b && a.contains( b );
  239. },
  240. // only used by resizable
  241. hasScroll: function( el, a ) {
  242. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  243. if ( $( el ).css( "overflow" ) === "hidden") {
  244. return false;
  245. }
  246. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  247. has = false;
  248. if ( el[ scroll ] > 0 ) {
  249. return true;
  250. }
  251. // TODO: determine which cases actually cause this to happen
  252. // if the element doesn't have the scroll set, see if it's possible to
  253. // set the scroll
  254. el[ scroll ] = 1;
  255. has = ( el[ scroll ] > 0 );
  256. el[ scroll ] = 0;
  257. return has;
  258. },
  259. // these are odd functions, fix the API or move into individual plugins
  260. isOverAxis: function( x, reference, size ) {
  261. //Determines when x coordinate is over "b" element axis
  262. return ( x > reference ) && ( x < ( reference + size ) );
  263. },
  264. isOver: function( y, x, top, left, height, width ) {
  265. //Determines when x, y coordinates is over "b" element
  266. return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
  267. }
  268. });
  269. })( jQuery );