Modify text in editor
#1
Hi!

We are trying to develop a plugin to turn MyBB into a roleplaying forum. For this we have a special button which should insert a "[character]Big evil dragon[/character]" into the text. When the enhanced texteditor (with buttons for bold, italic, etc.) is disabled you can acess this easily with JavaScript-object "document.all.message.innerHTML". But how can I access the message when the enhanced editor is enabled and add my little text into it? And how can I find out, which editor is enabled? The plain html textarea or the enhanced one?

Thanks so far!

Murray_B
Reply
#2
Okay, I found the solution myself, it is quite easy if you know how to do it… Like many things…

But maybe somebody need this too, so here it is:

Check the editor: if($mybb->settings['bbcodeinserter'] == 1) {extended editor} else {plain text editor}

Write in plaintext editor (JavaScript): this.form.message.value="...."

Write in extended editor (JavaScript): MyBBEditor.insertText("....")
Reply
#3
Thanks Murray - where exactly does this code go? In the templates? In the php?

I am interested to see how to do it that is all.
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply
#4
(2015-01-08, 08:22 PM)Leefish Wrote: Thanks Murray - where exactly does this code go? In the templates? In the php?

Uh, very mixed… I am using the following hooks:

$plugins->add_hook("newthread_start", "rpgchar_createlist");
$plugins->add_hook("newreply_start", "rpgchar_createlist");
$plugins->add_hook("editpost_start", "rpgchar_createlist");

In the function rpg_createlist I have the the switch between the 2 editors.

And there I create a global variable $rpgcharlist with a piece of html with a button. The button has the JavaScript event onclick=\"MyBBEditor.insertText('[character]' + this.form.rpgchars.value + '[/character]')\"><br />";


Well and in the editpost, newthread and newreply template I put the "{$rpgcharlist}".

I hope this answers your question.

Maybe we'll publish the plugin here when it's ready. Forum RPGs are a bit oldschool, but I think our plugin is a great piece of software for a forum RPG. But I guess we need "some" more days… ;-)


BTW, I just read your signature, how do I mark a thread as solved?
Reply
#5
You cant mark it as solved as that function isnt available on all forums. Its visible in support.

I would be interested in the plugin because I cannot believe how unfriendly the new editor is to edits - especially of the toolbar.
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply
#6
(2015-01-08, 10:18 PM)Leefish Wrote: I cannot believe how unfriendly the new editor is to edits - especially of the toolbar.

Why? As much as I'm not the biggest fan of SCEditor, I think it's much easier to extend than the 1.6 editor.

Only the following 2 steps are required:
1. Edit the codebuttons template - add the button name to toolbar: and include a new JS file or add a new script tag.
2. In the JS file/script tag define new $.sceditor.plugins.bbcode.bbcode.set and $.sceditor.command.set for the button. Multiple examples are in jscripts/bbcodes_sceditor.js. And more info can be found in documentation:
http://www.sceditor.com/documentation/custom-commands/
http://www.sceditor.com/documentation/custom-bbcodes/
Reply
#7
(2015-01-09, 08:50 AM)Destroy666 Wrote:
(2015-01-08, 10:18 PM)Leefish Wrote: I cannot believe how unfriendly the new editor is to edits - especially of the toolbar.

Why? As much as I'm not the biggest fan of SCEditor, I think it's much easier to extend than the 1.6 editor.

Only the following 2 steps are required:
1. Edit the codebuttons template - add the button name to toolbar: and include a new JS file or add a new script tag.
2. In the JS file/script tag define new $.sceditor.plugins.bbcode.bbcode.set and $.sceditor.command.set for the button. Multiple examples are in jscripts/bbcodes_sceditor.js. And more info can be found in documentation:
http://www.sceditor.com/documentation/custom-commands/
http://www.sceditor.com/documentation/custom-bbcodes/

That is my point - having to edit the js file. I am not keen on changing MyBB files. In the 1.6 editor it was possible to add a new button to the toolbar via a plugin. I cant quite figure out how to do that with this new editor - so TO ME (and one is allowed a personal opinion) this editor is a pita.
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply
#8
Hm, maybe it is simple to work with sceditor, but I am no javascript programmer and I found it hard to read and understand. AJAX and XML is not easy too… Maybe it would be easier to work if it, if you place a FAQ with the link to the editors site in your FAQ ;-)

My plugin is nearly ready, I guess I send you a PM with a link to in in a few days, but I guess it is quite boring how I work with the editor.
Reply
#9
(2015-01-08, 09:47 PM)Murray_B Wrote:
(2015-01-08, 08:22 PM)Leefish Wrote: Thanks Murray - where exactly does this code go? In the templates? In the php?

Uh, very mixed… I am using the following hooks:

$plugins->add_hook("newthread_start", "rpgchar_createlist");
$plugins->add_hook("newreply_start", "rpgchar_createlist");
$plugins->add_hook("editpost_start", "rpgchar_createlist");

In the function rpg_createlist I have the the switch between the 2 editors.

And there I create a global variable $rpgcharlist with a piece of html with a button. The button has the JavaScript event onclick=\"MyBBEditor.insertText('[character]' + this.form.rpgchars.value + '[/character]')\"><br />";


Well and in the editpost, newthread and newreply template I put the "{$rpgcharlist}".

I hope this answers your question.

Maybe we'll publish the plugin here when it's ready. Forum RPGs are a bit oldschool, but I think our plugin is a great piece of software for a forum RPG. But I guess we need "some" more days… ;-)


BTW, I just read your signature, how do I mark a thread as solved?

Murray, thanks for this post. I think it will help me with my problem.

I am trying to add a button above the "Smilies" section when people are making a new post. I would like that to say "Add XYZ text" and when the user clicks that it populates the new post with a template I want them to use.

Does that make sense? Do you think i can use your method to do this?
If so, where do I put the code you mentioned?

Thank you so much,
Mike
Reply
#10
Sure you can, that's exactly what we do. You need a button with an onclick-event and can insert the text like mentioned above with that little java script piece. The add_hook-commands go straight into your plugin file and the java script code is generated in the subroutine (here: rpgchar_createlist) and put into the global variable $rpgcharlist which is printed with the template.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)