1; (function (window, $, undefined) { 2 $.fn.createTOC = function (settings) { 3 var option = $.extend({ 4 title: "", 5 insert: "body", 6 }, settings); 7 8 var ACTIVE_CLASS = 'active'; 9 10 var list = ["h2"]; 11 var $headings = this.find(list.join(",")); 12 13 var tocBox = document.createElement("ol"); 14 var $tocBox = $(tocBox); 15 tocBox.className = "toc-box"; 16 17 var idList = []; 18 19 $headings.map(function (i, head) { 20 var nodeName = head.nodeName; 21 var id = 'toc_' + i + '_' + nodeName; 22 head.id = id; 23 24 idList.push(id); 25 26 var row = document.createElement("li"); 27 28 row.className = 'toc-item toc-' + nodeName; 29 30 var link = document.createElement('a'); 31 32 link.innerHTML = head.innerHTML; 33 link.className = 'toc-item-link'; 34 link.href = '#' + id; 35 36 row.appendChild(link); 37 tocBox.appendChild(row); 38 }); 39 40 var isTakeOverByClick = false; 41 42 43 $tocBox.on("click", ".toc-item", function (ev) { 44 45 isTakeOverByClick = true; 46 47 var $item = $(this); 48 var $itemSiblings = $item.siblings(); 49 50 $itemSiblings.removeClass(ACTIVE_CLASS); 51 $item.addClass(ACTIVE_CLASS); 52 }); 53 54 var headBox = document.createElement("div"); 55 headBox.className = "toc-title"; 56 headBox.innerHTML = option.title; 57 58 var wrapBox = document.createElement("div"); 59 wrapBox.className = "wrap-toc"; 60 61 wrapBox.appendChild(headBox); 62 wrapBox.appendChild(tocBox); 63 64 var $insertBox = $(option.insert); 65 var $helperBox = $("<div></div>"); 66 $helperBox.append(wrapBox); 67 $insertBox.append($helperBox); 68 69 70 71 72 $(window).scroll(function () { 73 74 var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; 75 var scrollTop = scrollTop + 120; 76 !isTakeOverByClick && $.each(idList, function (index, id) { 77 var $head = $('#' + id); 78 var $item = $('[href="#' + id + '"]').parent(); 79 var $itemSiblings = $item.siblings(); 80 var offsetTopHead = $head.offset().top; 81 82 var isActived = $item.hasClass(ACTIVE_CLASS); 83 84 if (scrollTop >= offsetTopHead) { 85 $itemSiblings.removeClass(ACTIVE_CLASS); 86 !isActived && $item.addClass(ACTIVE_CLASS); 87 } else { 88 $item.removeClass(ACTIVE_CLASS); 89 } 90 91 }); 92 93 isTakeOverByClick = false; 94 95 }); 96 97 }; 98 $('.description').createTOC({ 99 title: "Table of content", 100 insert: ".anchorific" 101 }); 102 103}(this, jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.