\n`;
+ //preloader += `\t\t\t\t

\n`;
+ preloader += `\t\t\t\t
\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t\t\n`;
+ preloader += `\t\t\t\t
\n`;
+ preloader += `\t\t\t
\n`;
+ preloader += `\t\t\n`;
+
+ preloaderElem.innerHTML = preloader;
+
+ document.body.className += " has-preloader";
+ document.body.insertBefore(preloaderElem, document.body.firstChild);
+
+ /*const loader = document.querySelector('.sgn-preloader');
+ loader.fadeIn(2000);*/
+
+ return document.querySelector(".sgn-preloader");
+ };
+
+ const showPreLoader = (transitive = true, callback) => {
+ let loaders = document.querySelector(".sgn-preloader");
+ if(loaders === null || loaders.length < 1) {
+ loaders = printPreLoader();
+ }
+ if(transitive) {
+ instance.fadeOut(PRELOADER_TRANSITION_DURATION);
+ loaders.fadeIn(PRELOADER_TRANSITION_DURATION, callback);
+ } else {
+ loaders.fadeIn(0, callback);
+ }
+ };
+
+ const hidePreLoader = (transitive = true, callback) => {
+ const loader = document.querySelector(".sgn-preloader");
+
+ if(transitive) {
+ instance.fadeIn(PRELOADER_TRANSITION_DURATION);
+ //console.log(new Error());
+ loader.fadeOut(PRELOADER_TRANSITION_DURATION, () => {
+ loader.remove();
+ document.body.classList.remove("has-preloader");
+
+ if(typeof callback === "function")
+ callback();
+ });
+ } else {
+ instance.fadeIn(0);
+ loader.fadeOut(0, () => {
+ loader.remove();
+ document.body.classList.remove("has-preloader");
+
+ if(typeof callback === "function")
+ callback();
+ });
+ }
+ };
+
+ const isNodeExists = (current, element) => {
+ const data = Array.from(current);
+ return data.some(obj => {
+ return (obj.isEqualNode(element));
+ });
+ };
+
+ /**
+ *
+ * @param {string}msg
+ * @param {"error"|"success"|"warning"|"info"}[type="error"]
+ *
+ * @return {HTMLElement}
+ */
+ const showAlert = (msg, type = "error") => {
+ let $div = document.createElement("div").attr("class", `sgn-atom-alert ${type}`);
+ $div.innerHTML = msg;
+ $div.addEventListener("click", (e) => {
+ e.preventDefault();
+ hideAlert($div);
+ });
+ instance.appendChild($div);
+
+ $div.fadeIn(5000, () => hideAlert($div));
+
+ return $div;
+ };
+
+ /**
+ *
+ * @param {HTMLElement}$alert
+ */
+ const hideAlert = ($alert) => {
+ $alert.remove();
+ };
+
+ plugin.getNavigatorInstance = (guid) => {
+ const instances = SGNAtomNavigatorStates.instance;
+ if(instances.length > 0 && instances.hasOwnProperty(guid)) {
+ return instances[guid];
+ }
+ return undefined;
+ };
+
+ plugin.load = (page, callback, transitive = true) => {
+ if(page !== undefined && page !== null && page !== "") {
+ showPreLoader(transitive);
+ const url = page;
+
+ setTimeout(() => {
+ //debugger;
+ fetch(url, {
+ credentials: "include",
+ method: "GET", // or 'PUT'
+ headers: {
+ "Content-Type": "text/html",
+ },
+ }).then((response) => response.text())
+ .then((data) => {
+ // Initialize the DOM parser
+ const parser = new DOMParser();
+
+ // Parse the text
+ const doc = parser.parseFromString(data, "text/html");
+ const head = doc.querySelector("head"),
+ title = head.querySelector("title"),
+ body = doc.querySelector("body");
+
+ const headChildElems = document.head.children,
+ headElems = Array.from(headChildElems);
+ const newHeadElems = (plugin.options.resetHead) ? [] : rootHeadElements;
+
+ if(plugin.options.resetHead) {
+ headElems.forEach((c) => {
+ if(!isNodeExists(rootHeadElements, c) && c.nodeName !== "TITLE") {
+ document.head.removeChild(c);
+ }
+ });
+ } else {
+ //document.head.innerHTML = null;
+ //document.head.innerHTML += rootHeadElementsHTML;
+ }
+
+ const sgnatomScript = document.currentScript || document.querySelector("script[src*=\"SGNAtom.js\"]") || document.querySelector("script[src*=\"SGNAtom.min.js\"]");
+ Array.from(head.children).forEach((item) => {
+ if(!isNodeExists(rootHeadElements, item) && item.nodeName !== "TITLE") {
+ document.head.append(item);
+ newHeadElems.push(item);
+ }
+ });
+ let headHTML = "";
+ newHeadElems.forEach((c) => {
+ headHTML += `${c.outerHTML}\n`;
+ });
+
+ document.title = (title !== undefined && title !== null) ? title.innerText : document.title;
+ instance.innerHTML = body.innerHTML;
+
+ const elems = document.querySelectorAll("a, button");
+
+
+ const origin = window.location.origin;
+ let urlPath = (url.indexOf(origin) !== -1) ? url.replace(origin, "") : url;
+ urlPath = (urlPath === _plugin.defaultPage) ? "/" : urlPath;
+ const cUrl = new URL(urlPath, origin).href;
+
+ const historyObjectGUID = _plugin.GUID();
+ const stateObj = {
+ "title": document.title,
+ "guid": historyObjectGUID,
+ };
+ const historyObject = new HistoryObject(cUrl, stateObj, document.title, new HistoryNodeObject([doc]), new HistoryNodeObject(newHeadElems), new HistoryNodeObject([body]), historyObjectGUID);
+ const historyStack = setHistoryStack(historyObject);
+ const historySggtack = getHistoryObject(historyObjectGUID);
+
+ setupNavigator(elems, !defaultPageLoaded);
+ defaultPageLoaded = true;
+ if(typeof callback === "function")
+ callback(false, data);
+ })
+ .catch((error) => {
+ if(_plugin.debugMode) {
+ console.error("Error:", error);
+ }
+ if(_plugin.showErrors) {
+ showAlert("Failed to load the page!");
+ }
+ if(typeof callback === "function")
+ callback(true, error);
+ })
+ .finally(() => hidePreLoader());
+ }, (transitive ? PRELOADER_TRANSITION_DURATION + 1000 : 0));
+ }
+ };
+
+ plugin.isInitialized = () => {
+ return SGNAtomNavigatorStates.isNavigatorReady;
+ };
+
+ if(!SGNAtomNavigatorStates.navigatorReady)
+ init();
+
+ sgnatomcore.navigator = plugin;
+
+ return plugin;
+};
+
+/**
+ * Creates new instance of