/** * jquery Tocify - v1.9.0 - 2013-10-01 * http://www.gregfranko.com/jquery.tocify.js/ * Copyright (c) 2013 Greg Franko; * Copyright (c) ppy Pty Ltd ; * Licensed MIT */ import 'jquery-ui/ui/widget'; /* globals $, document, window */ var tocClassName = 'tocify'; var tocFocusClassName = 'tocify-focus'; var tocHoverClassName = 'tocify-hover'; var hideTocClassName = 'tocify-hide'; var headerClassName = 'tocify-header'; var headerClass = '.' + headerClassName; var subheaderClassName = 'tocify-subheader'; var subheaderClass = '.' + subheaderClassName; var itemClassName = 'tocify-item'; var itemClass = '.' + itemClassName; var extendPageClassName = 'tocify-extend-page'; var extendPageClass = '.' + extendPageClassName; // Calling the jQueryUI Widget Factory Method $.widget('toc.tocify', { // _addCSSClasses // -------------- // Adds CSS classes to the newly generated table of contents HTML _addCSSClasses() { if (this.options.theme === 'jqueryui') { // If the user wants a jqueryUI theme this.focusClass = 'ui-state-default'; this.hoverClass = 'ui-state-hover'; // Adds the default styling to the dropdown list this.element.addClass('ui-widget').find('.toc-title').addClass('ui-widget-header').end().find('li').addClass('ui-widget-content'); } else if (this.options.theme === 'bootstrap') { // If the user wants a twitterBootstrap theme this.element.find(headerClass + ',' + subheaderClass).addClass('nav nav-list'); this.focusClass = 'active'; // If a user does not want a prebuilt theme } else { // Adds more neutral classes (instead of jqueryui) this.focusClass = tocFocusClassName; this.hoverClass = tocHoverClassName; } // Maintains chainability return this; }, // _appendSubheaders // --------------- // Helps create the table of contents list by appending subheader elements _appendSubheaders(self, ul) { // The current element index var index = $(this).index(self.options.selectors); // Finds the previous header DOM element var previousHeader = $(self.options.selectors).eq(index - 1); var currentTagName = +$(this).prop('tagName').charAt(1); var previousTagName = +previousHeader.prop('tagName').charAt(1); if (currentTagName < previousTagName) { // If the current header DOM element is smaller than the previous header DOM element or the first subheader // Selects the last unordered list HTML found within the HTML element calling the plugin self.element.find(subheaderClass + '[data-tag=' + currentTagName + ']').last().append(self._nestElements($(this), index)); } else if (currentTagName === previousTagName) { // If the current header DOM element is the same type of header(eg. h4) as the previous header DOM element ul.find(itemClass).last().after(self._nestElements($(this), index)); } else { // Selects the last unordered list HTML found within the HTML element calling the plugin ul.find(itemClass).last(). // Appends an unorderedList HTML element to the dynamic `unorderedList` variable and sets a common class name after($('