HighlightTerms.js: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
/******* Vars ********/ | |||
$jquery_dir = 'http://vanipedia.org/w/index.php?title=MediaWiki:'; | |||
$raw_mode = '&action=raw&ctype=text/javascript'; | |||
// Dependencies | |||
document.write('<script type="text/javascript" src="'+$jquery_dir+'Jquery.highlight_sanskrit.js'+$raw_mode+'"></' + 'script>'); | |||
//Jquery highlighting function taking terms from page header inside <span class="terms" id="termN"> | |||
//Jquery highlighting function taking terms from page header inside <span class="terms" id="termN"> | //Jquery highlighting function taking terms from page header inside <span class="terms" id="termN"> | ||
function high_this(key) { | |||
$('p b a').parent().parent().highlight_sanskrit(quotemeta(key)); | |||
high_this | |||
$('p').filter(function() { | |||
return ! $(this).children().size() > 0; | |||
}).highlight_sanskrit(quotemeta(key)); | |||
$ | |||
} | |||
} | } | ||
function quotemeta (string) { | |||
return string.replace(/([\(\)])/g, "\\$1"); | |||
} | } | ||
//BEGIN!!! | //BEGIN!!! | ||
$(document).ready(function() { | $(document).ready(function() { | ||
//First check if the current page is an Article and that we are on view mode | //First check if the current page is an Article and that we are on view mode | ||
if (wgCanonicalNamespace == | if (wgCanonicalNamespace == '' && wgAction == 'view') { | ||
//if spans with class terms exist | //if spans with class terms exist | ||
if ($('span.terms').length) { | if ($('span.terms').length) { | ||
Line 54: | Line 32: | ||
hi_term[i] = $(this).text().replace(/"/g, ""); | hi_term[i] = $(this).text().replace(/"/g, ""); | ||
hi_term[i] = hi_term[i].replace(/(^ *| *$)/mg, ""); | hi_term[i] = hi_term[i].replace(/(^ *| *$)/mg, ""); | ||
hi_term[i] = hi_term[i].replace(/ | hi_term[i] = hi_term[i].replace(/ {2,}/g, ' '); | ||
high_this(hi_term[i]); | high_this(hi_term[i]); | ||
}); | }); | ||
} else { | } else { | ||
//if no terms found, use wgTitle(title of article) as the search term for highlighting | //if no terms found, use wgTitle(title of article) as the search term for highlighting | ||
hi_term = wgTitle; | hi_term = wgTitle; | ||
high_this(hi_term); | high_this(hi_term); | ||
} | } | ||
} | } | ||
}); | }); |
Latest revision as of 16:18, 31 July 2008
/******* Vars ********/ $jquery_dir = 'http://vanipedia.org/w/index.php?title=MediaWiki:'; $raw_mode = '&action=raw&ctype=text/javascript'; // Dependencies document.write('<script type="text/javascript" src="'+$jquery_dir+'Jquery.highlight_sanskrit.js'+$raw_mode+'"></' + 'script>'); //Jquery highlighting function taking terms from page header inside <span class="terms" id="termN"> //Jquery highlighting function taking terms from page header inside <span class="terms" id="termN"> function high_this(key) { $('p b a').parent().parent().highlight_sanskrit(quotemeta(key)); $('p').filter(function() { return ! $(this).children().size() > 0; }).highlight_sanskrit(quotemeta(key)); } function quotemeta (string) { return string.replace(/([\(\)])/g, "\\$1"); } //BEGIN!!! $(document).ready(function() { //First check if the current page is an Article and that we are on view mode if (wgCanonicalNamespace == '' && wgAction == 'view') { //if spans with class terms exist if ($('span.terms').length) { //iterate hi_term = new Array(); $('span.terms').each(function(i) { //sanitize hi_term for search hi_term[i] = $(this).text().replace(/"/g, ""); hi_term[i] = hi_term[i].replace(/(^ *| *$)/mg, ""); hi_term[i] = hi_term[i].replace(/ {2,}/g, ' '); high_this(hi_term[i]); }); } else { //if no terms found, use wgTitle(title of article) as the search term for highlighting hi_term = wgTitle; high_this(hi_term); } } });