PageSourceSearch

https://explore.gastateparks.org/core/js/BrowserUtil.js

js gastateparks.org collected 2026-10-10 00:05:00 UTC 11,332 bytes, 271 lines download raw bytes

1// // Also resides at /audio/play/js/browserutil.js
2
3(function (window) {
4
5    if (typeof (window.BrowserUtil) != "undefined") {
6        return;
7    }
8
9    var BrowserUtil = function () {
10        /*** Properties ***/
11        // An array of query string names and values
12        /*this.queryStringParams = (function (arrayQueryString) {
13            if (arrayQueryString == "") return {};
14            var nameValueCollection = {};
15            for (var i = 0; i < arrayQueryString.length; ++i) {
16                // Break up the name/value pair into a separate name and value
17                var nameValuePair = arrayQueryString[i].split('=');
18                if (nameValuePair.length != 2) continue; // If there is no querystring value, then skip it.
19                // Add the querystring name and value to the collection.
20                nameValueCollection[nameValuePair[0]] = decodeURIComponent(nameValuePair[1].replace(/\+/g, " "));
21            }
22            return nameValueCollection;
23        })(window.location.search.substr(1).split('&')); // Pass an array of the querystring name/value pairs to the anonymous function and execute it.
24        */
25        this.queryStringParams = this.parseQueryString(window.location.search);
26        this.host = location.host.toLowerCase();
27    }
28
29    /*** Methods ***/
30    BrowserUtil.prototype.parseQueryString = function (queryString) {
31        if (queryString == "") return {};
32        if (queryString.indexOf('?') == 0) {
33            queryString = queryString.substr(1);
34        }
35
36        var arrayQueryString = queryString.split('&');
37        var nameValueCollection = {};
38        for (var i = 0; i < arrayQueryString.length; ++i) {
39            // Break up the name/value pair into a separate name and value
40            var nameValuePair = arrayQueryString[i].split('=');
41            if (nameValuePair.length != 2) continue; // If there is no querystring value, then skip it.
42            // Add the querystring name and value to the collection.
43            nameValueCollection[nameValuePair[0]] = decodeURIComponent(nameValuePair[1].replace(/\+/g, " "));
44        }
45        return nameValueCollection;
46    }
47
48    // Retrieve the value of the cookie with the specified name.
49    BrowserUtil.prototype.getCookie = function (cookieName) {
50        var i, currentCookieName, currentCookieValue;
51
52        // Cookies are separated by semicolons
53        var cookies = document.cookie.split(";");
54
55        for (i = 0; i < cookies.length; i++) {
56            // A name/value pair (a crumb) is separated by an equal sign
57            currentCookieName = cookies[i].substr(0, cookies[i].indexOf("="));
58            currentCookieValue = cookies[i].substr(cookies[i].indexOf("=") + 1);
59            currentCookieName = currentCookieName.replace(/^\s+|\s+$/g, "");
60            if (currentCookieName.toLowerCase() == cookieName.toLowerCase()) {
61                return unescape(currentCookieValue);
62            }
63        }
64
65        // A cookie with the requested name does not exist
66        return "";
67    }
68
69    // Create a cookie with the specified name, value, and optional days to keep before expiration
70    BrowserUtil.prototype.setCookie = function (cookieName, cookieValue, daysToKeep, path) {
71        var expirationDate = new Date();
72        expirationDate.setDate(expirationDate.getDate() + daysToKeep);
73        var cookiePath = "/";
74        if (typeof (path) == 'string' && path != '') {
75            cookiePath = path;
76        }
77        var newCookieValue = escape(cookieValue) +
78        ((daysToKeep == null || daysToKeep == '') ? "" : "; expires=" + expirationDate.toUTCString())
79        + "; path=" + cookiePath;
80        document.cookie = cookieName + "=" + newCookieValue;
81    }
82
83    // Delete the cookie with the specified name.
84    BrowserUtil.prototype.deleteCookie = function (cookieName) {
85        document.cookie = cookieName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
86    }
87
88    // Add script dynamically to the DOM
89    /*
90    Examples:
91    1. Add external script
92    addScript('/js/myscript.js');
93
94    2. Add inline script
95    addScript(null, 'var test = "Hello World";');
96
97    3. Set multiple attributes and a callback
98    addScript({
99        src: '/js/myscript.js',
100        type: 'text/javascript',
101        async: true
102    }, null, function(){});
103    */
104    BrowserUtil.prototype.addScript = function (fileNameOrAttributes, inlineSrc, callback) {
105        var newScript = document.createElement('script');
106        if (fileNameOrAttributes != null) {
107            if (typeof (fileNameOrAttributes) == "string") {
108                newScript.src = fileNameOrAttributes;
109            }
110            else {
111                // fileNameOrAttributes should be a javascript object
112                for (var attr in fileNameOrAttributes) {
113                    newScript.setAttribute(attr, fileNameOrAttributes[attr] ? fileNameOrAttributes[attr] : null)
114                }
115            }
116        }
117        if (typeof (inlineSrc) == "string" && inlineSrc != "") {
118            newScript.text = inlineSrc;
119        }
120        if (callback != null) {
121            newScript.onload = callback;
122        }
123
124        // Verify the document.body property is supported and the body tag has been loaded before trying to append to it.
125        var bodyElements;
126        if (!document.body) {
127            bodyElements = document.getElementsByTagName("body");
128        }
129        if (document.body || bodyElements.length > 0) {
130            (document.body || bodyElements[0]).appendChild(newScript);
131        }
132        else {
133            (document.head || document.getElementsByTagName("head")[0]).appendChild(newScript);
134        }
135    }
136
137    // Create BrowserUtil and expose it to the global object
138    window.BrowserUtil = new BrowserUtil();
139
140})(window);
141
142if (typeof (jQuery.cachedScript) == "undefined") {
143    // The jQuery.getScript() method sets the cache to false.
144    // Use the cachedScript() method to get the script using the browser's cached version if there is one.
145    jQuery.cachedScript = function (url, options) {
146        // allow user to set any option except for dataType, cache, and url
147        options = $.extend(options || {}, {
148            dataType: "script",
149            cache: true,
150            url: url
151        });
152        // Use $.ajax() since it is more flexible than $.getScript
153        // Return the jqXHR object so we can chain callbacks
154        return jQuery.ajax(options);
155    };
156}
157
158/*!
159* makeLinksAbsolute jQuery plugin
160* Converts relative links to absolute links using the specified domain
161*/
162(function ($) {
163    if (typeof ($.fn.makeLinksAbsolute) == "undefined") {
164        $.fn.makeLinksAbsolute = function (options) {
165            // default configuration
166            var settings = $.extend({}, {
167                domain: null
168            }, options);
169
170            // main function
171            function processLink(element) {
172                var $element = $(element);
173
174                if (element.tagName != 'A') {
175                    return;
176                }
177
178                var href = $element.attr('href'); // get the href attribute value
179
180                if (typeof (href) == 'undefined' ||
181                    href.length == 0 ||
182                    href.charAt(0) == '#' ||
183                    href.substr(0, 4) == 'http' ||
184                    href.substr(0, 10) == 'javascript') {
185                    return;
186                }
187
188                if (settings.domain.charAt(settings.domain.length - 1) == '/') {
189                    settings.domain = settings.domain.substr(0, settings.domain.length - 1);
190                }
191
192                href = element.href; // get the full url of this relative link
193
194                var currentDomain = location.href.substring(0, location.href.indexOf(location.pathname)); // get the domain used for relative links
195                href = href.replace(currentDomain, settings.domain); // replace the domain in the relative link
196                $element.attr('href', href); // update the element's href attribute
197            }
198
199            if (settings.domain != null && settings.domain.length != 0) {
200                // initialize every element
201                this.each(function () {
202                    processLink(this);
203                });
204            }
205
206            return this;
207        };
208    }
209})(jQuery);
210
211/*!
212* Material Icons font-load detection
213* Ported from localsite/js/localsite.js. Adds a "material-icons-loaded" class to <html> and
214* fires a "materialIconsLoaded" event once the "Material Symbols Outlined" webfont (see
215* /core/css/materialicons/icon.css) is actually ready, instead of just once its stylesheet is
216* linked. Pages put icon-ligature text (e.g. "search") inside a ".material-icons.show-on-load"
217* element - icon.css hides it via "visibility:hidden" until this fires, so the fallback-font
218* text never flashes before the icon glyph is available. Links icon.css itself if some other
219* script hasn't already, so this works whether or not a page has a static <link> for it.
220* The same process is also implemented in localsite.js by its markMaterialIconsLoaded() function -
221* the "materialIconsFontCheckStarted" flag below lets whichever of the two scripts runs first on
222* a page claim the job, so they never duplicate it.
223*/
224(function () {
225    if (window.materialIconsFontCheckStarted) {
226        return;
227    }
228    window.materialIconsFontCheckStarted = true;
229
230    var font = "1rem 'Material Symbols Outlined'";
231    var iconCssHref = '/core/css/materialicons/icon.css';
232    var canTrackFontLoad = !!(document.fonts && document.fonts.load);
233
234    function markMaterialIconsLoaded() {
235        document.documentElement.classList.add('material-icons-loaded');
236        if (typeof document.dispatchEvent === 'function') {
237            document.dispatchEvent(new CustomEvent('materialIconsLoaded'));
238        }
239    }
240
241    // Link the stylesheet ourselves unless a page-level <link> (or localsite.js) already has.
242    var links = document.getElementsByTagName('link');
243    var iconCssLinked = false;
244    for (var i = 0; i < links.length; i++) {
245        if (links[i].href && links[i].href.indexOf(iconCssHref) !== -1) {
246            iconCssLinked = true;
247            break;
248        }
249    }
250    if (!iconCssLinked) {
251        var link = document.createElement('link');
252        link.type = 'text/css';
253        link.rel = 'stylesheet';
254        link.href = iconCssHref;
255        document.getElementsByTagName('head')[0].appendChild(link);
256    }
257
258    if (canTrackFontLoad) {
259        if (document.fonts.check && document.fonts.check(font)) {
260            markMaterialIconsLoaded(); // Already loaded/cached from a prior page view.
261        } else {
262            document.fonts.load(font).then(markMaterialIconsLoaded).catch(function () { });
263        }
264    } else if (window.addEventListener) {
265        // Older browser without the Font Loading API - reveal on window load rather than
266        // leaving .show-on-load content hidden forever.
267        window.addEventListener('load', markMaterialIconsLoaded);
268    } else {
269        markMaterialIconsLoaded();
270    }
271})();

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.