Roo.form.FCKeditor = function(config){
Roo.form.FCKeditor.superclass.constructor.call(this, config);
this.addEvents({
editorinit : true
});
};
Roo.form.FCKeditor.editors = { };
Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
{
fckconfig : false,
toolbarSet : 'Basic',
basePath : '/fckeditor/',
frame : false,
value : '',
onRender : function(ct, position)
{
if(!this.el){
this.defaultAutoCreate = {
tag: "textarea",
style:"width:300px;height:60px;",
autocomplete: "new-password"
};
}
Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
Roo.form.FCKeditor.editors[this.getId()] = this;
this.replaceTextarea() ;
},
getEditor : function() {
return this.fckEditor;
},
setValue : function(value)
{
if(typeof(value) == 'undefined') { return;
}
Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
if(!this.getEditor()) {
return;
}
this.getEditor().SetData(value);
},
getValue : function()
{
if (this.frame && this.frame.dom.style.display == 'none') {
return Roo.form.FCKeditor.superclass.getValue.call(this);
}
if(!this.el || !this.getEditor()) {
return this.value;
}
var value=this.getEditor().GetData();
Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
return Roo.form.FCKeditor.superclass.getValue.call(this);
},
getRawValue : function()
{
if (this.frame && this.frame.dom.style.display == 'none') {
return Roo.form.FCKeditor.superclass.getRawValue.call(this);
}
if(!this.el || !this.getEditor()) {
return this.value;
return;
}
var value=this.getEditor().GetData();
Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
return Roo.form.FCKeditor.superclass.getRawValue.call(this);
},
setSize : function(w,h) {
Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
this.frame.dom.setAttribute('width', w);
this.frame.dom.setAttribute('height', h);
this.frame.setSize(w,h);
},
toggleSourceEdit : function(value) {
this.el.dom.style.display = value ? '' : 'none';
this.frame.dom.style.display = value ? 'none' : '';
},
focus: function(tag)
{
if (this.frame.dom.style.display == 'none') {
return Roo.form.FCKeditor.superclass.focus.call(this);
}
if(!this.el || !this.getEditor()) {
this.focus.defer(100,this, [tag]);
return;
}
var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
this.getEditor().Focus();
if (tgs.length) {
if (!this.getEditor().Selection.GetSelection()) {
this.focus.defer(100,this, [tag]);
return;
}
var r = this.getEditor().EditorDocument.createRange();
r.setStart(tgs[0],0);
r.setEnd(tgs[0],0);
this.getEditor().Selection.GetSelection().removeAllRanges();
this.getEditor().Selection.GetSelection().addRange(r);
this.getEditor().Focus();
}
},
replaceTextarea : function()
{
if ( document.getElementById( this.getId() + '___Frame' ) ) {
return ;
}
var oTextarea = document.getElementById( this.getId() );
var colElementsByName = document.getElementsByName( this.getId() ) ;
oTextarea.style.display = 'none' ;
if ( oTextarea.tabIndex ) {
this.TabIndex = oTextarea.tabIndex ;
}
this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
this.frame = Roo.get(this.getId() + '___Frame')
},
_getConfigHtml : function()
{
var sConfig = '' ;
for ( var o in this.fckconfig ) {
sConfig += sConfig.length > 0 ? '&' : '';
sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
}
return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
},
_getIFrameHtml : function()
{
var sFile = 'fckeditor.html' ;
var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
var html = '<iframe id="' + this.getId() +
'___Frame" src="' + sLink +
'" width="' + this.width +
'" height="' + this.height + '"' +
(this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
' frameborder="0" scrolling="no"></iframe>' ;
return html ;
},
_insertHtmlBefore : function( html, element )
{
if ( element.insertAdjacentHTML ) {
element.insertAdjacentHTML( 'beforeBegin', html ) ;
} else { var oRange = document.createRange() ;
oRange.setStartBefore( element ) ;
var oFragment = oRange.createContextualFragment( html );
element.parentNode.insertBefore( oFragment, element ) ;
}
}
});
function FCKeditor_OnComplete(editorInstance){
var f = Roo.form.FCKeditor.editors[editorInstance.Name];
f.fckEditor = editorInstance;
f.fireEvent('editorinit', f, editorInstance);
}