PageSourceSearch

https://wdn-cdn.unl.edu/wdn/templates_6.1/js/components/component.search.js?v=6.1.6

js unl.edu collected 2026-09-24 06:52:16 UTC 9,555 bytes, 170 lines download raw bytes

1var __defProp = Object.defineProperty;
2var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
3import UNLDialog from "./component.dialog.js?v=6.1.6";
4class UNLSearch {
5  static {
6    __name(this, "UNLSearch");
7  }
8  searchContainer = null;
9  searchDialogElement = null;
10  domDesktopSearchLink = null;
11  domDesktopSearchBtns = [];
12  domMobileSearchLink = null;
13  domMobileSearchBtns = [];
14  mobileSearchBtn = null;
15  domSearchResultWrapper = null;
16  domQ = null;
17  domSearchForm = null;
18  domEmbed = null;
19  searchEmbedVersion = "5.0";
20  submitted = !1;
21  postReady = !1;
22  searchHost = "https://search.unl.edu";
23  // domain of UNL Search app
24  searchPath = "/";
25  // path to UNL Search app
26  allowSearchParams = ["u", "cx"];
27  // QS Params allowed by UNL Search app
28  searchAction = "";
29  searchFrameAction = "";
30  siteHomepage = "";
31  localSearch = null;
32  progress = null;
33  unlSearch = null;
34  searchOpenedEvent = new Event(UNLSearch.events("searchOpened"));
35  searchClosedEvent = new Event(UNLSearch.events("searchClosed"));
36  constructor() {
37    if (this.searchContainer = document.getElementById("dcf-search"), this.searchDialogElement = document.querySelector("dialog#dcf-search-dialog"), this.searchDialogElement === null)
38      throw new Error("Missing Search Dialog Element");
39    if (this.domDesktopSearchLink = document.getElementById("dcf-search-toggle-link"), this.domDesktopSearchBtns = Array.from(document.getElementsByClassName("dcf-btn-search-desktop")), this.domMobileSearchLink = document.getElementById("dcf-mobile-search-link"), this.domMobileSearchBtns = Array.from(document.getElementsByClassName("dcf-btn-search-mobile")), this.mobileSearchBtn = null, this.domMobileSearchLink && this.domMobileSearchBtns && this.domMobileSearchBtns.length && (this.domMobileSearchLink.setAttribute("hidden", ""), this.domMobileSearchBtns.forEach((singleMobileButton) => {
40      singleMobileButton.removeAttribute("hidden"), singleMobileButton.setAttribute("aria-expanded", "false"), this.mobileSearchBtn = singleMobileButton;
41    })), this.domDesktopSearchLink && this.domDesktopSearchBtns && this.domDesktopSearchBtns.length && (this.domDesktopSearchLink.setAttribute("hidden", ""), this.domDesktopSearchLink.setAttribute("aria-hidden", !0), this.domDesktopSearchBtns.forEach((singleDesktopButton) => {
42      singleDesktopButton.removeAttribute("hidden"), singleDesktopButton.setAttribute("aria-expanded", "false"), singleDesktopButton.innerHTML = this.domDesktopSearchLink.innerHTML;
43    })), this.domSearchResultWrapper = document.getElementById("dcf-search-results-wrapper"), this.domQ = document.getElementById("dcf-search_query"), this.domSearchForm = document.getElementById("dcf-search-form"), this.searchAction = `${this.searchHost}${this.searchPath}`, this.searchFrameAction = `${this.searchAction}?embed=${this.searchEmbedVersion}`, this.siteHomepage = `${location.protocol}//${location.host}/`, this.localSearch = this.#getLocalSearch(), !!this.domSearchForm) {
44      if (this.domSearchForm.action !== this.searchAction && this.domSearchForm.setAttribute("action", this.searchAction), this.localSearch && this.localSearch.indexOf(`${this.searchAction}?`) === 0) {
45        let localSearchParams;
46        try {
47          if (window.URLSearchParams) {
48            localSearchParams = new URLSearchParams(this.localSearch.slice(this.localSearch.indexOf("?") + 1));
49            for (let index = 0; index < this.allowSearchParams.length; index++)
50              if (localSearchParams.has(this.allowSearchParams[index])) {
51                const input = document.createElement("input");
52                input.type = "hidden", input.name = this.allowSearchParams[index], input.value = localSearchParams.get(this.allowSearchParams[index]), this.domSearchForm.appendChild(input);
53              }
54          } else {
55            let paramPair;
56            localSearchParams = this.localSearch.slice(this.localSearch.indexOf("?") + 1).split("&");
57            for (let index = 0; index < localSearchParams.length; index++)
58              if (paramPair = localSearchParams[index].split("="), this.allowSearchParams.indexOf(paramPair[0]) >= 0) {
59                const input = document.createElement("input");
60                input.type = "hidden", input.name = paramPair[0], input.value = decodeURIComponent(paramPair[1]), this.domSearchForm.appendChild(input);
61              }
62          }
63        } catch (err) {
64          console.error(err);
65        }
66      } else if (this.siteHomepage && !/^https?:\/\/www\.unl\.edu\/$/.test(this.siteHomepage)) {
67        const input = document.createElement("input");
68        input.type = "hidden", input.name = "u", input.value = this.siteHomepage, this.domSearchForm.appendChild(input), this.searchFrameAction += `&u=${encodeURIComponent(this.siteHomepage)}`;
69      }
70      this.progress = document.createElement("progress"), this.progress.setAttribute("id", "wdn_search_progress"), this.progress.innerText = "Loading...", this.domEmbed = document.createElement("input"), this.domEmbed.type = "hidden", this.domEmbed.name = "embed", this.domEmbed.value = this.searchEmbedVersion, this.domSearchForm.appendChild(this.domEmbed), window.addEventListener("message", function(event) {
71        event.data === UNLSearch.events("iframeMessage") && this.closeSearch();
72      }, !1), this.searchDialogElement.addEventListener(UNLDialog.events("dialogPreOpen"), this.#dialogOpened.bind(this)), this.searchDialogElement.addEventListener(UNLDialog.events("dialogPostClose"), this.#dialogClosed.bind(this)), this.domSearchForm.addEventListener("submit", this.#handleFormSubmit.bind(this)), this.searchContainer.dis
72patchEvent(new CustomEvent(UNLSearch.events("searchReady"), {
73        detail: {
74          classInstance: this
75        }
76      })), this.searchDialogElement.dispatchEvent(new CustomEvent(UNLSearch.events("searchReady"), {
77        detail: {
78          classInstance: this
79        }
80      })), window.UNL = window.UNL || {}, window.UNL.classes = window.UNL.classes || {}, window.UNL.classes["dcf-search"] = this, this.searchContainer.dispatchEvent(new Event("UNLClassReady"));
81    }
82  }
83  // The names of the events to be used easily
84  static events(name) {
85    const events = {
86      searchReady: "searchReady",
87      iframeMessage: "wdn.search.close",
88      searchClosed: "searchClosed",
89      searchOpened: "searchOpened"
90    };
91    return Object.freeze(events), name in events ? events[name] : void 0;
92  }
93  /**
94   * Handles when the search form submits
95   *
96   * @param {Event} event
97   * @returns { Void }
98   */
99  #handleFormSubmit(event) {
100    event.preventDefault(), this.#createSearchFrame(), this.#activateSearch(), this.domEmbed.disabled = !1, this.domSearchResultWrapper.parentElement.classList.add("dcf-overflow-y-hidden"), this.domSearchResultWrapper.parentElement.classList.remove("dcf-overflow-y-auto"), (!event.detail || event.detail !== "auto") && this.unlSearch.focus(), this.postReady && this.#postSearchMessage(this.domQ.value);
101  }
102  /**
103   * Creates the search iframe element
104   *
105   * @returns { Void }
106   */
107  #createSearchFrame() {
108    this.unlSearch === null && (this.unlSearch = document.createElement("iframe"), this.unlSearch.name = "unlsearch", this.unlSearch.setAttribute("id", "wdn_search_frame"), this.unlSearch.title = "Search", this.unlSearch.className = "dcf-b-0 dcf-w-100% dcf-h-100%", this.unlSearch.src = `${this.searchFrameAction}&q=${this.domQ.value}`, this.unlSearch.addEventListener("load", function() {
109      this.postReady = !0, this.progress.remove();
110    }.bind(this)), this.domSearchResultWrapper.appendChild(this.progress), this.domSearchResultWrapper.appendChild(this.unlSearch), this.searchDialogElement.style.height = "100%");
111  }
112  /**
113   * Activates search input
114   *
115   * @returns { Void }
116   */
117  #activateSearch() {
118    this.domSearchForm.parentElement.classList.add("active"), this.progress.remove();
119  }
120  /**
121   * Posts new queries into the iframe instead of having to reload it every time
122   *
123   * @param { String } query
124   * @returns { Void }
125   */
126  #postSearchMessage(query) {
127    this.unlSearch.contentWindow.postMessage({ type: "search", query }, this.searchHost), this.progress.remove();
128  }
129  /**
130   * Function to be called when the dialog closes
131   *
132   * @returns { Void }
133   */
134  #dialogClosed() {
135    this.domQ.value = "", this.domSearchForm.parentElement.classList.remove("active"), this.domSearchForm.reset(), window.dataLayer = window.dataLayer || [];
136    function gtag() {
137      window.dataLayer.push(arguments);
138    }
139    __name(gtag, "gtag"), gtag("event", "UNL_search_closed", {
140      app_name: "UNL_search"
141    }), this.unlSearch && (this.unlSearch = null, this.domSearchResultWrapper.innerHTML = "", this.postReady = !1), document.dispatchEvent(this.searchClosedEvent);
142  }
143  /**
144   * Function to be called when the dialog Opens
145   *
146   * @returns { Void }
147   */
148  #dialogOpened() {
149    document.dispatchEvent(this.searchOpenedEvent), window.dataLayer = window.dataLayer || [];
150    function gtag() {
151      window.dataLayer.push(arguments);
152    }
153    __name(gtag, "gtag"), gtag("event", "UNL_search_opened", {
154      app_name: "UNL_search"
155    });
156  }
157  /**
158   * Gets local search link on the page
159   *
160   * @returns { String|null }
161   */
162  #getLocalSearch() {
163    const link = document.querySelector('link[rel="search"]');
164    return link && link.type !== "application/opensearchdescription+xml" ? link.href : null;
165  }
166}
167export {
168  UNLSearch as default
169};
170//# sourceMappingURL=component.search.js.map

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.