MediaWiki

UpdateLinks.js: Difference between revisions

(New page: $(document).ready(function() { //Update links pointing to vanisource with terms found in spans with class="terms" //get terms from <span class="terms" and sanitize them terms = ""; ...)
 
(No difference)

Latest revision as of 14:36, 17 March 2008


$(document).ready(function() {
  //Update links pointing to vanisource with terms found in spans with class="terms"
  //get terms from <span class="terms" and sanitize them
  terms = "";
  if ($('span.terms').length) {
    $('span.terms').each(function () {
      text = $(this).text().replace(/"/g, "");
      text = text.replace(/(\w+) {2,}(\w+)/g, "$1 $2");
      text = text.replace(/^\ {0,}/m, "");
      text = text.replace(/\ {0,}$/m, ""); 
      terms += text+'+';
    });
  } else { terms = wgTitle; }
  //serach in the body for any anchor <a with a attribute href pointing to Vanisource
  //and append the terms to be passed to Vanisource for highlighting
  //Define function to append terms
  append_terms = function() {
    class_this = $(this).attr('class');
    //alert(class_this);
    //Check if class has been already defined with this same routine (if we have been here), the terms have already been appended
    if(class_this != 'selected'){
      search_str1 = this.href+'?terms='+terms;
      $(this).attr({href: search_str1, class: 'selected'});
    }
  }
  //Now bind it onclick
  $('#bodyContent a[@href*="vanisource.org"]').not( $('#bodyContent a[@href*="edit"]') ).click(append_terms);
    
});