Welcome to mirror list, hosted at ThFree Co, Russian Federation.

myFunctions.js « js « static - github.com/darshanbaral/kitab.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b376afb1b96aec6a47475f1d1b6d5a38eeb26b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
window.onclick = function(event) {
  let insideMenu = false;
  Array.from(document.querySelectorAll(".show")).forEach(menu => {
    insideMenu = insideMenu || menu.contains(event.target);
  });
  if (!insideMenu && !event.target.matches(".hover-menu")) {
    Array.from(document.querySelectorAll(".hover-menu")).forEach(hovermenu => {
      hovermenu.nextElementSibling.style.maxHeight = "0px";
    });
  }
};
let expandMenu = function(x) {
  Array.from(document.querySelectorAll(".hover-menu")).forEach(hovermenu => {
    hovermenu.nextElementSibling.style.maxHeight = "0px";
  });
  let thisMenu = x.nextElementSibling;
  thisMenu.style.maxHeight = thisMenu.scrollHeight + "px";
};
let scrollToTop = () => {
  const c = document.documentElement.scrollTop || document.body.scrollTop;
  if (c > 0) {
    window.requestAnimationFrame(scrollToTop);
    window.scrollTo(0, c - c / 8);
  }
};

function copyUrl(text) {
  let copyFrom = document.createElement("textarea");
  copyFrom.textContent = text;
  document.body.appendChild(copyFrom);
  copyFrom.select();
  document.execCommand("copy");
  copyFrom.blur();
  document.body.removeChild(copyFrom);

  let copiedMessage = document.createElement("div");
  copiedMessage.id = "copiedMessage";
  copiedMessage.textContent = "Link copied to clipboard";
  copiedMessage.classList.add("bg-warning", "shadow", "d-block", "text-center");
  document.body.appendChild(copiedMessage);

  setTimeout(function() {
    copiedMessage.style.opacity = 0;
  }, 500);
  setTimeout(function() {
    document.body.removeChild(copiedMessage);
  }, 1500);
}