Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   $.fn.replaceText = function( search, replace, text_only ) {
  2.     return this.each(function(){
  3.       var node = this.firstChild,
  4.         val,
  5.         new_val,
  6.         remove = [];
  7.       if ( node ) {
  8.         do {
  9.           if ( node.nodeType === 3 ) {
  10.             val = node.nodeValue;
  11.             new_val = val.replace( search, replace );
  12.             if ( new_val !== val ) {
  13.               if ( !text_only && /</.test( new_val ) ) {
  14.                 $(node).before( new_val );
  15.                 remove.push( node );
  16.               } else {
  17.                 node.nodeValue = new_val;
  18.               }
  19.             }
  20.           }
  21.         } while ( node = node.nextSibling );
  22.       }
  23.       remove.length && $(remove).remove();
  24.     });
  25.   };
  26.  
  27. jQuery(document).ready(function(){
  28.     $('.txtSearch').focus(function(){
  29.         if ($(this).val() == 'Faça sua busca ...') { $(this).val(''); }
  30.     }).blur(function(){
  31.         if ($(this).val() == '') { $(this).val('Faça sua busca ...'); }
  32.     });
  33.  
  34.     $("form.valida_busca").submit(function() {
  35.         if ($('.txtSearch', this).val() == 'Faça sua busca ...') { alert('Digite uma busca válida!'); return false; } else {return true;}
  36.     });
  37.  
  38.     $(document).bind('click', function(e) {
  39.       $that = $(e.target).attr('class');
  40.       if($that != 'ordem') {
  41.         $('.order ul').hide();
  42.       } else { $('.order ul').toggle(); }
  43.     });
  44.  
  45.     $('#selectOrder li').bind('click', function(e){
  46.       $valor = $(e.target).attr("rel");
  47.       $urlNavegador = location.href.split('?');
  48.       $ultimo = new Array();
  49.       $url = "";
  50.       $newUrl = "";
  51.  
  52.       if ($urlNavegador.length > 1) {
  53.         $verificar = $urlNavegador[1].split('&');
  54.         if ($verificar.length > 1) {
  55.           $.each($verificar, function(i, val){
  56.             $ultimo = $verificar[i].split('=');
  57.             if (($ultimo[0] != 'order') && ($ultimo[0] != 'ordem')) {
  58.               if (i == $verificar.length - 1) { $newUrl += $verificar[i]; } else { $newUrl += $verificar[i] + '&'; }
  59.             } else if ($ultimo[0] == 'order') {
  60.                 if (i == $verificar.length - 1) { $newUrl += 'order=' + $valor; } else { $newUrl += 'order=' + $valor + '&'; }
  61.             } else if ($ultimo[0] == 'ordem') {
  62.                if (i == $verificar.length - 1) { $newUrl += $verificar[i]; } else { $newUrl += $verificar[i] + '&'; }
  63.             }
  64.           });
  65.         } else { $newUrl = $urlNavegador[1] + "&order=" + $valor + '&ordem=ASC'; }
  66.         $url = $urlNavegador[0] + "?" + $newUrl;
  67.            
  68.       } else { $url = location.href + "?order=" + $valor + '&ordem=ASC'; }
  69.       window.location = $url;
  70.     });
  71.  
  72.     $(function(){
  73.       $urlNavegador = location.href.split('?');
  74.       if ($urlNavegador.length > 1) {
  75.         $valores = $urlNavegador[1].split('&');
  76.         if ($valores.length > 1) {
  77.           $ordem = new Array();
  78.           $valorOrder = "";
  79.           $texto = "";
  80.           $textInverter = "";
  81.           $textoSelect = "";
  82.           $newUrl = "";
  83.  
  84.           $.each($valores, function(i, val){
  85.             $ordem = $valores[i].split('=');
  86.             if (($ordem[0] != 'order') && ($ordem[0] != 'ordem')) {
  87.               if (i == $valores.length - 1) { $newUrl += $valores[i]; } else { $newUrl += $valores[i] + '&'; }
  88.             } else if ($ordem[0] == 'order') {
  89.                 $('#selectOrder li').each(function(i, val){
  90.                     if ($(this).attr('rel') == $ordem[1]) { $texto = $(this).text(); }
  91.                 });
  92.                 $('.ordem').text('Ordem: ' + $texto);
  93.                 if (i == $valores.length - 1) { $newUrl += $valores[i]; } else { $newUrl += $valores[i] + '&'; }
  94.             } else if ($ordem[0] == 'ordem'){
  95.               switch ($ordem[1]) {
  96.                 case 'ASC':
  97.                   $textInverter = '▼ Z..A';
  98.                   if (i == $valores.length - 1) { $newUrl += 'ordem=DESC'; } else { $newUrl += 'ordem=DESC&'; }
  99.                   break;
  100.                 case 'DESC':
  101.                   $textInverter = '▲ A..Z';
  102.                   if (i == $valores.length - 1) { $newUrl += 'ordem=ASC'; } else { $newUrl += 'ordem=ASC&'; }
  103.                   break;
  104.               }
  105.             }
  106.           });
  107.           $('.ordenar').attr('href', $urlNavegador[0] + '?' + $newUrl).text($textInverter);
  108.         }
  109.       }
  110.     });
  111.  
  112.     _replaceCaracteres = function(valor) {
  113.         $specialChars = [{val:"a",let:"áàãâä"},{val:"e",let:"éèêë"},{val:"i",let:"íìîï"},{val:"o",let:"óòõôö"},{val:"u",let:"úùûü"},{val:"c",let:"ç"},{val:"A",let:"ÁÀÃÂÄ"},{val:"E",let:"ÉÈÊË"},{val:"I",let:"ÍÌÎÏ"},{val:"O",let:"ÓÒÕÔÖ"},{val:"U",let:"ÚÙÛÜ"},{val:"C",let:"Ç"},{val:"\n",let:"?!()./-/+"}];
  114.         $spaceSymbol = "+";
  115.         $regex = null;
  116.         $returnString = valor;
  117.         $.each($specialChars, function(i, val){
  118.             $regex = new RegExp("["+$specialChars[i].let+"]", "g");
  119.             $returnString = $returnString.replace($regex, $specialChars[i].val);
  120.             $regex = null;
  121.         });
  122.         return $returnString.replace(/\s/g,$spaceSymbol);
  123.     }
  124.  
  125.     $(function(){
  126.       $urlNavegador = location.href.split('?');
  127.       if ($urlNavegador.length > 1) {
  128.         $novoTesto = "";
  129.         $valores = $urlNavegador[1].split('&');
  130.         $.each($valores, function(i, val){
  131.             $ordem = $valores[i].split('=');
  132.             if ($ordem[0] == 'search') { $novoTesto = $ordem[1].replace("+", " ").trim(); }
  133.         });
  134.         $('form .txtSearch').val($novoTesto);
  135.         $form = $('#search_form').attr('action').split('/')
  136.         $location = $form[$form.length - 1];
  137.  
  138.         $('#'+$location+' tr').each(function(){
  139.             searchRegex = new RegExp($novoTesto, 'gi');
  140.             $(" *", this).replaceText(searchRegex, '<em class="search_result">'+$novoTesto+'</em>');
  141.         });
  142.       }
  143.     });
  144.  
  145. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement