2012-06-06 06:13:19 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +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;
|
|
|
|
*/
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* @augments et2_inputWidget
|
|
|
|
*/
|
|
|
|
var et2_htmlarea = et2_inputWidget.extend(
|
|
|
|
{
|
2013-06-26 21:34:14 +02:00
|
|
|
modes: ['ascii','simple','extended','advanced'],
|
2013-11-04 11:13:28 +01:00
|
|
|
|
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,
|
2013-11-04 11:13:28 +01:00
|
|
|
'type':'boolean',
|
2013-06-17 23:22:32 +02:00
|
|
|
'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
|
2013-06-17 23:22:32 +02:00
|
|
|
'name': 'Internal configuration',
|
2012-06-06 06:13:19 +02:00
|
|
|
'type':'any',
|
2013-06-17 23:22:32 +02:00
|
|
|
'default': et2_no_init,
|
2013-10-10 13:57:18 +02:00
|
|
|
'description': 'Internal configuration - managed by preferences & framework, passed in here',
|
|
|
|
'translate': 'no_lang'
|
2012-06-06 06:13:19 +02:00
|
|
|
},
|
2014-02-14 11:14:28 +01:00
|
|
|
value: {
|
|
|
|
name: "Value",
|
|
|
|
description: "The value of the widget",
|
|
|
|
type: "html", // "string" would remove html tags by running html_entity_decode
|
|
|
|
default: et2_no_init
|
|
|
|
}
|
2012-06-06 06:13:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
legacyOptions: ['mode','height','width','expand_toolbar','base_href'],
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2013-11-04 11:13:28 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @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 = [];
|
2013-06-26 21:34:14 +02:00
|
|
|
this.htmlNode = $j(document.createElement("textarea"))
|
|
|
|
.css('height', this.options.height)
|
|
|
|
.addClass('et2_textbox_ro');
|
2012-06-06 06:13:19 +02:00
|
|
|
this.setDOMNode(this.htmlNode[0]);
|
|
|
|
},
|
2013-11-04 11:13:28 +01:00
|
|
|
|
2013-06-26 21:34:14 +02:00
|
|
|
transformAttributes: function(_attrs) {
|
2012-06-06 06:13:19 +02:00
|
|
|
|
2013-06-26 21:34:14 +02:00
|
|
|
// Check mode, some apps jammed everything in there
|
2013-10-10 13:57:18 +02:00
|
|
|
if(_attrs['mode'] && jQuery.inArray(_attrs['mode'], this.modes) < 0)
|
2013-06-26 21:34:14 +02:00
|
|
|
{
|
2013-10-10 13:57:18 +02:00
|
|
|
this.egw().debug("warn", "'%s' is an invalid mode for htmlarea '%s'. Valid options:", _attrs['mode'],_attrs['id'], this.modes);
|
2013-06-26 21:34:14 +02:00
|
|
|
var list = _attrs['mode'].split(',');
|
|
|
|
for(var i = 0; i < list.length && i < this.legacyOptions.length; i++)
|
|
|
|
{
|
|
|
|
_attrs[this.legacyOptions[i]] = list[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
2013-11-04 11:13:28 +01:00
|
|
|
|
2012-06-06 06:13:19 +02:00
|
|
|
doLoadingFinished: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2013-06-26 21:34:14 +02:00
|
|
|
if(this.mode == 'ascii') return;
|
2013-11-04 11:13:28 +01:00
|
|
|
|
2012-06-12 22:50:45 +02:00
|
|
|
var self = this;
|
2013-04-09 13:50:14 +02:00
|
|
|
var ckeditor;
|
2013-03-20 21:45:43 +01:00
|
|
|
try
|
|
|
|
{
|
2013-08-23 16:10:37 +02:00
|
|
|
CKEDITOR.replace(this.dom_id,jQuery.extend({},this.options.config,this.options));
|
|
|
|
ckeditor = CKEDITOR.instances[this.dom_id];
|
2013-04-09 13:50:14 +02:00
|
|
|
ckeditor.setData(self.value);
|
|
|
|
delete self.value;
|
2013-03-20 21:45:43 +01:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
2013-08-23 16:10:37 +02:00
|
|
|
if(CKEDITOR.instances[this.dom_id])
|
2013-03-20 21:45:43 +01:00
|
|
|
{
|
2013-08-23 16:10:37 +02:00
|
|
|
CKEDITOR.instances[this.dom_id].destroy();
|
2013-03-20 21:45:43 +01:00
|
|
|
}
|
2013-03-25 23:22:53 +01:00
|
|
|
if(this.htmlNode.ckeditor)
|
|
|
|
{
|
2013-08-23 16:10:37 +02:00
|
|
|
CKEDITOR.replace(this.dom_id,this.options.config);
|
|
|
|
ckeditor = CKEDITOR.instances[this.dom_id];
|
2013-04-09 13:50:14 +02:00
|
|
|
ckeditor.setData(self.value);
|
|
|
|
delete self.value;
|
2013-03-25 23:22:53 +01:00
|
|
|
}
|
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
|
|
|
|
{
|
2013-04-09 13:50:14 +02:00
|
|
|
//this.htmlNode.ckeditorGet().destroy(true);
|
2013-08-23 16:10:37 +02:00
|
|
|
var ckeditor = CKEDITOR.instances[this.dom_id];
|
|
|
|
if (ckeditor) ckeditor.destroy(true);
|
2013-03-26 16:54:18 +01:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
2013-10-10 13:57:18 +02:00
|
|
|
this.egw().debug("warn","Removing CKEDITOR: " + e.message, this,e);
|
|
|
|
// Finish it
|
|
|
|
delete CKEDITOR.instances[this.dom_id];
|
2013-03-26 16:54:18 +01:00
|
|
|
}
|
2013-10-10 13:57:18 +02:00
|
|
|
this.htmlNode.remove();
|
|
|
|
this.htmlNode = null;
|
|
|
|
this._super.apply(this, arguments);
|
2012-06-06 06:13:19 +02:00
|
|
|
},
|
|
|
|
set_value: function(_value) {
|
2013-08-23 17:15:30 +02:00
|
|
|
this._oldValue = _value;
|
|
|
|
|
2012-06-12 22:50:45 +02:00
|
|
|
try {
|
2013-04-09 13:50:14 +02:00
|
|
|
//this.htmlNode.ckeditorGet().setData(_value);
|
2013-08-23 16:10:37 +02:00
|
|
|
var ckeditor = CKEDITOR.instances[this.dom_id];
|
|
|
|
if (ckeditor)
|
|
|
|
{
|
|
|
|
ckeditor.setData(_value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-04 11:13:28 +01:00
|
|
|
this.htmlNode.val(_value);
|
2013-08-23 16:10:37 +02:00
|
|
|
this.value = _value;
|
|
|
|
}
|
2012-06-12 22:50:45 +02:00
|
|
|
} 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
|
|
|
|
{
|
2013-04-09 13:50:14 +02:00
|
|
|
//return this.htmlNode.ckeditorGet().getData();
|
2013-08-23 16:10:37 +02:00
|
|
|
var ckeditor = CKEDITOR.instances[this.dom_id];
|
|
|
|
return ckeditor ? ckeditor.getData() : this.htmlNode.val();
|
2013-03-20 21:45:43 +01:00
|
|
|
}
|
|
|
|
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"]);
|
|
|
|
|