PageSourceSearch

https://www.blejski-grad.si/scripts/scripts.js?v=p7YA-pKv9fCcjVNu0w8oDxW4wGqdiSIeSUxF7p4Ppxw

js blejski-grad.si collected 2026-10-02 10:36:40 UTC 51,786 bytes, 1,476 lines download raw bytes

1// ==============================================
2// GLOBALS
3// ==============================================
4var loadingOverlayTmr = null;
5var formSubmitting = false;
6var scrollPosition = 0;
7
8// ==============================================
9// COMMON
10// ==============================================
11function ShowLoadingOverlay(delay) {
12    if (isNaN(delay)) {
13        delay = 500;
14    }
15    if (loadingOverlayTmr) {
16        clearTimeout(loadingOverlayTmr);
17    }
18    loadingOverlayTmr = setTimeout(function () {
19        $(".loading-overlay").show();
20        $("html").addClass("no-scroll");
21    }, delay);
22}
23
24function HideLoadingOverlay() {
25    if (loadingOverlayTmr) {
26        clearTimeout(loadingOverlayTmr);
27    }
28    $(".loading-overlay").hide();
29    $("html").removeClass("no-scroll");
30}
31
32function BlockUI() {
33    if (loadingOverlayTmr) {
34        clearTimeout(loadingOverlayTmr);
35    }
36    loadingOverlayTmr = setTimeout(function () {
37        $(".block-ui").show();
38        $("html").addClass("no-scroll");
39    }, 500);
40}
41
42function UnblockUI() {
43    if (loadingOverlayTmr) {
44        clearTimeout(loadingOverlayTmr);
45    }
46    $(".block-ui").hide();
47    $("html").removeClass("no-scroll");
48}
49
50function jsRedirect(url, target) {
51    var a = document.createElement('a');
52    a.target = target;
53    a.href = url;
54    a.click();
55}
56
57function strToDate(_date, _format, _delimiter) {
58    var formatLowerCase = _format.toLowerCase();
59    var formatItems = formatLowerCase.split(_delimiter);
60    var dateItems = _date.split(_delimiter);
61    var monthIndex = formatItems.indexOf("mm");
62    var dayIndex = formatItems.indexOf("dd");
63    var yearIndex = formatItems.indexOf("yyyy");
64    var month = parseInt(dateItems[monthIndex]);
65    month -= 1;
66    var formatedDate = new Date(dateItems[yearIndex], month, dateItems[dayIndex]);
67    return formatedDate;
68}
69
70function isDate(dt) {
71    return Date.parse(dt) > 0 ? true : false;
72}
73
74function IsEmail(mail) {
75    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(mail)) {
76        return (true);
77    }
78    return (false);
79}
80
81function modulo11() {
82    /*
83    $('.thebutton').click(function() {
84    
85      var d = $('#number').val().split('');
86      var total=0;
87      
88      for (var i = 0; i < d.length; i++)
89      {
90            var x = Number(d[i]);
91        var temp = x * (8-i);
92        total += temp;
93      }
94      
95      var remainder = total % 11;
96      var checkDigit = 11-remainder;
97      
98      $('#check').val(checkDigit);
99    });
100    */
101}
102
103// offset is variabile according to header height
104function ScrollTo(elm, offset, callback) {
105    offset = offset || ($(".navi").height() * 2);
106    //console.log(offset);
107    //console.log(elm.position().top);
108    //console.log($(elm)[0].getBoundingClientRect().top);
109    //console.log((window.scrollY || document.body.scrollTop));
110    //console.log(document.documentElement.scrollTop);
111    //console.log(elm.position().top - offset);
112
113    $("html, body").animate({ scrollTop: elm.position().top + (window.scrollY || document.body.scrollTop) - offset }, "slow", function () {
114        if (callback) {
115            callback();
116        }
117    });
118}
119
120function setCookie(key, value, forever) {
121    document.cookie = key + '=' + value + (forever === true ? ';max-age=315360000;' : '');
122}
123function setNoticeCookie(key, value, forever) {
124    var currentCookieVal = getCookie(key);
125    document.cookie = key + '=' + (currentCookieVal ? currentCookieVal : '') + "$" + value + (forever === true ? ';max-age=315360000;' : '');
126}
127
128function getCookie(key) {
129    var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
130    return keyValue ? keyValue[2] : null;
131}
132
133function deleteCookie(key) {
134    var keyValue = getCookie(key);
135    setCookie(key, keyValue, '-1');
136}
137
138function SessionSet(key, value, callback) {
139    $.post('/Api/SessionSet',
140        { k: key, v: value }, function (result) {
141            if (callback) {
142                callback(result.value);
143            }
144        });
145}
146
147function SessionGet(key, callback) {
148    $.get('/Api/SessionGet',
149        { k: key }, function (result) {
150            if (callback) {
151                callback(result.value);
152            } else {
153                return result.value;
154            }
155        });
156}
157
158function ChangeQuerystringParam(key, value) {
159    var url = new URL(window.location.href);
160    var search_params = url.searchParams;
161    search_params.set(key, value);
162    url.search = search_params.toString();
163    var new_url = url.pathname + url.search;
164    window.history.replaceState({}, '', new_url);
165}
166
167function Debounce(func, wait, immediate) {
168    var timeout;
169    return function () {
170        var context = this,
171            args = arguments;
172        var later = function () {
173            timeout = null;
174            if (!immediate) {
175                func.apply(context, args);
176            }
177        };
178        var callNow = immediate && !timeout;
179        clearTimeout(timeout);
180        timeout = setTimeout(later, wait);
181        if (callNow) {
182            func.apply(context, args);
183        }
184    };
185}
186
187function ConcatValues(obj) {
188    var value = '';
189    for (var prop in obj) {
190        value += obj[prop];
191    }
192    return value;
193}
194
195function Rand(min, max) { // min and max included
196    return Math.floor(Math.random() * (max - min + 1) + min);
197}
198
199// ==============================================
200
201// ==============================================
202// AJAX
203// ==============================================
204document.addEventListener('DOMContentLoaded', function (e) {
205    $(".ajax").each(function (index, item) {
206        var url = $(item).attr("data-url");
207        if (url && url.length > 0) {
208            $(item).load(url);
209        }
210    });
211});
212
213// ==============================================
214
215// ==============================================
216/* Deadly simple toast message */
217// ==============================================
218var Toast = {
219    _msg: "Toast message",
220    _color: "#000",
221    _bgColor: "#c0c0c0",
222    _cls: "",
223    _time: 4000,
224    _t: $("._toast") || [],
225    _hide: function (_tc) {
226        var _this = this;
227        if (_this._t.length > 0) {
228            _this._t.fadeOut(500, function () {
229                _this._t.remove();
230                _this._t = [];
231                clearTimeout(window['_toastCounter_' + _tc]);
232            });
233        }
234    },
235    _show: function (_tc, time) {
236        var _this = this;
237        _this._t.fadeIn(500);
238        window['_toastCounter_' + _tc] = setTimeout(function () {
239            _this._hide();
240        }, time);
241    },
242    show: function (params) {
243        params = params || [];
244        var msg = params.msg || this._msg;
245        var color = params.color || this._color;
246        var bgColor = params.bgColor || this._bgColor;
247        var cls = params.cls || this._cls;
248        var time = params.time || this._time;
249        if (time < 500) {
250            time = 500;
251        }
252        if (this._t.length == 0) {
253            var _tc = Date.now();
254            //$("body").append("<div onclick='Toast._hide(" + _tc + ");' title='×' class='_toast" + (cls.length > 0 ? " " + cls : "") + "' style='color:" + color + ";background-color:" + bgColor + ";'>" + msg + "</div>");
255            $("body").append("<div onclick='Toast._hide(" + _tc + ");' title='×' class='_toast" + (cls.length > 0 ? " " + cls : "") + "'>" + msg + "</div>");
256            this._t = $("._toast");
257            this._show(_tc, time);
258        }
259    }
260};
261// usage: Toast.show({ color: 'yellow', bgColor: 'red', msg: 'Lorem ipsum', time: 2000, cls: '_toast--success' });
262// ==============================================
263
264// ==============================================
265// FORMS
266// ==============================================
267function ClearForm(formId) {
268    var $frm = $("#" + formId);
269    if ($frm == null) return;
270
271    // remove previous error
272    $("#" + formId + " .form-group").removeClass("has-error");
273    $("#" + formId + " .err-text").addClass("hidden");
274
275    // clear values
276    $frm.removeClass("hidden");
277    $("#post_" + formId).addClass("hidden");
278    $("#" + formId + " .form-control").val("");
279    $("#" + formId + " .form-check-input").attr("checked", false);
280
281    // files
282    $("#" + formId + " .file-upload-filename span").text("");
283    $("#" + formId + " .file-upload-filename").addClass("hidden");
284}
285
286function SubmitFormRenderer(formId, ParentNodeId, FormNodeId, lang, name, gaObject) {
287
288    var $frm = $("#" + formId);
289    if ($frm == null) return;
290
291    var firstElm = null; // for scroll to
292    var isOk = true;
293    var formContent = {};
294    formContent.ParentNodeId = ParentNodeId;
295    formContent.FormNodeId = FormNodeId;
296    formContent.FormId = formId;
297    formContent.Lang = lang;
298    formContent.Name = name;
299    formContent.Data = [];
300
301    var formData = new FormData();
302
303    // remove previous error
304    $frm.children(".form-group").removeClass("has-error");
305    $frm.find(".err-text").addClass("hidden");
306
307    // loop
308    $("[id^=" + formId + "]", $frm).each(function () {
309        $this = $(this);
310        // get parent
311        var $parent = $this.parent().closest(".form-group");
312
313        // CHECKBOX
314        if ($this.attr("type") == "checkbox") {
315            if ($parent.hasClass("req")) {
316                if (!$("[name='" + $this.attr("name") + "']").is(":checked")) {
317                    isOk = false;
318                    $parent.addClass("has-error");
319                    $parent.find(".err-text").removeClass("hidden");
320                    if (firstElm == null) {
321                        firstElm = $this;
322                    }
323                }
324            }
325            if (isOk && $this.is(":checked")) {
326                formContent.Data.push({
327                    "Id": $parent.attr("data-id"),
328                    "Name": $parent.attr("data-name"),
329                    "Value": $this.val(),
330                    "Type": "checkbox"
331                });
332            }
333            // RADIO
334        } else if ($this.attr("type") == "radio") {
335            if ($parent.hasClass("req")) {
336                if (!$("[name='" + $this.attr("name") + "']").is(":checked")) {
337                    isOk = false;
338                    $parent.addClass("has-error");
339                    $parent.find(".err-text").removeClass("hidden");
340                    if (firstElm == null) {
341                        firstElm = $this;
342                    }
343                }
344            }
345            if (isOk && $this.is(":checked")) {
346                formContent.Data.push({
347                    "Id": $parent.attr("data-id"),
348                    "Name": $parent.attr("data-name"),
349                    "Value": $this.val(),
350                    "Type": "radio"
351                });
352            }
353            // FILE UPLOAD
354        } else if ($this.attr("type") == "file") {
355            if ($parent.hasClass("req") && $this[0].files?.length == 0) {
356                isOk = false;
357                $parent.addClass("has-error");
358                $parent.find(".err-text").removeClass("hidden");
359                if (firstElm == null) {
360                    firstElm = $this;
361                }
362            }
363            else if ($this[0].files?.length > 0) {
364                var allowedTypes = $parent.attr("data-allowed-file-types");
365                if (!allowedTypes.includes($this[0].files[0].name.split('.').pop())) {
366                    isOk = false;
367                    $parent.addClass("has-error");
368                    $parent.find(".err-text").removeClass("hidden");
369                    if (firstElm == null) {
370                        firstElm = $this;
371                    }
372                }
373                if (isOk) {
374                    // max 500MB - see web.config also
375                    if ($this[0].files[0].size > (500 * 1024 * 1024)) {
376                        isOk = false;
377                        $parent.addClass("has-error");
378                        $parent.find(".err-text").removeClass("hidden");
379                        if (firstElm == null) {
380                            firstElm = $this;
381                        }
382                    }
383                }
384                if (isOk) {
385                    formContent.Data.push({
386                        "Id": $parent.attr("data-id"),
387                        "Name": $parent.attr("data-name"),
388                        "Value": $this[0].files[0].name,
389                        "Type": "file"
390                    });
391                    formData.append("FormFiles", $this[0].files[0]);
392                }
393            }
394            // HIDDEN - exclude flatpick hidden input
395        } else if ($this.attr("type") == "hidden" && $this.attr("data-type") != "date") {
396            formContent.Data.push({
397                "Id": $this.attr("data-id"),
398                "Name": $this.attr("data-name"),
399                "Value": $this.val(),
400                "Type": "hidden"
401            });
402            //} else if ($this.attr("data-type") == "date") {
403            // do something with date
404        } else {
405            // REST
406            if ($parent.hasClass("req") && $this.val().length == 0) {
407                isOk = false;
408                $parent.addClass("has-error");
409                $parent.find(".err-text").removeClass("hidden");
410                if (firstElm == null) {
411                    firstElm = $this;
412                }
413            }
414
415            // regex
416            var dataRegex = $parent.attr("data-regex") || "";
417            if (isOk && dataRegex.length > 0) {
418                var regex = new RegExp(dataRegex);
419                if ($this.val().length > 0) {
420                    var tmpRetVal = regex.test($this.val());
421                    if (!tmpRetVal) {
422                        $parent.addClass("has-error");
423                        $parent.find(".err-text").removeClass("hidden");
424                        isOk = false;
425                        if (firstElm == null) {
426                            firstElm = $this;
427                        }
428                    }
429                }
430            }
431
432            // change val() to variable
433            var tmpVal = $this.val();
434
435            if (isOk) {
436                formContent.Data.push({
437                    "Id": $parent.attr("data-id"),
438                    "Name": $parent.attr("data-name"),
439                    "Value": tmpVal,
440                    "Type": "text"
441                });
442            }
443        }
444    });
445    // debug
446    // console.log(JSON.stringify(formData));
447    // return;
448
449    if (isOk) {
450        if (!formSubmitting) {
451            formSubmitting = true;
452            ShowLoadingOverlay();
453
454            formData.append("FormContent", JSON.stringify(formContent));
455
456            $.ajax({
457                type: "POST",
458                url: "/api/FormRendererPost",
459                contentType: false,
460                cache: false,
461                processData: false,
462                data: formData
463            })
464                .done(function (response) {
465                    if (response.status) {
466                        // trigger analytics
467                        if (gaObject) {
468                            try {
469                                gtag("event", gaObject.EventName, {
470                                    "event_label": gaObject.EventLabel || "",
471                                    "event_properties": gaObject.EventProperties || ""
472                                });
473                            }
474                            catch (ex) { }
475                        }
476
477                        // show submission modal
478                        $("#" + formId + "_submission_modal").appendTo("body").modal('show');
479                        // or show div
480                        //$frm.addClass("hidden");
481                        //$("#post_" + formId).removeClass("hidden");
482                        //ScrollTo($("#post_" + formId), 100);
483
484                        // clear previous data
485                        ClearForm(formId);
486
487                        // set new antiForgery Token
488                        $frm.find("#" + formId + "_aft").val(response.antiForgeryToken);
489                    } else {
490                        // server error
491                        console.log('server error');
492                    }
493                })
494                .fail(function (errorResponse) {
495                    // server error
496                    console.log(errorResponse);
497                })
498                .always(function () {
499                    formSubmitting = false;
500                    HideLoadingOverlay();
501                });
502        }
503    } else {
504        ScrollTo(firstElm, null, function () {
505            firstElm.trigger("focus");
506        });
507    }
508}
509// ==============================================
510
511// ==============================================
512// JALERT
513// ==============================================
514(function ($) {
515    $.alerts = {
516        defaults: {
517            okButton: '&nbsp;V redu&nbsp;',				// text for the OK button
518            cancelButton: '&nbsp;Prekliči&nbsp;',		// text for the Cancel button
519            autoClose: null,							// auto-close dialog after x seconds
520            iconType: null
521        },
522
523        settings: null,
524        _t: null,
525
526        // public methods
527        info: function (message, callback, options) {
528            this.settings = $.extend({}, this.defaults, options);
529            this._show(message, 'info', function (result) {
530                if (callback) callback(result);
531            });
532        },
533        alert: function (message, callback, options) {
534            this.settings = $.extend({}, this.defaults, options);
535            this._show(message, 'alert', function (result) {
536                if (callback) callback(result);
537            });
538        },
539        confirm: function (message, callback, options) {
540            this.settings = $.extend({}, this.defaults, options);
541            this._show(message, 'confirm', function (result) {
542                if (callback) callback(result);
543            });
544        },
545        modal: function (message, callback, options) {
546            this.settings = $.extend({}, this.defaults, options);
547            this._show(message, 'modal', function (result) {
548                if (callback) callback(result);
549            });
550        },
551
552        // private methods
553        _show: function (msg, type, callback) {
554            $.alerts._hide();
555            $.alerts._overlay('show');
556            $("BODY").append(
557                '<div id="alertsContainer">' +
558                '   <div id="alertsContent">' +
559                '       <div id="alertsIcon">' +
560                '       </div>' +
561                '       <div id="alertsMessage">' +
562                '       </div>' +
563                '   </div>' +
564                '</div>');
565
566            $("#alertsIcon").addClass("_" + ($.alerts.settings.iconType == null ? type : $.alerts.settings.iconType));
567            $("#alertsMessage").text(msg);
568            $("#alertsMessage").html($("#alertsMessage").text().replace(/\n/g, '<br />'));
569
570            switch (type) {
571                case 'info':
572                    $("#alertsMessage").after('<div id="alertsButtons"><button class="btn_1" id="dialogOk">' + $.alerts.settings.okButton + '</button></div>');
573                    $("#dialogOk").on("click", function (e) {
574                        e.preventDefault();
575                        e.stopPropagation();
576                        $.alerts._hide();
577                        callback(true);
578                    });
579                    $("#dialogOk").trigger("focus").on("keyup", function (e) {
580                        if (e.key == "Enter" || e.key == "Escape") $("#dialogOk").trigger('click');
581                    });
582                    break;
583                case 'alert':
584                    $("#alertsMessage").after('<div id="alertsButtons"><button class="btn_1" id="dialogOk">' + $.alerts.settings.okButton + '</button></div>');
585                    $("#dialogOk").on("click", function (e) {
586                        e.preventDefault();
587                        e.stopPropagation();
588                        $.alerts._hide();
589                        callback(true);
590                    });
591                    $("#dialogOk").trigger("focus").on("keyup", function (e) {
592                        if (e.key == "Enter" || e.key == "Escape") $("#dialogOk").trigger('click');
593                    });
594                    break;
595                case 'confirm':
596                    $("#alertsMessage").after('<div id="alertsButtons"><button class="btn_1" id="dialogOk">' + $.alerts.settings.okButton + '</button>&nbsp;<button class="btn_1 outline" id="dialogCancel">' + $.alerts.settings.cancelButton + '</button></div>');
597                    $("#dialogOk").on("click", function (e) {
598                        e.preventDefault();
599                        e.stopPropagation();
600                        $.alerts._hide();
601                        if (callback) callback(true);
602                    });
603                    $("#dialogCancel").on("click", function (e) {
604                        e.preventDefault();
605                        e.stopPropagation();
606                        $.alerts._hide();
607                        if (callback) callback(false);
608                    });
609                    $("#dialogOk").trigger("focus");
610                    $("#dialogOk, #dialogCancel").on("keyup", function (e) {
611                        if (e.key == "Enter") $("#dialogOk").trigger('click');
612                        if (e.key == "Escape") $("#dialogCancel").trigger('click');
613                    });
614                    break;
615                case 'modal':
616                    break;
617            }
618
619            if ($.alerts.settings.autoClose) {
620                $.alerts._t = setTimeout('$.alerts._hide();', $.alerts.settings.autoClose);
621                $.alerts.settings.autoClose = null;
622            }
623        },
624
625        _hide: function () {
626            $("#alertsContainer").remove();
627            $.alerts._overlay('hide');
628            if ($.alerts._t) clearTimeout($.alerts._t);
629        },
630
631        _overlay: function (status) {
632            switch (status) {
633                case 'show':
634                    $.alerts._overlay('hide');
635                    $("BODY").append('<div id="alertsOverlay" tabindex="0"></div>');
636                    break;
637                case 'hide':
638                    $("#alertsOverlay").remove();
639                    break;
640            }
641        },
642    }
643
644    // shortuct functions
645    jModal = function (message, callback, options) { $.alerts.modal(message, callback, options); }
646    jInfo = function (message, callback, options) { $.alerts.info(message, callback, options); }
647    jAlert = function (message, callback, options) { $.alerts.alert(message, callback, options); }
648    jConfirm = function (message, callback, options) { $.alerts.confirm(message, callback, options); };
649
650})(jQuery);
651
652/*
653// usage
654document.addEventListener('DOMContentLoaded', function () {
655    jConfirm("Confirm", function (callback) {
656        if (callback) {
657            jInfo("Confirmed");
658        }
659        else {
660            jAlert("Not confirmed");
661        }
662    });
663});
664
665regular href confirm simulation - oneliner
666onclick="(function(e){ jConfirm('Confirm!', function(callback) { if(callback) { window.location = e.target; } }); e.preventDefault(); })(event)"
667 */
668// ==============================================
669
670// ==============================================
671// COLLAPSIBLE
672// ==============================================
673// Collapsible
674(function ($) {
675    $.fn.collapsible = function (options) {
676        var defaults = {
677            maintainState: false,
678        };
679        var settings = $.extend({}, defaults, options);
680        if (this.length > 1) {
681            this.each(function () { $(this).pluginName(options) });
682            return this;
683        }
684
685        return this.each(function () {
686            var base = $(this);
687
688            $('.r-collapsible-title', base).on("click", function () {
689                $this = $(this);
690                if (settings.maintainState) {
691                    $this.next('.r-collapsible-content').slideToggle('fast');
692                    $this.toggleClass('r-collapsible-title-closed');
693                    $this.toggleClass('r-collapsible-title-opened');
694                }
695                else {
696                    if ($this.hasClass('r-collapsible-title-opened')) {
697                        $this.next('.r-collapsible-content', base).slideUp('fast');
698                        $this.removeClass('r-collapsible-title-opened');
699                        $this.addClass('r-collapsible-title-closed');
700                    }
701                    else {
702                        // all
703                        $('.r-collapsible-content', base).slideUp('fast');
704                        $('.r-collapsible-title', base).removeClass('r-collapsible-title-opened');
705                        $('.r-collapsible-title', base).addClass('r-collapsible-title-closed');
706
707                        // this
708                        $this.next('.r-collapsible-content').slideToggle('fast');
709                        $this.toggleClass('r-collapsible-title-closed');
710                        $this.toggleClass('r-collapsible-title-opened');
711                    }
712                }
713            });
714
715            var hash = window.location.hash || '';
716            if (hash.length > 0) hash = hash.replace('#', '');
717            if (hash.length > 0) {
718                var $item = base.find(".r-collapsible-title[data-anchor='" + hash + "']") || [];
719                if ($item.length > 0 && $item.hasClass("r-collapsible-title-closed")) {
720                    $item.get(0).trigger("click");
721                }
722            }
723        });
724    };
725})(jQuery);
726// ==============================================
727
728// ==============================================
729// TABS
730// ==============================================
731(function ($) {
732    $.fn.tabs = function (options) {
733        var defaults = {
734            openedId: 0,
735            addHash: false
736        };
737        var settings = $.extend({}, defaults, options);
738        if (this.length > 1) {
739            this.each(function () { $(this).pluginName(options) });
740            return this;
741        }
742
743        return this.each(function () {
744            var base = $(this);
745
746            $('.r-tab', base).on("click", function () {
747                var $this = $(this);
748                $('.r-tabs-content', base).hide();
749                var activeTab = $this.attr('rel');
750                $('.r-tab', base).removeClass('active');
751                $this.addClass('active');
752                $('.r-tabs-content.' + activeTab, base).fadeIn();
753
754                if (settings.addHash) {
755                    window.location.hash = "#" + $this.data('anchor');
756                }
757            });
758
759
760            var hash = window.location.hash || '';
761            if (hash.length > 0) hash = hash.replace('#', '');
762            if (hash.length > 0) {
763                var $hash = base.find(".r-tab[data-anchor='" + hash + "']") || [];
764                if ($hash.length > 0) {
765                    $hash.first().trigger("click");
766                    return;
767                }
768            }
769
770            if (settings.openedId != null) {
771                $('.r-tab', base).eq(settings.openedId).trigger("click");
772                return;
773            }
774
775            $(".r-tab", base).first().trigger("click");
776        });
777    };
778})(jQuery);
779// ==============================================
780
781// ==============================================
782// GLIGHTBOX
783// ==============================================
784document.addEventListener('DOMContentLoaded', function () {
785    var magnify_target_position = 0;
786    const magnify = GLightbox({
787        selector: '.magnify',
788        onOpen: function (target) {
789            magnify_target_position = scrollPosition;
790        },
791        onClose: function () {
792            $("html, body").scrollTop(magnify_target_position);
793            magnify_target_position = 0;
794        }
795    });
796});
797// ==============================================
798
799// ==============================================
800// PLAY VIDEO ON SIGHT
801// ==============================================
802/*
803document.addEventListener('DOMContentLoaded', function () {
804    var $win = $(window);
805    var elementTop, elementBottom, viewportTop, viewportBottom;
806
807    function isScrolledIntoView(elem) {
808        elementTop = $(elem).offset().top;
809        elementBottom = elementTop + $(elem).outerHeight();
810        viewportTop = $win.scrollTop();
811        viewportBottom = viewportTop + $win.height();
812        return (elementBottom > viewportTop && elementTop < viewportBottom);
813    }
814
815    if ($(".r-video video").length) {
816        var loadVideo;
817        $(".r-video video").each(function (idx) {
818            $(this).attr("webkit-playsinline", "");
819            $(this).attr("playsinline", "");
820            $(this).attr("muted", "muted");
821
822            $(this).attr("id", "video_" + idx);
823            loadVideo = document.getElementById("video_" + idx);
824            loadVideo.load();
825        });
826
827        $win.on("scroll wheel DOMMouseScroll mousewheel touchmove", function () {
828            $(".r-video video").each(function () {
829                var autoplay = $(this).attr("data-autoplay");
830                if (autoplay && autoplay.toLowerCase() == "true") {
831                    if (isScrolledIntoView(this) == true) {
832                        $(this)[0].play();
833                    } else {
834                        $(this)[0].pause();
835                    }
836                }
837            });
838        });
839    }
840});
841*/
842
843var ytPlayers = [];
844
845function initYouTubeAPI() {
846    if (typeof YT === 'undefined' || typeof YT.Player === 'undefined') {
847        var tag = document.createElement('script');
848        tag.src = "https://www.youtube.com/iframe_api";
849        document.head.appendChild(tag);
850    } else {
851        onYouTubeIframeAPIReady(); // če je že naložen
852    }
853}
854
855window.onYouTubeIframeAPIReady = function () {
856    $('.r-video.r-video-yt').each(function (index) {
857        var $wrapper = $(this);
858        var $iframe = $wrapper.find('iframe.video-youtube');
859        var iframeEl = $iframe.get(0);
860
861        // Dodeli ID, če ga iframe nima
862        if (!$iframe.attr('id')) {
863            $iframe.attr('id', 'ytplayer-' + index);
864        }
865
866        var player = new YT.Player($iframe.attr('id'), {
867            events: {
868                'onReady': function () {
869                    ytPlayers[index] = player;
870                }
871            }
872        });
873
874        // Shrani referenco v wrapper
875        $wrapper.data('yt-player-index', index);
876    });
877};
878
879document.addEventListener('DOMContentLoaded', function () {
880    var $win = $(window);
881
882    function isScrolledIntoView(elem) {
883        var elementTop = $(elem).offset().top;
884        var elementBottom = elementTop + $(elem).outerHeight();
885        var viewportTop = $win.scrollTop();
886        var viewportBottom = viewportTop + $win.height();
887        return (elementBottom > viewportTop && elementTop < viewportBottom);
888    }
889
890    $(".r-video-video").each(function (idx) {
891        var $container = $(this);
892        var $video = $container.find("video");
893        var autoplay = $video.attr("data-autoplay");
894        var videoId = "video_" + idx;
895        $video.attr("id", videoId);
896        $video.attr("webkit-playsinline", "").attr("playsinline", "");
897        $video[0].load();
898
899        var $btnPlay = $container.find(".btn-toggle-play");
900        var $btnMute = $container.find(".btn-toggle-mute");
901        var $iconPlay = $btnPlay.find(".icon-play i");
902        var $iconMute = $btnMute.find(".icon-mute i");
903
904        function updatePlayIcon() {
905            $video[0].paused ? $iconPlay.changeClass("bi-pause-fill", "bi-play-fill") : $iconPlay.changeClass("bi-play-fill", "bi-pause-fill");
906        }
907
908        function updateMuteIcon() {
909            $video[0].muted ? $iconMute.changeClass("bi-volume-mute-fill", "bi-volume-off-fill") : $iconMute.changeClass("bi-volume-off-fill", "bi-volume-mute-fill");
910        }
911
912        var pauseClicked = false;
913        $btnPlay.on("click", function () {
914            if ($video[0].paused) {
915                $video[0].play();
916            } else {
917                $video[0].pause();
918                $video[0].muted = true;
919                pauseClicked = true;
920            }
921            updatePlayIcon();
922            updateMuteIcon();
923        });
924
925        $btnMute.on("click", function () {
926            $video[0].muted = !$video[0].muted;
927            updateMuteIcon();
928        });
929
930        // Scroll sync za autoplay videe
931        if (autoplay && autoplay.toLowerCase() === "true") {
932            $win.on("scroll wheel DOMMouseScroll mousewheel touchmove", function () {
933                if (!pauseClicked) {
934                    if (isScrolledIntoView($video)) {
935                        $video[0].play();
936                    } else {
937                        $video[0].pause();
938                    }
939                    updatePlayIcon();
940                }
941            });
942        }
943
944        // Initial icon sync
945        updatePlayIcon();
946        updateMuteIcon();
947    });
948
949    // Preveri, če obstajajo iframe-i
950    if ($('iframe.video-youtube').length > 0) {
951        initYouTubeAPI();
952    }
953
954    // Gumb za mute/unmute
955    $(document).on('click', '.r-video.r-video-yt .btn-toggle-mute', function () {
956        var $wrapper = $(this).closest('.r-video.r-video-yt');
957        var index = $wrapper.data('yt-player-index');
958        var $icon = $(this).find('.icon-mute i');
959        var player = ytPlayers[index];
960
961        if (player && typeof player.isMuted === 'function') {
962            if (player.isMuted()) {
963                player.unMute();
964                $icon.removeClass('bi-volume-off-fill').addClass('bi-volume-mute-fill');
965            } else {
966                player.mute();
967                $icon.removeClass('bi-volume-mute-fill').addClass('bi-volume-off-fill');
968            }
969        } else {
970            console.warn("Player ni pripravljen za ta video.");
971        }
972    });
973
974
975
976});
977// ==============================================
978
979// ==============================================
980// Equal Heights
981// ==============================================
982function _eqh() {
983    $('.eqh-row').each(function () {
984        var $this = $(this);
985        if ($(document).width() >= 992) {
986            var highestBox = 0;
987            $('.eqh-col', $this).each(function () {
988                $(this).height('auto');
989                if ($(this).height() > highestBox) {
990                    highestBox = $(this).height();
991                }
992            });
993            $('.eqh-col', $this).height(highestBox);
994        } else {
995            $('.eqh-col', $this).height('auto');
996        }
997    });
998}
999
1000function Eqh() {
1001    var totalImages = $("img").length;
1002    if (totalImages > 0) {
1003        $('body').imagesLoaded(function () {
1004            setTimeout(function () {
1005                _eqh();
1006            }, 0);
1007        });
1008    } else {
1009        setTimeout(function () {
1010            _eqh();
1011        }, 0);
1012    }
1013}
1014// ==============================================
1015
1016// ==============================================
1017// SEARCH
1018// ==============================================
1019function DoSearch() {
1020    var $txtSearch = $("#txtSearch");
1021    if ($txtSearch.val().length >= 3) {
1022        window.location.href = $txtSearch.attr("data-action") + "?q=" + encodeURIComponent($txtSearch.val());
1023    }
1024    else {
1025        jAlert(Translate["search_min_length"], function () {
1026            setTimeout(function () {
1027                $("#txtSearch").trigger("focus");
1028            }, 300);
1029        });
1030    }
1031}
1032
1033document.addEventListener('DOMContentLoaded', function () {
1034    $("#modalSearch").on('shown.bs.modal', function () {
1035        $("#txtSearch").trigger("focus");
1036    });
1037
1038    $(".btnSearch").on("click", function (e) {
1039        e.preventDefault();
1040        e.stopPropagation();
1041        DoSearch();
1042    });
1043
1044    $("#txtSearch").on("keyup", function (e) {
1045        var keycode = e.key || e.which;
1046        if (keycode == "Enter") {
1047            e.preventDefault();
1048            e.stopPropagation();
1049            DoSearch();
1050        }
1051    });
1052});
1053
1054// ==============================================
1055// NAVI - MENU
1056// ==============================================
1057document.addEventListener('touchstart', function () { }, true);
1058
1059document.addEventListener("DOMContentLoaded", function () {
1060    // hamburger button
1061    $(".navi .menu-toggler").on("click", function () {
1062        $(this).toggleClass("active");
1063        $(".navi .menu").toggleClass("active");
1064        //$(".navi").toggleClass("active");
1065    });
1066
1067    // adjust left-right opening according to near border position
1068    $(".navi .dropdown-toggler").on("mouseenter", function () {
1069        var $this = $(this);
1070        var submenuLeft = $this.next(".navi .submenu").offset()?.left;
1071        var submenuWidth = $this.next(".navi .submenu").outerWidth();
1072        var windowWidth = $(window).width();
1073        var diff = windowWidth - (submenuLeft + submenuWidth)
1074        if (diff <= 0) {
1075            $this.next(".navi .submenu").addClass("left");
1076        }
1077    });
1078
1079    // TAB navigation
1080    $(".navi .dropdown-toggler").on('keyup', function (e) {
1081        var keyCode = e.key || e.which;
1082        if (keyCode == "Tab") {
1083            var submenuLeft = $(this).next(".navi .submenu").offset().left;
1084            var submenuWidth = $(this).next(".navi .submenu").outerWidth();
1085            var windowWidth = $(window).width();
1086            var diff = windowWidth - (submenuLeft + submenuWidth)
1087            if (diff <= 0) {
1088                $(this).next(".navi .submenu").addClass("left");
1089            }
1090        }
1091    });
1092
1093    // add animation
1094    $(".navi .submenu").addClass("animated animatedIn");
1095
1096    // adjust navi next siblibng's top margin
1097    $(".navi").parent().css("margin-top", $(".navi").outerHeight() + "px");
1098
1099    // close manually opened popups
1100    $('body').on('click', function (e) {
1101        //if ($(e.target).closest('.search').length == 0) {
1102        //    $(".search").removeClass("submenu-open");
1103        //}
1104        //if ($(e.target).closest('.navi').length == 0) {
1105        //    $(".navi .menu-toggler").removeClass("active");
1106        //    $(".navi .menu").removeClass("active");
1107        //}
1108    });
1109
1110    //STARTUP
1111    // debounced events on window resize
1112    var debounce = null;
1113    $(window).on("load resize", function () {
1114        clearTimeout(debounce);
1115        debounce = setTimeout(function () {
1116            // adjust navi next siblibng's top margin
1117            $(".navi").parent().css("margin-top", $(".navi").outerHeight() + "px");
1118        }, 300);
1119    });
1120});
1121// ==============================================
1122
1123// castle pattern
1124function initCastlePattern() {
1125    $(".r-text-with-image.castel-pattern .text-part-right .text-part .text").each(function (idx) {
1126        var container = $(this)[0];
1127        container.style.height = 'auto';
1128        var containerHeight = container.scrollHeight;
1129        var numSquares = Math.ceil((containerHeight + 20) / 40);
1130        var totalHeight = numSquares * 40 - 20;
1131        container.style.height = totalHeight + 'px';
1132
1133        var clipPath = 'polygon(0 0, calc(100% - 20px) 0, ';
1134        for (var i = 0; i < numSquares; i++) {
1135            var y1 = (i * 40) + 'px';
1136            var y2 = (i * 40 + 20) + 'px';
1137            var y3 = (i * 40 + 40) + 'px';
1138
1139            clipPath += '100% ' + y1 + ', 100% ' + y2 + ', calc(100% - 20px) ' + y2 + ', calc(100% - 20px) ' + y3 + ', ';
1140        }
1141
1142        clipPath += '0 ' + totalHeight + 'px, 0 0)';
1143        container.style.clipPath = clipPath;
1144    });
1145    $(".r-text-with-image.castel-pattern .text-part-left .text-part .text").each(function () {
1146        var container = $(this)[0];
1147        container.style.height = 'auto';
1148        var containerHeight = container.scrollHeight;
1149        var numSquares = Math.ceil((containerHeight + 20) / 40);
1150        var totalHeight = numSquares * 40 - 20;
1151        container.style.height = totalHeight + 'px';
1152
1153        var clipPath = 'polygon(0 0, 100% 0px, 100% ' + totalHeight + 'px, 0px ' + totalHeight + 'px, ';
1154        for (var i = 0; i <= numSquares - 1; i++) {
1155            var y = totalHeight - (i * 40);
1156            clipPath += '0px ' + y + 'px, 0px ' + (y - 20) + 'px, 20px ' + (y - 20) + 'px, 20px ' + (y - 40) + 'px, ';
1157        }
1158        clipPath += ' 0px 0px)';
1159        container.style.clipPath = clipPath;
1160    });
1161}
1162
1163// ==============================================
1164// CHANGE CLASS
1165// ==============================================
1166(function ($) {
1167    $.fn.changeClass = function (remove, add) {
1168        return this.each(function () {
1169            $(this).removeClass(remove).addClass(add);
1170        });
1171    };
1172})(jQuery);
1173
1174// ==============================================
1175// TEXT MARQUEE
1176// ==============================================
1177(function ($) {
1178    $.fn.textMarquee = function () {
1179        return this.each(function () {
1180            var $base = $(this);
1181            var $marquee = $base.find(".marquee");
1182            var windowWidth = $(window).width();
1183            var $marqueeClone = $marquee.clone();
1184            var marqueeWidth = $marquee.outerWidth();
1185            var loop = Math.floor(windowWidth / marqueeWidth);
1186
1187            for (var i = 0; i <= loop - 1; i++) {
1188                $marquee.append($marqueeClone.html());
1189            }
1190
1191            $tickerClone = $base.clone();
1192            $($tickerClone).find(".marquee").attr("aria-hidden", "true");
1193            $base.append($tickerClone.html());
1194
1195            $base.find(".marquee").addClass("animation");
1196        });
1197    };
1198})(jQuery);
1199// ==============================================
1200
1201
1202// ==============================================
1203// owl carousel for events
1204// ==============================================
1205document.addEventListener('DOMContentLoaded', function () {
1206    //$(".owl-carousel.owl-catalogue-items").each(function () {
1207    //    const $carousel = $(this);
1208
1209    //    const itemCount = $carousel.find('.catalogue-list-item').length;
1210    //    const loopSetting = itemCount >= 3;
1211
1212    //    $carousel.owlCarousel({
1213    //        loop: loopSetting,
1214    //        margin: 20,
1215    //        center: !loopSetting,
1216    //        responsive: {
1217    //            0: { items: 1 },
1218    //            672: { items: 2 },
1219    //            1200: { items: 3 }
1220    //        },
1221    //        nav: false,
1222    //        dots: false,
1223    //        pagination: false
1224    //    });
1225
1226    //    var $nav = $carousel.next(".owl-catalogue-items-nav");
1227    //    $nav.find(".owlNext").on("click", function () {
1228    //        $carousel.trigger('next.owl.carousel');
1229    //    });
1230
1231    //    $nav.find(".owlPrev").on("click", function () {
1232    //        $carousel.trigger('prev.owl.carousel');
1233    //    });
1234
1235    //});
1236});
1237//function toggleOwlCarouselCatalogueItemsNavigation() {
1238//    $(".owl-carousel.owl-catalogue-items").each(function () {
1239//        var $carousel = $(this);
1240//        var itemCount = $carousel.find('.catalogue-list-item').length;
1241//        var visibleItems = $carousel.find('.owl-item.active').length;
1242//        var $nav = $carousel.next(".owl-catalogue-items-nav");
1243//        if (itemCount > visibleItems) {
1244//            $nav.find(".nav-buttons").show();
1245//        } else {
1246//            $nav.find(".nav-buttons").hide();
1247//        }
1248//    });
1249//}
1250// ==============================================
1251
1252// ==============================================
1253// owl carousel for galleries with data
1254// ==============================================
1255document.addEventListener('DOMContentLoaded', function () {
1256    $(".owl-carousel").each(function () {
1257        var $carousel = $(this);
1258
1259        var hasLoop = $carousel.hasClass("owl-carousel-loop") || false;
1260
1261        $carousel.on('initialized.owl.carousel', function () {
1262            var $this = $(this);
1263            var itemCount = $this.find('.owl-item').length;
1264            var visibleItems = $this.find('.owl-item.active').length;
1265            var $nav = $this.next(".owl-items-nav");
1266            if (itemCount > visibleItems) {
1267                $nav.find(".nav-buttons").show();
1268                $nav.find(".owlNext").on("click", function () {
1269                    $this.trigger('next.owl.carousel');
1270                });
1271                $nav.find(".owlPrev").on("click", function () {
1272                    $this.trigger('prev.owl.carousel');
1273                });
1274            } else {
1275                $nav.find(".nav-buttons").hide();
1276            }
1277
1278            $this.find('img').each(function () {
1279                $(this).on('load', function () {
1280                    $('.owl-carousel').trigger('refresh.owl.carousel');
1281                });
1282            });
1283        });
1284
1285        $carousel.owlCarousel({
1286            loop: hasLoop,
1287            autoWidth: false,
1288            margin: 20,
1289            responsiveClass: true,
1290            dots: false,
1291            nav: true,
1292            navText: ["<i class='chevron-left'></i>", "<i class='chevron-right'></i>"],
1293            autoHeight: true,
1294            responsive: {
1295                0: {
1296                    items: 1,
1297                },
1298                600: {
1299                    items: 2,
1300                },
1301                900: {
1302                    items: 3,
1303                },
1304                //1200: {
1305                //    items: 4,
1306                //}
1307            }
1308        });
1309    });
1310
1311
1312
1313
1314
1315    //$(".r-gallery-with-data .owl-carousel").each(function () {
1316    //    const $this = $(this);
1317
1318    //    const itemCount = $this.find('.gallery-item').length;
1319    //    const loopSetting = itemCount >= 3;
1320
1321    //    $this.owlCarousel({
1322    //        loop: loopSetting,
1323    //        margin: 20,
1324    //        center: !loopSetting,
1325    //        responsive: {
1326    //            0: { items: 1 },
1327    //            672: { items: 2 },
1328    //            1200: { items: 3 }
1329    //        },
1330    //        nav: false,
1331    //        dots: false,
1332    //        pagination: false
1333    //    });
1334
1335    //    var $nav = $this.next(".owl-gallery-items-nav");
1336    //    $nav.find(".owlNext").on("click", function () {
1337    //        $this.trigger('next.owl.carousel');
1338    //    });
1339
1340    //    $nav.find(".owlPrev").on("click", function () {
1341    //        $this.trigger('prev.owl.carousel');
1342    //    });
1343
1344    //});
1345});
1346//function toggleOwlCarouselGalleryWIthDataNavigation() {
1347//    $(".r-gallery-with-data .owl-carousel").each(function () {
1348//        var $this = $(this);
1349//        var itemCount = $this.find('.gallery-item').length;
1350//        var visibleItems = $this.find('.owl-item.active').length;
1351//        var $nav = $this.next(".owl-gallery-items-nav");
1352//        if (itemCount > visibleItems) {
1353//            $nav.find(".nav-buttons").show();
1354//        } else {
1355//            $nav.find(".nav-buttons").hide();
1356//        }
1357//    });
1358//}
1359// ==============================================
1360
1361// ==============================================
1362// STARTUP
1363// ==============================================
1364document.addEventListener('DOMContentLoaded', function () {
1365    /* skip to content */
1366    $(".skip-to-content a").on("click", function (e) {
1367        e.preventDefault();
1368        $(this).trigger("blur");
1369        var section = $(this).attr("data-section");
1370        //$("html, body").animate({ scrollTop: $(section).offset().top - $(".header-area").height() }, "slow", function () {
1371        //    $(section).trigger("focus");
1372        //});
1373        ScrollTo($("." + section), 0, function () {
1374            $("." + section).trigger("focus");
1375        });
1376        return false;
1377    });
1378
1379    // set breadcrumbs bgcolor as first row
1380    //$(".container-fluid-breadcrumbs").css("background-color", $(".bl-row:first").css("background-color"));
1381
1382    // scroll top button
1383    $(window).on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove", function (e) {
1384        if ($("body").scrollTop() > 300) {
1385            $(".scroll-to-top").addClass('show');
1386        } else {
1387            $(".scroll-to-top").removeClass('show');
1388        }
1389    });
1390
1391    $(".scroll-to-top").on('click', function (e) {
1392        e.preventDefault();
1393        ScrollTo($("body"), 0, function () {
1394            $(".skip-to-content").trigger("focus");
1395        });
1396    });
1397
1398    // bootstrap tooltip
1399    $('[data-toggle="tooltip"]').tooltip()
1400
1401    // select italic
1402    $(".r-form select").each(function () {
1403        if ($(this).val() === "") {
1404            $(this).addClass('italic');
1405        }
1406    });
1407
1408    $('.r-form select').on('change', function () {
1409        if ($(this).val() === '') {
1410            $(this).addClass('italic');
1411        } else {
1412            $(this).removeClass('italic');
1413        }
1414    });
1415    // select italic
1416
1417    // debounced events on window resize
1418    var debounce = null;
1419    $(window).on("load resize", function () {
1420        clearTimeout(debounce);
1421        debounce = setTimeout(function () {
1422            // adjust Eqh
1423            Eqh();
1424
1425            initCastlePattern();
1426
1427            //toggleOwlCarouselCatalogueItemsNavigation();
1428            //toggleOwlCarouselGalleryWIthDataNavigation();
1429
1430            // adjust navi next siblibng's top margin
1431            //$(".navi").parent().css("margin-top", $(".navi").outerHeight() + "px");
1432        }, 300);
1433    });
1434
1435    $("body").on('scroll', function () {
1436        scrollPosition = window.scrollY || document.body.scrollTop || document.documentElement.scrollTop;
1437        //console.log('body scroll position: ' + scrollPosition);
1438    });
1439
1440    // AOS
1441    /*
1442    AOS.init({
1443        duration: 1000,
1444        once: true,
1445        disable: function () {
1446            var maxWidth = 800;
1447            return window.innerWidth < maxWidth;
1448        }
1449    });
1450*/
1451
1452    // FOUC - keep last here
1453    $("body").css("opacity", 1);
1454});
1455
1456// maintain scroll on pager
1457history.scrollRestoration = "manual";
1458
1459document.addEventListener("click", e => {
1460    const isPager = e.target.closest(".pager, .pagination, .page-link");
1461    if (isPager) {
1462        sessionStorage.setItem("scrollPos", window.scrollY);
1463        sessionStorage.setItem("restoreScroll", "1");
1464    }
1465});
1466
1467window.addEventListener("load", () => {
1468    if (sessionStorage.getItem("restoreScroll") === "1") {
1469        sessionStorage.setItem("restoreScroll", null);
1470        const y = sessionStorage.getItem("scrollPos");
1471        if (y !== null) {
1472            window.scrollTo(0, parseInt(y, 10));
1473        }
1474    }
1475});
1476// maintain scroll on pager

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.