|
1 | 1 | ;(function(factory) {
|
2 |
| - typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) : |
| 2 | + typeof module === 'object' && module.exports ? module.exports = factory( require( 'jquery' ) ) : |
3 | 3 | typeof define === 'function' && define.amd ? define(['jquery'], factory) :
|
4 | 4 | factory(jQuery);
|
5 | 5 | }(function($, undefined) {
|
6 |
| - "use strict"; |
| 6 | + 'use strict'; |
7 | 7 |
|
8 | 8 | var NS = 'validator',
|
9 | 9 | CLS_NS = '.' + NS,
|
|
282 | 282 | }
|
283 | 283 | options = me._opt = options || {};
|
284 | 284 | dataOpt = attr(element, 'data-'+ NS +'-option');
|
285 |
| - dataOpt = me._dataOpt = dataOpt && dataOpt.charAt(0) === '{' ? (new Function("return " + dataOpt))() : {}; |
| 285 | + dataOpt = me._dataOpt = dataOpt && dataOpt.charAt(0) === '{' ? (new Function('return ' + dataOpt))() : {}; |
286 | 286 | themeOpt = me._themeOpt = themes[ options.theme || dataOpt.theme || defaults.theme ];
|
287 | 287 | opt = me.options = $.extend({}, defaults, fieldDefaults, themeOpt, me.options, options, dataOpt);
|
288 | 288 |
|
|
332 | 332 |
|
333 | 333 | if ( !(me.isAjaxSubmit = !!me.options.valid) ) {
|
334 | 334 | // if there is a "valid.form" event
|
335 |
| - var events = ($._data || $.data)(form, "events"); |
| 335 | + var events = ($._data || $.data)(form, 'events'); |
336 | 336 | me.isAjaxSubmit = issetEvent(events, 'valid', 'form') || issetEvent(events, 'submit', 'form-plugin');
|
337 | 337 | }
|
338 | 338 |
|
|
457 | 457 | var args = arguments;
|
458 | 458 | args[4] = args[4] || args[5];
|
459 | 459 | field._rules.push({
|
460 |
| - and: args[1] === "&", |
461 |
| - not: args[2] === "!", |
462 |
| - or: args[6] === "|", |
| 460 | + and: args[1] === '&', |
| 461 | + not: args[2] === '!', |
| 462 | + or: args[6] === '|', |
463 | 463 | method: args[3],
|
464 | 464 | params: args[4] ? $.map( args[4].split(', '), trim ) : undefined
|
465 | 465 | });
|
|
774 | 774 | me.showMsg(type)
|
775 | 775 | }
|
776 | 776 | else if ( type === 'tip' ) {
|
777 |
| - me.$el.find(INPUT_SELECTOR +"["+ DATA_TIP +"]", el).each(function(){ |
| 777 | + me.$el.find(INPUT_SELECTOR +'['+ DATA_TIP +']', el).each(function(){ |
778 | 778 | me.showMsg(this, {type: type, msg: msg});
|
779 | 779 | });
|
780 | 780 | }
|
|
890 | 890 | rule = field._rules[field._i];
|
891 | 891 | if (rule.not) {
|
892 | 892 | msg = undefined;
|
893 |
| - isValid = method === "required" || !isValid; |
| 893 | + isValid = method === 'required' || !isValid; |
894 | 894 | }
|
895 | 895 | if (rule.or) {
|
896 | 896 | if (isValid) {
|
|
995 | 995 | field._r = method;
|
996 | 996 |
|
997 | 997 | if (old && !field.must && !rule.must && rule.result !== undefined &&
|
998 |
| - old.ruleName === method && old.id === el.id && |
| 998 | + old.ruleName === method && old.id === el.id && |
999 | 999 | field.value && old.value === field.value )
|
1000 | 1000 | {
|
1001 | 1001 | // get result from cache
|
|
1408 | 1408 | },
|
1409 | 1409 | getValue: function() {
|
1410 | 1410 | var elem = this.element;
|
1411 |
| - if (elem.type === "number" && elem.validity && elem.validity.badInput) { |
| 1411 | + if (elem.type === 'number' && elem.validity && elem.validity.badInput) { |
1412 | 1412 | return 'NaN';
|
1413 | 1413 | }
|
1414 | 1414 | return $(elem)[this._valHook()]();
|
|
1516 | 1516 | var k, that = context ? context === true ? this : context : Rules.prototype;
|
1517 | 1517 |
|
1518 | 1518 | for (k in obj) {
|
1519 |
| - if (_checkRuleName(k)) |
| 1519 | + if (_checkRuleName(k)) { |
1520 | 1520 | that[k] = _getRule(obj[k]);
|
| 1521 | + } |
1521 | 1522 | }
|
1522 | 1523 | }
|
1523 | 1524 |
|
|
1591 | 1592 | function _getDataRule(el, method) {
|
1592 | 1593 | var fn = trim(attr(el, DATA_RULE + '-' + method));
|
1593 | 1594 |
|
1594 |
| - if ( fn && (fn = new Function("return " + fn)()) ) { |
| 1595 | + if ( fn && (fn = new Function('return ' + fn)()) ) { |
1595 | 1596 | return _getRule(fn);
|
1596 | 1597 | }
|
1597 | 1598 | }
|
|
1634 | 1635 |
|
1635 | 1636 | // Translate field key to jQuery selector.
|
1636 | 1637 | function _key2selector(key) {
|
1637 |
| - var isID = key.charAt(0) === "#"; |
1638 |
| - key = key.replace(/([:.{(|)}/\[\]])/g, "\\$1"); |
| 1638 | + var isID = key.charAt(0) === '#'; |
| 1639 | + key = key.replace(/([:.{(|)}/\[\]])/g, '\\$1'); |
1639 | 1640 | return isID ? key : '[name="'+ key +'"]:first';
|
1640 | 1641 | }
|
1641 | 1642 |
|
|
1676 | 1677 | });
|
1677 | 1678 |
|
1678 | 1679 | new Messages({
|
1679 |
| - fallback: "This field is not valid.", |
| 1680 | + fallback: 'This field is not valid.', |
1680 | 1681 | loading: 'Validating...'
|
1681 | 1682 | });
|
1682 | 1683 |
|
|
1830 | 1831 | }
|
1831 | 1832 |
|
1832 | 1833 | // If both fields are blank
|
1833 |
| - if (!me.required && a === "" && b === "") { |
| 1834 | + if (!me.required && a === '' && b === '') { |
1834 | 1835 | return null;
|
1835 | 1836 | }
|
1836 | 1837 |
|
|
1846 | 1847 | }
|
1847 | 1848 |
|
1848 | 1849 | // If the compared field is incorrect, we only ensure that this field is correct.
|
1849 |
| - if (type !== "eq" && !isNaN(+a) && isNaN(+b)) { |
| 1850 | + if (type !== 'eq' && !isNaN(+a) && isNaN(+b)) { |
1850 | 1851 | return true;
|
1851 | 1852 | }
|
1852 | 1853 |
|
|
2013 | 2014 | */
|
2014 | 2015 | filter: function(element, params) {
|
2015 | 2016 | var value = this.value,
|
2016 |
| - temp = value.replace( params ? (new RegExp("[" + params[0] + "]", "gm")) : rUnsafe, '' ); |
| 2017 | + temp = value.replace( params ? (new RegExp('[' + params[0] + ']', 'gm')) : rUnsafe, '' ); |
2017 | 2018 | if (temp !== value) this.setValue(temp);
|
2018 | 2019 | }
|
2019 | 2020 | });
|
|
0 commit comments