jquery.ui.core.js 9.0 KB

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