Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2008, 01:02 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Insert text into WYSIWYG Editor via link

I have seen a few requests for this in the past, however I cannot seem to understand how to achieve the same effect for the WYSIWYG editor as I have for the standard text editor.

All I am trying to do is have text appear in the textarea when creating a new post based on clicking a link, similar to how you click on a smilie and it appears inside the editor.

Here is my code:

Code:
<script type="text/javascript">
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;
    }
}
</script>
And this is the link:
Code:
<input type="button" value="hello" onclick="insert(this.form.{$editorid}_textarea,'hello')">
Unfortunately, this only works for the standard editor, and can't seem to figure out why it does not appear inside the WYSIWYG editor aswell. Any help would be appreciated.

--------------- Added [DATE]1209215442[/DATE] at [TIME]1209215442[/TIME] ---------------

=== UPDATE ===
?????????????????
Alright, I have made some progress and have found a partial solution but require someones helpful guidance with javascript in order to make it fully functional. Here is my dilemma.

I have 2 javascripts which I need to merge. Here is the first:

Code:
<script type="text/javascript">
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;
    }
}
</script>
Code:
<input type="button" value="test" onclick="insert(this.form.{$editorid}_textarea,'test123')">
The following script allows me to only insert text as many times as I wish into the Standard Editor only (not wysiwyg) and works as it should.

Code:
<script>
function insertText() {
var textstring = "Insert me into the Iframe please";
document.getElementById
("{$editorid}_iframe").contentWindow.document.body.innerHTML = textstring;
}
</script>
Code:
<a href="javascript:;" onClick="insertText()">test</a>
Since the wysiwyg editor is an iframe, I seem to require a different kind of code. In this case, the script allows me to have content appear in the wysiwyg only, but the issue with it is that it will remove any other text that was there earlier, and only allows me to enter it once. So if press it 10 times, it still only shows up once.
---

Bottom line, I'd like to have a dual action javascript which allows for the detection of {$editorid}_textarea being the textarea (standard editor) and {$editorid}_iframe being an iframe (wysiwyg editor)and allows for specific content to be placed within both via an OnClick event from a link.
Reply With Quote
  #2  
Old 04-27-2008, 09:24 PM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Although I understand this is quite a daunting request, since it involves a substantial amount of thought. Would anyone be so kind to point me to a forum that may also be able to help me with this problem in case no one here is able to help?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:38 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04514 seconds
  • Memory Usage 2,178KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete