HighlightTermsURL.js: Difference between revisions
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
} | } | ||
} | } | ||
$.scrollTo('span.highlight_terms', '1500', {offset:-100}); | |||
} | } | ||
} | }); |
Revision as of 23:00, 20 March 2008
//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}); } });