2012-06-06 06:13:19 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate2 - JS widget for HTML editing
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
*/
|
|
|
|
|
|
|
|
var et2_htmlarea = et2_inputWidget.extend({
|
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
'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
|
|
|
|
'type':'any',
|
|
|
|
'default': et2_no_init
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
legacyOptions: ['mode','height','width','expand_toolbar','base_href'],
|
|
|
|
|
|
|
|
ck_props: {},
|
|
|
|
init: function(_parent, _attrs) {
|
|
|
|
this.ck_props = _attrs['config'] ? _attrs['config'] : {};
|
|
|
|
|
|
|
|
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);
|
2012-06-12 22:50:45 +02:00
|
|
|
var self = this;
|
2013-03-20 21:45:43 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
this.htmlNode.ckeditor(function() {
|
|
|
|
// If value is set, pass it in here.
|
|
|
|
this.setData(self.value);
|
|
|
|
delete self.value;
|
|
|
|
},this.ck_props);
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
if(CKEDITOR.instances[this.id])
|
|
|
|
{
|
|
|
|
CKEDITOR.instances[this.id].destroy();
|
|
|
|
}
|
2013-03-25 23:22:53 +01:00
|
|
|
if(this.htmlNode.ckeditor)
|
|
|
|
{
|
|
|
|
this.htmlNode.ckeditor(function() {
|
|
|
|
// If value is set, pass it in here.
|
|
|
|
this.setData(self.value);
|
|
|
|
delete self.value;
|
|
|
|
},this.ck_props);
|
|
|
|
}
|
2013-03-20 21:45:43 +01:00
|
|
|
}
|
2012-06-06 06:13:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2013-03-26 16:54:18 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
this.htmlNode.ckeditorGet().destroy(true);
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
this.egw().debug("warn",e);
|
|
|
|
this.htmlNode = null;
|
|
|
|
}
|
2012-06-06 06:13:19 +02:00
|
|
|
},
|
|
|
|
set_value: function(_value) {
|
2012-06-12 22:50:45 +02:00
|
|
|
try {
|
|
|
|
this.htmlNode.ckeditorGet().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() {
|
2013-03-20 21:45:43 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return this.htmlNode.ckeditorGet().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"]);
|
|
|
|
|
|
|
|
|