MyBB Community Forums

Full Version: How to create Select All for Code on 1.6 Version
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
As I tried to use existing one code I failed, I made a decision to help other users.

So, Go to ACP -> Templates -> Header Templates -> Header

Add this code on the bottom of header:
<script type="text/javascript">
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
      {
         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();
   }
}
</script> 

Then go to your default forum language, if is english, go to english and go to global.lang.php which is in public_html/inc/languages/english/global.lang.php and search for php_code

Now instead of:
$l['php_code'] = "PHP Code: ";

Add:
$l['php_code'] = "PHP Code: <a href='#' onclick='selectCode(this); return false;'>(Select All)</a>";

And instead of:
$l['code'] = "Code: ";
add this:
$l['code'] = "Code: <a href='#' onclick='selectCode(this); return false;'>(SELECT ALL)</a>";

Now save the file and overwrite it, if (editor ask for it).

And you're done.
Hope this helps.
dont work.
How come it dont work? Ive tested this on my own.
I dont see any [code] tag in there.
Is there a demo?