jquery-ui-core.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*!
  2. * jQuery UI Core @VERSION
  3. * http://jqueryui.com
  4. *
  5. * Copyright 2014 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( factory ) {
  12. if ( typeof define === "function" && define.amd ) {
  13. // AMD. Register as an anonymous module.
  14. define( [ "jquery" ], factory );
  15. } else {
  16. // Browser globals
  17. factory( jQuery );
  18. }
  19. }(function( $ ) {
  20. // $.ui might exist from components with no dependencies, e.g., $.ui.position
  21. $.ui = $.ui || {};
  22. $.extend( $.ui, {
  23. version: "@VERSION",
  24. keyCode: {
  25. BACKSPACE: 8,
  26. COMMA: 188,
  27. DELETE: 46,
  28. DOWN: 40,
  29. END: 35,
  30. ENTER: 13,
  31. ESCAPE: 27,
  32. HOME: 36,
  33. LEFT: 37,
  34. PAGE_DOWN: 34,
  35. PAGE_UP: 33,
  36. PERIOD: 190,
  37. RIGHT: 39,
  38. SPACE: 32,
  39. TAB: 9,
  40. UP: 38
  41. }
  42. });
  43. // plugins
  44. $.fn.extend({
  45. scrollParent: function() {
  46. var position = this.css( "position" ),
  47. excludeStaticParent = position === "absolute",
  48. scrollParent = this.parents().filter( function() {
  49. var parent = $( this );
  50. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  51. return false;
  52. }
  53. return (/(auto|scroll)/).test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) );
  54. }).eq( 0 );
  55. return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent;
  56. },
  57. uniqueId: (function() {
  58. var uuid = 0;
  59. return function() {
  60. return this.each(function() {
  61. if ( !this.id ) {
  62. this.id = "ui-id-" + ( ++uuid );
  63. }
  64. });
  65. };
  66. })(),
  67. removeUniqueId: function() {
  68. return this.each(function() {
  69. if ( /^ui-id-\d+$/.test( this.id ) ) {
  70. $( this ).removeAttr( "id" );
  71. }
  72. });
  73. }
  74. });
  75. // selectors
  76. function focusable( element, isTabIndexNotNaN ) {
  77. var map, mapName, img,
  78. nodeName = element.nodeName.toLowerCase();
  79. if ( "area" === nodeName ) {
  80. map = element.parentNode;
  81. mapName = map.name;
  82. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  83. return false;
  84. }
  85. img = $( "img[usemap='#" + mapName + "']" )[ 0 ];
  86. return !!img && visible( img );
  87. }
  88. return ( /input|select|textarea|button|object/.test( nodeName ) ?
  89. !element.disabled :
  90. "a" === nodeName ?
  91. element.href || isTabIndexNotNaN :
  92. isTabIndexNotNaN) &&
  93. // the element and all of its ancestors must be visible
  94. visible( element );
  95. }
  96. function visible( element ) {
  97. return $.expr.filters.visible( element ) &&
  98. !$( element ).parents().addBack().filter(function() {
  99. return $.css( this, "visibility" ) === "hidden";
  100. }).length;
  101. }
  102. $.extend( $.expr[ ":" ], {
  103. data: $.expr.createPseudo ?
  104. $.expr.createPseudo(function( dataName ) {
  105. return function( elem ) {
  106. return !!$.data( elem, dataName );
  107. };
  108. }) :
  109. // support: jQuery <1.8
  110. function( elem, i, match ) {
  111. return !!$.data( elem, match[ 3 ] );
  112. },
  113. focusable: function( element ) {
  114. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  115. },
  116. tabbable: function( element ) {
  117. var tabIndex = $.attr( element, "tabindex" ),
  118. isTabIndexNaN = isNaN( tabIndex );
  119. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  120. }
  121. });
  122. // support: jQuery <1.8
  123. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  124. $.each( [ "Width", "Height" ], function( i, name ) {
  125. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  126. type = name.toLowerCase(),
  127. orig = {
  128. innerWidth: $.fn.innerWidth,
  129. innerHeight: $.fn.innerHeight,
  130. outerWidth: $.fn.outerWidth,
  131. outerHeight: $.fn.outerHeight
  132. };
  133. function reduce( elem, size, border, margin ) {
  134. $.each( side, function() {
  135. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  136. if ( border ) {
  137. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  138. }
  139. if ( margin ) {
  140. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  141. }
  142. });
  143. return size;
  144. }
  145. $.fn[ "inner" + name ] = function( size ) {
  146. if ( size === undefined ) {
  147. return orig[ "inner" + name ].call( this );
  148. }
  149. return this.each(function() {
  150. $( this ).css( type, reduce( this, size ) + "px" );
  151. });
  152. };
  153. $.fn[ "outer" + name] = function( size, margin ) {
  154. if ( typeof size !== "number" ) {
  155. return orig[ "outer" + name ].call( this, size );
  156. }
  157. return this.each(function() {
  158. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  159. });
  160. };
  161. });
  162. }
  163. // support: jQuery <1.8
  164. if ( !$.fn.addBack ) {
  165. $.fn.addBack = function( selector ) {
  166. return this.add( selector == null ?
  167. this.prevObject : this.prevObject.filter( selector )
  168. );
  169. };
  170. }
  171. // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
  172. if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  173. $.fn.removeData = (function( removeData ) {
  174. return function( key ) {
  175. if ( arguments.length ) {
  176. return removeData.call( this, $.camelCase( key ) );
  177. } else {
  178. return removeData.call( this );
  179. }
  180. };
  181. })( $.fn.removeData );
  182. }
  183. // deprecated
  184. $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
  185. $.fn.extend({
  186. focus: (function( orig ) {
  187. return function( delay, fn ) {
  188. return typeof delay === "number" ?
  189. this.each(function() {
  190. var elem = this;
  191. setTimeout(function() {
  192. $( elem ).focus();
  193. if ( fn ) {
  194. fn.call( elem );
  195. }
  196. }, delay );
  197. }) :
  198. orig.apply( this, arguments );
  199. };
  200. })( $.fn.focus ),
  201. disableSelection: (function() {
  202. var eventType = "onselectstart" in document.createElement( "div" ) ?
  203. "selectstart" :
  204. "mousedown";
  205. return function() {
  206. return this.bind( eventType + ".ui-disableSelection", function( event ) {
  207. event.preventDefault();
  208. });
  209. };
  210. })(),
  211. enableSelection: function() {
  212. return this.unbind( ".ui-disableSelection" );
  213. },
  214. zIndex: function( zIndex ) {
  215. if ( zIndex !== undefined ) {
  216. return this.css( "zIndex", zIndex );
  217. }
  218. if ( this.length ) {
  219. var elem = $( this[ 0 ] ), position, value;
  220. while ( elem.length && elem[ 0 ] !== document ) {
  221. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  222. // This makes behavior of this function consistent across browsers
  223. // WebKit always returns auto if the element is positioned
  224. position = elem.css( "position" );
  225. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  226. // IE returns 0 when zIndex is not specified
  227. // other browsers return a string
  228. // we ignore the case of nested elements with an explicit value of 0
  229. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  230. value = parseInt( elem.css( "zIndex" ), 10 );
  231. if ( !isNaN( value ) && value !== 0 ) {
  232. return value;
  233. }
  234. }
  235. elem = elem.parent();
  236. }
  237. }
  238. return 0;
  239. }
  240. });
  241. // $.ui.plugin is deprecated. Use $.widget() extensions instead.
  242. $.ui.plugin = {
  243. add: function( module, option, set ) {
  244. var i,
  245. proto = $.ui[ module ].prototype;
  246. for ( i in set ) {
  247. proto.plugins[ i ] = proto.plugins[ i ] || [];
  248. proto.plugins[ i ].push( [ option, set[ i ] ] );
  249. }
  250. },
  251. call: function( instance, name, args, allowDisconnected ) {
  252. var i,
  253. set = instance.plugins[ name ];
  254. if ( !set ) {
  255. return;
  256. }
  257. if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) ) {
  258. return;
  259. }
  260. for ( i = 0; i < set.length; i++ ) {
  261. if ( instance.options[ set[ i ][ 0 ] ] ) {
  262. set[ i ][ 1 ].apply( instance.element, args );
  263. }
  264. }
  265. }
  266. };
  267. }));