Page 1 of 1
Formatting for Textarea text.. like this one!
Posted: Wed Oct 17, 2007 4:09 am
by arpowers
Hey everybody,
I'm trying to develop a custom 'wiki' type functionality for a project. I have a couple questions...
I know on a lot of forums, email services, etc.. there is a text formatting bar. What is the easiest way of implementing this for wiki editing?
Also I'm curious what the best way to track changes made to text over time?
Thanks Guys..
Andrew
Posted: Wed Oct 17, 2007 4:16 am
by Josh1billion
You should use Javascript for that type of bar. Have each button on the formatting bar link to specific Javascript functions, and then have that function insert the text into the textarea. For example, here's the Javascript function which for phpBB which inserts a smily face (:)) into the textarea:
Code: Select all
function emoticon(text) {
var txtarea = document.post.message;
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}
On line 2, notice "message" is the name of the textarea. So if you wanted to have a clickable ":)" image that inserts the text ": )" (without the space inbetween), you would have this HTML wherever you want that clickable image to be:
Code: Select all
<a href="javascript:emoticon(':)')"><img src="smily.png"></a>
And that's exactly how phpBB does it.
Posted: Wed Oct 17, 2007 4:23 am
by Kieran Huggins
there's a UNIX tool called "diff" that may be of interest.
Posted: Wed Oct 17, 2007 12:16 pm
by arpowers
Thanks for the replies!
The js explanation is great! How much time do you think it would take to create something (writing js is my weakpoint)....
I also checked out 'diff', how would you implement something like that with php/mysql?
best
Posted: Wed Oct 17, 2007 12:49 pm
by RobertGonzalez
You could always use something like FCKEditor or TinyMCE, which have done all the development work for you already.
Posted: Wed Oct 17, 2007 12:50 pm
by RobertGonzalez
PS Moved to Client Side.
Posted: Wed Oct 17, 2007 1:41 pm
by arpowers
cool, I checked out the open source editors... they look good...
Any ideas on tracking changes?
ways of comparing text with php?

:)
Posted: Wed Oct 17, 2007 1:46 pm
by RobertGonzalez
Store every change as a new row in the database and use the most recent row for your display. Then string compare them later.
Posted: Wed Oct 17, 2007 3:45 pm
by arpowers
Great... and thanks
But what is the best way of comparing strings?
Don't those functions just return a bool?
I suppose it could be possible to go word by word, but then a removed word would throw things off.... hmmm..
interesting problem.
Any further suggestions or ideas.
Thanks !