Edit File by line
/home/barbar84/www/wp-inclu.../js/tinymce/utils
File: validate.js
/**
[0] Fix | Delete
* validate.js
[1] Fix | Delete
*
[2] Fix | Delete
* Released under LGPL License.
[3] Fix | Delete
* Copyright (c) 1999-2017 Ephox Corp. All rights reserved
[4] Fix | Delete
*
[5] Fix | Delete
* License: http://www.tinymce.com/license
[6] Fix | Delete
* Contributing: http://www.tinymce.com/contributing
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
// String validation:
[11] Fix | Delete
[12] Fix | Delete
if (!Validator.isEmail('myemail'))
[13] Fix | Delete
alert('Invalid email.');
[14] Fix | Delete
[15] Fix | Delete
// Form validation:
[16] Fix | Delete
[17] Fix | Delete
var f = document.forms['myform'];
[18] Fix | Delete
[19] Fix | Delete
if (!Validator.isEmail(f.myemail))
[20] Fix | Delete
alert('Invalid email.');
[21] Fix | Delete
*/
[22] Fix | Delete
[23] Fix | Delete
var Validator = {
[24] Fix | Delete
isEmail : function (s) {
[25] Fix | Delete
return this.test(s, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$');
[26] Fix | Delete
},
[27] Fix | Delete
[28] Fix | Delete
isAbsUrl : function (s) {
[29] Fix | Delete
return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$');
[30] Fix | Delete
},
[31] Fix | Delete
[32] Fix | Delete
isSize : function (s) {
[33] Fix | Delete
return this.test(s, '^[0-9.]+(%|in|cm|mm|em|ex|pt|pc|px)?$');
[34] Fix | Delete
},
[35] Fix | Delete
[36] Fix | Delete
isId : function (s) {
[37] Fix | Delete
return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$');
[38] Fix | Delete
},
[39] Fix | Delete
[40] Fix | Delete
isEmpty : function (s) {
[41] Fix | Delete
var nl, i;
[42] Fix | Delete
[43] Fix | Delete
if (s.nodeName == 'SELECT' && s.selectedIndex < 1) {
[44] Fix | Delete
return true;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
if (s.type == 'checkbox' && !s.checked) {
[48] Fix | Delete
return true;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
if (s.type == 'radio') {
[52] Fix | Delete
for (i = 0, nl = s.form.elements; i < nl.length; i++) {
[53] Fix | Delete
if (nl[i].type == "radio" && nl[i].name == s.name && nl[i].checked) {
[54] Fix | Delete
return false;
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
return true;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
return new RegExp('^\\s*$').test(s.nodeType == 1 ? s.value : s);
[62] Fix | Delete
},
[63] Fix | Delete
[64] Fix | Delete
isNumber : function (s, d) {
[65] Fix | Delete
return !isNaN(s.nodeType == 1 ? s.value : s) && (!d || !this.test(s, '^-?[0-9]*\\.[0-9]*$'));
[66] Fix | Delete
},
[67] Fix | Delete
[68] Fix | Delete
test : function (s, p) {
[69] Fix | Delete
s = s.nodeType == 1 ? s.value : s;
[70] Fix | Delete
[71] Fix | Delete
return s == '' || new RegExp(p).test(s);
[72] Fix | Delete
}
[73] Fix | Delete
};
[74] Fix | Delete
[75] Fix | Delete
var AutoValidator = {
[76] Fix | Delete
settings : {
[77] Fix | Delete
id_cls : 'id',
[78] Fix | Delete
int_cls : 'int',
[79] Fix | Delete
url_cls : 'url',
[80] Fix | Delete
number_cls : 'number',
[81] Fix | Delete
email_cls : 'email',
[82] Fix | Delete
size_cls : 'size',
[83] Fix | Delete
required_cls : 'required',
[84] Fix | Delete
invalid_cls : 'invalid',
[85] Fix | Delete
min_cls : 'min',
[86] Fix | Delete
max_cls : 'max'
[87] Fix | Delete
},
[88] Fix | Delete
[89] Fix | Delete
init : function (s) {
[90] Fix | Delete
var n;
[91] Fix | Delete
[92] Fix | Delete
for (n in s) {
[93] Fix | Delete
this.settings[n] = s[n];
[94] Fix | Delete
}
[95] Fix | Delete
},
[96] Fix | Delete
[97] Fix | Delete
validate : function (f) {
[98] Fix | Delete
var i, nl, s = this.settings, c = 0;
[99] Fix | Delete
[100] Fix | Delete
nl = this.tags(f, 'label');
[101] Fix | Delete
for (i = 0; i < nl.length; i++) {
[102] Fix | Delete
this.removeClass(nl[i], s.invalid_cls);
[103] Fix | Delete
nl[i].setAttribute('aria-invalid', false);
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
c += this.validateElms(f, 'input');
[107] Fix | Delete
c += this.validateElms(f, 'select');
[108] Fix | Delete
c += this.validateElms(f, 'textarea');
[109] Fix | Delete
[110] Fix | Delete
return c == 3;
[111] Fix | Delete
},
[112] Fix | Delete
[113] Fix | Delete
invalidate : function (n) {
[114] Fix | Delete
this.mark(n.form, n);
[115] Fix | Delete
},
[116] Fix | Delete
[117] Fix | Delete
getErrorMessages : function (f) {
[118] Fix | Delete
var nl, i, s = this.settings, field, msg, values, messages = [], ed = tinyMCEPopup.editor;
[119] Fix | Delete
nl = this.tags(f, "label");
[120] Fix | Delete
for (i = 0; i < nl.length; i++) {
[121] Fix | Delete
if (this.hasClass(nl[i], s.invalid_cls)) {
[122] Fix | Delete
field = document.getElementById(nl[i].getAttribute("for"));
[123] Fix | Delete
values = { field: nl[i].textContent };
[124] Fix | Delete
if (this.hasClass(field, s.min_cls, true)) {
[125] Fix | Delete
message = ed.getLang('invalid_data_min');
[126] Fix | Delete
values.min = this.getNum(field, s.min_cls);
[127] Fix | Delete
} else if (this.hasClass(field, s.number_cls)) {
[128] Fix | Delete
message = ed.getLang('invalid_data_number');
[129] Fix | Delete
} else if (this.hasClass(field, s.size_cls)) {
[130] Fix | Delete
message = ed.getLang('invalid_data_size');
[131] Fix | Delete
} else {
[132] Fix | Delete
message = ed.getLang('invalid_data');
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
message = message.replace(/{\#([^}]+)\}/g, function (a, b) {
[136] Fix | Delete
return values[b] || '{#' + b + '}';
[137] Fix | Delete
});
[138] Fix | Delete
messages.push(message);
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
return messages;
[142] Fix | Delete
},
[143] Fix | Delete
[144] Fix | Delete
reset : function (e) {
[145] Fix | Delete
var t = ['label', 'input', 'select', 'textarea'];
[146] Fix | Delete
var i, j, nl, s = this.settings;
[147] Fix | Delete
[148] Fix | Delete
if (e == null) {
[149] Fix | Delete
return;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
for (i = 0; i < t.length; i++) {
[153] Fix | Delete
nl = this.tags(e.form ? e.form : e, t[i]);
[154] Fix | Delete
for (j = 0; j < nl.length; j++) {
[155] Fix | Delete
this.removeClass(nl[j], s.invalid_cls);
[156] Fix | Delete
nl[j].setAttribute('aria-invalid', false);
[157] Fix | Delete
}
[158] Fix | Delete
}
[159] Fix | Delete
},
[160] Fix | Delete
[161] Fix | Delete
validateElms : function (f, e) {
[162] Fix | Delete
var nl, i, n, s = this.settings, st = true, va = Validator, v;
[163] Fix | Delete
[164] Fix | Delete
nl = this.tags(f, e);
[165] Fix | Delete
for (i = 0; i < nl.length; i++) {
[166] Fix | Delete
n = nl[i];
[167] Fix | Delete
[168] Fix | Delete
this.removeClass(n, s.invalid_cls);
[169] Fix | Delete
[170] Fix | Delete
if (this.hasClass(n, s.required_cls) && va.isEmpty(n)) {
[171] Fix | Delete
st = this.mark(f, n);
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
if (this.hasClass(n, s.number_cls) && !va.isNumber(n)) {
[175] Fix | Delete
st = this.mark(f, n);
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
if (this.hasClass(n, s.int_cls) && !va.isNumber(n, true)) {
[179] Fix | Delete
st = this.mark(f, n);
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
if (this.hasClass(n, s.url_cls) && !va.isAbsUrl(n)) {
[183] Fix | Delete
st = this.mark(f, n);
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
if (this.hasClass(n, s.email_cls) && !va.isEmail(n)) {
[187] Fix | Delete
st = this.mark(f, n);
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
if (this.hasClass(n, s.size_cls) && !va.isSize(n)) {
[191] Fix | Delete
st = this.mark(f, n);
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
if (this.hasClass(n, s.id_cls) && !va.isId(n)) {
[195] Fix | Delete
st = this.mark(f, n);
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
if (this.hasClass(n, s.min_cls, true)) {
[199] Fix | Delete
v = this.getNum(n, s.min_cls);
[200] Fix | Delete
[201] Fix | Delete
if (isNaN(v) || parseInt(n.value) < parseInt(v)) {
[202] Fix | Delete
st = this.mark(f, n);
[203] Fix | Delete
}
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
if (this.hasClass(n, s.max_cls, true)) {
[207] Fix | Delete
v = this.getNum(n, s.max_cls);
[208] Fix | Delete
[209] Fix | Delete
if (isNaN(v) || parseInt(n.value) > parseInt(v)) {
[210] Fix | Delete
st = this.mark(f, n);
[211] Fix | Delete
}
[212] Fix | Delete
}
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
return st;
[216] Fix | Delete
},
[217] Fix | Delete
[218] Fix | Delete
hasClass : function (n, c, d) {
[219] Fix | Delete
return new RegExp('\\b' + c + (d ? '[0-9]+' : '') + '\\b', 'g').test(n.className);
[220] Fix | Delete
},
[221] Fix | Delete
[222] Fix | Delete
getNum : function (n, c) {
[223] Fix | Delete
c = n.className.match(new RegExp('\\b' + c + '([0-9]+)\\b', 'g'))[0];
[224] Fix | Delete
c = c.replace(/[^0-9]/g, '');
[225] Fix | Delete
[226] Fix | Delete
return c;
[227] Fix | Delete
},
[228] Fix | Delete
[229] Fix | Delete
addClass : function (n, c, b) {
[230] Fix | Delete
var o = this.removeClass(n, c);
[231] Fix | Delete
n.className = b ? c + (o !== '' ? (' ' + o) : '') : (o !== '' ? (o + ' ') : '') + c;
[232] Fix | Delete
},
[233] Fix | Delete
[234] Fix | Delete
removeClass : function (n, c) {
[235] Fix | Delete
c = n.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ');
[236] Fix | Delete
return n.className = c !== ' ' ? c : '';
[237] Fix | Delete
},
[238] Fix | Delete
[239] Fix | Delete
tags : function (f, s) {
[240] Fix | Delete
return f.getElementsByTagName(s);
[241] Fix | Delete
},
[242] Fix | Delete
[243] Fix | Delete
mark : function (f, n) {
[244] Fix | Delete
var s = this.settings;
[245] Fix | Delete
[246] Fix | Delete
this.addClass(n, s.invalid_cls);
[247] Fix | Delete
n.setAttribute('aria-invalid', 'true');
[248] Fix | Delete
this.markLabels(f, n, s.invalid_cls);
[249] Fix | Delete
[250] Fix | Delete
return false;
[251] Fix | Delete
},
[252] Fix | Delete
[253] Fix | Delete
markLabels : function (f, n, ic) {
[254] Fix | Delete
var nl, i;
[255] Fix | Delete
[256] Fix | Delete
nl = this.tags(f, "label");
[257] Fix | Delete
for (i = 0; i < nl.length; i++) {
[258] Fix | Delete
if (nl[i].getAttribute("for") == n.id || nl[i].htmlFor == n.id) {
[259] Fix | Delete
this.addClass(nl[i], ic);
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
return null;
[264] Fix | Delete
}
[265] Fix | Delete
};
[266] Fix | Delete
[267] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function