Saurdo
06-29-2009, 08:28 AM
On my forum I have replaced the attachment window popup with a window.open link to a page of my own. I want this page to operate in a manner similar to the smilies page. In that, when you click on a link, it puts text in the textarea for your post.
I wanted to use the exact method the smilies page used but the code has been compressed and is too hard to read. Instead, I tried to simulate that page from what I could decipher.
In the post area I modified the existing attachment javascript to be this:
document.write('<input type="button" id="manage_attachments_button" class="button" tabindex="1" style="font-weight:normal" value="$vbphrase[manage_attachments]" title="$vbphrase[add_edit_files_attached]" onclick="window.open(\'http://www.reefsome.com/gallery/v/ludnix\',\'\',\'width=1024,height=768\');" />');
I removed the usual method just to make sure it wasn't messing things up. (it didn't work with the usual function either)
In the page that opens I put this javascript:
function addToPost(text){
posttext = window.opener.document.getElementById('vB_Editor_0 01_textarea');
posttext.value += text;
}
if(window.opener != null){
document.write('<br /><a onclick="addToPost(\'\\nadded some content\');" style="cursor: pointer;">test</a>');
}
What the code does is detect if the page was opened by a window.open function and then writes a link that calls the "addToPost" function when clicked. The add to post function simply gets the text from the textarea and then adds to the textareas value.
This code works - but not for everyone.
It seems as though, on some systems, it doesn't write to the text area. However, when tested, it does write to another textarea on the same page. When I added another textarea to the post page and modified the javascript to add to that textarea it successfully added the message to that textarea.
You can test if for yourself by going to www.reefsome.com/forums/ (http://www.reefsome.com/forums/newreply.php?do=newreply&noquote=1&p=49) and using this login:
username: test
password: brokenjs
Simply click the attachment button, and then in the window that opens click the "test" link. It should add some text to your textarea.
I have absolutely no idea what could be causing this. The smilies page works on the same systems and as far as I could tell (and it was kind of hard to tell) the smilies page works in a manner similar to this.
--------------- Added 1246328205 at 1246328205 ---------------
I retrieved the generated HTML source code from one of the systems that this code wasn't working on. I then compared that source with the html source of my own and found that this line did not match:
<input type="hidden" name="wysiwyg" id="vB_Editor_001_mode" value="1" />
<script type="text/javascript">
<!--
vB_Editor['vB_Editor_001'] = new vB_Text_Editor('vB_Editor_001', 1, '14', '1', undefined, '');
//-->
</script>
The difference between my code and the others is that the second value in the vb_text_editor class was 0 instead of 1.
After figuring out that these lines were the difference between the "enhanced" editor and the "standard" editor I ended up disabling use of the enhanced editor.
This is sort of the easy way out but I really don't feel as though the use of the enhanced editor is worth the time it would take to learn vbulletin's method and adapt it.
However, if anyone could offer insight on an easy way to get around this then I'm all for it.
I wanted to use the exact method the smilies page used but the code has been compressed and is too hard to read. Instead, I tried to simulate that page from what I could decipher.
In the post area I modified the existing attachment javascript to be this:
document.write('<input type="button" id="manage_attachments_button" class="button" tabindex="1" style="font-weight:normal" value="$vbphrase[manage_attachments]" title="$vbphrase[add_edit_files_attached]" onclick="window.open(\'http://www.reefsome.com/gallery/v/ludnix\',\'\',\'width=1024,height=768\');" />');
I removed the usual method just to make sure it wasn't messing things up. (it didn't work with the usual function either)
In the page that opens I put this javascript:
function addToPost(text){
posttext = window.opener.document.getElementById('vB_Editor_0 01_textarea');
posttext.value += text;
}
if(window.opener != null){
document.write('<br /><a onclick="addToPost(\'\\nadded some content\');" style="cursor: pointer;">test</a>');
}
What the code does is detect if the page was opened by a window.open function and then writes a link that calls the "addToPost" function when clicked. The add to post function simply gets the text from the textarea and then adds to the textareas value.
This code works - but not for everyone.
It seems as though, on some systems, it doesn't write to the text area. However, when tested, it does write to another textarea on the same page. When I added another textarea to the post page and modified the javascript to add to that textarea it successfully added the message to that textarea.
You can test if for yourself by going to www.reefsome.com/forums/ (http://www.reefsome.com/forums/newreply.php?do=newreply&noquote=1&p=49) and using this login:
username: test
password: brokenjs
Simply click the attachment button, and then in the window that opens click the "test" link. It should add some text to your textarea.
I have absolutely no idea what could be causing this. The smilies page works on the same systems and as far as I could tell (and it was kind of hard to tell) the smilies page works in a manner similar to this.
--------------- Added 1246328205 at 1246328205 ---------------
I retrieved the generated HTML source code from one of the systems that this code wasn't working on. I then compared that source with the html source of my own and found that this line did not match:
<input type="hidden" name="wysiwyg" id="vB_Editor_001_mode" value="1" />
<script type="text/javascript">
<!--
vB_Editor['vB_Editor_001'] = new vB_Text_Editor('vB_Editor_001', 1, '14', '1', undefined, '');
//-->
</script>
The difference between my code and the others is that the second value in the vb_text_editor class was 0 instead of 1.
After figuring out that these lines were the difference between the "enhanced" editor and the "standard" editor I ended up disabling use of the enhanced editor.
This is sort of the easy way out but I really don't feel as though the use of the enhanced editor is worth the time it would take to learn vbulletin's method and adapt it.
However, if anyone could offer insight on an easy way to get around this then I'm all for it.