Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.fn.replaceText = function( search, replace, text_only ) {
- return this.each(function(){
- var node = this.firstChild,
- val,
- new_val,
- remove = [];
- if ( node ) {
- do {
- if ( node.nodeType === 3 ) {
- val = node.nodeValue;
- new_val = val.replace( search, replace );
- if ( new_val !== val ) {
- if ( !text_only && /</.test( new_val ) ) {
- $(node).before( new_val );
- remove.push( node );
- } else {
- node.nodeValue = new_val;
- }
- }
- }
- } while ( node = node.nextSibling );
- }
- remove.length && $(remove).remove();
- });
- };
- jQuery(document).ready(function(){
- $('.txtSearch').focus(function(){
- if ($(this).val() == 'Faça sua busca ...') { $(this).val(''); }
- }).blur(function(){
- if ($(this).val() == '') { $(this).val('Faça sua busca ...'); }
- });
- $("form.valida_busca").submit(function() {
- if ($('.txtSearch', this).val() == 'Faça sua busca ...') { alert('Digite uma busca válida!'); return false; } else {return true;}
- });
- $(document).bind('click', function(e) {
- $that = $(e.target).attr('class');
- if($that != 'ordem') {
- $('.order ul').hide();
- } else { $('.order ul').toggle(); }
- });
- $('#selectOrder li').bind('click', function(e){
- $valor = $(e.target).attr("rel");
- $urlNavegador = location.href.split('?');
- $ultimo = new Array();
- $url = "";
- $newUrl = "";
- if ($urlNavegador.length > 1) {
- $verificar = $urlNavegador[1].split('&');
- if ($verificar.length > 1) {
- $.each($verificar, function(i, val){
- $ultimo = $verificar[i].split('=');
- if (($ultimo[0] != 'order') && ($ultimo[0] != 'ordem')) {
- if (i == $verificar.length - 1) { $newUrl += $verificar[i]; } else { $newUrl += $verificar[i] + '&'; }
- } else if ($ultimo[0] == 'order') {
- if (i == $verificar.length - 1) { $newUrl += 'order=' + $valor; } else { $newUrl += 'order=' + $valor + '&'; }
- } else if ($ultimo[0] == 'ordem') {
- if (i == $verificar.length - 1) { $newUrl += $verificar[i]; } else { $newUrl += $verificar[i] + '&'; }
- }
- });
- } else { $newUrl = $urlNavegador[1] + "&order=" + $valor + '&ordem=ASC'; }
- $url = $urlNavegador[0] + "?" + $newUrl;
- } else { $url = location.href + "?order=" + $valor + '&ordem=ASC'; }
- window.location = $url;
- });
- $(function(){
- $urlNavegador = location.href.split('?');
- if ($urlNavegador.length > 1) {
- $valores = $urlNavegador[1].split('&');
- if ($valores.length > 1) {
- $ordem = new Array();
- $valorOrder = "";
- $texto = "";
- $textInverter = "";
- $textoSelect = "";
- $newUrl = "";
- $.each($valores, function(i, val){
- $ordem = $valores[i].split('=');
- if (($ordem[0] != 'order') && ($ordem[0] != 'ordem')) {
- if (i == $valores.length - 1) { $newUrl += $valores[i]; } else { $newUrl += $valores[i] + '&'; }
- } else if ($ordem[0] == 'order') {
- $('#selectOrder li').each(function(i, val){
- if ($(this).attr('rel') == $ordem[1]) { $texto = $(this).text(); }
- });
- $('.ordem').text('Ordem: ' + $texto);
- if (i == $valores.length - 1) { $newUrl += $valores[i]; } else { $newUrl += $valores[i] + '&'; }
- } else if ($ordem[0] == 'ordem'){
- switch ($ordem[1]) {
- case 'ASC':
- $textInverter = '▼ Z..A';
- if (i == $valores.length - 1) { $newUrl += 'ordem=DESC'; } else { $newUrl += 'ordem=DESC&'; }
- break;
- case 'DESC':
- $textInverter = '▲ A..Z';
- if (i == $valores.length - 1) { $newUrl += 'ordem=ASC'; } else { $newUrl += 'ordem=ASC&'; }
- break;
- }
- }
- });
- $('.ordenar').attr('href', $urlNavegador[0] + '?' + $newUrl).text($textInverter);
- }
- }
- });
- _replaceCaracteres = function(valor) {
- $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:"?!()./-/+"}];
- $spaceSymbol = "+";
- $regex = null;
- $returnString = valor;
- $.each($specialChars, function(i, val){
- $regex = new RegExp("["+$specialChars[i].let+"]", "g");
- $returnString = $returnString.replace($regex, $specialChars[i].val);
- $regex = null;
- });
- return $returnString.replace(/\s/g,$spaceSymbol);
- }
- $(function(){
- $urlNavegador = location.href.split('?');
- if ($urlNavegador.length > 1) {
- $novoTesto = "";
- $valores = $urlNavegador[1].split('&');
- $.each($valores, function(i, val){
- $ordem = $valores[i].split('=');
- if ($ordem[0] == 'search') { $novoTesto = $ordem[1].replace("+", " ").trim(); }
- });
- $('form .txtSearch').val($novoTesto);
- $form = $('#search_form').attr('action').split('/')
- $location = $form[$form.length - 1];
- $('#'+$location+' tr').each(function(){
- searchRegex = new RegExp($novoTesto, 'gi');
- $(" *", this).replaceText(searchRegex, '<em class="search_result">'+$novoTesto+'</em>');
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement