HomeHome  
  • WelcomeWelcome  
  • Events  
  • PublicationsPublications  
  • FAQFAQ  
  • SearchSearch  
  • MemberlistMemberlist  
  • UsergroupsUsergroups  
  • RegisterRegister  
  • Log inLog in  
  • You are not connected. Please login or register


    Add a button "select content" in code tags

    avatar
    • Veteran staff member

        Reputation : 8
        Registered on : 2012-03-24
        Posts : 30
      Add a button "select content" in code tags

      Description


      This Javascript code will allow you to put a "select content" to the code box, which makes it easier to select it. ;)

      Set up


      You will have to create a new Javascript. For this, go in your administration control panel like this:
      > ACP | Modules | HTML & JAVASCRIPT | Javascript codes management | Create a new Javascript

      [PHPBB3, INVISION, PUNBB] Insert this code in the topics:
      Code:
      function selectCode(a)
          {
            var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
       
            if (window.getSelection)
            {
                var s = window.getSelection();

                if (s.setBaseAndExtent)
                {
                  s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
                }

                else
                {

                  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);
                }
            }

            else if (document.getSelection)
            {
                var s = document.getSelection();
                var r = document.createRange();
                r.selectNodeContents(e);
                s.removeAllRanges();
                s.addRange(r);
            }

            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="selectCode"> Select Content </a>');
          });

      [PHPBB2] Insert this code in the topics:
      Code:
      function selectCode(a)
          {

          var e = jQuery(a).closest('tr').next().find('.cont_code')[0];


          if (window.getSelection)
          {
          var s = window.getSelection();

          if (s.setBaseAndExtent)
          {
          s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
          }

          else
          {

          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);
          }
          }

          else if (document.getSelection)
          {
          var s = document.getSelection();
          var r = document.createRange();
          r.selectNodeContents(e);
          s.removeAllRanges();
          s.addRange(r);
          }

          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:
          <span class="selectContent"><a href="javascript:void()" onClick="selectCode(this)"><font
          face="verdana" color="red"></font> Select Content </a></span>');
          });

      After this, insert this code in your CSS Stylesheet by going in your administration control panel like this:
      > ACP | Display | Pictures and Colors | Colors | CSS Stylesheet
      Code:
      .selectCode { float:right; text-transform: uppercase; cursor:pointer; }


      Customize the tutorial


      You can modify the appearance of the button with CSS. For any questions about the customization, feel free to post them here.

      Demonstration




      Technical problems


      The tutorial was tested on this forum and with the browser Google Chrome; If you notice that the tutorial doesn't work for a browser or for a version of forum (PhpBB2, PhpBB3, PunBB, Invision) contact an administrator and we will fill this field with your reporting.

      Thanks, the staff
      For every problem or question please, contact us in the section Support for the tutorials, The staff will answer you as soon as it is possible...


      Friendly,
      The team of the Forum of Codes.

      avatar
      • Veteran staff member

          Reputation : 19
          Registered on : 2012-04-05
          Posts : 77
        Please know that this post is not saying your code is bad or wrong but I thought I would share this written by a friend of mine: http://www.avacweb.com/t113-select-code

        Its more up to date and much shorter and nicer on browsers.
        A lot of the scripts around for this feature are longer than they need to be and getting outdated.

        avatar
        • Administrator

            Reputation : 315
            Registered on : 2012-02-22
            Posts : 2362
            School of codes courses: coming soon
          @LGforum wrote:Please know that this post is not saying your code is bad or wrong but I thought I would share this written by a friend of mine: http://www.avacweb.com/t113-select-code

          Its more up to date and much shorter and nicer on browsers.
          A lot of the scripts around for this feature are longer than they need to be and getting outdated.

          I know... You're right!



          Niko wants you in the team Guest

          Community manager and Administrator at Forumattivo.com

          • Co-Founder

              Reputation : 40
              Registered on : 2012-02-26
              Posts : 284
            Thank you! Can we use this code in the tutorial?

            avatar
            • Veteran staff member

                Reputation : 19
                Registered on : 2012-04-05
                Posts : 77
              I didn't write it, you would need to contact the author.

              avatar
              • Administrator

                  Reputation : 315
                  Registered on : 2012-02-22
                  Posts : 2362
                  School of codes courses: coming soon
                @LGforum wrote:I didn't write it, you would need to contact the author.

                Well, This tutorial is provided and copied in all the forums...
                I can ask to my friend Leeloo if you want (:



                Niko wants you in the team Guest

                Community manager and Administrator at Forumattivo.com

                avatar
                • Veteran staff member

                    Reputation : 19
                    Registered on : 2012-04-05
                    Posts : 77
                  Up to you. As I say, the tutorial I linked to is a much more up to date and nicer code nowadays, but its not up to me for it to be posted elsewhere, I didn't write it. I can only link to it.

                  • Co-Founder

                      Reputation : 40
                      Registered on : 2012-02-26
                      Posts : 284
                    Ok, thanks!


                    YOUR BANNER HERE
                    728x90
                    DMCA.com Protection Status
                    © PunBB | Contact | Report an abuse