vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Insert text into editor (https://vborg.vbsupport.ru/showthread.php?t=179442)

GameWizard 05-19-2008 11:24 AM

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">
// This is to insert text into the Standard Editor
function insert(el,ins) {
    if (el.setSelectionRange){
        el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length);
    }
    else if (document.selection && document.selection.createRange) {
        el.focus();
        var range = document.selection.createRange();
        range.text = ins + range.text;
    }
}
// This is to insert text into the WYSIWYG Editor
function insertText() {
var textstring = "This text will be inserted into WYSIWYG";
document.getElementById
("{$editorid}_iframe").contentWindow.document.body.innerHTML = textstring;
}
</script>

In the code above, the only thing that needs to be changed is the text that you wish to appear in the WYSIWYG editor as it needs to be defined in the code directly.

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')">
Once again you must define the text (the same as defined in the javascript) which will appear in the Standard editor this time. In addition, as you can see it's a dual action script, meaning it applies the same text to the Standard AND Wysiwyg editors, as the ID's for each editor are different and requires 2 sets of different code for each 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.

Boofo 05-19-2008 01:17 PM

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:08 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
  • Page Generation 0.02316 seconds
  • Memory Usage 1,721KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_html_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete