/*======================================================================*\ || #################################################################### || || # vBulletin 3.6.4 || # ---------------------------------------------------------------- # || || # Copyright ©2000-2007 Jelsoft Enterprises Ltd. All Rights Reserved. || || # This file may not be redistributed in whole or significant part. # || || # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # || || # http://www.vbulletin.com | http://www.vbulletin.com/license.html # || || #################################################################### || \*======================================================================*/ // ############################################################################# // vB_Text_Editor /** * vBulletin Editor Class * * Activates any HTML controls for an editor * * @param string Unique key for this editor * @param boolean Initialise to WYSIWYG mode? * @param string Forumid / Calendar etc. * @param boolean Parse smilies? * @param string (Optional) Initial text for the editor */ function vB_Text_Editor(editorid, mode, parsetype, parsesmilies, initial_text) { /** * Miscellaneous variables * * @var string Unique Editor ID * @var boolean WYSIWYG mode * @var boolean Have we initialized the editor? * @var mixed Passed parsetype (corresponds to bbcodeparse forumid) * @var boolean Passed parsesmilies option * @var boolean Can we use vBmenu popups? * @var object The element containing controls * @var object The textarea object containing the initial text * @var array Array containing all button objects * @var array Array containing all popup objects * @var string State of the font context control * @var string State of the size context control * @var string State of the color context control * @var string String to contain the fake 'clipboard' * @var boolean Is the editor 'disabled'? (quick reply use) * @var vB_History History manager for undo/redo systems * @var integer Is the editor mode trying to be changed? */ this.editorid = editorid; this.wysiwyg_mode = parseInt(mode, 10) ? 1 : 0; this.initialized = false; this.parsetype = (typeof parsetype == 'undefined' ? 'nonforum' : parsetype); this.parsesmilies = (typeof parsesmilies == 'undefined' ? 1 : parsesmilies); this.popupmode = (typeof vBmenu == 'undefined' ? false : true); this.controlbar = fetch_object(this.editorid + '_controls'); this.textobj = fetch_object(this.editorid + '_textarea'); this.buttons = new Array(); this.popups = new Array(); this.fontstate = null; this.sizestate = null; this.colorstate = null; this.clipboard = ''; this.disabled = false; this.history = new vB_History(); this.influx = 0; // ============================================================================= // vB_Text_Editor methods /** * Editor initialization wrapper */ this.init = function() { if (this.initialized) { return; } this.textobj.disabled = false; if (this.tempiframe) { this.tempiframe.parentNode.removeChild(this.tempiframe); } this.set_editor_contents(initial_text); this.set_editor_functions(); this.init_controls(); this.init_smilies(fetch_object(this.editorid + '_smiliebox')); if (typeof smilie_window != 'undefined' && !smilie_window.closed) { this.init_smilies(smilie_window.document.getElementById('smilietable')); } this.initialized = true; }; /** * Check if we need to refocus the editor window */ this.check_focus = function() { if (!this.editwin.hasfocus) { this.editwin.focus(); if (is_opera) { // see http://www.vbulletin.com/forum/bugs35.php?do=view&bugid=687 this.editwin.focus(); } } } /** * Init button controls for the editor */ this.init_controls = function() { var controls = new Array(); if (this.controlbar == null) { return; } var buttons = fetch_tags(this.controlbar, 'div'); for (var i = 0; i < buttons.length; i++) { if (buttons[i].className == 'imagebutton' && buttons[i].id) { controls[controls.length] = buttons[i].id; } } for (var i = 0; i < controls.length; i++) { var control = fetch_object(controls[i]); if (control.id.indexOf(this.editorid + '_cmd_') != -1) { this.init_command_button(control); } else if (control.id.indexOf(this.editorid + '_popup_') != -1) { this.init_popup_button(control); } } set_unselectable(this.controlbar); }; /** * Init Smilies */ this.init_smilies = function(smilie_container) { if (smilie_container != null) { var smilies = fetch_tags(smilie_container, 'img'); for (var i = 0; i < smilies.length; i++) { if (smilies[i].id && smilies[i].id.indexOf('_smilie_') != false) { smilies[i].style.cursor = pointer_cursor; smilies[i].editorid = this.editorid; smilies[i].onclick = vB_Text_Editor_Events.prototype.smilie_onclick; smilies[i].unselectable = 'on'; } } } } /** * Init command button (b, i, u etc.) * * @param object Current HTML button node */ this.init_command_button = function(obj) { obj.cmd = obj.id.substr(obj.id.indexOf('_cmd_') + 5); obj.editorid = this.editorid; this.buttons[obj.cmd] = obj; if (obj.cmd == 'switchmode') { if (AJAX_Compatible) { obj.state = this.wysiwyg_mode ? true : false; this.set_control_style(obj, 'button', this.wysiwyg_mode ? 'selected' : 'normal'); } else { obj.parentNode.removeChild(obj); } } else { obj.state = false; obj.mode = 'normal'; } // event handlers obj.onclick = obj.onmousedown = obj.onmouseover = obj.onmouseout = vB_Text_Editor_Events.prototype.command_button_onmouseevent; } /** * Init popup button (forecolor, fontname etc.) * * @param object Current HTML button node */ this.init_popup_button = function(obj) { obj.cmd = obj.id.substr(obj.id.indexOf('_popup_') + 7); if (this.popupmode) { // register popup menu control vBmenu.register(obj.id, true); vBmenu.menus[obj.id].open_steps = 5; obj.editorid = this.editorid; obj.state = false; this.buttons[obj.cmd] = obj; if (obj.cmd == 'fontname') { this.fontout = fetch_object(this.editorid + '_font_out'); this.fontout.innerHTML = obj.title; this.fontoptions = {'' : this.fontout}; for (var option in fontoptions) { var div = document.createElement('div'); div.id = this.editorid + '_fontoption_' + fontoptions[option]; div.style.width = this.fontout.style.width; div.style.display = 'none'; div.innerHTML = fontoptions[option]; this.fontoptions[fontoptions[option]] = this.fontout.parentNode.appendChild(div); } } else if (obj.cmd == 'fontsize') { this.sizeout = fetch_object(this.editorid + '_size_out'); this.sizeout.innerHTML = obj.title; this.sizeoptions = {'' : this.sizeout}; for (var option in sizeoptions) { var div = document.createElement('div'); div.id = this.editorid + '_sizeoption_' + sizeoptions[option]; div.style.width = this.sizeout.style.width; div.style.display = 'none'; div.innerHTML = sizeoptions[option]; this.sizeoptions[sizeoptions[option]] = this.sizeout.parentNode.appendChild(div); } } // extend onmouseover obj._onmouseover = obj.onmouseover; // extend onclick obj._onclick = obj.onclick; // event handlers obj.onmouseover = obj.onmouseout = obj.onclick = vB_Text_Editor_Events.prototype.popup_button_onmouseevent; // extend menu show vBmenu.menus[obj.id]._show = vBmenu.menus[obj.id].show; vBmenu.menus[obj.id].show = vB_Text_Editor_Events.prototype.popup_button_show; } else { this.build_select(obj); } } /** * Replace the popup controls with