{"size": 11663, "ext": "js", "max_stars_repo_path": "script.js", "max_stars_repo_name": "pdq/copenhagen_theme", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "script.js", "max_issues_repo_name": "pdq/copenhagen_theme", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "script.js", "max_forks_repo_name": "pdq/copenhagen_theme", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.0412087912, "max_line_length": 124, "alphanum_fraction": 0.6458029666}
redirectBrokenLinks(); // Redirect based on URL, no need to wait for the page to load

document.addEventListener("DOMContentLoaded", function() {
  //Assign highlight.js formatting to pre code blocks:
  codeHighlighting();

  //pre-fill search box on 404 page
  populateSearch();

  //pre-fill Request submission form
  populateSubmitForm();

  function closest(element, selector) {
    if (Element.prototype.closest) {
      return element.closest(selector);
    }
    do {
      if (
        (Element.prototype.matches && element.matches(selector)) ||
        (Element.prototype.msMatchesSelector &&
          element.msMatchesSelector(selector)) ||
        (Element.prototype.webkitMatchesSelector &&
          element.webkitMatchesSelector(selector))
      ) {
        return element;
      }
      element = element.parentElement || element.parentNode;
    } while (element !== null && element.nodeType === 1);
    return null;
  }

  // social share popups
  Array.prototype.forEach.call(document.querySelectorAll(".share a"), function(
    anchor
  ) {
    anchor.addEventListener("click", function(e) {
      e.preventDefault();
      window.open(this.href, "", "height = 500, width = 500");
    });
  });

  // In some cases we should preserve focus after page reload
  function saveFocus() {
    var activeElementId = document.activeElement.getAttribute("id");
    sessionStorage.setItem("returnFocusTo", "#" + activeElementId);
  }
  var returnFocusTo = sessionStorage.getItem("returnFocusTo");
  if (returnFocusTo) {
    sessionStorage.removeItem("returnFocusTo");
    var returnFocusToEl = document.querySelector(returnFocusTo);
    returnFocusToEl && returnFocusToEl.focus && returnFocusToEl.focus();
  }

  // show form controls when the textarea receives focus or backbutton is used and value exists
  var commentContainerTextarea = document.querySelector(
      ".comment-container textarea"
    ),
    commentContainerFormControls = document.querySelector(
      ".comment-form-controls, .comment-ccs"
    );

  if (commentContainerTextarea) {
    commentContainerTextarea.addEventListener(
      "focus",
      function focusCommentContainerTextarea() {
        commentContainerFormControls.style.display = "block";
        commentContainerTextarea.removeEventListener(
          "focus",
          focusCommentContainerTextarea
        );
      }
    );

    if (commentContainerTextarea.value !== "") {
      commentContainerFormControls.style.display = "block";
    }
  }

  // Expand Request comment form when Add to conversation is clicked
  var showRequestCommentContainerTrigger = document.querySelector(
      ".request-container .comment-container .comment-show-container"
    ),
    requestCommentFields = document.querySelectorAll(
      ".request-container .comment-container .comment-fields"
    ),
    requestCommentSubmit = document.querySelector(
      ".request-container .comment-container .request-submit-comment"
    );

  if (showRequestCommentContainerTrigger) {
    showRequestCommentContainerTrigger.addEventListener("click", function() {
      showRequestCommentContainerTrigger.style.display = "none";
      Array.prototype.forEach.call(requestCommentFields, function(e) {
        e.style.display = "block";
      });
      requestCommentSubmit.style.display = "inline-block";

      if (commentContainerTextarea) {
        commentContainerTextarea.focus();
      }
    });
  }

  // Mark as solved button
  var requestMarkAsSolvedButton = document.querySelector(
      ".request-container .mark-as-solved:not([data-disabled])"
    ),
    requestMarkAsSolvedCheckbox = document.querySelector(
      ".request-container .comment-container input[type=checkbox]"
    ),
    requestCommentSubmitButton = document.querySelector(
      ".request-container .comment-container input[type=submit]"
    );

  if (requestMarkAsSolvedButton) {
    requestMarkAsSolvedButton.addEventListener("click", function() {
      requestMarkAsSolvedCheckbox.setAttribute("checked", true);
      requestCommentSubmitButton.disabled = true;
      this.setAttribute("data-disabled", true);
      // Element.closest is not supported in IE11
      closest(this, "form").submit();
    });
  }

  // Change Mark as solved text according to whether comment is filled
  var requestCommentTextarea = document.querySelector(
    ".request-container .comment-container textarea"
  );

  if (requestCommentTextarea) {
    requestCommentTextarea.addEventListener("input", function() {
      if (requestCommentTextarea.value === "") {
        if (requestMarkAsSolvedButton) {
          requestMarkAsSolvedButton.innerText = requestMarkAsSolvedButton.getAttribute(
            "data-solve-translation"
          );
        }
        requestCommentSubmitButton.disabled = true;
      } else {
        if (requestMarkAsSolvedButton) {
          requestMarkAsSolvedButton.innerText = requestMarkAsSolvedButton.getAttribute(
            "data-solve-and-submit-translation"
          );
        }
        requestCommentSubmitButton.disabled = false;
      }
    });
  }

  // Disable submit button if textarea is empty
  if (requestCommentTextarea && requestCommentTextarea.value === "") {
    requestCommentSubmitButton.disabled = true;
  }

  // Submit requests filter form on status or organization change in the request list page
  Array.prototype.forEach.call(
    document.querySelectorAll(
      "#request-status-select, #request-organization-select"
    ),
    function(el) {
      el.addEventListener("change", function(e) {
        e.stopPropagation();
        saveFocus();
        closest(this, "form").submit();
      });
    }
  );

  // Submit requests filter form on search in the request list page
  var quickSearch = document.querySelector("#quick-search");
  quickSearch &&
    quickSearch.addEventListener("keyup", function(e) {
      if (e.keyCode === 13) {
        // Enter key
        e.stopPropagation();
        saveFocus();
        closest(this, "form").submit();
      }
    });

  function toggleNavigation(toggle, menu) {
    var isExpanded = menu.getAttribute("aria-expanded") === "true";
    menu.setAttribute("aria-expanded", !isExpanded);
    toggle.setAttribute("aria-expanded", !isExpanded);
  }

  function closeNavigation(toggle, menu) {
    menu.setAttribute("aria-expanded", false);
    toggle.setAttribute("aria-expanded", false);
    toggle.focus();
  }

  var burgerMenu = document.querySelector(".header .icon-menu");
  var userMenu = document.querySelector("#user-nav");

  burgerMenu.addEventListener("click", function(e) {
    e.stopPropagation();
    toggleNavigation(this, userMenu);
  });

  burgerMenu.addEventListener("keyup", function(e) {
    if (e.keyCode === 13) {
      // Enter key
      e.stopPropagation();
      toggleNavigation(this, userMenu);
    }
  });

  userMenu.addEventListener("keyup", function(e) {
    if (e.keyCode === 27) {
      // Escape key
      e.stopPropagation();
      closeNavigation(burgerMenu, this);
    }
  });

  if (userMenu.children.length === 0) {
    burgerMenu.style.display = "none";
  }

  // Toggles expanded aria to collapsible elements
  var collapsible = document.querySelectorAll(
    ".collapsible-nav, .collapsible-sidebar"
  );

  Array.prototype.forEach.call(collapsible, function(el) {
    var toggle = el.querySelector(
      ".collapsible-nav-toggle, .collapsible-sidebar-toggle"
    );

    el.addEventListener("click", function(e) {
      toggleNavigation(toggle, this);
    });

    el.addEventListener("keyup", function(e) {
      if (e.keyCode === 27) {
        // Escape key
        closeNavigation(toggle, this);
      }
    });
  });

  // Submit organization form in the request page
  var requestOrganisationSelect = document.querySelector(
    "#request-organization select"
  );

  if (requestOrganisationSelect) {
    requestOrganisationSelect.addEventListener("change", function() {
      closest(this, "form").submit();
    });
  }

  // If a section has more than 6 subsections, we collapse the list, and show a trigger to display them all
  const seeAllTrigger = document.querySelector("#see-all-sections-trigger");
  const subsectionsList = document.querySelector(".section-list");

  if (subsectionsList && subsectionsList.children.length > 6) {
    seeAllTrigger.setAttribute("aria-hidden", false);

    seeAllTrigger.addEventListener("click", function(e) {
      subsectionsList.classList.remove("section-list--collapsed");
      seeAllTrigger.parentNode.removeChild(seeAllTrigger);
    });
  }
});

function redirectBrokenLinks() {
  if (window.location.href.indexOf("/knowledge-base/") > -1) {
    var title = window.location.href
      .match(/\/knowledge-base\/.*/gm)[0]
      .replace("/knowledge-base/", "")
      .replace(/-/gm, "+");
    window.location.href =
      window.location.protocol +
      "//" +
      window.location.hostname +
      "/hc/search?query=" +
      title;
  } else if (
    window.location.href.indexOf("/posts/") > -1 &&
    window.location.href.indexOf("/community/posts/") === -1
  ) {
    var title = window.location.href
      .match(/\/posts\/.*/gm)[0]
      .replace("/posts/", "")
      .replace(/-/gm, "+");
    window.location.href =
      window.location.protocol +
      "//" +
      window.location.hostname +
      "/hc/search?query=" +
      title;
  }
}

function codeHighlighting() {
  //Highlight code in <pre> tags created with the content editor
  $("pre").each(function(i, block) {
    hljs.highlightBlock(block);
  });
}

function populateSearch() {
  //populate the search on the 404 page
  if (
    document.getElementsByClassName("error-page").length &&
    document.getElementsByClassName("search").length
  ) {
    var searchTerms = window.location.pathname
      .split("/")
      .pop()
      .replace(/-/gm, " ")
      .trim();
    searchTerms = decodeURI(searchTerms);
    var searchBox = document.getElementById("query");
    searchBox.focus();
    searchBox.value = searchTerms;
  }
}

function populateSubmitForm() {
  if (document.getElementsByClassName("request-form").length) {
    console.log("filling form");
    var qs = window.location.search;
    var params = getQueryParams(qs);

    var product = "";
    if (params.product) {
      if (params.product === "deploy") product = "pdq_deploy";
      if (params.product === "inventory") product = "pdq_inventory";
    }
    //Product field
    document.getElementById("request_custom_fields_304389").value = product;

    //Version field
    document.getElementById(
      "request_custom_fields_22752330"
    ).value = params.version ? params.version : "";

    //Email field doesn't exist if you're signed in.
    var emailField = document.getElementById(
      "request_anonymous_requester_email"
    );
    if (emailField && params.email) emailField.value = params.email;
  }
}

//This function borrowed from here: https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters
//Using this function to be cross-browser compatible and to avoid dependencies.
function getQueryParams(qs) {
  qs = qs.split("+").join(" ");

  var params = {},
    tokens,
    re = /[?&]?([^=]+)=([^&]*)/g;

  while ((tokens = re.exec(qs))) {
    params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
  }

  return params;
}
