MediaWiki:HighlightTermsURL.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
//jQuery function to parse url_terms from url when current page was linked from Vaniquotes
//The vaniquotes link was modified to include these url_terms in order to highlight them in the current page in Vanisource
$(document).ready(function() {
//First check if the current page is an Article
if (wgCanonicalNamespace == "" && location.search && wgAction == "view") {
var body_html = $('#bodyContent').html();
search_str = decodeURI(this.location.search);
search_str = search_str.replace(/\?terms=/, '');
search_str = search_str.replace(/\+$/m, '');
url_terms = search_str.split('+');
url_terms = $(url_terms);
for (var i = 0, len = url_terms.length; i < len; ++i) {
//sanitize text for search
if (url_terms[i] != "") {
url_term = url_terms[i];
//regex search including "text" which is the current url_term in the loop
var search1 = new RegExp('([^a-zA-Z])('+url_term+')([^a-zA-Z])', 'img');
//search and replace where url_term is found in html copy
body_html = body_html.replace(search1, "$1<span class='highlight_terms'>$2</span>$3");
$('#bodyContent').html(body_html);
}
}
$.scrollTo('span.highlight_terms', '1500', {offset:-100});
}
});