diff options
Diffstat (limited to 'help3xsl')
-rw-r--r-- | help3xsl/online_transform.xsl | 15 | ||||
-rw-r--r-- | help3xsl/paginathing.js | 45 |
2 files changed, 42 insertions, 18 deletions
diff --git a/help3xsl/online_transform.xsl b/help3xsl/online_transform.xsl index 8b215f218c..2feda208ac 100644 --- a/help3xsl/online_transform.xsl +++ b/help3xsl/online_transform.xsl @@ -306,16 +306,15 @@ var liElements = Array.prototype.slice.call(document.getElementsByClassName("list")[0].getElementsByTagName("li")).map(function(elm) { var item = elm; var linktext = item.childNodes[0].textContent; - return { - item, linktext - }; + var fuseObject = { item: item, linktext: linktext }; + return fuseObject; }); var fuse = new Fuse(liElements, { keys: ["linktext"], - distance: 80, + distance: 60, location: 0, - threshold: 0.4, + threshold: 0.2, tokenize: true, matchAllTokens: true, maxPatternLength: 24, @@ -352,13 +351,13 @@ return function () { clearTimeout(timeout); timeout = setTimeout(function () { - fn.apply(this, arguments) + fn.apply(this, arguments); }, (wait || 150)); - } }; + } Paginator(document.getElementsByClassName("list")[0]); - search.addEventListener('keyup', debounce(filter, 200)); + search.addEventListener('keyup', debounce(filter, 300)); ]]> </script> <xsl:choose> diff --git a/help3xsl/paginathing.js b/help3xsl/paginathing.js index 6eb1ca6ab3..184a698550 100644 --- a/help3xsl/paginathing.js +++ b/help3xsl/paginathing.js @@ -1,26 +1,26 @@ /** * Paginathing * Paginate Everything - * + * * Original @author Alfred Crosby <https://github.com/alfredcrosby> * Inspired from http://esimakin.github.io/twbs-pagination/ * Modified to pure JavaScript and specialised to LibreOffice Help by * Ilmari Lauhakangas - * + * * MIT License (Expat) - * + * * Copyright (c) 2018 Alfred Crosby - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,6 +29,31 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +// Polyfill for .after() +(function (arr) { + arr.forEach(function (item) { + if (item.hasOwnProperty('after')) { + return; + } + Object.defineProperty(item, 'after', { + configurable: true, + enumerable: true, + writable: true, + value: function after() { + var argArr = Array.prototype.slice.call(arguments), + docFrag = document.createDocumentFragment(); + + argArr.forEach(function (argItem) { + var isNode = argItem instanceof Node; + docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem))); + }); + + this.parentNode.insertBefore(docFrag, this.nextSibling); + } + }); + }); +})([Element.prototype, CharacterData.prototype, DocumentType.prototype]); + var options = { perPage: 10, limitPagination: 6, @@ -174,7 +199,7 @@ var Paginator = function(element) { } } - // Manage active state + // Manage active state var ulKids = ul.getElementsByTagName("li"); for (var i = 0, len = ulKids.length; i < len; i++) { @@ -183,7 +208,7 @@ var Paginator = function(element) { switch (type) { case 'number': - if (parseInt(_li.getAttribute('data-page')) === page) { + if (parseInt(_li.getAttribute('data-page'), 10) === page) { _li.classList.add(options.activeClass); } break; @@ -214,10 +239,10 @@ var Paginator = function(element) { for (var i = 0, len = pagLi.length; i < len; i++) { (function() { var item = pagLi[i]; - + item.addEventListener('click', function(e) { e.preventDefault(); - var page = parseInt(item.getAttribute('data-page')); + var page = parseInt(item.getAttribute('data-page'), 10); currentPage = page; // let's prevent the pagination from flowing to two rows if (currentPage >= 98) { |