" + ipb.lang['ck_saved_title'] + "
" + ipb.lang['ck_saved_desc'] + "
",
ajaxUrl: '',
initialize: function( editorId, options )
{
if ( inACP )
{
ipb.textEditor.ajaxUrl = ipb.vars['front_url'];
ipb.vars['secure_hash'] = ipb.vars['md5_hash'];
}
else
{
ipb.textEditor.ajaxUrl = ipb.vars['base_url'];
}
/* Insert into main store */
if ( ! ipb.textEditor.mainStore.get( editorId ) )
{
newEditorObject = new ipb.textEditorObjects( editorId, options );
ipb.textEditor.mainStore.set( editorId, newEditorObject );
}
/* Set up */
ipb.textEditor.lastSetUp = editorId;
},
/**
* Bind a HTML checkbox to the toggle stuffs
*/
bindHtmlCheckbox: function( elem, editorId )
{
editorId = ( editorId ) ? editorId : ipb.textEditor.getEditor().editorId;
if ( $( elem ) )
{
ipb.textEditor.htmlCheckbox[ editorId ] = $( elem );
$( elem ).writeAttribute( 'data-editorId', editorId );
$( elem ).observe('change', ipb.textEditor.htmlModeToggled.bindAsEventListener( this, $( elem ) ) );
}
},
/**
* HTML mode has been toggled so we force STD mode
*/
htmlModeToggled: function( e, elem )
{
textObj = ipb.textEditor.getEditor( $( elem ).readAttribute( 'data-editorId' ) );
isRte = textObj.isRte();
button = $( 'cke_' + textObj.editorId ).down('.cke_button_ipsswitch');
if ( elem.checked )
{
$('editor_html_message_' + textObj.editorId).show();
if ( isRte )
{
button.hide();
ipb.textEditor.switchEditor(true, textObj.editorId);
}
else
{
button.hide();
}
}
else
{
$('editor_html_message_' + textObj.editorId).hide();
if ( ! button.visible() )
{
button.show();
}
}
},
/**
* Switches an editor from rte to std or vice-versa
*/
switchEditor: function( noSaveChange, editorId )
{
editorId = ( editorId ) ? editorId : ipb.textEditor.getEditor().editorId;
textObj = ipb.textEditor.getEditor( editorId );
isRte = textObj.isRte();
ourcontent = textObj.getText();
saveCookie = ( noSaveChange ) ? false : true;
htmlOps = null;
noSmilies = 0;
if ( $( 'noSmilies_' + editorId ) )
{
noSmilies = parseInt( $F( 'noSmilies_' + editorId ) );
}
if ( $( ipb.textEditor.htmlCheckbox[ editorId ] ) )
{
htmlOps = ( ipb.textEditor.htmlCheckbox[ editorId ].checked ) ? 1 : 0;
}
var _url = ipb.textEditor.ajaxUrl + '&app=core&module=ajax§ion=editor&do=switch&secure_key=' + ipb.vars['secure_hash'];
if ( htmlOps !== null )
{
_url += '&htmlStatus=' + htmlOps;
}
Debug.write( _url );
Debug.write( 'Fetched editor content: ' + ourcontent );
new Ajax.Request( _url,
{
method: 'post',
parameters: { 'content' : ourcontent.encodeParam(),
'isRte' : isRte,
'noSmilies' : noSmilies },
onSuccess: function(t)
{
/* No Permission */
if ( t.responseText != 'nopermission' )
{
Debug.write( 'Converted to: ' + t.responseText );
/* Switch the text editor around */
if ( textObj.isRte() )
{
/* Reset flag */
textObj.setIsRte( false, noSaveChange );
textObj.CKEditor.setMode( 'source' );
/* Update */
$( textObj.editorId ).value = ipb.textEditor.stdPre( t.responseText );
try
{
Debug.write( $F( textObj.editorId ) );
textObj.CKEditor.setData( $F( textObj.editorId ) );
}
catch( err )
{
Debug.write( "CKEditor error: " + err );
}
if ( saveCookie )
{
ipb.Cookie.set( 'rteStatus', 'std' );
}
/* Update text-direction, since CKE forces LTR in 'source' mode */
if( isRTL )
{
$$('.cke_contents > textarea').each( function(elem) {
$(elem).setStyle( { textAlign: 'right' } );
});
}
if ( $('cke_' + textObj.editorId + '_stray') )
{
$('cke_' + textObj.editorId + '_stray').remove();
if ( $('ips_x_smile_show_all') )
{
$('ips_x_smile_show_all').remove();
}
}
}
else
{
/* Reset flag */
textObj.setIsRte( true, noSaveChange );
try
{
textObj.CKEditor.setData( ipb.textEditor.ckPre( t.responseText ) );
}
catch( err )
{
Debug.write( "CKEditor error: " + err );
}
/* Init editor */
textObj.CKEditor.setMode( 'wysiwyg' );
if ( saveCookie )
{
ipb.Cookie.set( 'rteStatus', 'rte' );
}
}
}
}.bind(this),
onException: function (t)
{
Debug.dir( t );
}
} );
},
/*
* Change all editor modes besides the current one
* (current one is changed inside switchEditor)
*/
toggleEditors: function( mode )
{
return false;
/* We no longer use this as it doesn't ping ajax to convert! */
ipb.textEditor.mainStore.each( function( instance ){
if( instance.key != ipb.textEditor.lastSetUp )
{
_editor = ipb.textEditor.getEditor( instance.key );
if ( ! _editor.options.isHtml )
{
if( mode == 'std' )
{
instance.value.setIsRte( false );
instance.value.CKEditor.setMode( 'source' );
if ( $('cke_' + _editor.editorId + '_stray') )
{
$('cke_' + _editor.editorId + '_stray').remove();
if ( $('ips_x_smile_show_all') )
{
$('ips_x_smile_show_all').remove();
}
}
}
else
{
instance.value.setIsRte( true );
instance.value.CKEditor.setMode( 'wysiwyg' );
}
}
}
});
},
/*
* Fetches an editor by ID
*/
getEditor: function( editorId )
{
editorId = ( ! editorId ) ? ipb.textEditor.getCurrentEditorId() : editorId;
return ipb.textEditor.mainStore.get( editorId );
},
/**
* Fetches the current focused editor or the last one set up
* @returns string editor id
*/
getCurrentEditorId: function()
{
if ( typeof(CKEDITOR) == 'undefined' || Object.isUndefined( CKEDITOR ) )
{
return ipb.textEditor.lastSetUp;
}
else
{
if ( CKEDITOR.currentInstance && ipb.textEditor.mainStore.get( CKEDITOR.currentInstance.name ).CKEditor )
{
return CKEDITOR.currentInstance.name;
}
else
{
return ipb.textEditor.lastSetUp;
}
}
},
/**
* Make safe for CKEditor
*/
ckPre: function( text )
{
text = text.replace( '