PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/jquery-validate/demo/multipart/js/ui.core.js

#
JavaScript | 519 lines | 383 code | 83 blank | 53 comment | 89 complexity | 7ba404374e3e38ebd3e869c444a10fcd MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /*
  2. * jQuery UI 1.7.1
  3. *
  4. * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI
  9. */
  10. ;jQuery.ui || (function($) {
  11. var _remove = $.fn.remove,
  12. isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9);
  13. //Helper functions and ui object
  14. $.ui = {
  15. version: "1.7.1",
  16. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  17. plugin: {
  18. add: function(module, option, set) {
  19. var proto = $.ui[module].prototype;
  20. for(var i in set) {
  21. proto.plugins[i] = proto.plugins[i] || [];
  22. proto.plugins[i].push([option, set[i]]);
  23. }
  24. },
  25. call: function(instance, name, args) {
  26. var set = instance.plugins[name];
  27. if(!set || !instance.element[0].parentNode) { return; }
  28. for (var i = 0; i < set.length; i++) {
  29. if (instance.options[set[i][0]]) {
  30. set[i][1].apply(instance.element, args);
  31. }
  32. }
  33. }
  34. },
  35. contains: function(a, b) {
  36. return document.compareDocumentPosition
  37. ? a.compareDocumentPosition(b) & 16
  38. : a !== b && a.contains(b);
  39. },
  40. hasScroll: function(el, a) {
  41. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  42. if ($(el).css('overflow') == 'hidden') { return false; }
  43. var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
  44. has = false;
  45. if (el[scroll] > 0) { return true; }
  46. // TODO: determine which cases actually cause this to happen
  47. // if the element doesn't have the scroll set, see if it's possible to
  48. // set the scroll
  49. el[scroll] = 1;
  50. has = (el[scroll] > 0);
  51. el[scroll] = 0;
  52. return has;
  53. },
  54. isOverAxis: function(x, reference, size) {
  55. //Determines when x coordinate is over "b" element axis
  56. return (x > reference) && (x < (reference + size));
  57. },
  58. isOver: function(y, x, top, left, height, width) {
  59. //Determines when x, y coordinates is over "b" element
  60. return $.ui.isOverAxis(y, top, height) && $.ui.isOverAxis(x, left, width);
  61. },
  62. keyCode: {
  63. BACKSPACE: 8,
  64. CAPS_LOCK: 20,
  65. COMMA: 188,
  66. CONTROL: 17,
  67. DELETE: 46,
  68. DOWN: 40,
  69. END: 35,
  70. ENTER: 13,
  71. ESCAPE: 27,
  72. HOME: 36,
  73. INSERT: 45,
  74. LEFT: 37,
  75. NUMPAD_ADD: 107,
  76. NUMPAD_DECIMAL: 110,
  77. NUMPAD_DIVIDE: 111,
  78. NUMPAD_ENTER: 108,
  79. NUMPAD_MULTIPLY: 106,
  80. NUMPAD_SUBTRACT: 109,
  81. PAGE_DOWN: 34,
  82. PAGE_UP: 33,
  83. PERIOD: 190,
  84. RIGHT: 39,
  85. SHIFT: 16,
  86. SPACE: 32,
  87. TAB: 9,
  88. UP: 38
  89. }
  90. };
  91. // WAI-ARIA normalization
  92. if (isFF2) {
  93. var attr = $.attr,
  94. removeAttr = $.fn.removeAttr,
  95. ariaNS = "http://www.w3.org/2005/07/aaa",
  96. ariaState = /^aria-/,
  97. ariaRole = /^wairole:/;
  98. $.attr = function(elem, name, value) {
  99. var set = value !== undefined;
  100. return (name == 'role'
  101. ? (set
  102. ? attr.call(this, elem, name, "wairole:" + value)
  103. : (attr.apply(this, arguments) || "").replace(ariaRole, ""))
  104. : (ariaState.test(name)
  105. ? (set
  106. ? elem.setAttributeNS(ariaNS,
  107. name.replace(ariaState, "aaa:"), value)
  108. : attr.call(this, elem, name.replace(ariaState, "aaa:")))
  109. : attr.apply(this, arguments)));
  110. };
  111. $.fn.removeAttr = function(name) {
  112. return (ariaState.test(name)
  113. ? this.each(function() {
  114. this.removeAttributeNS(ariaNS, name.replace(ariaState, ""));
  115. }) : removeAttr.call(this, name));
  116. };
  117. }
  118. //jQuery plugins
  119. $.fn.extend({
  120. remove: function() {
  121. // Safari has a native remove event which actually removes DOM elements,
  122. // so we have to use triggerHandler instead of trigger (#3037).
  123. $("*", this).add(this).each(function() {
  124. $(this).triggerHandler("remove");
  125. });
  126. return _remove.apply(this, arguments );
  127. },
  128. enableSelection: function() {
  129. return this
  130. .attr('unselectable', 'off')
  131. .css('MozUserSelect', '')
  132. .unbind('selectstart.ui');
  133. },
  134. disableSelection: function() {
  135. return this
  136. .attr('unselectable', 'on')
  137. .css('MozUserSelect', 'none')
  138. .bind('selectstart.ui', function() { return false; });
  139. },
  140. scrollParent: function() {
  141. var scrollParent;
  142. if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
  143. scrollParent = this.parents().filter(function() {
  144. 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));
  145. }).eq(0);
  146. } else {
  147. scrollParent = this.parents().filter(function() {
  148. return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
  149. }).eq(0);
  150. }
  151. return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
  152. }
  153. });
  154. //Additional selectors
  155. $.extend($.expr[':'], {
  156. data: function(elem, i, match) {
  157. return !!$.data(elem, match[3]);
  158. },
  159. focusable: function(element) {
  160. var nodeName = element.nodeName.toLowerCase(),
  161. tabIndex = $.attr(element, 'tabindex');
  162. return (/input|select|textarea|button|object/.test(nodeName)
  163. ? !element.disabled
  164. : 'a' == nodeName || 'area' == nodeName
  165. ? element.href || !isNaN(tabIndex)
  166. : !isNaN(tabIndex))
  167. // the element and all of its ancestors must be visible
  168. // the browser may report that the area is hidden
  169. && !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
  170. },
  171. tabbable: function(element) {
  172. var tabIndex = $.attr(element, 'tabindex');
  173. return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
  174. }
  175. });
  176. // $.widget is a factory to create jQuery plugins
  177. // taking some boilerplate code out of the plugin code
  178. function getter(namespace, plugin, method, args) {
  179. function getMethods(type) {
  180. var methods = $[namespace][plugin][type] || [];
  181. return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
  182. }
  183. var methods = getMethods('getter');
  184. if (args.length == 1 && typeof args[0] == 'string') {
  185. methods = methods.concat(getMethods('getterSetter'));
  186. }
  187. return ($.inArray(method, methods) != -1);
  188. }
  189. $.widget = function(name, prototype) {
  190. var namespace = name.split(".")[0];
  191. name = name.split(".")[1];
  192. // create plugin method
  193. $.fn[name] = function(options) {
  194. var isMethodCall = (typeof options == 'string'),
  195. args = Array.prototype.slice.call(arguments, 1);
  196. // prevent calls to internal methods
  197. if (isMethodCall && options.substring(0, 1) == '_') {
  198. return this;
  199. }
  200. // handle getter methods
  201. if (isMethodCall && getter(namespace, name, options, args)) {
  202. var instance = $.data(this[0], name);
  203. return (instance ? instance[options].apply(instance, args)
  204. : undefined);
  205. }
  206. // handle initialization and non-getter methods
  207. return this.each(function() {
  208. var instance = $.data(this, name);
  209. // constructor
  210. (!instance && !isMethodCall &&
  211. $.data(this, name, new $[namespace][name](this, options))._init());
  212. // method call
  213. (instance && isMethodCall && $.isFunction(instance[options]) &&
  214. instance[options].apply(instance, args));
  215. });
  216. };
  217. // create widget constructor
  218. $[namespace] = $[namespace] || {};
  219. $[namespace][name] = function(element, options) {
  220. var self = this;
  221. this.namespace = namespace;
  222. this.widgetName = name;
  223. this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
  224. this.widgetBaseClass = namespace + '-' + name;
  225. this.options = $.extend({},
  226. $.widget.defaults,
  227. $[namespace][name].defaults,
  228. $.metadata && $.metadata.get(element)[name],
  229. options);
  230. this.element = $(element)
  231. .bind('setData.' + name, function(event, key, value) {
  232. if (event.target == element) {
  233. return self._setData(key, value);
  234. }
  235. })
  236. .bind('getData.' + name, function(event, key) {
  237. if (event.target == element) {
  238. return self._getData(key);
  239. }
  240. })
  241. .bind('remove', function() {
  242. return self.destroy();
  243. });
  244. };
  245. // add widget prototype
  246. $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
  247. // TODO: merge getter and getterSetter properties from widget prototype
  248. // and plugin prototype
  249. $[namespace][name].getterSetter = 'option';
  250. };
  251. $.widget.prototype = {
  252. _init: function() {},
  253. destroy: function() {
  254. this.element.removeData(this.widgetName)
  255. .removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
  256. .removeAttr('aria-disabled');
  257. },
  258. option: function(key, value) {
  259. var options = key,
  260. self = this;
  261. if (typeof key == "string") {
  262. if (value === undefined) {
  263. return this._getData(key);
  264. }
  265. options = {};
  266. options[key] = value;
  267. }
  268. $.each(options, function(key, value) {
  269. self._setData(key, value);
  270. });
  271. },
  272. _getData: function(key) {
  273. return this.options[key];
  274. },
  275. _setData: function(key, value) {
  276. this.options[key] = value;
  277. if (key == 'disabled') {
  278. this.element
  279. [value ? 'addClass' : 'removeClass'](
  280. this.widgetBaseClass + '-disabled' + ' ' +
  281. this.namespace + '-state-disabled')
  282. .attr("aria-disabled", value);
  283. }
  284. },
  285. enable: function() {
  286. this._setData('disabled', false);
  287. },
  288. disable: function() {
  289. this._setData('disabled', true);
  290. },
  291. _trigger: function(type, event, data) {
  292. var callback = this.options[type],
  293. eventName = (type == this.widgetEventPrefix
  294. ? type : this.widgetEventPrefix + type);
  295. event = $.Event(event);
  296. event.type = eventName;
  297. // copy original event properties over to the new event
  298. // this would happen if we could call $.event.fix instead of $.Event
  299. // but we don't have a way to force an event to be fixed multiple times
  300. if (event.originalEvent) {
  301. for (var i = $.event.props.length, prop; i;) {
  302. prop = $.event.props[--i];
  303. event[prop] = event.originalEvent[prop];
  304. }
  305. }
  306. this.element.trigger(event, data);
  307. return !($.isFunction(callback) && callback.call(this.element[0], event, data) === false
  308. || event.isDefaultPrevented());
  309. }
  310. };
  311. $.widget.defaults = {
  312. disabled: false
  313. };
  314. /** Mouse Interaction Plugin **/
  315. $.ui.mouse = {
  316. _mouseInit: function() {
  317. var self = this;
  318. this.element
  319. .bind('mousedown.'+this.widgetName, function(event) {
  320. return self._mouseDown(event);
  321. })
  322. .bind('click.'+this.widgetName, function(event) {
  323. if(self._preventClickEvent) {
  324. self._preventClickEvent = false;
  325. event.stopImmediatePropagation();
  326. return false;
  327. }
  328. });
  329. // Prevent text selection in IE
  330. if ($.browser.msie) {
  331. this._mouseUnselectable = this.element.attr('unselectable');
  332. this.element.attr('unselectable', 'on');
  333. }
  334. this.started = false;
  335. },
  336. // TODO: make sure destroying one instance of mouse doesn't mess with
  337. // other instances of mouse
  338. _mouseDestroy: function() {
  339. this.element.unbind('.'+this.widgetName);
  340. // Restore text selection in IE
  341. ($.browser.msie
  342. && this.element.attr('unselectable', this._mouseUnselectable));
  343. },
  344. _mouseDown: function(event) {
  345. // don't let more than one widget handle mouseStart
  346. // TODO: figure out why we have to use originalEvent
  347. event.originalEvent = event.originalEvent || {};
  348. if (event.originalEvent.mouseHandled) { return; }
  349. // we may have missed mouseup (out of window)
  350. (this._mouseStarted && this._mouseUp(event));
  351. this._mouseDownEvent = event;
  352. var self = this,
  353. btnIsLeft = (event.which == 1),
  354. elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
  355. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  356. return true;
  357. }
  358. this.mouseDelayMet = !this.options.delay;
  359. if (!this.mouseDelayMet) {
  360. this._mouseDelayTimer = setTimeout(function() {
  361. self.mouseDelayMet = true;
  362. }, this.options.delay);
  363. }
  364. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  365. this._mouseStarted = (this._mouseStart(event) !== false);
  366. if (!this._mouseStarted) {
  367. event.preventDefault();
  368. return true;
  369. }
  370. }
  371. // these delegates are required to keep context
  372. this._mouseMoveDelegate = function(event) {
  373. return self._mouseMove(event);
  374. };
  375. this._mouseUpDelegate = function(event) {
  376. return self._mouseUp(event);
  377. };
  378. $(document)
  379. .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  380. .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  381. // preventDefault() is used to prevent the selection of text here -
  382. // however, in Safari, this causes select boxes not to be selectable
  383. // anymore, so this fix is needed
  384. ($.browser.safari || event.preventDefault());
  385. event.originalEvent.mouseHandled = true;
  386. return true;
  387. },
  388. _mouseMove: function(event) {
  389. // IE mouseup check - mouseup happened when mouse was out of window
  390. if ($.browser.msie && !event.button) {
  391. return this._mouseUp(event);
  392. }
  393. if (this._mouseStarted) {
  394. this._mouseDrag(event);
  395. return event.preventDefault();
  396. }
  397. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  398. this._mouseStarted =
  399. (this._mouseStart(this._mouseDownEvent, event) !== false);
  400. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  401. }
  402. return !this._mouseStarted;
  403. },
  404. _mouseUp: function(event) {
  405. $(document)
  406. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  407. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  408. if (this._mouseStarted) {
  409. this._mouseStarted = false;
  410. this._preventClickEvent = (event.target == this._mouseDownEvent.target);
  411. this._mouseStop(event);
  412. }
  413. return false;
  414. },
  415. _mouseDistanceMet: function(event) {
  416. return (Math.max(
  417. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  418. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  419. ) >= this.options.distance
  420. );
  421. },
  422. _mouseDelayMet: function(event) {
  423. return this.mouseDelayMet;
  424. },
  425. // These are placeholder methods, to be overriden by extending plugin
  426. _mouseStart: function(event) {},
  427. _mouseDrag: function(event) {},
  428. _mouseStop: function(event) {},
  429. _mouseCapture: function(event) { return true; }
  430. };
  431. $.ui.mouse.defaults = {
  432. cancel: null,
  433. distance: 1,
  434. delay: 0
  435. };
  436. })(jQuery);