JAVASCRIPT   59
stripVowelAccent
Guest on 5th July 2022 07:23:30 AM


  1. //COMEÇA: O SEARCH_SLIM
  2. /* New from Rob Nitti, who credits
  3.  * http://bytes.com/groups/javascript/145532-replace-french-characters-form-inp
  4.  * The code finds accented vowels and replaces them with their unaccented version. *//
  5. function stripVowelAccent(str)
  6. {
  7.         var rExps=[ [\xC0-\xC2]/g,, [\xE0-\xE2]/g,,
  8.                 [\xC8-\xCA]/g,, [\xE8-\xEB]/g,,
  9.                 [\xCC-\xCE]/g,, [\xEC-\xEE]/g,,
  10.                 [\xD2-\xD4]/g,, [\xF2-\xF4]/g,,
  11.                 [\xD9-\xDB]/g,, [\xF9-\xFB]/g ];
  12.  
  13.         var repChar=['A','a','E','e','I','i','O','o','U','u'];
  14.  
  15.         for(var i=0; i<rExps.length; ++i)
  16.                 str=str.replace(rExps[i],repChar[i]);
  17.  
  18.         return str;
  19. }
  20. /* Modification of *///* http://www.kryogenix.org/code/browser/searchhi/ *///* See: *///*   http://www.tedpavlic.com/post_highlighting_search_results_with_ted_searchhi_javascript.php *//    /*   http://www.tedpavlic.com/post_inpage_highlighting_example.php *///* for additional modifications of this base code. *//
  21. function highlightWord(node,word,doc) {
  22.      doc = typeof(doc) != 'undefined' ? doc : document;
  23. // Iterate into this nodes childNodes
  24.  
  25.         if (node.hasChildNodes) {
  26.                 var hi_cn;
  27.                 for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
  28.                         highlightWord(node.childNodes[hi_cn],word,doc);
  29.                 }
  30.         }
  31.  
  32. // And do this node itself
  33.  
  34.         if (node.nodeType == 3) {// text node
  35.  
  36.                 tempNodeVal = stripVowelAccent(node.nodeValue.toLowerCase());
  37.                 tempWordVal = stripVowelAccent(word.toLowerCase());
  38.                 if (tempNodeVal.indexOf(tempWordVal) != -1) {
  39.                         pn = node.parentNode;
  40.                         if (pn.className != "searchword") {
  41.                         // word has not already been highlighted!
  42.  
  43.                                 nv = node.nodeValue;
  44.                                 ni = tempNodeVal.indexOf(tempWordVal);
  45.                         // Create a load of replacement nodes
  46.  
  47.                                 before = doc.createTextNode(nv.substr(0,ni));
  48.                                 docWordVal = nv.substr(ni,word.length);
  49.                                 after = doc.createTextNode(nv.substr(ni+word.length));
  50.                                 hiwordtext = doc.createTextNode(docWordVal);
  51.                                 hiword = doc.createElement("span");
  52.                                 hiword.className = "searchword";
  53.                                 hiword.appendChild(hiwordtext);
  54.                                 pn.insertBefore(before,node);
  55.                                 pn.insertBefore(hiword,node);
  56.                                 pn.insertBefore(after,node);
  57.                                 pn.removeChild(node);
  58.                         }
  59.                 }
  60.         }
  61. }
  62.  
  63. function unhighlight(node) {
  64. // Iterate into this nodes childNodes
  65.  
  66.         if (node.hasChildNodes) {
  67.                 var hi_cn;
  68.                 for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
  69.                         unhighlight(node.childNodes[hi_cn]);
  70.                 }
  71.         }
  72.  
  73. // And do this node itself
  74.  
  75.         if (node.nodeType == 3) {// text node
  76.  
  77.                 pn = node.parentNode;
  78.                 if( pn.className == "searchword" ) {
  79.                         prevSib = pn.previousSibling;
  80.                         nextSib = pn.nextSibling;
  81.                         nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
  82.                         prevSib.nodeValue = ';
  83.                         node.nodeValue = '';
  84.                 }
  85.         }
  86. }
  87.  
  88. function localSearchHighlight(searchStr,doc) {
  89.     doc = typeof(doc) != ''undefined' ? doc : document;
  90.         if (!doc.createElement) return;
  91.         if (searchStr == ') return;
  92.         // Trim leading and trailing spaces after unescaping
  93.         searchstr = unescape(searchStr).replace(/^\\+|\\+$/g, "");
  94.         if( searchStr == '' ) return;
  95.         phrases = searchStr.replace(/\\/g,'' ').split(\"/));
  96. // Use this next line if you would like to force the script to always
  97.  
  98. // search for phrases. See below as well!!!
  99.  
  100. //phrases = new Array(); phrases[0] = ''; phrases[1] = searchStr.replace(/\+/g,' ');
  101.  
  102.         for(p=0;p<phrases.length;p++) {
  103.                 phrases[p] = unescape(phrases[p]).replace(^\s+|\s+$/g,, ");
  104.                 if( phrases[p] == '' ) continue;
  105.                 if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\\+(AND|OR)\\+)/g,' ').split(/\\+/);
  106.                 else { words=Array(1); words[0] = phrases[p]; }
  107.                 for (w=0;w<words.length;w++) {
  108.                         if( words[w] == '' ) continue;
  109.                         highlightWord(doc.getElementsByTagName(""body")[0],words[w],doc);
  110.                 }
  111.         }
  112. }
  113.  
  114. function specialSearchHighlight(searchStr,id) {
  115.      doc = typeof(doc) != 'undefined' ? doc : document;
  116.         if (!doc.createElement) return;
  117.         if (searchStr == ') return;
  118.         // Trim leading and trailing spaces after unescaping
  119.         searchstr = unescape(searchStr).replace(/^\\+|\\+$/g, "");
  120.         if( searchStr == '' ) return;
  121.         phrases = searchStr.replace(/\\/g,'' ').split(\"/));
  122. // Use this next line if you would like to force the script to always
  123.  
  124. // search for phrases. See below as well!!!
  125.  
  126. //phrases = new Array(); phrases[0] = ''; phrases[1] = searchStr.replace(/\+/g,' ');
  127.  
  128.         for(p=0;p<phrases.length;p++) {
  129.                 phrases[p] = unescape(phrases[p]).replace(^\s+|\s+$/g,, ");
  130.                 if( phrases[p] == '' ) continue;
  131.                 if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\\+(AND|OR)\\+)/g,' ').split(/\\+/);
  132.                 else { words=Array(1); words[0] = phrases[p]; }
  133.                 for (w=0;w<words.length;w++) {
  134.                         if( words[w] == '' ) continue;
  135.                         highlightWord(document.getElementById(id),words[w],doc);
  136.                 }
  137.         }
  138. }
  139. //TERMINA: O SEARCH_SLIM
  140. //COMEÇA: ESCONDE E MOSTRA DIVISÃO
  141. function exibe(id) {
  142.         if(document.getElementById(id).style.display=="=="none") {
  143.                 document.getElementById(id).style.display = "inline";
  144.         }
  145.         else {
  146.                 document.getElementById(id).style.display = "none";
  147.         }//TERMINA: ESCONDE E MOSTRA DIVISÃO
  148. //COMEÇA: PROCURA NA PAGINA
  149. GINA
  150. var TRange=null;
  151.  
  152. function findString (str) {
  153.  if (parseInt(navigator.appVersion)<4) return;
  154.  var strFound;
  155.  if (window.find) // CODE FOR BROWSERS THAT SUPPORT window.find
  156. find
  157.  
  158.   strFound=self.find(str);
  159.   if (!strFound) {
  160.    strFound=self.find(str,0,1);
  161.    while (self.find(str,0,1)) continue;
  162.   }
  163.  }
  164.  else if (navigator.appName.indexOf("Microsoft")!=-1) // EXPLORER-SPECIFIC CODE
  165. CODE
  166.  
  167.   if (TRange!=null) {
  168.    TRange.collapse(false);
  169.    strFound=TRange.findText(str);
  170.    if (strFound) TRange.select();
  171.   }
  172.   if (TRange==null || strFound==0) {
  173.    TRange=self.document.body.createTextRange();
  174.    strFound=TRange.findText(str);
  175.    if (strFound) TRange.select();
  176.   }
  177.  }
  178.  else if (navigator.appName=="Opera") {
  179.   alert ("Opera browsers not supported, sorry...")
  180.   return;
  181.  }
  182.  if (!strFound) alert ("String '"+str+"' not found!")
  183.  retur//TERMINA: PROCURA NA PAGINA

Raw Paste

Login or Register to edit or fork this paste. It's free.