Difference between revisions of "MediaWiki:Common.js"

From Free Software Directory
Jump to: navigation, search
m (+performance;)
(+better performance; +defensive programming; +support for aliases and templates;)
Line 9: Line 9:
 
   var containsMeta = srcontent.match(/.*\|.*=.*/i);
 
   var containsMeta = srcontent.match(/.*\|.*=.*/i);
 
   var containsRedi = srcontent.match(/#REDIRECT .*/i);
 
   var containsRedi = srcontent.match(/#REDIRECT .*/i);
 +
  var containsTmpl = srcontent.match(/.*(\{\{|\}\}).*/i);
 
   if(containsMeta !== null) return 1;
 
   if(containsMeta !== null) return 1;
 
   else if(containsRedi !== null) return 2;
 
   else if(containsRedi !== null) return 2;
 +
  else if(containsTmpl !== null) return 3;
 
   else return 0;
 
   else return 0;
 
  }
 
  }
 
  function correctSrTmplBug(i, el) {
 
  function correctSrTmplBug(i, el) {
 
   el = $(el);
 
   el = $(el);
   if(detectSrTmplBug(el.html()) > 0) {
+
   var tres = detectSrTmplBug(el.html());
     el.hide();
+
  switch(tres) {
 +
    case 0: break;
 +
    case 1:
 +
    case 3: el.html('(structured)');
 +
    break;
 +
    case 2: el.html('(alias)');
 +
     break;
 +
    default: el.hide();
 
   }
 
   }
   el = null;  
+
   el = null;
 +
  tres = null;
 
   return;
 
   return;
 
  }
 
  }
  
   if(iskSearchCurPage() == false) return false;
+
   if(iskSearchCurPage() === false) return false;
 
   else {
 
   else {
 
   var sresults = $('.searchresult');
 
   var sresults = $('.searchresult');

Revision as of 11:53, 9 November 2019

/* Any JavaScript here will be loaded for all users on every page load. */

/* Active Backlog: fix. "Fix search results, so that template data doesn't get dumped..." */
function fixSrTmplBug() {
 function iskSearchCurPage() {
   return window.location.href.match(/\w+\/wiki\?search=\w+/i) !== null;
 }
 function detectSrTmplBug(srcontent) {
   var containsMeta = srcontent.match(/.*\|.*=.*/i);
   var containsRedi = srcontent.match(/#REDIRECT .*/i);
   var containsTmpl = srcontent.match(/.*(\{\{|\}\}).*/i);
   if(containsMeta !== null) return 1;
   else if(containsRedi !== null) return 2;
   else if(containsTmpl !== null) return 3;
   else return 0;
 }
 function correctSrTmplBug(i, el) {
   el = $(el);
   var tres = detectSrTmplBug(el.html());
   switch(tres) {
    case 0: break;
    case 1:
    case 3: el.html('(structured)'); 
     break;
    case 2: el.html('(alias)');
     break;
    default: el.hide();
   }
   el = null;
   tres = null;
   return;
 }

  if(iskSearchCurPage() === false) return false;
  else {
   var sresults = $('.searchresult');
   if(sresults.length > 0) {
     sresults.each(correctSrTmplBug);
     sresults = null;
   }
  }
  return true;
};

$(document).ready(function(){fixSrTmplBug();});


Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the page “GNU Free Documentation License”.

The copyright and license notices on this page only apply to the text on this page. Any software or copyright-licenses or other similar notices described in this text has its own copyright notice and license, which can usually be found in the distribution or license text itself.