PageSourceSearch

https://a4-static.comparably.com/eyf/js/jquery-mvc-popup.js?314159

js comparably.com collected 2026-09-24 06:59:45 UTC 8,492 bytes, 206 lines download raw bytes

1var _popup_zindex_counter = 1000;
2
3$.alert = function (options) {
4    if (Object.prototype.toString.call(options) === '[object Array]') {
5        options = { messages: options };
6    } else if (Object.prototype.toString.call(options) === '[object String]') {
7        options = { messages: [{ level: "info", key: "msg", value: options }] };
8    } else if(options.message) {
9        options.messages = [{ level: options.level || "info", key: "msg", value: options.message }];
10    }
11    options = $.extend({ messages: [], buttons: [{ text: "Ok", styleClass: "button ok" }], background: true, canClose: true, close: function () { }, open: function () { } }, options);
12    var m = options.messages;
13    var obj = $("<div class=\"alert_popup\"/>");
14    var _i = [], _w = [], _e = [];
15
16    for (var i = 0; i < m.length; i++) {
17        var c = _w;
18        if (m[i].level == "error") c = _e;
19        else if (m[i].level == "info") c = _i;
20        c.push("<li k=\"");
21        c.push(m[i].key);
22        c.push("\">");
23        c.push(m[i].value);
24        c.push("</li>");
25    }
26    var html = "";
27    if (_i.length > 0) html += "<ul class=\"notifications ifo\">" + _i.join("") + "</ul>";
28    if (_w.length > 0) html += "<ul class=\"notifications wrn\">" + _w.join("") + "</ul>";
29    if (_e.length > 0) html += "<ul class=\"notifications err\">" + _e.join("") + "</ul>";
30
31    return obj.append(html).popup(options).bind("buttonclick", function () { $(this).closePopup(); });
32};
33
34$.fn.closePopup = function () {
35    return $(this).each(function () {
36        if ($(this).hasClass("popup_container"))
37            $(this).trigger("closepopup");
38        else
39            $(this).parents("div.popup_container").trigger("closepopup");
40        setTimeout(function () {
41            $(document.documentElement).toggleClass('is-popup-open', $('.popup_container').length > 0);
42        }, 200);
43    });
44};
45
46$.fn.popup = function (options) {
47    options = $.extend({ background: true, canClose: true, close: function () { }, open: function () { } }, options);
48
49    if(options.popupStateObject)
50    {
51        options._stateListener = function(event, popup){
52            if(event == "popupClosed")
53                options.popupStateObject.closed(popup);
54            else if(event == "popupOpened")
55                options.popupStateObject.opened(popup);
56        };
57    }
58
59    return $(this).each(function () {
60        $(document.documentElement).toggleClass('is-popup-open', true);
61        var c = $("<div class=\"popup_container" + (options.styleClass ? " " + options.styleClass : "") + "\"/>");
62        var bg = null;
63        var inst = $(this);
64
65        $("body").append(c);
66
67        if (options.canClose && !options.hideCloseIcon)
68            c.append("<a href=\"javascript:void(0);\" class=\"" + (options.closeStyleClass || '') + "\" onclick=\"$(this).closePopup();\">" + (options.closeContent || '') + "</a>");
69
70        if (options.title)
71            c.addClass("with-title").append("<h3 class=\"popup_t
71itle\">" + options.title + "</h3>");
72
73        if (options.background) {
74            bg = $("<div class=\"popup_background\"/>");
75            $("body").append(bg);
76            bg.css({ zIndex: (++_popup_zindex_counter) });
77            if (options.canClose && !options.disableBackgroundClose) bg.click(function () { c.closePopup(); });
78        }
79
80
81        var NAV_HEIGHT = 60;
82        var POPUP_TOP = 30 + NAV_HEIGHT;
83        c.append($(this))
84            .css({ zIndex: (++_popup_zindex_counter), "top": (($(window).scrollTop() > POPUP_TOP) ? $(window).scrollTop() + NAV_HEIGHT : POPUP_TOP) + "px" })
85            .bind("closepopup", function () {
86                $(this).remove();
87                bg && bg.remove();
88                options.close.call(inst);
89                if(options._stateListener)
90                    options._stateListener("popupClosed", inst);
91            });
92
93        if (options.body) {
94            var body = $('<div class="popup_content ' + (options.body.styleClass || "") + '"/>');
95            body.append(options.body.content);
96            c.append(body);
97        }
98
99        if (options.buttons) {
100            var btns = $("<div class=\"popup-buttons\"/>");
101            for (var i = 0 ; i < options.buttons.length; i++) {
102                btns.append($("<a class=\"button " + (options.buttons[i].styleClass || "") + "\" href=\"" + (options.buttons[i].href || '') + "\" bid=\"" + (options.buttons[i].id || "def") + "\">" + options.buttons[i].text + "</a>").click(function (e) {
103                    e.preventDefault();
104                    inst.trigger("buttonclick", $(this).attr("bid"));
105                }));
106            }
107            c.append(btns);
108        }
109
110        function updatePos() {
111            var windowWidth = $(window).width();
112            var popupWidth = c.width();
113            var n = parseInt(c.css("left")) || 0;
114            var x = parseInt(Math.round((windowWidth / 2) - (popupWidth / 2))) || 0;
115            var d = 0;
116            var c_css = {};
117
118            if (x !== n) {
119                d = Math.abs(x -n);
120                if (!isNaN(d) && d >= 2) c_css.left = x + "px";
121            }
122
123            if (bg) {
124                n = parseInt(bg.css("height")) || 0;
125                x = $(window).height();
126                if (x != n) {
127                    d = Math.abs(x - n);
128                    if (!isNaN(d) && d >= 2) bg.css({ height: x + "px" });
129                }
130            }
131
132            if (options.fixedPosition) {
133                if (options.fixedPosition === "center") {
134                    var h = c.height();
135                    var wh = $(window).innerHeight();
136                    var top = 0;
137                    if (h < wh) top = ((wh - h) / 2);
138                    c_css.top = Math.max(top, 0) + "px";
139                    if (c.css("position") !== "fixed") c_css.position = "fixed";
140                }
141                if (options.fixedPosition === "bottomRight") {
142                    c_css.top = "auto";
143                    c_css.left = "auto";
144                    c_css.bottom = "20px";
145                    c_css.right = "20px";
146                    if (c.css("position") !== "fixed") c_css.position = "fixed";
147                }
148            }
149
150            c.css(c_css);
151        }
152        options.open.call(inst);
153
154        if (options._stateListener)
155            options._stateListener("popupOpened", inst);
156
157        window.addEventListener('resize', updatePos, { passive: true });
158        c.on("controlLoaded", updatePos);
159        c.on("closepopup", function(){
160            window.removeEventListener('resize', updatePos);
161            c.off("controlLoaded", updatePos);
162        });
163        updatePos();
164
165
166        /* @NOTE https://stackoverflow.com/questions/41594997/ios-10-safari-prevent-scrolling-behind-a-fixed-overlay-and-maintain-scroll-posi */
167        /* Prevent scrolling of background when overlay is on*/
168        if (/iPad|iPhone|iPod/.test(navigator.userAgent)) {
169            function isOverlayTotallyScrolled() {
170                /* https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions*/
171                return c.prop("scrollHeight") - c.scrollTop() <= c.prop("clientHeight");
172            }
173
174            var _clientY = null; /* remember Y position on touch start */
175
176            function disableRubberBand(ev) {
177                var clientY = ev.originalEvent.targetTouches[0].clientY - _clientY;
178
179                if (c.scrollTop() === 0 && clientY > 0) {
180                    /* element is at the top of its scroll*/
181                    ev.preventDefault();
182                }
183
184                if (isOverlayTotallyScrolled() && clientY < 0) {
185                    /*element is at the top of its scroll*/
186                    ev.preventDefault();
187                }
188            }
189
190            c.on('touchstart', function (ev) {
191                window.xxx = ev;
192                if (ev.originalEvent.targetTouches.length === 1) {
193                    /* detect single touch*/
194                    _clientY = ev.originalEvent.targetTouches[0].clientY;
195                }
196            });
197
198
199            c.on('touchmove', function (ev) {
200                if (ev.originalEvent.targetTouches.length === 1) {
201                    disableRubberBand(ev);
202                }
203            });
204        }
205    });
206};

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.