MediaWiki

HighlightTermsURL.js: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
//jQuery function to parse url_terms from url when current page was linked from Vaniquotes
//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
//The vaniquotes link was modified to include these url_terms in order to highlight them in the current page in Vanisource
document.write('<script type="text/javascript" src="'+$jquery_dir+'/Jquery.highlight_sanskrit.js"></script>');
document.write('<script type="text/javascript" src="'+$jquery_dir+'/Jquery.getParams.js"></script>');


$(document).ready(function() {
$(document).ready(function() {
   //First check if the current page is an Article
   //First check if the current page is an Article
   if (wgIsArticle && location.search && wgAction == "view") {
   if (wgIsArticle && location.search && wgAction == "view") {
     var body_html = $('#bodyContent').html();
     if (this.location.search) {
    search_str = decodeURI(this.location.search);
      var url_string = $.getURLParam('terms');
    search_str = search_str.replace(/\?terms=/, '');
      var url_terms = decodeURI(url_string).split('+');
    search_str = search_str.replace(/\+$/m, '');
      if (url_terms.length > 0 ) {
    url_terms = search_str.split('+');
        for (var i = 0, len = url_terms.length; i < len; ++i) {
    url_terms = $(url_terms);
          //sanitize text for search
    for (var i = 0, len = url_terms.length; i < len; ++i) {
          if (url_terms[i] != "") {
        //sanitize text for search
            url_term = url_terms[i];
        if (url_terms[i] != "") {
            $('#bodyContent').highlight_sanskrit(url_term);
          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});
     }
     }
    $.scrollTo('span.highlight_terms', '1500', {offset:-100});
   }
   }
   
});
});

Revision as of 09:29, 11 July 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.write('<script type="text/javascript" src="'+$jquery_dir+'/Jquery.highlight_sanskrit.js"></script>');
document.write('<script type="text/javascript" src="'+$jquery_dir+'/Jquery.getParams.js"></script>');

$(document).ready(function() {
  //First check if the current page is an Article
  if (wgIsArticle && location.search && wgAction == "view") {
    if (this.location.search) {
      var url_string = $.getURLParam('terms');
      var url_terms = decodeURI(url_string).split('+');
      if (url_terms.length > 0 ) {
        for (var i = 0, len = url_terms.length; i < len; ++i) {
          //sanitize text for search
          if (url_terms[i] != "") {
            url_term = url_terms[i];
            $('#bodyContent').highlight_sanskrit(url_term);
          }
        }
      }
      $.scrollTo('span.highlight_terms', '1500', {offset:-100});
    }
  }
});