//------------------------------------------ // Invision Power Board v2 // Text Editor Global Functions // (c) 2006 Invision Power Services, Inc. // // http://www.invisionboard.com //------------------------------------------ var _options_done = 0; /** * Check side panel * * @param string Editor ID */ function check_side_panel( editor_id ) { //----------------------------------------- // Remove side panel? //----------------------------------------- if ( global_rte_remove_side_panel ) { //----------------------------------------- // Turn off button. //----------------------------------------- document.getElementById( 'rte-toggle-side-panel-button' ).style.display = 'none'; return true; } var _open = global_rte_side_panel_open; var _cookie = ipsclass.my_getcookie( 'rte-sidepanel' ); if ( _cookie == 'open' || _cookie == 'close' ) { _open = ( _cookie == 'open' ) ? 1 : 0; } if ( _open ) { show_options_panel( editor_id, _open ); } }; /** * Show more options panel * * @param string Editor ID */ function show_options_panel( editor_id, force, start_emo ) { //----------------------------------------- // Remove side panel? //----------------------------------------- if ( global_rte_remove_side_panel ) { //----------------------------------------- // Turn off button. //----------------------------------------- document.getElementById( 'rte-toggle-side-panel-button' ).style.display = 'none'; return true; } //----------------------------------------- // Set start.. //----------------------------------------- if ( typeof( start_emo ) == 'undefined' ) { start_emo = 0; } var _editor = document.getElementById( editor_id + '_main-bar' ); var _options = document.getElementById( editor_id + '_options-bar' ); var _height = parseInt( _editor.offsetHeight ); var _mode = 'open'; var _more_less = ''; //----------------------------------------- // Clear out content //----------------------------------------- _options.innerHTML = ''; //----------------------------------------- // Opening or closing? //----------------------------------------- if ( typeof( force ) != 'undefined' ) { _mode = ( force == 1 ) ? 'open' : 'close'; } else { if ( _options._panel_open ) { _mode = 'close'; } } //----------------------------------------- // Set cookie //----------------------------------------- ipsclass.my_setcookie( 'rte-sidepanel', _mode, 1 ); //----------------------------------------- // OPEN: Adjust editor to make room //----------------------------------------- if( _mode == 'open' && _options_done == 1 ) { _editor.style.width = '80%'; _options.style.width = 'auto'; _options.style.height = 'auto'; _options.style.display = 'block'; _options._panel_open = 1; document.getElementById( editor_id + '_spacer-bar' ).style.width = '4px'; } if ( _mode == 'open' ) { _editor.style.width = '80%'; if( is_opera ) { _editor.style.width = '100%'; _editor.style.display = 'block'; } _options.style.width = 'auto'; _options.style.height = 'auto'; _options.style.display = 'block'; _options._panel_open = 1; document.getElementById( editor_id + '_spacer-bar' ).style.width = '4px'; //----------------------------------------- // Build emoticons... //----------------------------------------- var _main_div = document.createElement( 'div' ); _main_div.className = 'rte-option-emo-box'; _main_div.style.width = '90%'; _main_div.innerHTML += '
' + ips_language_array['emos_show_all'] + '
'; var _div = document.createElement( 'div' ); _div.style.width = '100%'; _div.style.height = '120px'; _div.style.overflow = 'auto'; _div.style.overflowY = 'auto'; _div.style.overflowX = 'auto'; var table = document.createElement('table'); table.cellPadding = 0; table.cellSpacing = 0; table.border = 0; table.width = '99%'; var i = 0; var perrow = 3; var show_emos = 12; var show_rows = show_emos / perrow; var max_emos = 0; var _previous = 0; var _next = 0; //----------------------------------------- // Get max. emos //----------------------------------------- for( var emo in ips_smilie_items ) { max_emos++; } for( var emo in ips_smilie_items ) { var _tmp = ips_smilie_items[ emo ].split( "," ); var _id = _tmp[0] - 1; if ( _id < start_emo || _id >= ( show_emos + start_emo ) ) { continue; } if ( i % perrow == 0 ) { var tr = table.insertRow(-1); } i++; var div = document.createElement('div'); var img = ' '; div.innerHTML = img; var td = tr.insertCell(-1); td.width = '33%'; td.align = 'center'; td.className = 'rte-menu-emo-box'; td.appendChild(div); td.cmd = 'emoticons'; td.editor_id = editor_id; td.id = editor_id + '_emoticon_' + _tmp[0]; td.emo_id = _tmp[0]; td.emo_image = _tmp[1]; td.emo_code = emo; td.onclick = ips_editor_events.prototype.emoticon_onclick; } //----------------------------------------- // More? //----------------------------------------- _div.appendChild( table ); _main_div.appendChild( _div ); if ( start_emo > 0 ) { if ( start_emo + i < max_emos ) { _previous = start_emo - show_emos; } else { _previous = start_emo - show_emos; } _more_less = '
' + ips_language_array['emos_show_prev'] + '
'; } if ( show_emos + start_emo < max_emos ) { if ( start_emo < 1 ) { _next = start_emo + show_emos; } else { _next = start_emo + show_emos; } _more_less += '
' + ips_language_array['emos_show_next'] + '
'; } if ( _more_less ) { var _div = document.createElement('div'); _div.className = "rte-menu-emo-header"; _div.style.height = '17px'; _div.innerHTML = _more_less; _main_div.appendChild( _div ); } _options.appendChild( _main_div ); //----------------------------------------- // Special Items //----------------------------------------- var _main_div = document.createElement( 'div' ); _main_div.className = 'rte-option-emo-box'; _main_div.style.width = '90%'; _main_div.innerHTML += '
'+ips_language_array['ed_quick_access']+'
'; var _div = document.createElement( 'div' ); _div.style.width = '100%'; var table = document.createElement('table'); table.cellPadding = 0; table.cellSpacing = 0; table.border = 0; table.width = '99%'; var i = 0; var perrow = 3; for( var i in IPS_editor[ editor_id ].ips_special_items ) { var tr = table.insertRow(-1); var option = tr.insertCell(-1); var img = ( typeof IPS_editor[ editor_id ].ips_special_items[i][1] != 'undefined' ) ? ' ' : ''; option.innerHTML = img + IPS_editor[ editor_id ].ips_special_items[i][0]; option.className = 'rte-menu-face'; option.style.textAlign = 'left'; option.style.paddingLeft = '2px'; option.cmd = 'module_load', option.loader_key = i.replace( 'cmd_loader_', '' ); option.editor_id = editor_id; option.onmouseover = option.onclick = option.onmouseout = option.onmouseup = option.onmousedown = ips_editor_events.prototype.special_onmouse_event; } _div.appendChild( table ); _main_div.appendChild( _div ); _options.appendChild( _main_div ); _options_done = 1; ipsclass.set_unselectable( _options ); } else { _editor.style.width = '100%'; document.getElementById( editor_id + '_spacer-bar' ).style.width = '0px'; _options.style.width = '0px'; _options.style.display = 'none'; _options._panel_open = 0; //_options.innerHTML = ''; } return false; }; /** * Switch between STD and RTE editors on the fly * * @param string Editor ID */ function switch_editor_mode( editor_id ) { //---------------------------------- // INIT //---------------------------------- var url = ipb_var_base_url+'act=xmlout&do=post-editorswitch'; var fields = new Array(); if ( use_enhanced_js ) { var new_mode = IPS_editor[ editor_id ].is_rte ? 0 : 1; if ( IPS_editor[ editor_id ].is_loading ) { return; } else { IPS_editor[ editor_id ].is_loading = 1; } //----------------------------------------- // Close menus //----------------------------------------- if ( typeof( ipsmenu ) != 'undefined' ) { ipsmenu.close(); } //----------------------------------------- // Collect Info //----------------------------------------- var _file_path = IPS_editor[ editor_id ].file_path; var _is_ie = IPS_editor[ editor_id ].is_ie; var _is_moz = IPS_editor[ editor_id ].is_moz; //---------------------------------- // Populate fields //---------------------------------- fields['md5check'] = ipb_md5_check; fields['act'] = 'xmlout'; fields['do'] = 'post-editorswitch'; fields['to_rte'] = new_mode; fields['Post'] = IPS_editor[ editor_id ].editor_get_contents(); /*--------------------------------------------*/ // Main function to do on request // Must be defined first!! /*--------------------------------------------*/ do_request_function = function() { //---------------------------------- // Ignore unless we're ready to go //---------------------------------- if ( ! xmlobj.readystate_ready_and_ok() ) { xmlobj.show_loading(); return; } xmlobj.hide_loading(); //----------------------------------------- // Kill editor //----------------------------------------- IPS_editor[ editor_id ].destruct(); //---------------------------------- // INIT //---------------------------------- var text = xmlobj.xmlhandler.responseText; var matches = text.match( /&#([0-9]+);/g ); if ( matches ) { for ( var i = 0; typeof( matches[i] ) != 'undefined'; i++ ) { if ( sm = matches[i].match( /^&#([0-9]+);$/ ) ) { text = text.replace( sm[0], String.fromCharCode(sm[1]) ); } } } text = text.replace( /&(lt|gt|quot);/ig, "&$1;" ); text = text.replace( /"/g, '"' ); // Fix emoticons for ACP text = text.replace( /([^\/])style_emoticons\/$1([a-zA-Z0-9]+)/ig, global_rte_emoticons_url ); //----------------------------------------- // BBCode specific fixes //----------------------------------------- if ( ! new_mode ) { // Move closing tags on a new line up one text = text.replace( /(?:\n|\r){1,}(\[\/\w{1,}\])/g, "$1" ); // Make sure list bullets are on a new line text = text.replace( /(\S{1})\[\*\]/g, "$1\n[*]" ); } //----------------------------------------- // Get rid of old thing //----------------------------------------- IPS_editor[ editor_id ] = null; //----------------------------------------- // INIT New //----------------------------------------- IPS_editor[ editor_id ] = new ips_text_editor( editor_id, new_mode, new_mode == 1 ? 0 : 1, _file_path, text ); //----------------------------------------- // Other set up //----------------------------------------- // Set up defaults IPS_editor[ editor_id ].allow_advanced = 0; IPS_editor[ editor_id ].forum_fix_ie_newlines = 1; // Add bbcode items for( var i in ips_bbcode_items ) { IPS_editor[ editor_id ].module_add_item( 'bbcodeloader{id=' + i + '}', ips_language_array['insert_prefix'] + ": " + ips_bbcode_items[ i ]['title'] , 'rte-ipd-tag.png' ); } IPS_editor[ editor_id ].editor_check_focus(); //----------------------------------------- // Fix up forms //----------------------------------------- document.getElementById( editor_id + '_wysiwyg_used' ).value = new_mode; }; //---------------------------------- // LOAD XML //---------------------------------- xmlobj = new ajax_request(); xmlobj.onreadystatechange( do_request_function ); var xmlreturn = xmlobj.process( url, 'POST', xmlobj.format_for_post(fields) ); } } /** * Show all emoticons * * @param string Editor ID */ function show_all_emoticons( editor_id ) { IPS_editor[ editor_id ].emoticon_window_id = window.open( ipb_var_base_url + "act=legends&CODE=emoticons&editor_id=" + editor_id,"Legends","width=250,height=500,resizable=yes,scrollbars=yes"); menu_action_close(); return false; } /** * Show BBCode pop-up * */ function bbc_pop() { window.open( ipb_var_base_url + "act=legends&CODE=bbcode","Legends","width=700,height=500,resizable=yes,scrollbars=yes"); } /** * Legacy code validate form * */ function ValidateForm() { return validate_form(); } /** * IPB specific. * */ function validate_form() { //----------------------------------------- // Check for uploads... //----------------------------------------- try { if ( ipsattach.has_upload_pending ) { if ( confirm( ipb_global_lang['post_upload_not_empty'] ) ) { return true; } else { return false; } } } catch(e) { } for ( var i in IPS_editor ) { if( typeof( IPS_editor[i] ) != 'object' ) { continue; } var return_var = IPS_editor[ i ].update_for_form_submit(); if ( return_var == false ) { return false; } } return true; }