PageSourceSearch

https://catalog.dallaslibrary.org/polaris/scripts/modalBasic.js?ver=8.1.7065.1

js dallaslibrary.org collected 2026-09-24 19:57:13 UTC 8,181 bytes, 237 lines download raw bytes

1
2/******************************************************************************
3*** Modal Basic Functions
4******************************************************************************/
5
6/* Modification Actions */
7
8var maxIframeHeight;
9var verticalPadding = 280;
10var refreshNeeded = false;
11var forceGetAction = false;
12var lastKnownScrollPosition = 0;
13
14$(document).ready(function () {    
15    maxIframeHeight = window.innerHeight - verticalPadding; /* approximate spacing outside of modal-body */
16});
17
18function bindListeners() {
19    // Listener for when a modal becomes visible (after animations)
20    $("#modalBasic").off("shown.bs.modal").on("shown.bs.modal", function () {
21        $("#modalBasic-body").scrollTop(0);
22        $("#modalBasic-body").scrollLeft(0);
23    });
24
25    // Listener for when a modal is hidden (after animations)
26    $("#modalBasic").off("hidden.bs.modal").on("hidden.bs.modal", function () {
27        $(window).off("resize.modaliframe");
28        restoreScrollPosition();
29    });
30}
31
32// Ensure that elements do not stay focused (i.e. when clicked in a mobile browser that has a "sticky" focus)
33function bindAutoBlurOnFocus(id) {
34    $(id).on("focus", function () {
35        if (window.innerWidth < 650) { $(this).blur(); }
36    });
37}
38
39function startResize() {
40    $(window).on("resize.modaliframe", function () {
41        maxIframeHeight = window.innerHeight - verticalPadding; /* approximate spacing outside of modal-body */
42        $("#modalBasic-iframe").css("height", maxIframeHeight);
43    });
44}
45
46// Needed to remedy an Android device bug for Bootstrap v3.
47function restoreScrollPosition() {
48    // Scroll without animation
49    $(document).scrollTop(lastKnownScrollPosition);
50}
51
52// Allow for easy closing of the modal (i.e. from within an iframe).
53function closeModalBasic() {
54    $("#modalBasic").modal("hide");
55}
56
57function changeCloseButtonText() {
58    $("#modalBasic-footer #button_close").val($("#modalBasic_CancelBtn_Text").val());
59}
60
61function changeHeaderCloseButtonClickEvent(action) {
62    $("#modalBasic-header .close").attr("onclick", action);
63    $("#modalBasic-header .close").removeAttr("data-dismiss");
64}
65
66function clickIframeModalButton(id) {
67    $("#modalBasic-iframe").contents().find(id).click();
68}
69
70// Allow for quick disabling of all buttons in the modal footer
71function disableModalFooterButtons() {
72    $("#modalBasic-footer .btn").each(function () {
73        $(this).prop("disabled", true);
74    });
75}
76
77// Allow for quick enabling of all buttons in the modal footer
78function enableModalFooterButtons() {
79    $("#modalBasic-footer .btn").each(function () {
80        $(this).prop("disabled", false);
81    });
82}
83
84// Allow for easy changing of the content (e.g. buttons) within the modal footer
85function initModalBasicFooter(value) {
86    $("#modalBasic-footer").html(value);
87    bindAutoBlurOnFocus("#modalBasic-footer .btn");
88}
89
90// Allow for an iframe to be dynamically resized (i.e. after the inner document loads)
91function resizeModalBasicIframe(widthClass) {
92    setTimeout(function () {
93        // Get document height and update the modal iframe
94        var nInnerHeight, minHeight = 140;
95        var extraPadding = 60; // For modal header & footer spacing
96
97        nInnerHeight = $("#modalBasic-iframe").contents().find("body").height();
98
99        // Sometimes the function is called before the body is full height (i.e. a spinner is still displayed).
100        if (nInnerHeight < minHeight) {
101            nInnerHeight = minHeight;
102        }
103
104        // Make sure the iframe doesn't exceed the maximum height
105        if ((nInnerHeight + extraPadding) > maxIframeHeight) {
106            nInnerHeight = maxIframeHeight;
107        }
108
109        $("#modalBasic-iframe").css("height", nInnerHeight + extraPadding);
110        $("#modalBasic-dialog").addClass(widthClass);
111    }, 500);
112}
113
114function resizeModalBasicIframeToMaxHeight() {
115    var extraPadding = 60; // For modal header & footer spacing
116    $("#modalBasic-iframe").css("height", maxIframeHeight + extraPadding);
117}
118
119
120/* Generic Modal Process */
121
122function initModalBasic(label) {
123    // Update iframe size variable
124    maxIframeHeight = window.innerHeight - verticalPadding; /* approximate spacing outside of modal-body */
125
126    // Make sure a label is present
127    if (!label) {
128        label = "";
129    }
130
131    // Get scroll position
132    lastKnownScrollPosition = $(document).scrollTop();
133
134    $("#modalBasic-dialog").removeClass("modal-wide-80");
135    $("#modalBasic-dialog").removeClass("modal-wide-90");
136    $("#modalBasic-dialog").removeClass("modal-maxwide-50");
137
138    $("#modalBasic-title").html(label);
139    $("#modalBasic-body").html("");
140    initModalBasicFooter('<button type="button" class="btn btn-default" data-dismiss="modal">' + $("#modalBasic_CloseBtn_Text").val() + '</button>');
141
142    // Reset header close button
143    $("#modalBasic-header .close").removeAttr("onclick");
144    $("#modalBasic-header .close").attr("data-dismiss", "modal");
145
146    // Reset previous scroll position to top
147    $("#modalBasic-body").scrollTop();                                      // Firefox
148    $("#modalBasic-body").scrollLeft();                                     // Firefox
149    $("#modalBasic-body").animate({ scrollTop: 0, scrollLeft: 0 }, "slow"); // IE
150    $("#modalBasic-body").hide();                                           // IE
151    setTimeout(function () { $("#modalBasic-body").show(); }, 100);         // Chrome
152
153    // Bind event listeners
154    bindListeners();
155}
156
157function showModalBasic(url, label, fullscreen, refreshPage, forceGet) {
158    // For smaller screens, skip modal and go full screen.
159    if ((fullscreen === true) && (window.innerWidth < 650)) {
160        var newtab = window.open(url, "_blank");
161        newtab.focus();
162        return;
163    }
164
165    // Initialize variables (if needed)
166    if (refreshPage === true) {
167        refreshNeeded = true;
168    }
169
170    if (forceGet === true) {
171        forceGetAction = true;
172    }
173
174    initModalBasic(label);
175
176    $("#modalBasic-body").addClass("modalBasic--loading");
177    $("#modalBasic-body").load(url, function () {
178        $("#modalBasic-body").removeClass("modalBasic--loading");
179    });
180
181    $("#modalBasic").modal();
182
183    $("#modalBasic").on("hidden.bs.modal", function () {
184        if (refreshNeeded === true) {
185            if (forceGetAction === true)
186                window.location = window.location.href;
187            else
188                window.location.reload(true);
189        }
190    });
191}
192
193function showModalBasicWithIframe(url, label, fullscreen, refreshPage, forceGet, iframeAriaLabel) {
194    // For smaller screens, skip modal and go full screen.
195    if ((fullscreen === true) && (window.innerWidth < 650)) {
196        var newtab = window.open(url, "_blank");
197        newtab.focus();
198        return;
199    }
200
201    // Initialize variables (if needed)
202    if (refreshPage === true) {
203        refreshNeeded = true;
204    }
205
206    if (forceGet === true) {
207        forceGetAction = true;
208    }
209
210    // Make sure a iframeAriaLabel is present
211    if (!iframeAriaLabel) {
212        iframeAriaLabel = label;
213    }
214
215    initModalBasic(label);
216
217    $("#modalBasic-body").html('<iframe class="iframe modalBasic--loading" seamless="" id="modalBasic-iframe" aria-label="' + iframeAriaLabel + '" frameBorder="0"></iframe>');
218    $("#modalBasic-iframe").css("height", maxIframeHeight);
219    $("#modalBasic-iframe").attr("src", url);
220
221    $("#modalBasic-iframe").on("load", function (event) {
222        $(event.target).removeClass("modalBasic--loading");
223    });
224
225    $("#modalBasic").modal();
226
227    $("#modalBasic").on("hidden.bs.modal", function () {
228        if (refreshNeeded === true) {
229            if (forceGetAction === true)
230                window.location = window.location.href;
231            else
232                window.location.reload(true);
233        }
234    });
235
236    startResize(); // Resizes the modal dynamically when page is resized (only need to do this because of the fixed height of iframe we manually set)
237}

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.