Sellect All (code/Hack)?

Status
Not open for further replies.

PUMA

Active Member
70
2009
0
0
I want to be able to do this in a forum :
9s5nw5.png


sfhqp3.png

Can anyone help me on this?
The "Select All" code, I know the Link Checker is from TubeNow witch ;I'll be installing soon as well.

Thanks in advance.
 
16 comments
phpBB code for the select all:

Code:
<a href="#" onclick="selectCode(this); return false;">Select All</a>

Code:
<script type="text/javascript">
<!--
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 + '&nbsp;';
			}

			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();
	}
}
//-->
</script>

There is a catch though, that code will select all text wrapped with <code></code> tags, which is how its used in proSilver based templates.

If you're going to use this, you'll need to modify the code a bit, or you can just create your own JS function, which would be easier/better than using phpBB's.
 
you put that <script></script> in the header include template,
then add
<a href="#" onclick="selectCode(this); return false;">Select All</a>
where you want it.
 
create a new file something_select_all.js >paste all the code> upload to your server
edit header_include template and call that js
 
The code above didn't worked for me:
I used this:

Put this in your notepad and save it as selectall.js
Code:
function selectCode(a) 
{ 
   var e = a.parentNode.parentNode.getElementsByTagName('PRE')[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(); 
   }
- Upload selectall.js to /clientscripts


Template Edits
======================================================
Edit:headerinclude:

Add:
Code:
<script type="text/javascript" src="clientscript/selectall.js"></script>
======================================================
Edit: bbcode_code

After:
PHP:
$vbphrase[code]:
Add:
Code:
<a href="#" onclick="selectCode(this); return false;">Select All</a>
======================================================
Edit: bbcode_html

After:
PHP:
$vbphrase[code]:
Add:
Code:
<a href="#" onclick="selectCode(this); return false;">Select All</a>
======================================================
Edit: bbcode_php

After:
PHP:
$vbphrase[code]:
Add:
Code:
<a href="#" onclick="selectCode(this); return false;">Select All</a>
Replace:
Code:
$code
With:
Code:
<pre>$code</pre>
======================================================

Hope it was helpfull!
 
I follow sharingporn's instructions & it didn't work :( (I'm sure that I did something wrong).Everytime that I click on the SELECT ALL option it takes me to the top of the page! O.o

Any idea of what I'm doing wrong?

Thanks for Your help! :)
 
Open bbcode_code template at top add this:

Code:
<script type="text/javascript"> 
function selectCode(a) 
{ 
   var e = a.parentNode.parentNode.getElementsByTagName('PRE')[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>

Find:
PHP:
$vbphrase[code]:

Replace with:
PHP:
$vbphrase[code]: <a href="#" onclick="selectCode(this); return false;">Select All</a>
 
Status
Not open for further replies.
Back
Top