" + 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;
},
/**
* Switches an editor from rte to std or vice-versa
*/
switchEditor: function()
{
textObj = ipb.textEditor.getEditor();
isRte = textObj.isRte();
ourcontent = textObj.getText();
var _url = ipb.textEditor.ajaxUrl + '&app=core&module=ajax§ion=editor&do=switch&secure_key=' + ipb.vars['secure_hash'];
Debug.write( _url );
Debug.write( 'Fetched editor content: ' + ourcontent );
new Ajax.Request( _url,
{
method: 'post',
parameters: { 'content' : ourcontent.encodeParam(),
'isRte' : isRte },
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 );
/* Hackery! Passing t.responseText through to .setData doesn't allow html entities to parse in the text area
* literally, if you pass { it will show { - not good.
*/
$$('body').first().insert( new Element( 'code', { 'class': 'hide', 'id': 'xx-new-contents-xx' } ).update( t.responseText ) );
/* Can it sister */
textObj.CKEditor.setMode( 'source' );
textObj.insert( $('xx-new-contents-xx').innerHTML, false, true );
$('xx-new-contents-xx').remove();
ipb.Cookie.set( 'rteStatus', 'std' );
/* Update all other editors */
ipb.textEditor.toggleEditors( 'std' );
/* Update text-direction, since CKE forces LTR in 'source' mode */
if( isRTL )
{
$$('.cke_contents > textarea').each( function(elem) {
$(elem).setStyle( { textAlign: 'right' } );
});
}
}
else
{
/* Reset flag */
textObj.setIsRte( true );
try
{
textObj.CKEditor.setData( ipb.textEditor.ckPre( t.responseText ) );
}
catch( err )
{
Debug.write( "CKEditor error: " + err );
}
/* Init editor */
textObj.CKEditor.setMode( 'wysiwyg' );
ipb.Cookie.set( 'rteStatus', 'rte' );
/* Update all other editors */
ipb.textEditor.toggleEditors( '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 )
{
ipb.textEditor.mainStore.each( function( instance ){
if( instance.key != ipb.textEditor.lastSetUp )
{
if( mode == 'std' )
{
instance.value.setIsRte( false );
instance.value.CKEditor.setMode( 'source' );
}
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( 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( '