Jump to content


Tutorials buttons


1 reply to this topic

#1 Bl4ck-Vip3r

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 26 March 2007 - 01:59 PM

Well i was trying to creat a code box using bbcode but couldnt get it to work so no i want to use div classes that will just creat a div with a dotted outline for code and a scrollbar for long code. But.. to save me keep writing <duv class = fdfddf.... i want to add some buttons so i can just click them and it inserts it into the textbox where i am writing the tutorial... how would i do this? also is there a way i can stop the php from parsing or will highlight_string() do this for me aswell as highlight it? thanks

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 27 March 2007 - 03:29 PM

If you are pulling this text from a database, it will not execute unless passed through the eval() function, as it is plain text in a string.

As for the buttons, here is the function I use for mine, and an example button. Its all JavaScript.

// Borrowed from [url="http://massless.org/mozedit/"]http://massless.org/mozedit/[/url]
// Written by Chris Wetherell - [url="http://www.massless.org"]http://www.massless.org[/url] - chris [THE AT SIGN] massless.org
function mozWrap(txtarea, openTag, closeTag){
	txtarea = document.getElementById(txtarea);
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) selEnd = selLength;
	
	var s1 = (txtarea.value).substring(0, selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1+openTag+s2+closeTag+s3;
}
		
function IEWrap(openTag, closeTag){
	strSelection = document.selection.createRange().text;
	if(strSelection != '')	document.selection.createRange().text = openTag + strSelection + closeTag;
}
	
function wrapSelection(txtarea, openTag, closeTag){
	if(document.all) IEWrap(openTag, closeTag);
	else if(document.getElementById) mozWrap(txtarea, openTag, closeTag);
	document.getElementById(txtarea).focus();
	return false;
}

An example use.
<input type="button" onclick="return wrapSelection('test', '[b]', '[/b]');" value="Bold Text" />
<br />
<textarea id="test" name="test"></textarea>

Edited by Demonslay, 27 March 2007 - 03:30 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users