//------------------------------------------------------------------------------ // IPS Cross-Browser Global Text Editor Functions //------------------------------------------------------------------------------ // Supports all "v5" browsers (inc. Opera, Safari, etc) // Used for non RTE applications. // (c) 2005 Invision Power Services, Inc. // http://www.invisionpower.com //------------------------------------------------------------------------------ //----------------------------------------------------------- // This setting makes hitting the enter key in IE turn into a // newline (br tag) instead of the default action of using a // paragraph tag. This causes the indent and list options not // to work properly in IE, so do not enable this unless you // don't care about those options. This functionality will be // expanded upon in a future release, however this is not due // to an issue with IPB, but rather due to how IE handles the // javascript exec_command functions, and is beyond our control // without a lot of javascript rewriting of those functions, // specific to IE behaviors. //----------------------------------------------------------- var ie_ptags_to_newlines = true; var IPS_editor = new Array(); //------------------------------- // Define which buttons change // when clicked //------------------------------- var buttons_update = new Array( "bold", "italic", "underline", "justifyleft", "justifycenter", "justifyright", "insertorderedlist", "insertunorderedlist" ); var ips_primary_colors = new Array( '#000000' , '#A0522D' , '#556B2F' , '#006400' , '#483D8B' , '#000080' , '#4B0082' , '#1FDC97' , '#8B0000' , '#FF8C00' , '#808000' , '#008000' , '#008080' , '#0000FF' , '#708090' , '#696969' , '#FF0000' , '#F4A460' , '#9ACD32' , '#2E8B57' , '#48D1CC' , '#4169E1' , '#800080' , '#808080' , '#FF00FF' , '#FFA500' , '#FFFF00' , '#00FF00' , '#00FFFF' , '#00BFFF' , '#9932CC' , '#C0C0C0' , '#FFC0CB' , '#F5DEB3' , '#FFFACD' , '#98FB98' , '#AFEEEE' , '#ADD8E6' , '#DDA0DD' , '#FFFFFF' , '#053BD6' , '#FF6699' , '#2C2C2C' , '#FF0054' , '#ADF402' , '#7C1548' , '#40578D' , '#FC748A' , '#12BAEB' , '#E4E3E3' , '#DB0039' , '#FFE400' , '#381DDA' , '#80E200' , '#00ABB5' , '#FF5EAE' ); //------------------------------- // Define font faces //------------------------------- var ips_primary_fonts = new Array( "Arial", "Arial Black", "Arial Narrow", "Book Antiqua", "Century Gothic", "Comic Sans MS", "Courier New", "Franklin Gothic Medium", "Garamond", "Georgia", "Impact", "Lucida Console", "Lucida Sans Unicode", "Microsoft Sans Serif", "Palatino Linotype", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana" ); //------------------------------- // Remap font sizes //------------------------------- var ips_primary_sizes = new Array( 1, 2, 3, 4, 5, 6, 7 ); //----------------------------------------- // Insert Special Items //----------------------------------------- var ips_format_items = { 'cmd_subscript' : 'Sub-script', 'cmd_superscript' : 'Super-script', 'cmd_strikethrough' : 'Strikethrough' }; //----------------------------------------- // Special item images //----------------------------------------- var ips_format_item_images = { 'cmd_subscript' : 'rte-subscript.gif', 'cmd_superscript' : 'rte-superscript.gif', 'cmd_strikethrough' : 'rte-strike.gif' }; //----------------------------------------- // Language array //----------------------------------------- ips_language_array = {}; /** * Main function. * Creates instance of an IPS editor */ function ips_text_editor( editor_id, mode, use_bbcode, file_path, initial_text ) { /** * @var string Unique editor ID (allows multiple editors) * @var INT Is Rich Text Mode (WYSIWYG) * @var boolean Is initialized * @var array Buttons to track * @var array Fonts to track * @var array Item State * @var object Text Area object * @var object Controls Bar * @var object Font drop down object * @var object Size drop down object * @var object Special drop down object * @var object Font format drop down object * @var object Main bar object * @var boolean Use IPS menus * @var boolean Is Internet Explorer * @var boolean Is Mozilla * @var boolean Is Opera * @var boolean Is Safari * @var string RTE files path * @var string Current font-face * @var string Current font-size * @var boolean Using BBCode inplace of HTML * @var string Opening brace * @var string Closing brace * @var boolean Allow advanced options * @var string IPS Editor Frame HTML * @var array Array of pop-ups * @var string Character set of page * @var int Fix up IE

to
tags * @var object Emoticon window ID * @var int Editor is loading * @var array Array of hidden objects */ this.editor_id = editor_id; this.is_rte = mode; this.initialized = false; this.buttons = new Array(); this.fonts = new Array(); this.state = new Array(); this.text_obj = document.getElementById( this.editor_id + '_textarea' ); this.control_obj = document.getElementById( this.editor_id + '_controls' ); this.font_obj = document.getElementById( this.editor_id + '_out_fontname' ); this.size_obj = document.getElementById( this.editor_id + '_out_fontsize' ); this.special_obj = document.getElementById( this.editor_id + '_out_special' ); this.format_obj = document.getElementById( this.editor_id + '_out_format' ); this.mainbar = document.getElementById( this.editor_id + '_main-bar'); this.use_menus = ( typeof( ipsmenu ) == 'undefined' ? false : true ); this.is_ie = is_ie; this.is_moz = is_moz; this.is_opera = is_opera; this.is_safari = is_safari; this.file_path = file_path ? file_path : global_rte_includes_url; this.font_state = null; this.size_state = null; this.use_bbcode = use_bbcode; this.open_brace = this.use_bbcode ? '[' : '<'; this.close_brace = this.use_bbcode ? ']' : '>'; this.allow_advanced = this.use_bbcode ? 0 : 1; this.ips_frame_html = ''; this.popups = new Array(); this.char_set = global_rte_char_set ? global_rte_char_set : 'UTF-8'; this.forum_fix_ie_newlines = 0; this.emoticon_window_id = ''; this.is_loading = 0; this.hidden_objects = new Array(); /** * History stuff */ this.history_pointer = -1; this.history_recordings = new Array(); /** * HTML Toggle status */ this._showing_html = 0; /** * IE Range cache. * Prevents selection being lost when * iframe / popup is loaded */ this._ie_cache = null; /** * Current open bar object */ this.current_bar_object = null; /** * Special items menu */ this.ips_special_items = { /*'cmd_loader_link' : new Array( ips_language_array['js_rte_link'] ? ips_language_array['js_rte_link'] : 'Insert Link...' , 'rte-hyperlink.png' ), 'cmd_loader_unlink': new Array( ips_language_array['js_rte_unlink'] ? ips_language_array['js_rte_unlink'] : 'Unlink Text...' , 'rte-unlink.png', 'this.format_text( e, "unlink", false );' ), 'cmd_loader_image' : new Array( ips_language_array['js_rte_image'] ? ips_language_array['js_rte_image'] : 'Insert Image...' , 'rte-image.png' ), 'cmd_loader_email' : new Array( ips_language_array['js_rte_email'] ? ips_language_array['js_rte_email'] : 'Insert Email...' , 'rte-email.png' ), 'cmd_loader_table' : new Array( ips_language_array['js_rte_table'] ? ips_language_array['js_rte_table'] : 'Insert Table...' , 'rte-table.png' ), 'cmd_loader_div' : new Array( ips_language_array['js_rte_div'] ? ips_language_array['js_rte_div'] : 'Insert Div...' , 'rte-div.png' )*/ }; /** * Reset lang on format items menu */ ips_format_items['cmd_subscript'] = ips_language_array['js_rte_sub'] ? ips_language_array['js_rte_sub'] : 'Sub-script'; ips_format_items['cmd_superscript'] = ips_language_array['js_rte_sup'] ? ips_language_array['js_rte_sup'] : 'Super-script'; ips_format_items['cmd_strikethrough'] = ips_language_array['js_rte_strike'] ? ips_language_array['js_rte_strike'] : 'Strikethrough'; ips_language_array['emos_show_all'] = ips_language_array['emos_show_all'] ? ips_language_array['emos_show_all'] : 'Show All'; /** * INIT Text editor */ this.init = function() { if ( this.initialized ) { return; } //----------------------------------------- // Show control bar that's hidden for non-js //----------------------------------------- this.control_obj.style.display = ''; //----------------------------------------- // Reset WYSIWYG flag //----------------------------------------- try { document.getElementById( this.editor_id + '_wysiwyg_used' ).value = parseInt(this.is_rte); } catch(err) { } //----------------------------------------- // Get default frame HTML //----------------------------------------- this.ips_frame_html = this.get_frame_html(); //----------------------------------------- // Set editor up //----------------------------------------- this.editor_set_content( initial_text ); //----------------------------------------- // Set mouse events //----------------------------------------- this.editor_set_functions(); //----------------------------------------- // Set controls up //----------------------------------------- this.editor_set_controls(); this.initialized = true; }; /** * Returns frame HTML * * @return string Frame HTML */ this.get_frame_html = function() { var ips_frame_html = ""; ips_frame_html += "\n"; ips_frame_html += "\n"; ips_frame_html += ""; ips_frame_html += "\n"; ips_frame_html += "\n"; ips_frame_html += "\n"; ips_frame_html += "{:content:}\n"; ips_frame_html += "\n"; ips_frame_html += ""; return ips_frame_html; }; /** * Refocus editor check */ this.editor_check_focus = function() { if ( ! this.editor_window.has_focus ) { if ( this.is_opera ) { this.editor_window.focus(); } this.editor_window.focus(); } }; /** * INIT control bar * Goes through control bar images and sets up buttons * and drop down menus, adds classnames and sets up * onmouse events */ this.editor_set_controls = function() { var controls = new Array(); var _c = 0; if ( ! this.control_obj ) { return; } //----------------------------------------- // Grab all buttons // 2 step 'cos moz goes into infinite loop otherwise //----------------------------------------- var items = this.control_obj.getElementsByTagName("DIV"); for ( var i = 0 ; i < items.length ; i++ ) { if ( ( items[i].className == 'rte-normal' || items[i].className == 'rte-menu-button' || items[i].className == 'rte-normal-menubutton' ) && items[i].id ) { controls[ controls.length ] = items[i].id; } } for ( var i = 0 ; i < controls.length ; i++ ) { var control = document.getElementById( controls[i] ); if ( control.className == 'rte-normal' ) { this.init_editor_button( control ); } else if ( control.className == 'rte-menu-button' || control.className == 'rte-normal-menubutton' ) { this.init_editor_popup_button( control ); } } ipsclass.set_unselectable( this.control_obj ); }; /** * INIT Popup Menu * Dynamically builds up the context sensitive options * * @param object Button object * */ this.init_editor_popup_button = function( obj ) { //----------------------------------------- // Add to IPS Menu system //----------------------------------------- if ( ! this.use_menus ) { return; } ipsmenu.register( obj.id ); obj.cmd = obj.id.replace( new RegExp( '^' + this.editor_id + '_popup_(.+?)$' ), '$1' ); obj.editor_id = this.editor_id; obj.state = false; //----------------------------------------- // Add to buttons array //----------------------------------------- this.buttons[ obj.cmd ] = obj; //----------------------------------------- // Set Up Popup button display //----------------------------------------- if (obj.cmd == 'fontname') { this.fontout = this.font_obj; this.fontout.innerHTML = obj.title; this.fontoptions = {'' : this.fontout}; for (var option in ips_primary_fonts) { var div = document.createElement('div'); div.id = this.editor_id + '_fontoption_' + ips_primary_fonts[option]; div.style.width = this.fontout.style.width; div.style.display = 'none'; div.innerHTML = ips_primary_fonts[option]; this.fontoptions[ips_primary_fonts[option]] = this.fontout.parentNode.appendChild(div); } } else if (obj.cmd == 'fontsize') { this.sizeout = this.size_obj; this.sizeout.innerHTML = obj.title; this.sizeoptions = {'' : this.sizeout}; for (var option in ips_primary_sizes) { var div = document.createElement('div'); div.id = this.editor_id + '_sizeoption_' + ips_primary_sizes[option]; div.style.width = this.sizeout.style.width; div.style.display = 'none'; div.innerHTML = ips_primary_sizes[option]; this.sizeoptions[ips_primary_sizes[option]] = this.sizeout.parentNode.appendChild(div); } } obj._onmouseover = obj.onmouseover; obj._onclick = obj.onclick; obj.onmouseover = obj.onmouseout = obj.onclick = ips_editor_events.prototype.popup_button_onmouseevent; ipsmenu.menu_registered[obj.id]._open = ipsmenu.menu_registered[obj.id].open; ipsmenu.menu_registered[obj.id].open = ips_editor_events.prototype.popup_button_show; }; /** * Dynamically builds the HTML for the IPS Menu system * * @var object Javascript object clicked */ this.init_editor_menu = function( obj ) { //----------------------------------------- // Create menu wrapper //----------------------------------------- var menu = document.createElement('div'); menu.id = this.editor_id + '_popup_' + obj.cmd + '_menu'; menu.className = 'rte-popupmenu'; menu.style.display = 'none'; menu.style.cursor = 'default'; menu.style.padding = '3px'; menu.style.width = 'auto'; menu.style.height = 'auto'; menu.style.overflow = 'hidden'; //----------------------------------------- // What are we doing? //----------------------------------------- switch( obj.cmd ) { case 'fontsize': for( var i in ips_primary_sizes ) { if ( typeof( ips_primary_sizes[i] ) == 'function' ) { continue; } var option = document.createElement('div'); option.style.paddingTop = ips_primary_sizes[ i ]*2 + 'px'; option.style.paddingBottom = ips_primary_sizes[ i ]*2 + 'px'; option.innerHTML = '' + ips_primary_sizes[ i ] + ''; option.className = 'rte-menu-size'; option.title = ips_primary_sizes[ i ]; option.cmd = obj.cmd; option.editor_id = this.editor_id; option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = ips_editor_events.prototype.menu_option_onmouseevent; option.onclick = ips_editor_events.prototype.font_format_option_onclick; menu.style.width = this.size_obj.style.width; menu.appendChild(option); } break; case 'fontname': for( var i in ips_primary_fonts ) { if ( typeof( ips_primary_fonts[i] ) == 'function' ) { continue; } var option = document.createElement('div'); option.innerHTML = '' + ips_primary_fonts[ i ] + ''; option.className = 'rte-menu-face'; option.title = ips_primary_fonts[ i ]; option.cmd = obj.cmd; option.editor_id = this.editor_id; option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = ips_editor_events.prototype.menu_option_onmouseevent; option.onclick = ips_editor_events.prototype.font_format_option_onclick; menu.style.width = this.font_obj.style.width; menu.appendChild(option); } break; case 'special': for( var i in this.ips_special_items ) { if ( typeof( this.ips_special_items[i] ) == 'function' ) { continue; } var option = document.createElement('div'); var img = ( typeof this.ips_special_items[i][1] != 'undefined' ) ? ' ' : ''; option.innerHTML = img + this.ips_special_items[i][0]; option.className = 'rte-menu-face'; option.cmd = 'module_load', option.loader_key = i.replace( 'cmd_loader_', '' ); option.editor_id = this.editor_id; option.onmouseover = option.onclick = option.onmouseout = option.onmouseup = option.onmousedown = ips_editor_events.prototype.special_onmouse_event; menu.style.width = this.special_obj.style.width; menu.appendChild(option); } break; case 'format': for( var i in ips_format_items ) { if ( typeof( ips_format_items[i] ) == 'function' ) { continue; } var option = document.createElement('div'); var img = ( typeof ips_format_item_images[i] != 'undefined' ) ? ' ' : ''; option.innerHTML = img + ips_format_items[i]; option.className = 'rte-menu-face'; option.cmd = i.replace( 'cmd_', '' ); option.editor_id = this.editor_id; option.onmouseover = option.onclick = option.onmouseout = option.onmouseup = option.onmousedown = ips_editor_events.prototype.special_onmouse_event; menu.style.width = '130px'; menu.appendChild(option); } break; case 'emoticons': var table = document.createElement('table'); table.cellPadding = 0; table.cellSpacing = 0; table.border = 0; //table.width = 'auto'; if ( this.is_ie ) { table.style.paddingRight = '15px'; // Scrollbar fun } var i = 0; var perrow = 3; var tr = table.insertRow(-1); var td = tr.insertCell(-1); td.colSpan = perrow; td.align = 'center'; td.cellPadding = 0; td.innerHTML = '

' + ips_language_array['emos_show_all'] + '
'; for( var emo in ips_smilie_items ) { if ( i % perrow == 0 ) { var tr = table.insertRow(-1); } i++; var div = document.createElement('div'); var _tmp = ips_smilie_items[ emo ].split( "," ); var img = ' '; div.innerHTML = img; var option = tr.insertCell(-1); option.className = 'rte-menu-emo'; option.appendChild(div); option.cmd = obj.cmd; option.editor_id = this.editor_id; option.id = this.editor_id + '_emoticon_' + _tmp[0]; option.emo_id = _tmp[0]; option.emo_image = _tmp[1]; option.emo_code = emo; option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = ips_editor_events.prototype.menu_option_onmouseevent; option.onclick = ips_editor_events.prototype.emoticon_onclick; } if ( i > 0 ) { menu.style.width = 'auto'; if( this.is_ie ) { menu.style.paddingRight = '15px'; // Scrollbar fun } menu.style.height = '200px'; menu.style.overflow = 'auto'; menu.style.overflowX = 'hidden'; menu.appendChild(table); break; } else { // No emo's, but show the 'show all' link menu.style.width = 'auto'; menu.style.height = '40px'; menu.style.overflow = 'auto'; menu.appendChild(table); break; // document.getElementById( this.editor_id + '_popup_' + obj.cmd ).style.display = 'hidden'; // document.getElementById( this.editor_id + '_popup_' + obj.cmd + '_menu' ).style.display = 'hidden'; } case 'forecolor': case 'backcolor': var table = document.createElement('table'); table.cellPadding = 0; table.cellSpacing = 0; table.border = 0; var i = 0; for ( var hex in ips_primary_colors ) { if ( typeof( ips_primary_colors[hex] ) == 'function' ) { continue; } if ( i % 8 == 0 ) { var tr = table.insertRow(-1); } i++; var div = document.createElement('div'); div.style.backgroundColor = ips_primary_colors[hex]; div.innerHTML = ' '; var option = tr.insertCell(-1); option.className = 'rte-menu-color'; option.appendChild(div); option.cmd = obj.cmd; option.editor_id = this.editor_id; option.colorname = ips_primary_colors[hex]; option.id = this.editor_id + '_color_' + ips_primary_colors[hex]; option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = ips_editor_events.prototype.menu_option_onmouseevent; option.onclick = ips_editor_events.prototype.color_cell_onclick; } menu.style.overflow = 'visible'; menu.appendChild(table); break; } this.popups[ obj.cmd ] = this.control_obj.appendChild(menu); ipsclass.set_unselectable( menu ); }; /** * INIT Editor Button * Initialize an editor button (bold, italic, etc) * * @param object Button DIV object */ this.init_editor_button = function( obj ) { obj.cmd = obj.id.replace( new RegExp( '^' + this.editor_id + '_cmd_(.+?)$' ), '$1' ); obj.editor_id = this.editor_id; //----------------------------------------- // Add to buttons array //----------------------------------------- this.buttons[ obj.cmd ] = obj; //----------------------------------------- // Set up defaults //----------------------------------------- obj.state = false; obj.mode = 'normal'; obj.real_type = 'button'; obj.onclick = ips_editor_events.prototype.button_onmouse_event; obj.onmousedown = ips_editor_events.prototype.button_onmouse_event; obj.onmouseover = ips_editor_events.prototype.button_onmouse_event; obj.onmouseout = ips_editor_events.prototype.button_onmouse_event; }; /** * Toggle menu context * Toggles the menu's class for mouseover, select, etc * * @param object Menu object * @param object state */ this.set_menu_context = function(obj, state) { //----------------------------------------- // Show HTML? Return... //----------------------------------------- if ( this._showing_html ) { return false; } switch (obj.state) { case true: { this.editor_set_ctl_style(obj, 'menubutton', 'down'); break; } default: { switch (state) { case 'mouseout': { this.editor_set_ctl_style(obj, 'menubutton', 'normal'); break; } case 'mousedown': { this.editor_set_ctl_style(obj, 'menubutton', 'down'); break; } case 'mouseup': case 'mouseover': { this.editor_set_ctl_style(obj, 'menubutton', 'hover'); break; } } } } }; /** * Toggle button context * Toggles the menu's class for mouseover, select, etc * * @param object menu object * @param object state * @param object type */ this.set_button_context = function(obj, state, type) { //----------------------------------------- // Showing HTML? //----------------------------------------- if ( this._showing_html ) { return false; } if (typeof type == 'undefined') { type = 'button'; } if ( state == 'mousedown' && ( obj.cmd == 'undo' || obj.cmd == 'redo' ) ) { return false; } switch (obj.state) { case true: { switch (state) { case 'mouseout': { this.editor_set_ctl_style(obj, 'button', 'selected'); break; } case 'mouseover': case 'mousedown': case 'mouseup': { this.editor_set_ctl_style(obj, type, 'down'); break; } } break; } default: { switch (state) { case 'mouseout': { this.editor_set_ctl_style(obj, type, 'normal'); break; } case 'mousedown': { this.editor_set_ctl_style(obj, type, 'down'); break; } case 'mouseover': case 'mouseup': { this.editor_set_ctl_style(obj, type, 'hover'); break; } } break; } } }; /** * Sets the editor button control style * * @var object Button Object * @var string Control Type * @var string Control Mode */ this.editor_set_ctl_style = function( obj, type, mode ) { if ( obj.mode != mode ) { //----------------------------------------- // Add in -menu class //----------------------------------------- var extra = ''; if ( type == 'menu' ) { extra = '-menu'; } else if ( type == 'menubutton' ) { extra = '-menubutton'; } //----------------------------------------- // Add in -color if it's a color box //----------------------------------------- extra += obj.colorname ? '-color' : ''; //----------------------------------------- // Add in -emo if it's an emo //----------------------------------------- extra += obj.emo_id ? '-emo' : ''; //----------------------------------------- // Set mote... //----------------------------------------- obj.mode = mode; try { switch (mode) { case "normal": { // Normal obj.className = 'rte-normal' + extra; } break; case "hover": { // Hover obj.className = 'rte-hover' + extra; } break; case "selected": case "down": { // On obj.className = 'rte-selected' + extra; } break; } } catch (e) { } } }; /** * Format Text * * @var event Event Object * @var string Formatted command * @var string Formatting command extra */ this.format_text = function(e, command, arg) { e = ipsclass.cancel_bubble( e, true ); //----------------------------------------- // Special considerations... //----------------------------------------- if ( command.match( /resize_/ ) ) { this.resize_editorbox( command.replace( /resize_(up|down)/, "$1" ) ); } //----------------------------------------- // Switch editor... //----------------------------------------- if ( command.match( /switcheditor/i ) ) { switch_editor_mode( this.editor_id ); } //----------------------------------------- // Manually recording history? //----------------------------------------- if ( ! this.is_rte ) { if ( command != 'redo' ) { this.history_record_state( this.editor_get_contents() ); } } //----------------------------------------- // Continue... //----------------------------------------- this.editor_check_focus(); if ( this[ command ] ) { var return_val = this[ command ](e); } else { try { var return_val = this.apply_formatting( command, false, (typeof arg == 'undefined' ? true : arg) ); } catch(e) { var return_val = false; } } //----------------------------------------- // Manually recording history? //----------------------------------------- if ( ! this.is_rte ) { if ( command != 'undo' ) { this.history_record_state( this.editor_get_contents() ); } } //----------------------------------------- // Set context //----------------------------------------- this.set_context(command); //----------------------------------------- // Check focus //----------------------------------------- this.editor_check_focus(); return return_val; }; /** * Check spelling */ this.spellcheck = function() { if ( this.is_moz || this.is_opera ) { return false; } try { if ( this.rte_mode ) { var tmpis = new ActiveXObject("ieSpell.ieSpellExtension").CheckDocumentNode( this.editor_document ); } else { var tmpis = new ActiveXObject("ieSpell.ieSpellExtension").CheckAllLinkedDocuments( this.editor_document ); } } catch( exception ) { if ( exception.number == -2146827859 ) { if ( confirm( ips_language_array['js_rte_erroriespell'] ? ips_language_array['js_rte_erroriespell'] : "ieSpell not detected. Click Ok to go to download page." ) ) { window.open("http://www.iespell.com/download.php", "DownLoad"); } } else { alert( ips_language_array['js_rte_errorliespell'] ? ips_language_array['js_rte_errorliespell'] : "Error Loading ieSpell: Exception " + exception.number); } } }; /** * Removes items that you don't wish to have * @param string Command key */ this.module_remove_item = function( key ) { //----------------------------------------- // Remove... //----------------------------------------- var tmp = this.ips_special_items; this.ips_special_items = new Array(); for( var i in tmp ) { if ( i != 'cmd_loader_' + key ) { this.ips_special_items[ i ] = tmp[i]; } } }; /** * Add to special items array * @param string Command key * @param string Menu text * @param string Menu Image * @param string Javascript code to eval (Optional) */ this.module_add_item = function( key, text, image, evalcode ) { //----------------------------------------- // Add... //----------------------------------------- this.ips_special_items[ 'cmd_loader_' + key ] = new Array( text, image, evalcode ); }; /** * Load module * @param object Object * @param object Mouse event * @param string Loader function */ this.module_load = function( obj, e, loader_key ) { if ( ! loader_key ) { return false; } e = ipsclass.cancel_bubble( e, true ); this.editor_check_focus(); this.preserve_ie_range(); menu_action_close(); //----------------------------------------- // Extra args? //----------------------------------------- var _m = loader_key.match( /\{(.+?)\}$/ ); var _args = ''; try { if ( _m[1] ) { _args = _m[1]; } } catch(internetexplorer) { } //----------------------------------------- // Eval or show in control bar? //----------------------------------------- if ( typeof this.ips_special_items[ 'cmd_loader_' + loader_key ][2] != "undefined" ) { eval( this.ips_special_items[ 'cmd_loader_' + loader_key ][2] ); return false } else { this.module_show_control_bar( loader_key, _args ); } }; /** * Show new control bar * * @param type Type of control bar (must be same as function key) */ this.module_show_control_bar = function( type, _args ) { if ( ! this.control_obj ) { return; } type = type.replace( /(\{.+?\})$/, '' ); _args = ( typeof( _args ) != 'undefined' ) ? _args : ''; //----------------------------------------- // Already open? Kill it //----------------------------------------- if ( this.current_bar_object ) { this.module_remove_control_bar(); } //----------------------------------------- // Spawn new DIV object //----------------------------------------- var newdiv = document.createElement('div'); newdiv.id = this.editor_id + '_htmlblock_' + type + '_menu'; newdiv.style.display = ''; newdiv.className = 'rte-buttonbar'; newdiv.style.zIndex = parseInt( this.control_obj.style.zIndex ) + 1; newdiv.style.position = 'absolute'; newdiv.style.width = '320px'; newdiv.style.height = '400px'; newdiv.style.top = ipsclass.get_obj_toppos( this.mainbar ) + 'px'; var _left = ipsclass.get_obj_leftpos( this.mainbar ) - ( parseInt(newdiv.style.width) + 10 ); if ( _left < 1 ) { _left = ipsclass.get_obj_leftpos( this.mainbar ); } newdiv.style.left = ipsclass.get_obj_leftpos( this.mainbar ) - ( parseInt(newdiv.style.width) + 10 ) + 'px'; newdiv.style.left = _left + 'px'; var tmpheight = parseInt(newdiv.style.height) - 16; newdiv.innerHTML = this.module_wrap_html_panel( "" ); //----------------------------------------- // Add and show //----------------------------------------- this.mainbar.appendChild(newdiv); if ( is_ie ) { document.getElementById( this.editor_id + '_iframeblock_' + type + '_menu' ).style.backgroundColor = 'transparent'; document.getElementById( this.editor_id + '_iframeblock_' + type + '_menu' ).allowTransparency = true; } ipsclass.set_unselectable( newdiv ); //----------------------------------------- // INIT Drag //----------------------------------------- Drag.init( document.getElementById( this.editor_id + '_pallete-handle' ), newdiv ); this.current_bar_object = newdiv; }; /** * Remove control bar * Removes the control bar. */ this.module_remove_control_bar = function() { if ( ! this.current_bar_object ) { return; } //----------------------------------------- // Kill old bar //----------------------------------------- this.mainbar.removeChild( this.current_bar_object ); //----------------------------------------- // Reset bar object //----------------------------------------- this.current_bar_object = null; }; /** * Wrap HTML block with basic control panel stuff */ this.module_wrap_html_panel = function( html ) { var newhtml = ""; newhtml += "
"; newhtml += "
"; newhtml += "
"; newhtml += "
"; newhtml += "
"; newhtml += "
" + html + "
"; newhtml += "
"; newhtml += "
"; return newhtml; }; /** * Resize editor * * @param string Up (smaller) Down (Larger) */ this.resize_editorbox = function( direction ) { var inc_value = 100; var current_height = parseInt( this.editor_box.style.height ); var new_height = 0; current_height = current_height ? current_height : 300; //----------------------------------------- // If we're not going smaller than 300... //----------------------------------------- if ( current_height >= 50 ) { if ( direction == 'up' ) { new_height = current_height - inc_value; } else { new_height = current_height + inc_value; } if ( new_height > 249 ) { this.editor_box.style.height = new_height + 'px'; ipsclass.my_setcookie( 'ips_rte_height', new_height, 1 ); } } }; /** * Make HTML entities safe * @param string Raw HTML * @return string Treated HTML */ this.htmlspecialchars = function( html ) { html = html.replace(/&/g, "&"); html = html.replace(/"/g, """); html = html.replace(//g, ">"); return html; }; /** * Make HTML entities unsafe * @param string Raw HTML * @return string Treated HTML */ this.unhtmlspecialchars = function( html ) { html = html.replace( /"/g, '"' ); html = html.replace( /</g , '<' ); html = html.replace( />/g , '>' ); html = html.replace( /&/g , '&' ); return html; }; /** * Remove HTML tags. Ugly. * @param string Raw HTML * @return string Treated HTML */ this.strip_html = function( html ) { html = html.replace( /<\/?([^>]+?)>/ig, ""); return html; }; /** * Remove empty HTML tags. Ugly. * @param string Raw HTML * @return string Treated HTML */ this.strip_empty_html = function( html ) { html = html.replace( '<([^>]+?)>]+?)>', ""); return html; }; /** * Format HTML a bit nicely */ this.clean_html = function( t ) { if ( t == "" || typeof t == 'undefined' ) { return t; } //------------------------------- // Sort out BR tags //------------------------------- t = t.replace( /
/ig, "
"); //------------------------------- // Remove empty

tags //------------------------------- t = t.replace( /

(\s+?)?<\/p>/ig, ""); //------------------------------- // HR issues //------------------------------- t = t.replace( /


<\/p>/ig , "
"); t = t.replace( /

 <\/p>


 <\/p>/ig, "


"); //------------------------------- // Attempt to fix some formatting // issues.... //------------------------------- t = t.replace( /<(p|div)([^&]*)>/ig , "\n<$1$2>\n" ); t = t.replace( /<\/(p|div)([^&]*)>/ig , "\n\n"); t = t.replace( /
(?!<\/td)/ig , "
\n" ); //------------------------------- // And some table issues... //------------------------------- t = t.replace( /<\/(td|tr|tbody|table)>/ig , "\n"); t = t.replace( /<(tr|tbody|table(.+?)?)>/ig , "<$1>\n" ); t = t.replace( /<(td(.+?)?)>/ig , "\t<$1>" ); //------------------------------- // Newlines //------------------------------- t = t.replace( /

 <\/p>/ig , "
"); t = t.replace( /
/ig , "
\n"); t = t.replace( /
/ig , "
\n"); t = t.replace( /
\n<\/td>/ig , "
" ); //----------------------------------------- // Script tags //----------------------------------------- t = t.replace( /