1require(['gitbook', 'jQuery'], function(gitbook, $) { 2 var TOGGLE_CLASSNAME = 'expanded', 3 CHAPTER = '.chapter', 4 ARTICLES = '.articles', 5 TRIGGER_TEMPLATE = '<i class="exc-trigger fa"></i>', 6 LS_NAMESPACE = 'expChapters'; 7 var init = function () { 8 // adding the trigger element to each ARTICLES parent and binding the event 9 $(ARTICLES) 10 .parent(CHAPTER) 11 .children('a,span') 12 .append(TRIGGER_TEMPLATE) 13 .on('click', function(e) { 14 if (!$(e.target).is('a')) { 15 e.preventDefault(); 16 e.stopPropagation(); 17 toggle($(e.target).closest(CHAPTER)); 18 } 19 }); 20 21 expand(lsItem()); 22 //expand current selected chapter with it's parents 23 var activeChapter = $(CHAPTER + '.active'); 24 expand(activeChapter); 25 expand(activeChapter.parents(CHAPTER)); 26 27 28 } 29 var toggle = function ($chapter) { 30 if ($chapter.hasClass('expanded')) { 31 collapse($chapter); 32 } else { 33 expand($chapter); 34 } 35 } 36 var collapse = function ($chapter) { 37 if ($chapter.length && $chapter.hasClass(TOGGLE_CLASSNAME)) { 38 $chapter.removeClass(TOGGLE_CLASSNAME); 39 lsItem($chapter); 40 } 41 } 42 var expand = function ($chapter) { 43 if ($chapter.length && !$chapter.hasClass(TOGGLE_CLASSNAME)) { 44 $chapter.addClass(TOGGLE_CLASSNAME); 45 lsItem($chapter); 46 } 47 } 48 var lsItem = function () { 49 var map = JSON.parse(localStorage.getItem(LS_NAMESPACE)) || {} 50 if (arguments.length) { 51 var $chapters = arguments[0]; 52 $chapters.each(function (index, element) { 53 var level = $(this).data('level'); 54 var value = $(this).hasClass(TOGGLE_CLASSNAME); 55 map[level] = value; 56 }) 57 localStorage.setItem(LS_NAMESPACE, JSON.stringify(map)); 58 } else { 59 return $(CHAPTER).map(function(index, element){ 60 if (map[$(this).data('level')]) { 61 return this; 62 } 63 }) 64 } 65 } 66 gitbook.events.bind('page.change', function() { 67 init() 68 }); 69});
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.