PageSourceSearch

https://sprotin.fo/ease/3rdparty/js/Qodio/q.validator.jquery.js?v=3.28b.5-20_0

js sprotin.fo collected 2026-10-02 07:03:52 UTC 20,439 bytes, 469 lines download raw bytes

1/*
2 Validator jQuery Plugin
3 Validator is a JQuery validation plugin for forms.
4 version 1.11, Apr 25th, 2017
5 by Ingi á Steinamørk
6
7 The MIT License (MIT)
8
9 Copyright (c) 2013 QODIO
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy of
12 this software and associated documentation files (the "Software"), to deal in
13 the Software without restriction, including without limitation the rights to
14 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15 the Software, and to permit persons to whom the Software is furnished to do so,
16 subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
23 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
24 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29var Validator = {
30	elementErrorClass: 'error',
31	language: 'fo',
32	languages: {
33		'fo': {
34			textbox: {
35				required: 'Hetta økið er kravt',
36				min: 'Hetta økið skal í minsta lagi vera {characters} stavir',
37				max: 'Hetta økið skal í mesta lagi vera {characters} stavir',
38				email: 'Teldupost adressan er ikki gildig',
39				url: 'Vev adressan er ikki gildig',
40				number: 'Bert tøl eru loyvd',
41				digits: 'Bert tøl eru loyvd',
42				loweralpha: 'Bert smáair stavir eru loyvdir'
43			},
44			password: {
45				required: 'Hetta økið er kravt',
46				min: 'Hetta økið skal í minsta lagi vera {characters} stavir',
47				max: 'Hetta økið skal í mesta lagi vera {characters} stavir',
48				match: 'Loyniorðini eru ikki líka'
49			},
50			radio: {
51			},
52			checkbox: {
53				required: 'Hesin avkrossingarteigur er kravdur'
54			},
55			file: {
56				required: 'Ein fíla er kravd'
57			},
58			select: {
59				required: 'Vel eitt virði í hesum vallista'
60			},
61			textarea: {
62				required: 'Hetta økið er kravt',
63				min: 'Hetta økið skal í minsta lagi vera {characters} stavir',
64				max: 'Hetta økið skal í mesta lagi vera {characters} stavir',
65				url: 'Vev adressan er ikki gildig'
66			}
67		},
68		'da': {
69			textbox: {
70				required: 'Dette felt skal udfyldes',
71				min: 'Dette felt skal være mindst {characters} tegn',
72				max: 'Dette felt skal være højst {characters} tegn',
73				email: 'Denne email er ugyldig',
74				url: 'Denne webside er ugyldigt',
75				number: 'Kun tal er tilladte',
76				digits: 'Kun tal er tilladte',
77				loweralpha: 'Kun små bogstaver er tilladte'
78			},
79			password: {
80				required: 'Dette felt skal udfyldes',
81				min: 'Dette felt skal være mindst {characters} tegn',
82				max: 'Dette felt skal være højst {characters} tegn',
83				match: 'Adgangskoderne er ikke ens'
84			},
85			radio: {
86			},
87			checkbox: {
88				required: 'Denne checkbox skal checkes'
89			},
90			file: {
91				required: 'En fil er krævet'
92			},
93			select: {
94				required: 'Vælg et felt i listen'
95			},
96			textarea: {
97				required: 'Dette felt skal udfyldes',
98				min: 'Dette felt skal være mindst {characters} tegn',
99				max: 'Dette felt skal være højst {characters} tegn',
100				url: 'Denne webside er ugyldigt'
101			}
102		},
103		'en': {
104			textbox: {
105				required: 'This field is required',
106				min: 'This field must contain at least {characters} characters',
107				max: 'This field must not contain more than {characters} characters',
108				email: 'Email is not valid',
109				url: 'Website is not valid',
110				number: 'Only numbers are allowed',
111				digits: 'Only numbers are allowed',
112				loweralpha: 'Only lowercase letters are allowed'
113			},
114			password: {
115				required: 'This field is required',
116				min: 'This field must contain at least {characters} characters',
117				max: 'This field must not contain more than {characters} characters',
118				match: 'The passwords do not match'
119			},
120			radio: {
121			},
122			checkbox: {
123				required: 'This checkbox is required'
124			},
125			file: {
126				required: 'A file is required'
127			},
128			select: {
129				required: 'Choose a field from the list'
130			},
131			textarea: {
132				required: 'This field is required',
133				min: 'This field must contain at least {characters} characters',
134				max: 'This field must not contain more than {characters} characters',
135				url: 'Website is not valid'
136			}
137		}
138	},
139	patterns: {
140		url:        /^((https?|ftp|mailto):(\/\/)?)?((([a-z\d]+)([.@:-]))+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3}))(:\d+)?(\/[a-z\u00C0-\u00ff\d_\-+~%.()]*)*((\?|;)[\S\d_\-+~%.,=;&{}/()]*)?(#[\S\d_\-+~%.,=;&{}/()]*)?$/i,
141		email:      /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i,
142		number:     /^\s*([+-])?((\d+([.,]\d+)?)|([.,]\d+))%?\s*$/i,
143		digits:     /^\s*\d+\s*$/,
144		loweralpha: /^\s*[a-z0-9_\-]+\s*$/
145	},
146	showError: function (element, text) {
147		var $element = $(element);
148		if (!$element.hasClass(Validator.elementErrorClass)) {
149			var $error = $(document.createElement('div'));
150			$error.addClass('validator-error').html(text);
151
152			if ($element.attr('data-error-position') === undefined) {
153				var errorPosition = 'before';
154				if ($element.is('input') && $element.attr('type') === 'checkbox') {
155					errorPosition = 'before label';
156				}
157				if ($element.data('selectator') !== undefined) {
158					errorPosition = 'before next .selectator_element';
159				}
160			} else {
161				errorPosition = $element.attr('data-error-position');
162			}
163			var attrValue = errorPosition.split(' ');
164			var $targetElementForError;
165			if (attrValue[1] === undefined) {
166				$targetElementForError = $element;
167			} else if (attrValue[2] === undefined) {
168				$targetElementForError = $element.closest(attrValue[1]);
169			} else {
170				switch (attrValue[1]) {
171					case 'prev':
172					case 'previous':
173						$targetElementForError = $element.prev(attrValue[2]);
174						break;
175					case 'next':
176						$targetElementForError = $element.next(attrValue[2]);
177						break;
178					default:
179						$targetElementForError = $element.closest(attrValue[2]);
180						break;
181				}
182			}
183			if (attrValue[0] === 'before') {
184				$targetElementForError.before($error);
185				$targetElementForError.addClass(Validator.elementErrorClass);
186			} else if (attrValue[0] === 'after') {
187				$targetElementForError.after($error);
188				$targetElementForError.addClass(Validator.elementErrorClass);
189			} else if (attrValue[0] === 'prepend') {
190				$targetElementForError.prepend($error);
191				$element.addClass(Validator.elementErrorClass);
192			} else if (attrValue[0] === 'append') {
193				$targetElementForError.append($error);
194				$element.addClass(Validator.elementErrorClass);
195			}
196
197			if ($element.attr('data-match') !== undefined) {
198				$('#' + $element.attr('data-match')).addClass(Validator.elementErrorClass);
199			}
200		}
201	},
202	validate: function (form, onlyVisible) {
203		var hasErrors = false;
204		var firstErrorElement = null;
205		onlyVisible = typeof onlyVisible !== 'undefined' ? onlyVisible : false;
206
207		Validator.removeErrors(form);
208
209		$(form).find('input, select, textarea').each(function () {
210			var $this = $(this);
211			var $elementToCheckVisibilityOf = $this.data('selectator') === undefined ? $this : $this.next('.selectator_element');
212			if (!onlyVisible || $elementToCheckVisibilityOf.is(':visible')) {
213				// Input[type=text]
214				if ($this.is('input') && ($this.attr('type') === 'text' || $this.attr('type') === undefined)) {
215					// required
216					if ($this.attr('data-required') !== undefined && $this.val() === '' && $this.attr('data-required-if') === undefined) {
217						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
218						hasErrors = true;
219					}
220					// required-if & required-if-value
221					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
222						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
223						hasErrors = true;
224					}
225					// min
226					if ($this.attr('data-min') !== undefined && $this.val().length < parseFloat($this.attr('data-min')) && $this.val().length !== 0) {
227						Validator.showError(this, Validator.languages[Validator.language].textbox.min.replace('{characters}', $this.attr('data-min')));
228						hasErrors = true;
229					}
230					// max
231					if ($this.attr('data-max') !== undefined && $this.val().length > parseFloat($this.attr('data-max'))) {
232						Validator.showError(this, Validator.languages[Validator.language].textbox.max.replace('{characters}', $this.attr('data-min')));
233						hasErrors = true;
234					}
235
236					// patterns
237					if ($this.attr('data-type') !== undefined) {
238						switch ($this.attr('data-type')) {
239							case 'email':
240								if (!Validator.patterns.email.test($this.val()) && $this.val() !== '') {
241									Validator.showError(this, Validator.languages[Validator.language].textbox.email);
242									hasErrors = true;
243								}
244								break;
245							case 'url':
246								if ($this.val().substr(0, 1) !== '/' && !Validator.patterns.url.test($this.val().replace('_', '')) && $this.val() !== '') {
247									Validator.showError(this, Validator.languages[Validator.language].textbox.url);
248									hasErrors = true;
249								}
250								break;
251							case 'number':
252								if (!Validator.patterns.number.test($this.val()) && $this.val() !== '') {
253									Validator.showError(this, Validator.languages[Validator.language].textbox.number);
254									hasErrors = true;
255								}
256								break;
257							case 'digits':
258								if (!Validator.patterns.digits.test($this.val()) && $this.val() !== '') {
259									Validator.showError(this, Validator.languages[Validator.language].textbox.digits);
260									hasErrors = true;
261								}
262								break;
263							case 'loweralpha':
264								if (!Validator.patterns.loweralpha.test($this.val()) && $this.val() !== '') {
265									Validator.showError(this, Validator.languages[Validator.language].textbox.loweralpha);
266									hasErrors = true;
267								}
268								break;
269						}
270					}
271				}
272
273				// Input[type=date]
274				if ($this.is('input') && ($this.attr('type') === 'date' || $this.attr('type') === undefined)) {
275					// required
276					if ($this.attr('data-required') !== undefined && $this.val() === '' && $this.attr('data-required-if') === undefined) {
277						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
278						hasErrors = true;
279					}
280					// required-if & required-if-value
281					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
282						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
283						hasErrors = true;
284					}
285				}
286
287				// Input[type=time]
288				if ($this.is('input') && ($this.attr('type') === 'time' || $this.attr('type') === undefined)) {
289					// required
290					if ($this.attr('data-required') !== undefined && $this.val() === '' && $this.attr('data-required-if') === undefined) {
291						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
292						hasErrors = true;
293					}
294					// required-if & required-if-value
295					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
296						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
297						hasErrors = true;
298					}
299				}
300
301				// Input[type=datetime]
302				if ($this.is('input') && ($this.attr('type') === 'datetime' || $this.attr('type') === undefined)) {
303					// required
304					if ($this.attr('data-required') !== undefined && $this.val() === '' && $this.attr('data-required-if') === undefined) {
305						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
306						hasErrors = true;
307					}
308					// required-if & required-if-value
309					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
310						Validator.showError(this, Validator.languages[Validator.language].textbox.required);
311						hasErrors = true;
312					}
313				}
314
315				// Input[type=password]
316				if ($this.is('input') && $this.attr('type') === 'password') {
317					// required
318					if ($this.attr('data-required') !== undefined && $this.val() === '' && $this.attr('data-required-if') === undefined) {
319						Validator.showError(this, Validator.languages[Validator.language].password.required);
320						hasErrors = true;
321					}
322					// required-if & required-if-value
323					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
324						Validator.showError(this, Validator.languages[Validator.language].password.required);
325						hasErrors = true;
326					}
327					// min
328					if ($this.attr('data-min') !== undefined && $this.val().length < parseFloat($this.attr('data-min')) && $this.val().length !== 0) {
329						Validator.showError(this, Validator.languages[Validator.language].password.min.replace('{characters}', $this.attr('data-min')));
330						hasErrors = true;
331					}
332					// max
333					if ($this.attr('data-max') !== undefined && $this.val().length > parseFloat($this.attr('data-max'))) {
334						Validator.showError(this, Validator.languages[Validator.language].password.max.replace('{characters}', $this.attr('data-min')));
335						hasErrors = true;
336					}
337					// match
338					if ($this.attr('data-match') !== undefined && $this.val() !== $('#' + $this.attr('data-match')).val()) {
339						Validator.showError(this, Validator.languages[Validator.language].password.match);
340						hasErrors = true;
341					}
342				}
343
344				// Input[type=radio]
345				if ($this.is('input') && $this.attr('type') === 'radio') {
346				}
347
348				// Input[type=checkbox]
349				if ($this.is('input') && $this.attr('type') === 'checkbox') {
350					// required
351					if ($this.attr('data-required') !== undefined && !$this.is(':checked') && $this.attr('data-required-if') === undefined) {
352						Validator.showError(this, Validator.languages[Validator.language].checkbox.required);
353						hasErrors = true;
354					}
355					// required-if & required-if-value
356					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
357						Validator.showError(this, Validator.languages[Validator.language].checkbox.required);
358						hasErrors = true;
359					}
360				}
361
362				// Select
363				if ($this.is('select')) {
364					// required
365					if ($this.attr('data-required') !== undefined && ($this.val() === '' || (Array.isArray($this.val()) && !$this.val().length)) && $this.attr('data-required-if') === undefined) {
366						Validator.showError(this, Validator.languages[Validator.language].select.required);
367						hasErrors = true;
368					}
369					// required-if & required-if-value
370					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
371						Validator.showError(this, Validator.languages[Validator.language].select.required);
372						hasErrors = true;
373					}
374
375				}
376
377				// Textarea
378				if ($this.is('textarea')) {
379					// required
380					if ($this.attr('data-required') !== undefined && $this.val() === '' && $this.attr('data-required-if') === undefined) {
381						Validator.showError(this, Validator.languages[Validator.language].textarea.required);
382						hasErrors = true;
383					}
384					// required-if & required-if-value
385					if ($this.attr('data-required-if') !== undefined && $this.val() === '' && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
386						Validator.showError(this, Validator.languages[Validator.language].textarea.required);
387						hasErrors = true;
388					}
389					// min
390					if ($this.attr('data-min') !== undefined && $this.val().length < parseFloat($this.attr('data-min')) && $this.val().length !== 0) {
391						Validator.showError(this, Validator.languages[Validator.language].textarea.min.replace('{characters}', $this.attr('data-min')));
392						hasErrors = true;
393					}
394					// max
395					if ($this.attr('data-max') !== undefined && $this.val().length > parseFloat($this.attr('data-max'))) {
396						Validator.showError(this, Validator.languages[Validator.language].textarea.max.replace('{characters}', $this.attr('data-min')));
397						hasErrors = true;
398					}
399					// patterns
400					if ($this.attr('data-type') !== undefined) {
401						switch ($this.attr('data-type')) {
402							case 'url':
403								if (!Validator.patterns.url.test($this.val()) && $this.val() !== '') {
404									Validator.showError(this, Validator.languages[Validator.language].textarea.url);
405									hasErrors = true;
406								}
407								break;
408						}
409					}
410				}
411
412				// Input[type=file]
413				if ($this.is('input') && $this.attr('type') === 'file') {
414					// required
415					if ($this.attr('data-required') !== undefined && $this.get(0).files.length === 0 && $this.attr('data-required-if') === undefined) {
416						Validator.showError(this, Validator.languages[Validator.language].file.required);
417						hasErrors = true;
418					}
419					// required-if & required-if-value
420					if ($this.attr('data-required-if') !== undefined && $this.get(0).files.length === 0 && (($this.attr('data-required-if-value') === undefined && $('#' + $this.attr('data-required-if')).is(':checked')) || ($this.attr('data-required-if-value') !== undefined && $('#' + $this.attr('data-required-if')).val() === $this.attr('data-required-if-value')))) {
421						Validator.showError(this, Validator.languages[Validator.language].file.required);
422						hasErrors = true;
423					}
424				}
425
426				// Focus first element with error
427				if (hasErrors && firstErrorElement === null) {
428					firstErrorElement = this;
429					$this.focus();
430				}
431			}
432		});
433		return !hasErrors;
434	},
435	removeErrors: function (form) {
436		// Remove all error text divs
437		var $form = $(form);
438		$form.find('.validator-error').each(function () {
439			$(this).remove();
440		});
441		$form.find('.error').each(function () {
442			$(this).removeClass('error');
443		});
444
445		// Reset error classes
446		$form.find('input[type=text], input[type=password], input[type=radio], input[type=checkbox], select, textarea').each(function () {
447			var $this = $(this);
448			if ($this.attr('type') === 'radio' || $this.attr('type') === 'checkbox') {
449				$this.closest('label').removeClass(Validator.elementErrorClass);
450			} else {
451				$this.removeClass(Validator.elementErrorClass);
452			}
453		});
454
455	}
456};
457
458$(function () {
459	$('form.validator').each(function () {
460		$(this).submit(function () {
461			return Validator.validate(this, false);
462		});
463	});
464	$('form.validator-onlyvisible').each(function () {
465		$(this).submit(function () {
466			return Validator.validate(this, true);
467		});
468	});
469});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.