egroupware/etemplate/js/et2_widget_htmlarea.js

156 lines
3.3 KiB
JavaScript
Raw Normal View History

2012-06-06 06:13:19 +02:00
/**
* EGroupware eTemplate2 - JS widget for HTML editing
2012-06-06 06:13:19 +02:00
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray 2012
* @version $Id$
*/
"use strict";
/*egw:uses
jsapi.jsapi; // Needed for egw_seperateJavaScript
jquery.jquery;
2013-03-15 12:50:48 +01:00
/phpgwapi/js/ckeditor/ckeditor.js;
/phpgwapi/js/ckeditor/config.js;
/phpgwapi/js/ckeditor/adapters/jquery.js;
2012-06-06 06:13:19 +02:00
et2_core_baseWidget;
*/
/**
* @augments et2_inputWidget
*/
var et2_htmlarea = et2_inputWidget.extend(
{
2012-06-06 06:13:19 +02:00
attributes: {
'mode': {
'name': 'Mode',
'description': 'One of {ascii|simple|extended|advanced}',
'default': 'simple',
'type': 'string'
},
'height': {
'name': 'Height',
'default': et2_no_init,
'type': 'string'
},
'width': {
'name': 'Width',
'default': et2_no_init,
'type': 'string'
},
'expand_toolbar': {
'name': 'Expand Toolbar',
'default': true,
'type':'any',
'description': 'Have the toolbar expanded (visible)'
2012-06-06 06:13:19 +02:00
},
'base_href': {
'name': 'Image base path',
'default': et2_no_init,
'type': 'string',
'description': 'activates the browser for images at the path (relative to the docroot)'
},
'config': {
// internal default configuration
'name': 'Internal configuration',
2012-06-06 06:13:19 +02:00
'type':'any',
'default': et2_no_init,
'description': 'Internal configuration - managed by preferences & framework, passed in here'
2012-06-06 06:13:19 +02:00
},
},
legacyOptions: ['mode','height','width','expand_toolbar','base_href'],
/**
* Constructor
*
* @param _parent
* @param _attrs
* @memberOf et2_htmlarea
*/
2012-06-06 06:13:19 +02:00
init: function(_parent, _attrs) {
2013-04-09 13:50:14 +02:00
// _super.apply is responsible for the actual setting of the params (some magic)
2012-06-06 06:13:19 +02:00
this._super.apply(this, arguments);
// Allow no child widgets
this.supportedWidgetClasses = [];
this.htmlNode = $j(document.createElement("div"));
this.setDOMNode(this.htmlNode[0]);
},
doLoadingFinished: function() {
this._super.apply(this, arguments);
var self = this;
2013-04-09 13:50:14 +02:00
var ckeditor;
try
{
2013-04-09 13:50:14 +02:00
CKEDITOR.replace(this.id,this.options.config);
ckeditor = CKEDITOR.instances[this.id];
ckeditor.setData(self.value);
delete self.value;
}
catch (e)
{
if(CKEDITOR.instances[this.id])
{
CKEDITOR.instances[this.id].destroy();
}
if(this.htmlNode.ckeditor)
{
2013-04-09 13:50:14 +02:00
CKEDITOR.replace(this.id,this.options.config);
ckeditor = CKEDITOR.instances[this.id];
ckeditor.setData(self.value);
delete self.value;
}
}
2012-06-06 06:13:19 +02:00
},
destroy: function() {
try
{
2013-04-09 13:50:14 +02:00
//this.htmlNode.ckeditorGet().destroy(true);
ckeditor = CKEDITOR.instances[this.id];
ckeditor.destroy(true);
}
catch (e)
{
this.egw().debug("warn",e);
this.htmlNode = null;
}
2012-06-06 06:13:19 +02:00
},
set_value: function(_value) {
try {
2013-04-09 13:50:14 +02:00
//this.htmlNode.ckeditorGet().setData(_value);
ckeditor = CKEDITOR.instances[this.id];
ckeditor.setData(_value);
} catch (e) {
// CK editor not ready - callback will do it
this.value = _value;
}
2012-06-06 06:13:19 +02:00
},
getValue: function() {
try
{
2013-04-09 13:50:14 +02:00
//return this.htmlNode.ckeditorGet().getData();
ckeditor = CKEDITOR.instances[this.id];
return ckeditor.getData();
}
catch (e)
{
// CK Error
this.egw().debug("error",e);
return null;
}
2012-06-06 06:13:19 +02:00
}
});
et2_register_widget(et2_htmlarea, ["htmlarea"]);