From 246e9b4e37cf85a04f52a22a61a4e705d51f96b4 Mon Sep 17 00:00:00 2001 From: Sebastien SAUVAGE Date: Wed, 25 Sep 2013 21:27:50 +0200 Subject: [PATCH] Removed jQuery from almost all pages jQuery has been removed from all pages, except those who really require it (like autocomplete in link edition). Immediate gain: All pages weight 286 kb LESS ! \o/ Highlighting in search results has also been temporarly removed (and will be re-implemented). --- inc/jquery.highlight.js | 108 ---------------------------------------- tpl/changetag.html | 12 ++++- tpl/editlink.html | 12 ++++- tpl/includes.html | 1 - tpl/linklist.html | 1 - tpl/page.footer.html | 21 -------- tpl/picwall.html | 4 +- 7 files changed, 25 insertions(+), 134 deletions(-) delete mode 100644 inc/jquery.highlight.js diff --git a/inc/jquery.highlight.js b/inc/jquery.highlight.js deleted file mode 100644 index 9dcf3c7..0000000 --- a/inc/jquery.highlight.js +++ /dev/null @@ -1,108 +0,0 @@ -/* - * jQuery Highlight plugin - * - * Based on highlight v3 by Johann Burkard - * http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html - * - * Code a little bit refactored and cleaned (in my humble opinion). - * Most important changes: - * - has an option to highlight only entire words (wordsOnly - false by default), - * - has an option to be case sensitive (caseSensitive - false by default) - * - highlight element tag and class names can be specified in options - * - * Usage: - * // wrap every occurrance of text 'lorem' in content - * // with (default options) - * $('#content').highlight('lorem'); - * - * // search for and highlight more terms at once - * // so you can save some time on traversing DOM - * $('#content').highlight(['lorem', 'ipsum']); - * $('#content').highlight('lorem ipsum'); - * - * // search only for entire word 'lorem' - * $('#content').highlight('lorem', { wordsOnly: true }); - * - * // don't ignore case during search of term 'lorem' - * $('#content').highlight('lorem', { caseSensitive: true }); - * - * // wrap every occurrance of term 'ipsum' in content - * // with - * $('#content').highlight('ipsum', { element: 'em', className: 'important' }); - * - * // remove default highlight - * $('#content').unhighlight(); - * - * // remove custom highlight - * $('#content').unhighlight({ element: 'em', className: 'important' }); - * - * - * Copyright (c) 2009 Bartek Szopka - * - * Licensed under MIT license. - * - */ - -jQuery.extend({ - highlight: function (node, re, nodeName, className) { - if (node.nodeType === 3) { - var match = node.data.match(re); - if (match) { - var highlight = document.createElement(nodeName || 'span'); - highlight.className = className || 'highlight'; - var wordNode = node.splitText(match.index); - wordNode.splitText(match[0].length); - var wordClone = wordNode.cloneNode(true); - highlight.appendChild(wordClone); - wordNode.parentNode.replaceChild(highlight, wordNode); - return 1; //skip added node in parent - } - } else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children - !/(script|style)/i.test(node.tagName) && // ignore script and style nodes - !(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted - for (var i = 0; i < node.childNodes.length; i++) { - i += jQuery.highlight(node.childNodes[i], re, nodeName, className); - } - } - return 0; - } -}); - -jQuery.fn.unhighlight = function (options) { - var settings = { className: 'highlight', element: 'span' }; - jQuery.extend(settings, options); - - return this.find(settings.element + "." + settings.className).each(function () { - var parent = this.parentNode; - parent.replaceChild(this.firstChild, this); - parent.normalize(); - }).end(); -}; - -jQuery.fn.highlight = function (words, options) { - var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false }; - jQuery.extend(settings, options); - - if (words.constructor === String) { - words = [words]; - } - words = jQuery.grep(words, function(word, i){ - return word != ''; - }); - words = jQuery.map(words, function(word, i) { - return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); - }); - if (words.length == 0) { return this; }; - - var flag = settings.caseSensitive ? "" : "i"; - var pattern = "(" + words.join("|") + ")"; - if (settings.wordsOnly) { - pattern = "\\b" + pattern + "\\b"; - } - var re = new RegExp(pattern, flag); - - return this.each(function () { - jQuery.highlight(this, re, settings.element, settings.className); - }); -}; - diff --git a/tpl/changetag.html b/tpl/changetag.html index b0bd0d0..b22bdde 100644 --- a/tpl/changetag.html +++ b/tpl/changetag.html @@ -1,6 +1,8 @@ -{include="includes"} +{include="includes"} +{if="empty($GLOBALS['disablejquery'])"}{/if} + {include="page.footer"} +{if="($GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn()) && empty($GLOBALS['disablejquery'])"} + +{/if} \ No newline at end of file diff --git a/tpl/editlink.html b/tpl/editlink.html index ad54913..4a2c30c 100644 --- a/tpl/editlink.html +++ b/tpl/editlink.html @@ -1,6 +1,8 @@ -{include="includes"} +{include="includes"} +{if="empty($GLOBALS['disablejquery'])"}{/if} + {include="page.footer"} +{if="($GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn()) && empty($GLOBALS['disablejquery'])"} + +{/if} \ No newline at end of file diff --git a/tpl/includes.html b/tpl/includes.html index e0ad00d..2b61f1e 100644 --- a/tpl/includes.html +++ b/tpl/includes.html @@ -7,4 +7,3 @@ {if condition="is_file('inc/user.css')"}{/if} -{if="empty($GLOBALS['disablejquery'])"}{/if} diff --git a/tpl/linklist.html b/tpl/linklist.html index bce3fa9..ddc38cb 100644 --- a/tpl/linklist.html +++ b/tpl/linklist.html @@ -68,7 +68,6 @@ {include="page.footer"} {/if} - -{if="($GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn()) && empty($GLOBALS['disablejquery'])"} - -{/if} - -{if="empty($GLOBALS['disablejquery']) && isset($_GET['searchterm'])"} - - -{/if} \ No newline at end of file diff --git a/tpl/picwall.html b/tpl/picwall.html index 631e086..b78e260 100644 --- a/tpl/picwall.html +++ b/tpl/picwall.html @@ -2,7 +2,9 @@ {include="includes"} {if="empty($GLOBALS['disablejquery'])"} - + + + {/if}