You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Tutorials - Select Content Button Forumotion on Fri Dec 21, 2012 12:01 pm

Boyka


Member
Step 1:
Navigate to...
Administration Panel → Modules Tab → Javascript codes management → Create a new javascript


Step 2:
Call it whatever you like and set its placement to all pages.


Step 3:
Once you have done that, you will need to add the following code into 'Javascript Code' field (your forum version ONLY):


phpBB 2

Code:
   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>');
        });
phpBB 3, punBB and Invision

Code:
   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>');
        });

And your done if you did all right

respectyyy@hotmail.com maunomaunoo http://ev-forum.pops.tv/

runawayhorses


Owner
I want to point out that the "select Content" codes posted above will look exactly like the "Select Content" links you see above the code boxes on this forum, the codes do not produce "Buttons" but rather "text links" like you see above the code boxes here, the color of the text link and size of the font will be inherited from your forum settings.

Boyka


Member
the codes are different look better:D

respectyyy@hotmail.com maunomaunoo http://ev-forum.pops.tv/

runawayhorses


Owner
No I'm afraid not, I tested it to make sure the code works and it looks exactly the same as mine and produces a text link as I expected it would. You have to understand the link colors and size on the font used in the code is taken from your CSS stylesheet, so its going to use your forums styling, so it will look different on each forum it is used on, but the code is the same.

"Better" is relative term, thats a personal taste issue.

I was correcting your use of the word "Button", because that code does not produce a button, it produces a text link.

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum