29 isAbsUrl : function(s) { |
30 isAbsUrl : function(s) { |
30 return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$'); |
31 return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$'); |
31 }, |
32 }, |
32 |
33 |
33 isSize : function(s) { |
34 isSize : function(s) { |
34 return this.test(s, '^[0-9]+(%|in|cm|mm|em|ex|pt|pc|px)?$'); |
35 return this.test(s, '^[0-9.]+(%|in|cm|mm|em|ex|pt|pc|px)?$'); |
35 }, |
36 }, |
36 |
37 |
37 isId : function(s) { |
38 isId : function(s) { |
38 return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$'); |
39 return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$'); |
39 }, |
40 }, |
93 |
94 |
94 validate : function(f) { |
95 validate : function(f) { |
95 var i, nl, s = this.settings, c = 0; |
96 var i, nl, s = this.settings, c = 0; |
96 |
97 |
97 nl = this.tags(f, 'label'); |
98 nl = this.tags(f, 'label'); |
98 for (i=0; i<nl.length; i++) |
99 for (i=0; i<nl.length; i++) { |
99 this.removeClass(nl[i], s.invalid_cls); |
100 this.removeClass(nl[i], s.invalid_cls); |
|
101 nl[i].setAttribute('aria-invalid', false); |
|
102 } |
100 |
103 |
101 c += this.validateElms(f, 'input'); |
104 c += this.validateElms(f, 'input'); |
102 c += this.validateElms(f, 'select'); |
105 c += this.validateElms(f, 'select'); |
103 c += this.validateElms(f, 'textarea'); |
106 c += this.validateElms(f, 'textarea'); |
104 |
107 |
106 }, |
109 }, |
107 |
110 |
108 invalidate : function(n) { |
111 invalidate : function(n) { |
109 this.mark(n.form, n); |
112 this.mark(n.form, n); |
110 }, |
113 }, |
|
114 |
|
115 getErrorMessages : function(f) { |
|
116 var nl, i, s = this.settings, field, msg, values, messages = [], ed = tinyMCEPopup.editor; |
|
117 nl = this.tags(f, "label"); |
|
118 for (i=0; i<nl.length; i++) { |
|
119 if (this.hasClass(nl[i], s.invalid_cls)) { |
|
120 field = document.getElementById(nl[i].getAttribute("for")); |
|
121 values = { field: nl[i].textContent }; |
|
122 if (this.hasClass(field, s.min_cls, true)) { |
|
123 message = ed.getLang('invalid_data_min'); |
|
124 values.min = this.getNum(field, s.min_cls); |
|
125 } else if (this.hasClass(field, s.number_cls)) { |
|
126 message = ed.getLang('invalid_data_number'); |
|
127 } else if (this.hasClass(field, s.size_cls)) { |
|
128 message = ed.getLang('invalid_data_size'); |
|
129 } else { |
|
130 message = ed.getLang('invalid_data'); |
|
131 } |
|
132 |
|
133 message = message.replace(/{\#([^}]+)\}/g, function(a, b) { |
|
134 return values[b] || '{#' + b + '}'; |
|
135 }); |
|
136 messages.push(message); |
|
137 } |
|
138 } |
|
139 return messages; |
|
140 }, |
111 |
141 |
112 reset : function(e) { |
142 reset : function(e) { |
113 var t = ['label', 'input', 'select', 'textarea']; |
143 var t = ['label', 'input', 'select', 'textarea']; |
114 var i, j, nl, s = this.settings; |
144 var i, j, nl, s = this.settings; |
115 |
145 |
116 if (e == null) |
146 if (e == null) |
117 return; |
147 return; |
118 |
148 |
119 for (i=0; i<t.length; i++) { |
149 for (i=0; i<t.length; i++) { |
120 nl = this.tags(e.form ? e.form : e, t[i]); |
150 nl = this.tags(e.form ? e.form : e, t[i]); |
121 for (j=0; j<nl.length; j++) |
151 for (j=0; j<nl.length; j++) { |
122 this.removeClass(nl[j], s.invalid_cls); |
152 this.removeClass(nl[j], s.invalid_cls); |
|
153 nl[j].setAttribute('aria-invalid', false); |
|
154 } |
123 } |
155 } |
124 }, |
156 }, |
125 |
157 |
126 validateElms : function(f, e) { |
158 validateElms : function(f, e) { |
127 var nl, i, n, s = this.settings, st = true, va = Validator, v; |
159 var nl, i, n, s = this.settings, st = true, va = Validator, v; |