UNPKG

ncahec-northwest-theme

Version:

theme for northwest ahec

196 lines (180 loc) 5.75 kB
(function () { document.title = document.title === "Northwest Area Health Education Center" ? document.title + "(" + window.location.pathname + ")" : document.title; var script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("id", "hs-script-loader"); script.setAttribute("async", ""); script.setAttribute("defer", ""); script.setAttribute("src", '//js.hs-scripts.com/7413846.js";'); script.onload = function () { //do stuff with the script var lasttitle = document.title; // var lastlocation = window.location.pathname; setInterval(function () { // debugger; document.title = document.title.startsWith( "Northwest Area Health Education Center" ) ? "Northwest Area Health Education Center(" + window.location.pathname + ")" : document.title; if ( // don't report on the /elite page // !window.location.pathname.startsWith("/elite") && // don't report again if default title is set on courses-and-event pages document.title != lasttitle ) { lasttitle = document.title; // console.log("hubspot:", { lasttitle }); var _hsq = (window._hsq = window._hsq || []); _hsq.push(["setPath", window.location.pathname]); _hsq.push(["trackPageView"]); } else { // console.log("same:", { // lasttitle: [lasttitle, document.title], // }); } }, 1000); }; document.head.appendChild(script); })(); if (!String.prototype.startsWith) { Object.defineProperty(String.prototype, "startsWith", { value: function (search, rawPos) { var pos = rawPos > 0 ? rawPos | 0 : 0; return this.substring(pos, pos + search.length) === search; }, }); } if (!String.prototype.includes) { String.prototype.includes = function (search, start) { "use strict"; if (search instanceof RegExp) { throw TypeError("first argument must not be a RegExp"); } if (start === undefined) { start = 0; } return this.indexOf(search, start) !== -1; }; } function showNewsletterPopup() { $(".closeCampaignerModal").click(function (e) { $("#campaignerModal").modal("hide"); }); $("#campaignerModal").modal(); setCookie("newsletterPopup", "1", 90); } function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(";"); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == " ") c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { document.cookie = name + "=; Max-Age=-99999999;"; } function addTagToHead(selector, tag, properties) { var link = !!document.querySelector(selector) ? document.querySelector(selector) : document.createElement(tag); for (var index = 0; index < properties.length; index++) { var prop = properties[index]; link.setAttribute(prop.name, prop.value); } document.head.appendChild(link); } var runOg; function og() { var courseImage = document.querySelector("img.course-image"); if (courseImage) { clearInterval(runOg); addTagToHead("meta[property='og:image']", "meta", [ { name: "property", value: "og:image" }, { name: "content", value: courseImage.src }, ]); addTagToHead("meta[property='og:title']", "meta", [ { name: "property", value: "og:title" }, { name: "content", value: document.title }, ]); var desc = document.querySelector("section.description"); addTagToHead("meta[property='og:description']", "meta", [ { name: "property", value: "og:description" }, { name: "content", value: desc.textContent.substr(0, 200) }, ]); addTagToHead("meta[property='og:url']", "meta", [ { name: "property", value: "og:url" }, { name: "content", value: window.location.href }, ]); addTagToHead("meta[property='fb:app_id']", "meta", [ { name: "property", value: "fb:app_id" }, { name: "content", value: "112058815527969" }, ]); } } function northwestOpenButton() { return $('div[id^="course_"]:contains("Northwest AHEC")') .not(".found") .addClass("found"); } function northwestPanels() { return $('div[id^="course_"]:contains("Northwest AHEC")') .not(".found") .addClass("found"); } (function () { // check for updates to the url and update the canonical var interval, timeout; interval = setInterval(function () { var loc = window.location.href; var parts = loc.split("/"); if (parts.length === 6 && parts[3] === "courses-and-events") { clearTimeout(timeout); clearInterval(interval); addTagToHead("link[rel='canonical']", "link", [ { name: "rel", value: "canonical", }, { name: "href", value: window.location.href, }, ]); addTagToHead("meta[name='description']", "meta", [ { name: "name", value: "description" }, { name: "content", value: document.title }, ]); runOg = setInterval(og, 100); } }, 100); // stop checking after 5 seconds timeout = setTimeout(function () { clearInterval(interval); }, 5000); })(); export { showNewsletterPopup, setCookie, getCookie, eraseCookie, northwestOpenButton, northwestPanels, };