WEST SIDE CALI KILLERS


HOME OF WSCK CLAN
 
HomeCalendarFAQSearchMemberlistUsergroupsstoreRegisterLog in

Share | 
 

 Select Content Button

View previous topic View next topic Go down 
AuthorMessage
HolyHandGrenade
Founder
Founder
avatar

Xbox Live Gamertag HolyHandGrenade
Country : USA
Posts : 609
Caps : 1104
Times Thanked : 26
Comments : My Honor is Loyalty
Browser : Chrome

PostSubject: Select Content Button   Sun Aug 12, 2012 5:07 pm

Hello members, in this tutorial, you will discover how to put a 'Select Content' button for every code box as seen on this forum. This is tutorial is compatible for all forum versions.

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


Tutorial written by Base, with the help of k.201017 and Gangstar15

_________________

[You must be registered and logged in to see this image.]
Back to top Go down
FAAAEBS
Private First Class
Private First Class
avatar

Country : Portugal
Posts : 16
Caps : 13
Times Thanked : 0
Job/hobbies : Making Games
Language : English and Portuguese
Browser : Chrome

PostSubject: Re: Select Content Button   Thu Aug 30, 2012 6:25 am

Nice. I might put it in my forum.

_________________

What's red and bad for your teeth?
Spoiler:
 
Back to top Go down
 

Select Content Button

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Tutorials - Select Content Button Forumotion
» "Like" Button
» How do we feel about Marvel Select?
» Links for Sims 4 Custom Content
» The Fusion Pack - A ToonTown Rewritten Content Pack

Permissions in this forum:You cannot reply to topics in this forum
WEST SIDE CALI KILLERS :: Computer Related :: Coding :: Javascript-