Staffer Group BR™

Fórum interativo totalmente gratuito!


 VisualizaçõesPermissão deste fórum:
Não podes responder a tópicos


CurtirDiretório deste fórum:
Fóruns » Principal »  » Tutoriais » Tutoriais sobre programação

#1
 D'Leandro™

D'Leandro™
Fundador
[Tutorial] Selecionar código

Esse tutorial já existe? Não!
Como alguns de vocês já sabem existe um código de efeito igual que está rolando poraí. Este código foi criado pelo usuário Base do fórum de ajuda americano Help Forumotion. Caso este fórum esteja poraí com outros créditos, dane-se não é da minha conta.

Para começar vamos ver qual é a sua versão! Se ela for PhpBB3, PunBB ou Invísion, então siga estes passos.
Caso ela seja PhpBB2, então pule para o 2º código.

Então vamos adicionar o seguinte código no gestor de códigos JavaScript. Não sabe como fazer isso? Então pergunte aqui.

PhpBB 3, PunBB e Invision.
Código:
$.getScript('http://metalltestes.virtuaboard.com/16152.js');
function selectCode(a)
        {
          // Get ID of code block
          var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
      
         // Not IE
          if (window.getSelection)
          {
              var s = window.getSelection();
              // Safari
              if (s.setBaseAndExtent)
              {
                s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
              }
              // Firefox and Opera
              else
              {
                // workaround for bug # 42885
                if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
                {
                    e.innerHTML = e.innerHTML + ' ';
                }
      
               var r = document.createRange();
                r.selectNodeContents(e);
                s.removeAllRanges();
                s.addRange(r);
              }
          }
          // Some older browsers
          else if (document.getSelection)
          {
              var s = document.getSelection();
              var r = document.createRange();
              r.selectNodeContents(e);
              s.removeAllRanges();
              s.addRange(r);
          }
          // IE
          else if (document.selection)
          {
              var r = document.body.createTextRange();
              r.moveToElementText(e);
              r.select();
          }
        }
        if(text){}else{ var text = 'Selecionar todos';}
        jQuery(document).ready(function(){
          jQuery("dl.codebox dt").not("dl.spoiler > dt").HTML('Code: <a href="#" onclick="selectCode(this); return false;" title="Select all the content" class="code-a"> Select Content </a>');
        });


Agora salve e veja o resultado!

Sua versão é PbpBB2? Então utilize este código.
Vamos adiciona-lo ao gestor de códigos JavaScript. Não sabe como fazer isto? Então pergunte aqui.

PhpBB2.
Código:
$.getScript('http://metalltestes.virtuaboard.com/16152.js');
function selectCode(a)
        {
        // Get ID of code block
        var e = jQuery(a).closest('tr').next().find('.cont_code')[0];

        // Not IE
        if (window.getSelection)
        {
        var s = window.getSelection();
        // Safari
        if (s.setBaseAndExtent)
        {
        s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
        }
        // Firefox and Opera
        else
        {
        // workaround for bug # 42885
        if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
        {
        e.innerHTML = e.innerHTML + ' ';
        }

        var r = document.createRange();
        r.selectNodeContents(e);
        s.removeAllRanges();
        s.addRange(r);
        }
        }
        // Some older browsers
        else if (document.getSelection)
        {
        var s = document.getSelection();
        var r = document.createRange();
        r.selectNodeContents(e);
        s.removeAllRanges();
        s.addRange(r);
        }
        // IE
        else if (document.selection)
        {
        var r = document.body.createTextRange();
        r.moveToElementText(e);
        r.select();
        }
        }
        jQuery(function(){

        jQuery('div.postbody td.code').parent().prev().find('b').HTML('Code:
        <a href="JavaScript:void()" onClick="selectCode(this)"><font
        face="verdana" color="red"></font> Select Content </a>');
        });


Agora salve e veja o resultado!


  • Imagem meramente ilustrativa

■ Selecionar código para todas as versões Sem_ta21
( Testado no fórum de testes http://metalltestes.virtuaboard.com/fórum )

#2
 iHeload

iHeload
Membro
Legal!