comparison .cms/lib/codemirror/doc/activebookmark.js @ 0:78edf6b517a0 draft

24.10
author Coffee CMS <info@coffee-cms.ru>
date Fri, 11 Oct 2024 22:40:23 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:78edf6b517a0
1 // Kludge in HTML5 tag recognition in IE8
2 document.createElement("section");
3 document.createElement("article");
4
5 (function() {
6 if (!window.addEventListener) return;
7 var pending = false, prevVal = null;
8
9 function updateSoon() {
10 if (!pending) {
11 pending = true;
12 setTimeout(update, 250);
13 }
14 }
15
16 function update() {
17 pending = false;
18 var marks = document.getElementById("nav").getElementsByTagName("a"), found;
19 for (var i = 0; i < marks.length; ++i) {
20 var mark = marks[i], m;
21 if (mark.getAttribute("data-default")) {
22 if (found == null) found = i;
23 } else if (m = mark.href.match(/#(.*)/)) {
24 var ref = document.getElementById(m[1]);
25 if (ref && ref.getBoundingClientRect().top < 50)
26 found = i;
27 }
28 }
29 if (found != null && found != prevVal) {
30 prevVal = found;
31 var lis = document.getElementById("nav").getElementsByTagName("li");
32 for (var i = 0; i < lis.length; ++i) lis[i].className = "";
33 for (var i = 0; i < marks.length; ++i) {
34 if (found == i) {
35 marks[i].className = "active";
36 for (var n = marks[i]; n; n = n.parentNode)
37 if (n.nodeName == "LI") n.className = "active";
38 } else {
39 marks[i].className = "";
40 }
41 }
42 }
43 }
44
45 window.addEventListener("scroll", updateSoon);
46 window.addEventListener("load", updateSoon);
47 window.addEventListener("hashchange", function() {
48 setTimeout(function() {
49 var hash = document.location.hash, found = null, m;
50 var marks = document.getElementById("nav").getElementsByTagName("a");
51 for (var i = 0; i < marks.length; i++)
52 if ((m = marks[i].href.match(/(#.*)/)) && m[1] == hash) { found = i; break; }
53 if (found != null) for (var i = 0; i < marks.length; i++)
54 marks[i].className = i == found ? "active" : "";
55 }, 300);
56 });
57 })();