PageSourceSearch

https://www.segurancarodoviaria.pt/Scripts/seguranca-rodoviaria.js?v=14

js segurancarodoviaria.pt collected 2026-09-24 12:38:44 UTC 18,744 bytes, 500 lines download raw bytes

1
2$(document).ready(function () {
3
4    $('[data-toggle="tooltip"]').tooltip();
5
6	updateNavbarHeight();
7
8	$(window).resize(function () {
9		updateNavbarHeight();
10	});
11
12
13    $('.formSearch').keydown(function (event) {
14        if (event.which == 13) {
15            var $searchTextInput = $(this).find('.searchTextBody');
16            var searchUrl = $(this).attr("data-search-url");
17            var searchRequest = searchUrl + '?q=';
18
19            if ($searchTextInput.val() != '') {
20                $(this).attr('action', searchRequest + $searchTextInput.val()).submit();
21			}
22			return false;
23		}
24	});
25
26    $('.searchButton').on('click', function (event) {
27        var $form = $(this).closest('form'),
28            $searchTextInput = $form.find('.searchTextBody');
29
30        if ($searchTextInput.val() != '') {
31            $form.attr('action', '/search?q=' + $searchTextInput.val()).submit();
32		}
33		return false;
34	});
35});
36
37$(window).on('scroll', function (event) {
38	var scrollValue = $(window).scrollTop();
39
40	if (scrollValue > 130) {
41		$('.menu-top').addClass('sticky-header');
42		$('#menu-top-second-row').removeClass('h-50').addClass('h-100');
43		$('#menu-top-second-row').children('.d-none').removeClass('d-none').addClass('d-none d-md-block');
44	}
45	else if (scrollValue < 60) {
46		$('.menu-top').removeClass('sticky-header');
47		$('#menu-top-second-row').removeClass('h-100').addClass('h-50');
48		$('#menu-top-second-row').children('.d-md-block').removeClass('d-none d-md-block').addClass('d-none');
49	}
50});
51
52$(document).on('click', '[data-card-url]', function (e) {
53	window.location = $(this).data('card-url');
54});
55
56$(document).on('click', '.btn-close-window', function () {
57    window.open('', '_self', '').close();
58});
59
60// Tests Checkbox Actions
61//
62$(document).on('change', '.content-list .content .abc-checkbox .form-check-input', function () {
63    var $questionItem = $(this).closest('.content'),
64        $questionList = $questionItem.closest('.content-list'),
65        $questionItemSiblings = $questionItem.siblings('.content'),
66        disableSiblings = $questionList.data("uncheck-siblings") || false;
67
68    if (disableSiblings) {
69        $questionItemSiblings.removeClass('active');
70        $questionItemSiblings.find(".form-check-input").prop('checked', false);
71    }
72
73    var $hasCheckAll = $questionList.find(".check-all");
74    if ($hasCheckAll.length > 0) {
75        if ($questionList.find(".content .form-check-input:checked").length == $questionList.find(".content .form-check-input").length && !$hasCheckAll.is(":checked")) {
76            $hasCheckAll.prop('checked', true);
77        }
78        else if ($questionList.find(".content .form-check-input:checked").length != $questionList.find(".content .form-check-input").length && $hasCheckAll.is(":checked")){
79            $hasCheckAll.prop('checked', false);
80        }
81    }
82
83    if ($(this).is(":checked")) {
84        $questionItem.addClass("active");
85    }
86    else {
87        $questionItem.removeClass("active");
88    }
89
90    $(document).trigger('onlinetestequestion.trigger.change', [$(this), $(this).is(":checked")]
90);
91});
92$(document).on('change', '.card-select-all .abc-checkbox .form-check-input', function () {
93    var $cardbody = $(this).closest('.card-body'),
94        $cardSubcategorieItems = $cardbody.find('.content-test-categories-item');
95
96    if ($(this).is(":checked")) {
97        $cardSubcategorieItems.addClass("active");
98        $cardSubcategorieItems.find(".content-status .form-check-input").prop("checked", true);
99    }
100    else {
101        $cardSubcategorieItems.removeClass("active");
102        $cardSubcategorieItems.find(".content-status .form-check-input").prop("checked", false);
103    }
104});
105
106// Show/Hide Password
107//
108$(document).on('click', '[data-password-show]', function (e) {
109    var targetControlId = $(this).data("password-show"),
110        $toggleIcon = $(this).find("[data-password-toggle-icon]");
111
112    if (targetControlId != undefined && targetControlId.length > 0) {
113        var $control = $("#" + targetControlId);
114
115        if ($control.length > 0 && $control.is("input")) {
116            if ($control.attr("type") === "password") {
117                $control.attr("type", "text");
118            }
119            else {
120                $control.attr("type", "password");
121            }
122
123            if ($toggleIcon != undefined && $toggleIcon.length > 0) {
124                var currentIcon = $toggleIcon.attr("class");
125
126                $toggleIcon.attr("class", $toggleIcon.data("password-toggle-icon"));
127                $toggleIcon.data("password-toggle-icon", currentIcon);
128            }
129        }
130    }
131});
132
133
134// Minus Plus Control Actions
135//
136$(document).on('click', '.control-plusminus .btn-number', function (e) {
137    e.preventDefault();
138    type = $(this).attr('data-type');
139    var input = $(this).closest('.control-plusminus').find("input");
140    var currentVal = parseInt(input.val());
141    if (!isNaN(currentVal)) {
142        if (type == 'minus') {
143
144            if (currentVal > input.attr('min')) {
145                input.val(currentVal - 1).change();
146            }
147            if (parseInt(input.val()) == input.attr('min')) {
148                $(this).attr('disabled', true);
149            }
150
151        } else if (type == 'plus') {
152
153            if (currentVal < input.attr('max')) {
154                input.val(currentVal + 1).change();
155            }
156            if (parseInt(input.val()) == input.attr('max')) {
157                $(this).attr('disabled', true);
158            }
159
160        }
161    } else {
162        input.val(0);
163    }
164});
165$(document).on('focusin', '.control-plusminus .input-number', function () {
166    $(this).data('oldValue', $(this).val());
167});
168$(document).on('change', '.control-plusminus .input-number', function (e) {
169
170    minValue = parseInt($(this).attr('min'));
171    maxValue = parseInt($(this).attr('max'));
172    valueCurrent = parseInt($(this).val());
173
174    name = $(this).attr('name');
175    if (valueCurrent >= minValue) {
176        $(this).closest(".control-plusminus").find(".btn-number[data-type='minus']").removeAttr('disabled');
177    } else {
178        $(this).val($(this).data('oldValue'));
179    }
180    if (valueCurrent <= maxValue) {
181        $(this).closest(".control-plusminus").find(".btn-number[data-type='plus']").removeAttr('disabled');
182    } else {
183        $(this).val($(this).data('oldValue'));
184    }
185    $(document).trigger('controlplusminus.trigger.change', [$(this), valueCurrent]);
186});
187$(document).on('keydown', '.control-plusminus .input-number', function (e) {
188    // Allow: backspace, delete, tab, escape, enter and .
189    if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
190        // Allow: Ctrl+A
191        (e.keyCode == 65 && e.ctrlKey === true) ||
192        // Allow: home, end, left, right
193        (e.keyCode >= 35 && e.keyCode <= 39)) {
194        // let it happen, don't do anything
195        return;
196    }
197    // Ensure that it is a number and stop the keypress
198    if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
199        e.preventDefault();
200    }
201});
202$(document).bind('controlplusminus.trigger.change', function (e, control, value) {
203    var $controlToUpdate = $(control).closest('.basket-item').find(".product-qtd");
204    
205    if ($controlToUpdate.length > 0) {
206        $controlToUpdate.val(value);
207        $controlToUpdate.trigger("change");
208    }
209});
210
211function ScrollToError(validator, speed, offset) {
212    var errors = validator.numberOfInvalids();
213    if (errors) {
214        $('html, body').animate({
215            scrollTop: ScrollToErrorValue(validator, offset)
216        }, speed);
217    }
218}
219function ScrollToErrorValue(validator, offset) {
220    var elem = validator.errorList,
221        valueToReturn = 0;
222
223    if (elem.length) {
224        $.each(elem, function () {
225            var object = $($(this)[0].element);
226            if (object.is(':visible')) {
227                valueToReturn = (object.offset().top - (offset == undefined ? 0 : offset) - (object.height()));
228                return false;
229            }
230        });
231    }
232
233    return valueToReturn;
234}
235
236function goBack(url = undefined) {
237    event.preventDefault();
238
239    if (history.length > 2) {
240        history.go(-1);
241    }
242    else {
243        console.log("Went in here and the url is:", url);
244        if (url) {
245            window.location = url;
246        } else {
247            window.location = "/";
248        }
249    }
250}
251
252function updateNavbarHeight() {
253
254    if ($(window).width() > 767) {
255        $(".pnl-menu-cart").removeAttr("style");
256        $(".container-fluid-menus").css("display", "block");
257
258        var $closeButton = $(".menu-top .btn-close");
259        if (!$closeButton.hasClass("collapsed") && $("#navbarTopMenu").hasClass("show")) {
260            $closeButton.click();
261        }
262    }
263
264	if (!$("#navbarTopMenu").is(":visible")) {
265		$(".menu-top").height(70);
266		//$(".navbar-brand").width("60%");
267	}
268	else {
269		$(".menu-top").removeAttr("style");
270		//$(".navbar-brand").width("30%");
271	}
272}
273
274function updateCarouselHeight() {
275	var screenSizeHeight = $(window).height();
276
277	//var menutopHeight = $(".menu-top").outerHeight(true);
278
279	//$("#navbar").css("height", ($(window).height() - menuHeight) + "px");
280	//$("#navbar").css("max-height", ($(window).height() - menuHeight) + "px");
281
282	//$(".newface-header").css("height", $(window).height() + "px");
283}
284
285function dynamicSort(property) {
286    var sortOrder = 1;
287
288    if (property[0] === "-") {
289        sortOrder = -1;
290        property = property.substr(1);
291    }
292
293    return function (a, b) {
294        if (sortOrder == -1) {
295            return b[property].localeCompare(a[property]);
296        } else {
297            return a[property].localeCompare(b[property]);
298        }
299    }
300}
301
302function SuccessAddSubscriber(data) {
303	if (data) {
304		if (data.htmlResult == "ERRO") {
305			if ($(".newsletter-message-success").hasClass("d-block")) {
306				$(".newsletter-message-success").removeClass("d-block").addClass("d-none");
307			}
308
309			$(".newsletter-message-error").removeClass("d-none").addClass("d-block");
310		}
311		else {
312			if ($(".newsletter-message-error").hasClass("d-block")) {
313				$(".newsletter-message-error").removeClass("d-block").addClass("d-none");
314			}
315
316			$(".newsletter-message-success").removeClass("d-none").addClass("d-block");
317		}
318	}
319}
320
321//Show Generic Messages
322//
323function ShowGenericMessages(messages) {
324    if (messages) {
325        $("body").append(messages);
326    }
327}
328
329//Progress bar cicle countdown
330//
331$.fn.progressCountDown = function () {
332    var $currentStatus = $(this).find(".progress-status"),
333        step = parseInt($(this).data("step")),
334        startProgress = $(this).data("start-progress"),
335        endProgress = $(this).data("end-progress"),
336        currentProgress = parseFloat($(this).attr("data-current-progress")),
337        fillColor = $(this).data("fill-color"),
338        emptyColor = $(this).data("empty-color");
339
340    if ($currentStatus.length > 0) {
341        currentProgress = currentProgress + step;
342        
343        var currentPercentage = (360 * Math.round(100 - ((currentProgress * 100) / startProgress))) / 100;
344        $(this).attr('data-current-progress', currentProgress);
345        
346        if (currentPercentage <= 180) {
347            $currentStatus.css('background-image', 'linear-gradient(' + (90 + currentPercentage) + 'deg, transparent 50%, ' + emptyColor + ' 50%),linear-gradient(90deg, ' + emptyColor + ' 50%, transparent 50%)');
348        }
349        else {
350            $currentStatus.css('background-image', 'linear-gradient(' + (currentPercentage - 90) + 'deg, transparent 50%, ' + fillColor + ' 50%),linear-gradient(90deg, ' + emptyColor + ' 50%, transparent 50%)');
351        }
352
353        if (currentProgress == endProgress) {
354            $(document).trigger('progresscountdown.trigger.finished', $(this));
355            return;
356        }
357        else {
358            $(document).trigger('progresscountdown.trigger.currenttime', [$(this), currentProgress]);
359        }
360    }
361}
362
363function invokeCSCode(data) {
364    try {
365        invokeCSharpAction(data);
366    }
367    catch (err) {
368    }
369}
370
371//Jquery Helpers
372//
373$.fn.addLoading = function () {
374	$(this).append('<div class="loading-container"><div class="fas fa-circle-notch fa-spin fa-3x fa-fw loading-spinner"></div></div>');
375	$(this).addClass("loading");
376}
377
378$.fn.removeLoading = function () {
379    var loadingContainer = $(this).children(".loading-container");
380    if (loadingContainer) {
381        loadingContainer.remove();
382    }
383
384    $(this).removeClass("loading");
385}
386
387// Language Selection Functions
388function InitLanguageSelectionControls() {
389    $(document).on("click", '.content-language-selection .dropdown-item', function () {
390        var currentForm = $(this).closest(".content-language-selection"),
391            languageName = $(this).html().replace('(Default)', '').trim(),
392            languageId = $(this).data('language-id'),
393            containerId = $(currentForm).data("containerid"),
394            showMultipleTranslation = $(currentForm).data("show-multiple-translation");
395
396        if ($(this).closest(".modal").length == 0) {
397            if (containerId != undefined && containerId.length > 0) {
398                $(`#${containerId}`).attr('data-language', languageId);
399            }
400            else {
401                $('body').attr('data-language', languageId);
402            }
403        }
404
405        $.each(currentForm, function () {
406            $(this).find('[data-toggle="dropdown"] > span').html(languageName);
407            $(this).find(".dropdown-item").removeClass("active");
408            $(this).find("[data-language-id='" + languageId + "']").addClass('active')
409        });
410
411        ChangeControlLanguage($(this), $(this).data("language-id"), containerId, showMultipleTranslation);
412    });
413}
414function GetSelectedLanguageName(languageSelected) {
415    return $('.content-language-selection').find(".dropdown-item[data-language-id='" + languageSelected + "'] > span").text();
416}
417function ChangeControlLanguage(controlo, idiomaSelecionado, containerId, showMultipleTranslation) {
418    var $controlo = $(controlo).closest('.modal').length > 0 ? $(controlo).closest('.modal') : $(controlo),
419        stringControlosCarregar = `${(containerId != undefined && containerId.length > 0 ? "#" + containerId : '')} .translation-control:not(.translation-tabs)`;
420    var controlosDisponiveis = containerId == undefined || containerId.length == 0
421        ? $controlo.find(".translation-control:not(.translation-tabs)")
422        : $(stringControlosCarregar),
423    currentLanguageFlags = $controlo.find(".language-switch");
424
425    var currentLanguageName = GetSelectedLanguageName(idiomaSelecionado);
426    currentLanguageName = currentLanguageName.length > 0 ? currentLanguageName.replace('(Default)', '').trim() : '';
427
428    if (currentLanguageFlags != undefined && currentLanguageFlags.length > 0) {
429        var languageFlagItem = $(controlo).find("[data-lang='" + idiomaSelecionado + "']");
430        if (languageFlagItem != undefined && languageFlagItem.length > 0) {
431            $(controlo).find(".language-switch").removeClass("active");
432            languageFlagItem.addClass("active");
433        }
434    }
435
436    $.each(controlosDisponiveis, function () {
437        SetActiveLanguageControl($(this), idiomaSelecionado, currentLanguageName, showMultipleTranslation);
438    });
439}
440function SetActiveLanguageControl(control, languageSelected, languageSelectedName, showMultipleTranslation) {
441    var currentLanguageDropdown = $(control).find(".form-language-selection");
442
443    if (currentLanguageDropdown != undefined && currentLanguageDropdown.length > 0) {
444        var languageDropdownItem = $(currentLanguageDropdown).find("[data-language-id='" + languageSelected + "']");
445        if (languageDropdownItem != undefined && languageDropdownItem.length > 0) {
446            currentLanguageDropdown.find('[data-toggle="dropdown"] > span').html(languageDropdownItem.html());
447            currentLanguageDropdown.find(".dropdown-item").removeClass("active");
448            languageDropdownItem.addClass("active");
449
450            currentLanguageText = languageDropdownItem.html();
451        }
452    }
453
454    if (control.find('.tab-pane[data-language-id="' + languageSelected + '"]')) {
455        $.each(control.find('.tab-pane'), function () {
456            var isReadonly = $(this).closest(".item-readonly").length > 0;
457
458            if ($(this).data("default") == true && !isReadonly) {
459                $(this).addClass("active");
460            }
461
462            if ($(this).data("language") != languageSelected && ($(this).data("default") == false
463                || isReadonly
464                || !showMultipleTranslation)) {
465                $(this).removeClass("active");
466            }
467            else {
468                $(this).addClass("active");
469
470                var $isFormGroup = $(this).closest(".form-group"),
471                    $isModulesContentItem = $isFormGroup.length > 0 ? null : $(this).closest(".modules-content-item"),
472                    $isContentTestAnswers = $isModulesContentItem != null && $isModulesContentItem.length > 0 ? null : $(this).closest(".content-test-answers");
473
474                if ($isFormGroup.length > 0) {
475                    var $label = $isFormGroup.find("label");
476                    if ($label.length > 0) {
477                        if ((typeof $label.data('title-text') === 'undefined')) {
478                            $label.data('title-text', $label.text());
479                        }
480
481                        //$label.text(`${$label.data('title-text')} (${languageSelectedName})`);
482                    }
483                }
484                else if ($isModulesContentItem.length > 0) {
485                    //$isModulesContentItem.get(0).style.setProperty("--title-text", ` '${$isModulesContentItem.data('type-text')} (${languageSelectedName})'`);
486                }
487                else if ($isContentTestAnswers.length > 0) {
488                    var $titulo = $isContentTestAnswers.closest(".content").find(".content-header h2");
489                    if ($titulo.length > 0) {
490                        if ((typeof $titulo.data('title-text') === 'undefined')) {
491                            $titulo.data('title-text', $titulo.text());
492                        }
493
494                        //$titulo.text(`${$titulo.data('title-text')} (${languageSelectedName})`);
495                    }
496                }
497            }
498        });
499    }
500}

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.