![]() |
Insert text into editor
I never imagined something like this would be so complicated, but I'm looking for a way to add text into the editor (both wysiwyg and standard editors) when clicking a link or button.
|
In the postbit or where?
|
Into the editor when writing a post. Namely for the "newthread" template. I'd like to create a button which would populate/insert text into the textarea of the editor when clicked. Similarly to how you press a Smilie and it appears inside the textarea.
|
That will take a hack like they use here for the Unlicensed User messages. One hasn't been released yet that I know of.
|
I'm well aware that nothing has been released, otherwise I would of already of tried it. :p I am trying to create one. My understanding is that it would take an OnClick event based on a javascript function to accomplish this. But my javascript coding skills are very poor so I hope someone out there can help.
|
There is kinda a hack like this, but it will effect all newthreads in a forum. It's call the Stencil Hack (I think). You may want to check it out and see what they do and then modify it for what you want.
|
The javascript is only the small part of it.
|
This is the hack in question:
https://vborg.vbsupport.ru/showthread.php?t=130162 Although not exactly what I need, I will certainly try it out and see if this will work for my purposes. Quote:
|
I did a version of the hack they have hear from the Unlicensed user message. I use the javascript for the pull down menu that has like 6 different messages to add to posts.
|
Quote:
As for the stencil hack, although it functions as it should. The limitation is that I am forcefully restricted to 1 message, but I have at least 3 different preset text templates I would like users to chose from. |
The one I did only works on post replies in the postbit, not new posts or new threads.
|
Can you link me to the code anyway? It may provide me with some insight as to how I can maybe adapt it to my existing code.
|
Quote:
|
Salmon? That's the best you can come up with? Although that really doesn't sound too bad right now. OK, I'll take it! ;)
|
I thought bears liked salmon? ;)
|
Actually this bear does! Maybe I really am part bear. :(
|
Quote:
Hopefully someone can help... but I also managed to discover another possible way of getting this to work, rather than using pure javascript, maybe there is another way of doing this via php? In the stencil hack, here are some interresting bits of code I discovered that seem to do what I need, but now need to find a way to actually create a button that performs the actions on demand, rather than pre-defined in the AdminCP as it currently does. PHP Code:
|
This is what I use for the drop down javascript if it will help you at all:
Code:
<div class="vbmenu_popup" id="rules_$post[postid]_menu" style="display:none"> |
Not quite sure what your code pertains to, but the only difference to regular VB code is at the end of the code you have textsel=1 which seems to do nothing on my board. I guess it's hopeless for me then. :(
|
The textsel=1 is from the case statement part of the code. I have different templates to insert into messages. As my setup doesn't work on new threads or posts, it wouldn't do you any good, anyway. I was just showing you the part for the javascript drop down since you said that was the part you were having problems with. Actually there are 2 parts to it but it works like a basic menu dropdown like in the navbar. Maybe I'm misunderstanding what you are wanting to do. That is entirely possible, given my age, and living in the woods. ;)
|
Alright I finally solved my problem after messing around with my Javascript code a bit.
Here is the final result: In my newthread template I added the following javascript (doesn't matter where): HTML Code:
<script type="text/javascript"> Below is the code for the button that will actually be used to input the text, a user presses this button, and the content defined appears in the editor: HTML Code:
<input type="button" value="My Button" onclick="insertText();insert(this.form.{$editorid}_textarea,'This text will be inserted into Standard Editor')"> The only problem I have noticed with this script is that for it to work, you MUST have Wysiwyg editor set to default. If you specify any other editor to load on default, the code won't work unless you switch editors first. I have no clue why this is, but most people I trust will be using WYSIWYG by default anyway, so I don't think it's really that much of an issue. |
I don't have as many users using the WYSIWYG editor as I do using the standard editor, since it is so easy for them to switch. ;)
|
All times are GMT. The time now is 01:01 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|