UNPKG

reclass-doc

Version:

Reclass model documentation generator.

304 lines (298 loc) 11 kB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { /** * Reclass doc generator * * @author Jiri Hybek <jiri@hybek.cz> * @license Apache-2.0 (c) 2017 Jiri Hybek */ "use strict"; var search_1 = __webpack_require__(1); var bindToggleDetails = function (parent) { if (parent === void 0) { parent = document.body; } var bind = function (el) { el.addEventListener("click", function () { el.parentElement.classList.toggle('show-details'); }); }; var items = parent.querySelectorAll(".toggle-details"); for (var i = 0; i < items.length; i++) bind(items.item(i)); }; var bindCollapseButtons = function (parent) { if (parent === void 0) { parent = document.body; } var bind = function (el) { el.addEventListener("click", function (ev) { ev.stopPropagation(); el.parentElement.parentElement.parentElement.classList.toggle('collapsed'); }); }; var items = parent.querySelectorAll(".collapse"); for (var i = 0; i < items.length; i++) bind(items.item(i)); }; var bindToggleInheritedProps = function (parent) { if (parent === void 0) { parent = document.body; } var bind = function (el) { var update = function () { if (el.checked) el.parentElement.parentElement.parentElement.parentElement.classList.add('inherited-props'); else el.parentElement.parentElement.parentElement.parentElement.classList.remove('inherited-props'); localStorage['reclass-doc-inherited'] = el.checked ? 1 : 0; }; el.addEventListener("change", function (ev) { ev.stopPropagation(); update(); }); if (localStorage['reclass-doc-inherited'] == 1) el.checked = true; update(); }; var items = parent.querySelectorAll(".toggle-inherited-props"); for (var i = 0; i < items.length; i++) bind(items.item(i)); }; var bindSearch = function (parent) { if (parent === void 0) { parent = document.body; } var bind = function (el) { if (el._searchBound) return; el._searchBound = true; var itemContainer = parent.querySelector(el.getAttribute('data-search-container')); if (!itemContainer) { console.warn("Search container '" + el.getAttribute('data-search-container') + "' not found."); return; } var index = search_1.buildSearchIndex(itemContainer, el.getAttribute('data-search-item')); var _search = function (term) { search_1.search(index, term); if (term.length > 0 && !itemContainer.classList.contains('search-active')) itemContainer.classList.add('search-active'); else if (term.length === 0 && itemContainer.classList.contains('search-active')) itemContainer.classList.remove('search-active'); if (el.getAttribute('data-search-session') == 'true') localStorage['reclass-doc-search'] = term; localStorage['reclass-doc-search-' + el.id] = term; }; el.addEventListener("input", function (ev) { var term = el.value.trim(); _search(term); }); //Restore search value if (el.getAttribute('data-search-session') == 'true' && localStorage['reclass-doc-search']) { el.value = localStorage['reclass-doc-search']; _search(localStorage['reclass-doc-search']); } else if (localStorage['reclass-doc-loc'] == location.href && localStorage['reclass-doc-search-' + el.id]) { el.value = localStorage['reclass-doc-search-' + el.id]; _search(localStorage['reclass-doc-search-' + el.id]); } else { _search(''); } }; var items = parent.querySelectorAll(".search-box[data-search-container][data-search-item]"); for (var i = 0; i < items.length; i++) bind(items.item(i)); }; var watchChanges = function () { var lastMod = null; var reload = function () { localStorage['reclass-doc-scroll'] = document.body.scrollTop; location.reload(); }; var check = function () { var xhrReq = new XMLHttpRequest(); //Bind handler xhrReq.addEventListener("load", function () { if (lastMod === null) lastMod = xhrReq.responseText; else if (lastMod != xhrReq.responseText) reload(); }); xhrReq.addEventListener("error", function (err) { console.error(err); }); xhrReq.open("GET", "/_modified"); xhrReq.send(); }; setInterval(check, 3000); if (localStorage['reclass-doc-scroll']) { document.body.scrollTop = localStorage['reclass-doc-scroll']; localStorage['reclass-doc-scroll'] = null; } }; window.addEventListener("load", function () { bindToggleDetails(); bindCollapseButtons(); bindToggleInheritedProps(); bindSearch(); setTimeout(function () { localStorage['reclass-doc-loc'] = location.href; }, 500); }); var w = window; //Export to window w.__bindSearch = bindSearch; w.__watchChanges = watchChanges; /***/ }), /* 1 */ /***/ (function(module, exports) { /** * Reclass doc generator * * @author Jiri Hybek <jiri@hybek.cz> * @license Apache-2.0 (c) 2017 Jiri Hybek */ "use strict"; function buildSearchIndex(container, itemSelector) { var indexKeywords = {}; var indexItems = []; var parseItems = function (parent, parentItem) { if (parentItem === void 0) { parentItem = null; } var items = parent.querySelectorAll(itemSelector); for (var i = 0; i < items.length; i++) { var _item = items.item(i); //Create search item var searchItem = { id: (parentItem ? parentItem.id + ":" : "") + i, el: _item, parent: parentItem, matched: false }; _item.classList.add('search-item'); indexItems.push(searchItem); if (_item.hasAttribute('data-fulltext')) { //Parse keywords var keywords = _item.getAttribute('data-fulltext').split(" "); //Add to index for (var k = 0; k < keywords.length; k++) { var term = keywords[k].toLowerCase(); if (indexKeywords[term] === undefined) indexKeywords[term] = []; indexKeywords[term].push(searchItem); } } //Parse children parseItems(_item, searchItem); } }; parseItems(container); return { keywords: indexKeywords, items: indexItems }; } exports.buildSearchIndex = buildSearchIndex; function search(index, term) { //Split term into keywords var keywords = term.split(" "); var indexKeywords = index.keywords; var indexItems = index.items; var matches = {}; //Reset matches for (var i = 0; i < indexItems.length; i++) indexItems[i].matched = false; if (term.length > 0) { //Process search for (var i = 0; i < keywords.length; i++) { var _kw = keywords[i].toLowerCase(); for (var j in indexKeywords) { var _match = false; //Exact match if (j == _kw) { _match = true; } else if (_kw.length > 0) { if (j.indexOf(_kw) >= 0) _match = true; } if (_match) { for (var p = 0; p < indexKeywords[j].length; p++) { var _matchItem = indexKeywords[j][p]; //Add to matches if not alreay if (!matches[_matchItem.id]) matches[_matchItem.id] = { item: _matchItem, keywords: {} }; if (!matches[_matchItem.id].keywords[_kw]) matches[_matchItem.id].keywords[_kw] = true; } } } } //Activate matches var toggleItem_1 = function (item) { item.matched = true; if (item.parent && !item.parent.matched) toggleItem_1(item.parent); }; for (var i in matches) { var skip = false; for (var k in keywords) if (!matches[i].keywords[keywords[k].toLowerCase()]) { skip = true; break; } if (skip) continue; toggleItem_1(matches[i].item); } } //Update classes for (var i = 0; i < indexItems.length; i++) { if (indexItems[i].matched && !indexItems[i].el.classList.contains('search-match')) indexItems[i].el.classList.add('search-match'); else if (!indexItems[i].matched && indexItems[i].el.classList.contains('search-match')) indexItems[i].el.classList.remove('search-match'); } } exports.search = search; /***/ }) /******/ ]); //# sourceMappingURL=bundle.js.map