jquery.validate-vsdoc.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. /*
  2. * This file has been commented to support Visual Studio Intellisense.
  3. * You should not use this file at runtime inside the browser--it is only
  4. * intended to be used only for design-time IntelliSense. Please use the
  5. * standard jQuery library for all production use.
  6. *
  7. * Comment version: 1.8
  8. */
  9. /*
  10. * Note: While Microsoft is not the author of this file, Microsoft is
  11. * offering you a license subject to the terms of the Microsoft Software
  12. * License Terms for Microsoft ASP.NET Model View Controller 3.
  13. * Microsoft reserves all other rights. The notices below are provided
  14. * for informational purposes only and are not the license terms under
  15. * which Microsoft distributed this file.
  16. *
  17. * jQuery validation plugin 1.8.0
  18. *
  19. * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
  20. * http://docs.jquery.com/Plugins/Validation
  21. *
  22. * Copyright (c) 2006 - 2011 Jörn Zaefferer
  23. *
  24. */
  25. (function($) {
  26. $.extend($.fn, {
  27. // http://docs.jquery.com/Plugins/Validation/validate
  28. validate: function( options ) {
  29. /// <summary>
  30. /// Validates the selected form. This method sets up event handlers for submit, focus,
  31. /// keyup, blur and click to trigger validation of the entire form or individual
  32. /// elements. Each one can be disabled, see the onxxx options (onsubmit, onfocusout,
  33. /// onkeyup, onclick). focusInvalid focuses elements when submitting a invalid form.
  34. /// </summary>
  35. /// <param name="options" type="Object">
  36. /// A set of key/value pairs that configure the validate. All options are optional.
  37. /// </param>
  38. // if nothing is selected, return nothing; can't chain anyway
  39. if (!this.length) {
  40. options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" );
  41. return;
  42. }
  43. // check if a validator for this form was already created
  44. var validator = $.data(this[0], 'validator');
  45. if ( validator ) {
  46. return validator;
  47. }
  48. validator = new $.validator( options, this[0] );
  49. $.data(this[0], 'validator', validator);
  50. if ( validator.settings.onsubmit ) {
  51. // allow suppresing validation by adding a cancel class to the submit button
  52. this.find("input, button").filter(".cancel").click(function() {
  53. validator.cancelSubmit = true;
  54. });
  55. // when a submitHandler is used, capture the submitting button
  56. if (validator.settings.submitHandler) {
  57. this.find("input, button").filter(":submit").click(function() {
  58. validator.submitButton = this;
  59. });
  60. }
  61. // validate the form on submit
  62. this.submit( function( event ) {
  63. if ( validator.settings.debug )
  64. // prevent form submit to be able to see console output
  65. event.preventDefault();
  66. function handle() {
  67. if ( validator.settings.submitHandler ) {
  68. if (validator.submitButton) {
  69. // insert a hidden input as a replacement for the missing submit button
  70. var hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);
  71. }
  72. validator.settings.submitHandler.call( validator, validator.currentForm );
  73. if (validator.submitButton) {
  74. // and clean up afterwards; thanks to no-block-scope, hidden can be referenced
  75. hidden.remove();
  76. }
  77. return false;
  78. }
  79. return true;
  80. }
  81. // prevent submit for invalid forms or custom submit handlers
  82. if ( validator.cancelSubmit ) {
  83. validator.cancelSubmit = false;
  84. return handle();
  85. }
  86. if ( validator.form() ) {
  87. if ( validator.pendingRequest ) {
  88. validator.formSubmitted = true;
  89. return false;
  90. }
  91. return handle();
  92. } else {
  93. validator.focusInvalid();
  94. return false;
  95. }
  96. });
  97. }
  98. return validator;
  99. },
  100. // http://docs.jquery.com/Plugins/Validation/valid
  101. valid: function() {
  102. /// <summary>
  103. /// Checks if the selected form is valid or if all selected elements are valid.
  104. /// validate() needs to be called on the form before checking it using this method.
  105. /// </summary>
  106. /// <returns type="Boolean" />
  107. if ( $(this[0]).is('form')) {
  108. return this.validate().form();
  109. } else {
  110. var valid = true;
  111. var validator = $(this[0].form).validate();
  112. this.each(function() {
  113. valid &= validator.element(this);
  114. });
  115. return valid;
  116. }
  117. },
  118. // attributes: space seperated list of attributes to retrieve and remove
  119. removeAttrs: function(attributes) {
  120. /// <summary>
  121. /// Remove the specified attributes from the first matched element and return them.
  122. /// </summary>
  123. /// <param name="attributes" type="String">
  124. /// A space-seperated list of attribute names to remove.
  125. /// </param>
  126. var result = {},
  127. $element = this;
  128. $.each(attributes.split(/\s/), function(index, value) {
  129. result[value] = $element.attr(value);
  130. $element.removeAttr(value);
  131. });
  132. return result;
  133. },
  134. // http://docs.jquery.com/Plugins/Validation/rules
  135. rules: function(command, argument) {
  136. /// <summary>
  137. /// Return the validations rules for the first selected element.
  138. /// </summary>
  139. /// <param name="command" type="String">
  140. /// Can be either "add" or "remove".
  141. /// </param>
  142. /// <param name="argument" type="">
  143. /// A list of rules to add or remove.
  144. /// </param>
  145. var element = this[0];
  146. if (command) {
  147. var settings = $.data(element.form, 'validator').settings;
  148. var staticRules = settings.rules;
  149. var existingRules = $.validator.staticRules(element);
  150. switch(command) {
  151. case "add":
  152. $.extend(existingRules, $.validator.normalizeRule(argument));
  153. staticRules[element.name] = existingRules;
  154. if (argument.messages)
  155. settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
  156. break;
  157. case "remove":
  158. if (!argument) {
  159. delete staticRules[element.name];
  160. return existingRules;
  161. }
  162. var filtered = {};
  163. $.each(argument.split(/\s/), function(index, method) {
  164. filtered[method] = existingRules[method];
  165. delete existingRules[method];
  166. });
  167. return filtered;
  168. }
  169. }
  170. var data = $.validator.normalizeRules(
  171. $.extend(
  172. {},
  173. $.validator.metadataRules(element),
  174. $.validator.classRules(element),
  175. $.validator.attributeRules(element),
  176. $.validator.staticRules(element)
  177. ), element);
  178. // make sure required is at front
  179. if (data.required) {
  180. var param = data.required;
  181. delete data.required;
  182. data = $.extend({required: param}, data);
  183. }
  184. return data;
  185. }
  186. });
  187. // Custom selectors
  188. $.extend($.expr[":"], {
  189. // http://docs.jquery.com/Plugins/Validation/blank
  190. blank: function(a) {return !$.trim("" + a.value);},
  191. // http://docs.jquery.com/Plugins/Validation/filled
  192. filled: function(a) {return !!$.trim("" + a.value);},
  193. // http://docs.jquery.com/Plugins/Validation/unchecked
  194. unchecked: function(a) {return !a.checked;}
  195. });
  196. // constructor for validator
  197. $.validator = function( options, form ) {
  198. this.settings = $.extend( true, {}, $.validator.defaults, options );
  199. this.currentForm = form;
  200. this.init();
  201. };
  202. $.validator.format = function(source, params) {
  203. /// <summary>
  204. /// Replaces {n} placeholders with arguments.
  205. /// One or more arguments can be passed, in addition to the string template itself, to insert
  206. /// into the string.
  207. /// </summary>
  208. /// <param name="source" type="String">
  209. /// The string to format.
  210. /// </param>
  211. /// <param name="params" type="String">
  212. /// The first argument to insert, or an array of Strings to insert
  213. /// </param>
  214. /// <returns type="String" />
  215. if ( arguments.length == 1 )
  216. return function() {
  217. var args = $.makeArray(arguments);
  218. args.unshift(source);
  219. return $.validator.format.apply( this, args );
  220. };
  221. if ( arguments.length > 2 && params.constructor != Array ) {
  222. params = $.makeArray(arguments).slice(1);
  223. }
  224. if ( params.constructor != Array ) {
  225. params = [ params ];
  226. }
  227. $.each(params, function(i, n) {
  228. source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
  229. });
  230. return source;
  231. };
  232. $.extend($.validator, {
  233. defaults: {
  234. messages: {},
  235. groups: {},
  236. rules: {},
  237. errorClass: "error",
  238. validClass: "valid",
  239. errorElement: "label",
  240. focusInvalid: true,
  241. errorContainer: $( [] ),
  242. errorLabelContainer: $( [] ),
  243. onsubmit: true,
  244. ignore: [],
  245. ignoreTitle: false,
  246. onfocusin: function(element) {
  247. this.lastActive = element;
  248. // hide error label and remove error class on focus if enabled
  249. if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
  250. this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
  251. this.addWrapper(this.errorsFor(element)).hide();
  252. }
  253. },
  254. onfocusout: function(element) {
  255. if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
  256. this.element(element);
  257. }
  258. },
  259. onkeyup: function(element) {
  260. if ( element.name in this.submitted || element == this.lastElement ) {
  261. this.element(element);
  262. }
  263. },
  264. onclick: function(element) {
  265. // click on selects, radiobuttons and checkboxes
  266. if ( element.name in this.submitted )
  267. this.element(element);
  268. // or option elements, check parent select in that case
  269. else if (element.parentNode.name in this.submitted)
  270. this.element(element.parentNode);
  271. },
  272. highlight: function( element, errorClass, validClass ) {
  273. $(element).addClass(errorClass).removeClass(validClass);
  274. },
  275. unhighlight: function( element, errorClass, validClass ) {
  276. $(element).removeClass(errorClass).addClass(validClass);
  277. }
  278. },
  279. // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
  280. setDefaults: function(settings) {
  281. /// <summary>
  282. /// Modify default settings for validation.
  283. /// Accepts everything that Plugins/Validation/validate accepts.
  284. /// </summary>
  285. /// <param name="settings" type="Options">
  286. /// Options to set as default.
  287. /// </param>
  288. $.extend( $.validator.defaults, settings );
  289. },
  290. messages: {
  291. required: "This field is required.",
  292. remote: "Please fix this field.",
  293. email: "Please enter a valid email address.",
  294. url: "Please enter a valid URL.",
  295. date: "Please enter a valid date.",
  296. dateISO: "Please enter a valid date (ISO).",
  297. number: "Please enter a valid number.",
  298. digits: "Please enter only digits.",
  299. creditcard: "Please enter a valid credit card number.",
  300. equalTo: "Please enter the same value again.",
  301. accept: "Please enter a value with a valid extension.",
  302. maxlength: $.validator.format("Please enter no more than {0} characters."),
  303. minlength: $.validator.format("Please enter at least {0} characters."),
  304. rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
  305. range: $.validator.format("Please enter a value between {0} and {1}."),
  306. max: $.validator.format("Please enter a value less than or equal to {0}."),
  307. min: $.validator.format("Please enter a value greater than or equal to {0}.")
  308. },
  309. autoCreateRanges: false,
  310. prototype: {
  311. init: function() {
  312. this.labelContainer = $(this.settings.errorLabelContainer);
  313. this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
  314. this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );
  315. this.submitted = {};
  316. this.valueCache = {};
  317. this.pendingRequest = 0;
  318. this.pending = {};
  319. this.invalid = {};
  320. this.reset();
  321. var groups = (this.groups = {});
  322. $.each(this.settings.groups, function(key, value) {
  323. $.each(value.split(/\s/), function(index, name) {
  324. groups[name] = key;
  325. });
  326. });
  327. var rules = this.settings.rules;
  328. $.each(rules, function(key, value) {
  329. rules[key] = $.validator.normalizeRule(value);
  330. });
  331. function delegate(event) {
  332. var validator = $.data(this[0].form, "validator"),
  333. eventType = "on" + event.type.replace(/^validate/, "");
  334. validator.settings[eventType] && validator.settings[eventType].call(validator, this[0] );
  335. }
  336. $(this.currentForm)
  337. .validateDelegate(":text, :password, :file, select, textarea", "focusin focusout keyup", delegate)
  338. .validateDelegate(":radio, :checkbox, select, option", "click", delegate);
  339. if (this.settings.invalidHandler)
  340. $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
  341. },
  342. // http://docs.jquery.com/Plugins/Validation/Validator/form
  343. form: function() {
  344. /// <summary>
  345. /// Validates the form, returns true if it is valid, false otherwise.
  346. /// This behaves as a normal submit event, but returns the result.
  347. /// </summary>
  348. /// <returns type="Boolean" />
  349. this.checkForm();
  350. $.extend(this.submitted, this.errorMap);
  351. this.invalid = $.extend({}, this.errorMap);
  352. if (!this.valid())
  353. $(this.currentForm).triggerHandler("invalid-form", [this]);
  354. this.showErrors();
  355. return this.valid();
  356. },
  357. checkForm: function() {
  358. this.prepareForm();
  359. for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
  360. this.check( elements[i] );
  361. }
  362. return this.valid();
  363. },
  364. // http://docs.jquery.com/Plugins/Validation/Validator/element
  365. element: function( element ) {
  366. /// <summary>
  367. /// Validates a single element, returns true if it is valid, false otherwise.
  368. /// This behaves as validation on blur or keyup, but returns the result.
  369. /// </summary>
  370. /// <param name="element" type="Selector">
  371. /// An element to validate, must be inside the validated form.
  372. /// </param>
  373. /// <returns type="Boolean" />
  374. element = this.clean( element );
  375. this.lastElement = element;
  376. this.prepareElement( element );
  377. this.currentElements = $(element);
  378. var result = this.check( element );
  379. if ( result ) {
  380. delete this.invalid[element.name];
  381. } else {
  382. this.invalid[element.name] = true;
  383. }
  384. if ( !this.numberOfInvalids() ) {
  385. // Hide error containers on last error
  386. this.toHide = this.toHide.add( this.containers );
  387. }
  388. this.showErrors();
  389. return result;
  390. },
  391. // http://docs.jquery.com/Plugins/Validation/Validator/showErrors
  392. showErrors: function(errors) {
  393. /// <summary>
  394. /// Show the specified messages.
  395. /// Keys have to refer to the names of elements, values are displayed for those elements, using the configured error placement.
  396. /// </summary>
  397. /// <param name="errors" type="Object">
  398. /// One or more key/value pairs of input names and messages.
  399. /// </param>
  400. if(errors) {
  401. // add items to error list and map
  402. $.extend( this.errorMap, errors );
  403. this.errorList = [];
  404. for ( var name in errors ) {
  405. this.errorList.push({
  406. message: errors[name],
  407. element: this.findByName(name)[0]
  408. });
  409. }
  410. // remove items from success list
  411. this.successList = $.grep( this.successList, function(element) {
  412. return !(element.name in errors);
  413. });
  414. }
  415. this.settings.showErrors
  416. ? this.settings.showErrors.call( this, this.errorMap, this.errorList )
  417. : this.defaultShowErrors();
  418. },
  419. // http://docs.jquery.com/Plugins/Validation/Validator/resetForm
  420. resetForm: function() {
  421. /// <summary>
  422. /// Resets the controlled form.
  423. /// Resets input fields to their original value (requires form plugin), removes classes
  424. /// indicating invalid elements and hides error messages.
  425. /// </summary>
  426. if ( $.fn.resetForm )
  427. $( this.currentForm ).resetForm();
  428. this.submitted = {};
  429. this.prepareForm();
  430. this.hideErrors();
  431. this.elements().removeClass( this.settings.errorClass );
  432. },
  433. numberOfInvalids: function() {
  434. /// <summary>
  435. /// Returns the number of invalid fields.
  436. /// This depends on the internal validator state. It covers all fields only after
  437. /// validating the complete form (on submit or via $("form").valid()). After validating
  438. /// a single element, only that element is counted. Most useful in combination with the
  439. /// invalidHandler-option.
  440. /// </summary>
  441. /// <returns type="Number" />
  442. return this.objectLength(this.invalid);
  443. },
  444. objectLength: function( obj ) {
  445. var count = 0;
  446. for ( var i in obj )
  447. count++;
  448. return count;
  449. },
  450. hideErrors: function() {
  451. this.addWrapper( this.toHide ).hide();
  452. },
  453. valid: function() {
  454. return this.size() == 0;
  455. },
  456. size: function() {
  457. return this.errorList.length;
  458. },
  459. focusInvalid: function() {
  460. if( this.settings.focusInvalid ) {
  461. try {
  462. $(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
  463. .filter(":visible")
  464. .focus()
  465. // manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
  466. .trigger("focusin");
  467. } catch(e) {
  468. // ignore IE throwing errors when focusing hidden elements
  469. }
  470. }
  471. },
  472. findLastActive: function() {
  473. var lastActive = this.lastActive;
  474. return lastActive && $.grep(this.errorList, function(n) {
  475. return n.element.name == lastActive.name;
  476. }).length == 1 && lastActive;
  477. },
  478. elements: function() {
  479. var validator = this,
  480. rulesCache = {};
  481. // select all valid inputs inside the form (no submit or reset buttons)
  482. // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved
  483. return $([]).add(this.currentForm.elements)
  484. .filter(":input")
  485. .not(":submit, :reset, :image, [disabled]")
  486. .not( this.settings.ignore )
  487. .filter(function() {
  488. !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this);
  489. // select only the first element for each name, and only those with rules specified
  490. if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
  491. return false;
  492. rulesCache[this.name] = true;
  493. return true;
  494. });
  495. },
  496. clean: function( selector ) {
  497. return $( selector )[0];
  498. },
  499. errors: function() {
  500. return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext );
  501. },
  502. reset: function() {
  503. this.successList = [];
  504. this.errorList = [];
  505. this.errorMap = {};
  506. this.toShow = $([]);
  507. this.toHide = $([]);
  508. this.currentElements = $([]);
  509. },
  510. prepareForm: function() {
  511. this.reset();
  512. this.toHide = this.errors().add( this.containers );
  513. },
  514. prepareElement: function( element ) {
  515. this.reset();
  516. this.toHide = this.errorsFor(element);
  517. },
  518. check: function( element ) {
  519. element = this.clean( element );
  520. // if radio/checkbox, validate first element in group instead
  521. if (this.checkable(element)) {
  522. element = this.findByName(element.name).not(this.settings.ignore)[0];
  523. }
  524. var rules = $(element).rules();
  525. var dependencyMismatch = false;
  526. for (var method in rules) {
  527. var rule = { method: method, parameters: rules[method] };
  528. try {
  529. var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );
  530. // if a method indicates that the field is optional and therefore valid,
  531. // don't mark it as valid when there are no other rules
  532. if ( result == "dependency-mismatch" ) {
  533. dependencyMismatch = true;
  534. continue;
  535. }
  536. dependencyMismatch = false;
  537. if ( result == "pending" ) {
  538. this.toHide = this.toHide.not( this.errorsFor(element) );
  539. return;
  540. }
  541. if( !result ) {
  542. this.formatAndAdd( element, rule );
  543. return false;
  544. }
  545. } catch(e) {
  546. this.settings.debug && window.console && console.log("exception occured when checking element " + element.id
  547. + ", check the '" + rule.method + "' method", e);
  548. throw e;
  549. }
  550. }
  551. if (dependencyMismatch)
  552. return;
  553. if ( this.objectLength(rules) )
  554. this.successList.push(element);
  555. return true;
  556. },
  557. // return the custom message for the given element and validation method
  558. // specified in the element's "messages" metadata
  559. customMetaMessage: function(element, method) {
  560. if (!$.metadata)
  561. return;
  562. var meta = this.settings.meta
  563. ? $(element).metadata()[this.settings.meta]
  564. : $(element).metadata();
  565. return meta && meta.messages && meta.messages[method];
  566. },
  567. // return the custom message for the given element name and validation method
  568. customMessage: function( name, method ) {
  569. var m = this.settings.messages[name];
  570. return m && (m.constructor == String
  571. ? m
  572. : m[method]);
  573. },
  574. // return the first defined argument, allowing empty strings
  575. findDefined: function() {
  576. for(var i = 0; i < arguments.length; i++) {
  577. if (arguments[i] !== undefined)
  578. return arguments[i];
  579. }
  580. return undefined;
  581. },
  582. defaultMessage: function( element, method) {
  583. return this.findDefined(
  584. this.customMessage( element.name, method ),
  585. this.customMetaMessage( element, method ),
  586. // title is never undefined, so handle empty string as undefined
  587. !this.settings.ignoreTitle && element.title || undefined,
  588. $.validator.messages[method],
  589. "<strong>Warning: No message defined for " + element.name + "</strong>"
  590. );
  591. },
  592. formatAndAdd: function( element, rule ) {
  593. var message = this.defaultMessage( element, rule.method ),
  594. theregex = /\$?\{(\d+)\}/g;
  595. if ( typeof message == "function" ) {
  596. message = message.call(this, rule.parameters, element);
  597. } else if (theregex.test(message)) {
  598. message = jQuery.format(message.replace(theregex, '{$1}'), rule.parameters);
  599. }
  600. this.errorList.push({
  601. message: message,
  602. element: element
  603. });
  604. this.errorMap[element.name] = message;
  605. this.submitted[element.name] = message;
  606. },
  607. addWrapper: function(toToggle) {
  608. if ( this.settings.wrapper )
  609. toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
  610. return toToggle;
  611. },
  612. defaultShowErrors: function() {
  613. for ( var i = 0; this.errorList[i]; i++ ) {
  614. var error = this.errorList[i];
  615. this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
  616. this.showLabel( error.element, error.message );
  617. }
  618. if( this.errorList.length ) {
  619. this.toShow = this.toShow.add( this.containers );
  620. }
  621. if (this.settings.success) {
  622. for ( var i = 0; this.successList[i]; i++ ) {
  623. this.showLabel( this.successList[i] );
  624. }
  625. }
  626. if (this.settings.unhighlight) {
  627. for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
  628. this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
  629. }
  630. }
  631. this.toHide = this.toHide.not( this.toShow );
  632. this.hideErrors();
  633. this.addWrapper( this.toShow ).show();
  634. },
  635. validElements: function() {
  636. return this.currentElements.not(this.invalidElements());
  637. },
  638. invalidElements: function() {
  639. return $(this.errorList).map(function() {
  640. return this.element;
  641. });
  642. },
  643. showLabel: function(element, message) {
  644. var label = this.errorsFor( element );
  645. if ( label.length ) {
  646. // refresh error/success class
  647. label.removeClass().addClass( this.settings.errorClass );
  648. // check if we have a generated label, replace the message then
  649. label.attr("generated") && label.html(message);
  650. } else {
  651. // create label
  652. label = $("<" + this.settings.errorElement + "/>")
  653. .attr({"for": this.idOrName(element), generated: true})
  654. .addClass(this.settings.errorClass)
  655. .html(message || "");
  656. if ( this.settings.wrapper ) {
  657. // make sure the element is visible, even in IE
  658. // actually showing the wrapped element is handled elsewhere
  659. label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
  660. }
  661. if ( !this.labelContainer.append(label).length )
  662. this.settings.errorPlacement
  663. ? this.settings.errorPlacement(label, $(element) )
  664. : label.insertAfter(element);
  665. }
  666. if ( !message && this.settings.success ) {
  667. label.text("");
  668. typeof this.settings.success == "string"
  669. ? label.addClass( this.settings.success )
  670. : this.settings.success( label );
  671. }
  672. this.toShow = this.toShow.add(label);
  673. },
  674. errorsFor: function(element) {
  675. var name = this.idOrName(element);
  676. return this.errors().filter(function() {
  677. return $(this).attr('for') == name;
  678. });
  679. },
  680. idOrName: function(element) {
  681. return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
  682. },
  683. checkable: function( element ) {
  684. return /radio|checkbox/i.test(element.type);
  685. },
  686. findByName: function( name ) {
  687. // select by name and filter by form for performance over form.find("[name=...]")
  688. var form = this.currentForm;
  689. return $(document.getElementsByName(name)).map(function(index, element) {
  690. return element.form == form && element.name == name && element || null;
  691. });
  692. },
  693. getLength: function(value, element) {
  694. switch( element.nodeName.toLowerCase() ) {
  695. case 'select':
  696. return $("option:selected", element).length;
  697. case 'input':
  698. if( this.checkable( element) )
  699. return this.findByName(element.name).filter(':checked').length;
  700. }
  701. return value.length;
  702. },
  703. depend: function(param, element) {
  704. return this.dependTypes[typeof param]
  705. ? this.dependTypes[typeof param](param, element)
  706. : true;
  707. },
  708. dependTypes: {
  709. "boolean": function(param, element) {
  710. return param;
  711. },
  712. "string": function(param, element) {
  713. return !!$(param, element.form).length;
  714. },
  715. "function": function(param, element) {
  716. return param(element);
  717. }
  718. },
  719. optional: function(element) {
  720. return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch";
  721. },
  722. startRequest: function(element) {
  723. if (!this.pending[element.name]) {
  724. this.pendingRequest++;
  725. this.pending[element.name] = true;
  726. }
  727. },
  728. stopRequest: function(element, valid) {
  729. this.pendingRequest--;
  730. // sometimes synchronization fails, make sure pendingRequest is never < 0
  731. if (this.pendingRequest < 0)
  732. this.pendingRequest = 0;
  733. delete this.pending[element.name];
  734. if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) {
  735. $(this.currentForm).submit();
  736. this.formSubmitted = false;
  737. } else if (!valid && this.pendingRequest == 0 && this.formSubmitted) {
  738. $(this.currentForm).triggerHandler("invalid-form", [this]);
  739. this.formSubmitted = false;
  740. }
  741. },
  742. previousValue: function(element) {
  743. return $.data(element, "previousValue") || $.data(element, "previousValue", {
  744. old: null,
  745. valid: true,
  746. message: this.defaultMessage( element, "remote" )
  747. });
  748. }
  749. },
  750. classRuleSettings: {
  751. required: {required: true},
  752. email: {email: true},
  753. url: {url: true},
  754. date: {date: true},
  755. dateISO: {dateISO: true},
  756. dateDE: {dateDE: true},
  757. number: {number: true},
  758. numberDE: {numberDE: true},
  759. digits: {digits: true},
  760. creditcard: {creditcard: true}
  761. },
  762. addClassRules: function(className, rules) {
  763. /// <summary>
  764. /// Add a compound class method - useful to refactor common combinations of rules into a single
  765. /// class.
  766. /// </summary>
  767. /// <param name="name" type="String">
  768. /// The name of the class rule to add
  769. /// </param>
  770. /// <param name="rules" type="Options">
  771. /// The compound rules
  772. /// </param>
  773. className.constructor == String ?
  774. this.classRuleSettings[className] = rules :
  775. $.extend(this.classRuleSettings, className);
  776. },
  777. classRules: function(element) {
  778. var rules = {};
  779. var classes = $(element).attr('class');
  780. classes && $.each(classes.split(' '), function() {
  781. if (this in $.validator.classRuleSettings) {
  782. $.extend(rules, $.validator.classRuleSettings[this]);
  783. }
  784. });
  785. return rules;
  786. },
  787. attributeRules: function(element) {
  788. var rules = {};
  789. var $element = $(element);
  790. for (var method in $.validator.methods) {
  791. var value = $element.attr(method);
  792. if (value) {
  793. rules[method] = value;
  794. }
  795. }
  796. // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
  797. if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
  798. delete rules.maxlength;
  799. }
  800. return rules;
  801. },
  802. metadataRules: function(element) {
  803. if (!$.metadata) return {};
  804. var meta = $.data(element.form, 'validator').settings.meta;
  805. return meta ?
  806. $(element).metadata()[meta] :
  807. $(element).metadata();
  808. },
  809. staticRules: function(element) {
  810. var rules = {};
  811. var validator = $.data(element.form, 'validator');
  812. if (validator.settings.rules) {
  813. rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
  814. }
  815. return rules;
  816. },
  817. normalizeRules: function(rules, element) {
  818. // handle dependency check
  819. $.each(rules, function(prop, val) {
  820. // ignore rule when param is explicitly false, eg. required:false
  821. if (val === false) {
  822. delete rules[prop];
  823. return;
  824. }
  825. if (val.param || val.depends) {
  826. var keepRule = true;
  827. switch (typeof val.depends) {
  828. case "string":
  829. keepRule = !!$(val.depends, element.form).length;
  830. break;
  831. case "function":
  832. keepRule = val.depends.call(element, element);
  833. break;
  834. }
  835. if (keepRule) {
  836. rules[prop] = val.param !== undefined ? val.param : true;
  837. } else {
  838. delete rules[prop];
  839. }
  840. }
  841. });
  842. // evaluate parameters
  843. $.each(rules, function(rule, parameter) {
  844. rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
  845. });
  846. // clean number parameters
  847. $.each(['minlength', 'maxlength', 'min', 'max'], function() {
  848. if (rules[this]) {
  849. rules[this] = Number(rules[this]);
  850. }
  851. });
  852. $.each(['rangelength', 'range'], function() {
  853. if (rules[this]) {
  854. rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
  855. }
  856. });
  857. if ($.validator.autoCreateRanges) {
  858. // auto-create ranges
  859. if (rules.min && rules.max) {
  860. rules.range = [rules.min, rules.max];
  861. delete rules.min;
  862. delete rules.max;
  863. }
  864. if (rules.minlength && rules.maxlength) {
  865. rules.rangelength = [rules.minlength, rules.maxlength];
  866. delete rules.minlength;
  867. delete rules.maxlength;
  868. }
  869. }
  870. // To support custom messages in metadata ignore rule methods titled "messages"
  871. if (rules.messages) {
  872. delete rules.messages;
  873. }
  874. return rules;
  875. },
  876. // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
  877. normalizeRule: function(data) {
  878. if( typeof data == "string" ) {
  879. var transformed = {};
  880. $.each(data.split(/\s/), function() {
  881. transformed[this] = true;
  882. });
  883. data = transformed;
  884. }
  885. return data;
  886. },
  887. // http://docs.jquery.com/Plugins/Validation/Validator/addMethod
  888. addMethod: function(name, method, message) {
  889. /// <summary>
  890. /// Add a custom validation method. It must consist of a name (must be a legal javascript
  891. /// identifier), a javascript based function and a default string message.
  892. /// </summary>
  893. /// <param name="name" type="String">
  894. /// The name of the method, used to identify and referencing it, must be a valid javascript
  895. /// identifier
  896. /// </param>
  897. /// <param name="method" type="Function">
  898. /// The actual method implementation, returning true if an element is valid
  899. /// </param>
  900. /// <param name="message" type="String" optional="true">
  901. /// (Optional) The default message to display for this method. Can be a function created by
  902. /// jQuery.validator.format(value). When undefined, an already existing message is used
  903. /// (handy for localization), otherwise the field-specific messages have to be defined.
  904. /// </param>
  905. $.validator.methods[name] = method;
  906. $.validator.messages[name] = message != undefined ? message : $.validator.messages[name];
  907. if (method.length < 3) {
  908. $.validator.addClassRules(name, $.validator.normalizeRule(name));
  909. }
  910. },
  911. methods: {
  912. // http://docs.jquery.com/Plugins/Validation/Methods/required
  913. required: function(value, element, param) {
  914. // check if dependency is met
  915. if ( !this.depend(param, element) )
  916. return "dependency-mismatch";
  917. switch( element.nodeName.toLowerCase() ) {
  918. case 'select':
  919. // could be an array for select-multiple or a string, both are fine this way
  920. var val = $(element).val();
  921. return val && val.length > 0;
  922. case 'input':
  923. if ( this.checkable(element) )
  924. return this.getLength(value, element) > 0;
  925. default:
  926. return $.trim(value).length > 0;
  927. }
  928. },
  929. // http://docs.jquery.com/Plugins/Validation/Methods/remote
  930. remote: function(value, element, param) {
  931. if ( this.optional(element) )
  932. return "dependency-mismatch";
  933. var previous = this.previousValue(element);
  934. if (!this.settings.messages[element.name] )
  935. this.settings.messages[element.name] = {};
  936. previous.originalMessage = this.settings.messages[element.name].remote;
  937. this.settings.messages[element.name].remote = previous.message;
  938. param = typeof param == "string" && {url:param} || param;
  939. if ( this.pending[element.name] ) {
  940. return "pending";
  941. }
  942. if ( previous.old === value ) {
  943. return previous.valid;
  944. }
  945. previous.old = value;
  946. var validator = this;
  947. this.startRequest(element);
  948. var data = {};
  949. data[element.name] = value;
  950. $.ajax($.extend(true, {
  951. url: param,
  952. mode: "abort",
  953. port: "validate" + element.name,
  954. dataType: "json",
  955. data: data,
  956. success: function(response) {
  957. validator.settings.messages[element.name].remote = previous.originalMessage;
  958. var valid = response === true;
  959. if ( valid ) {
  960. var submitted = validator.formSubmitted;
  961. validator.prepareElement(element);
  962. validator.formSubmitted = submitted;
  963. validator.successList.push(element);
  964. validator.showErrors();
  965. } else {
  966. var errors = {};
  967. var message = response || validator.defaultMessage(element, "remote");
  968. errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
  969. validator.showErrors(errors);
  970. }
  971. previous.valid = valid;
  972. validator.stopRequest(element, valid);
  973. }
  974. }, param));
  975. return "pending";
  976. },
  977. // http://docs.jquery.com/Plugins/Validation/Methods/minlength
  978. minlength: function(value, element, param) {
  979. return this.optional(element) || this.getLength($.trim(value), element) >= param;
  980. },
  981. // http://docs.jquery.com/Plugins/Validation/Methods/maxlength
  982. maxlength: function(value, element, param) {
  983. return this.optional(element) || this.getLength($.trim(value), element) <= param;
  984. },
  985. // http://docs.jquery.com/Plugins/Validation/Methods/rangelength
  986. rangelength: function(value, element, param) {
  987. var length = this.getLength($.trim(value), element);
  988. return this.optional(element) || ( length >= param[0] && length <= param[1] );
  989. },
  990. // http://docs.jquery.com/Plugins/Validation/Methods/min
  991. min: function( value, element, param ) {
  992. return this.optional(element) || value >= param;
  993. },
  994. // http://docs.jquery.com/Plugins/Validation/Methods/max
  995. max: function( value, element, param ) {
  996. return this.optional(element) || value <= param;
  997. },
  998. // http://docs.jquery.com/Plugins/Validation/Methods/range
  999. range: function( value, element, param ) {
  1000. return this.optional(element) || ( value >= param[0] && value <= param[1] );
  1001. },
  1002. // http://docs.jquery.com/Plugins/Validation/Methods/email
  1003. email: function(value, element) {
  1004. // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
  1005. return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
  1006. },
  1007. // http://docs.jquery.com/Plugins/Validation/Methods/url
  1008. url: function(value, element) {
  1009. // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
  1010. return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
  1011. },
  1012. // http://docs.jquery.com/Plugins/Validation/Methods/date
  1013. date: function(value, element) {
  1014. return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
  1015. },
  1016. // http://docs.jquery.com/Plugins/Validation/Methods/dateISO
  1017. dateISO: function(value, element) {
  1018. return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
  1019. },
  1020. // http://docs.jquery.com/Plugins/Validation/Methods/number
  1021. number: function(value, element) {
  1022. return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
  1023. },
  1024. // http://docs.jquery.com/Plugins/Validation/Methods/digits
  1025. digits: function(value, element) {
  1026. return this.optional(element) || /^\d+$/.test(value);
  1027. },
  1028. // http://docs.jquery.com/Plugins/Validation/Methods/creditcard
  1029. // based on http://en.wikipedia.org/wiki/Luhn
  1030. creditcard: function(value, element) {
  1031. if ( this.optional(element) )
  1032. return "dependency-mismatch";
  1033. // accept only digits and dashes
  1034. if (/[^0-9-]+/.test(value))
  1035. return false;
  1036. var nCheck = 0,
  1037. nDigit = 0,
  1038. bEven = false;
  1039. value = value.replace(/\D/g, "");
  1040. for (var n = value.length - 1; n >= 0; n--) {
  1041. var cDigit = value.charAt(n);
  1042. var nDigit = parseInt(cDigit, 10);
  1043. if (bEven) {
  1044. if ((nDigit *= 2) > 9)
  1045. nDigit -= 9;
  1046. }
  1047. nCheck += nDigit;
  1048. bEven = !bEven;
  1049. }
  1050. return (nCheck % 10) == 0;
  1051. },
  1052. // http://docs.jquery.com/Plugins/Validation/Methods/accept
  1053. accept: function(value, element, param) {
  1054. param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
  1055. return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
  1056. },
  1057. // http://docs.jquery.com/Plugins/Validation/Methods/equalTo
  1058. equalTo: function(value, element, param) {
  1059. // bind to the blur event of the target in order to revalidate whenever the target field is updated
  1060. // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
  1061. var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
  1062. $(element).valid();
  1063. });
  1064. return value == target.val();
  1065. }
  1066. }
  1067. });
  1068. // deprecated, use $.validator.format instead
  1069. $.format = $.validator.format;
  1070. })(jQuery);
  1071. // ajax mode: abort
  1072. // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
  1073. // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
  1074. ;(function($) {
  1075. var pendingRequests = {};
  1076. // Use a prefilter if available (1.5+)
  1077. if ( $.ajaxPrefilter ) {
  1078. $.ajaxPrefilter(function(settings, _, xhr) {
  1079. var port = settings.port;
  1080. if (settings.mode == "abort") {
  1081. if ( pendingRequests[port] ) {
  1082. pendingRequests[port].abort();
  1083. } pendingRequests[port] = xhr;
  1084. }
  1085. });
  1086. } else {
  1087. // Proxy ajax
  1088. var ajax = $.ajax;
  1089. $.ajax = function(settings) {
  1090. var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
  1091. port = ( "port" in settings ? settings : $.ajaxSettings ).port;
  1092. if (mode == "abort") {
  1093. if ( pendingRequests[port] ) {
  1094. pendingRequests[port].abort();
  1095. }
  1096. return (pendingRequests[port] = ajax.apply(this, arguments));
  1097. }
  1098. return ajax.apply(this, arguments);
  1099. };
  1100. }
  1101. })(jQuery);
  1102. // provides cross-browser focusin and focusout events
  1103. // IE has native support, in other browsers, use event caputuring (neither bubbles)
  1104. // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
  1105. // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
  1106. ;(function($) {
  1107. // only implement if not provided by jQuery core (since 1.4)
  1108. // TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs
  1109. if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {
  1110. $.each({
  1111. focus: 'focusin',
  1112. blur: 'focusout'
  1113. }, function( original, fix ){
  1114. $.event.special[fix] = {
  1115. setup:function() {
  1116. this.addEventListener( original, handler, true );
  1117. },
  1118. teardown:function() {
  1119. this.removeEventListener( original, handler, true );
  1120. },
  1121. handler: function(e) {
  1122. arguments[0] = $.event.fix(e);
  1123. arguments[0].type = fix;
  1124. return $.event.handle.apply(this, arguments);
  1125. }
  1126. };
  1127. function handler(e) {
  1128. e = $.event.fix(e);
  1129. e.type = fix;
  1130. return $.event.handle.call(this, e);
  1131. }
  1132. });
  1133. };
  1134. $.extend($.fn, {
  1135. validateDelegate: function(delegate, type, handler) {
  1136. return this.bind(type, function(event) {
  1137. var target = $(event.target);
  1138. if (target.is(delegate)) {
  1139. return handler.apply(target, arguments);
  1140. }
  1141. });
  1142. }
  1143. });
  1144. })(jQuery);