Newer
Older
* @module package/quiqqer/ckeditor4/bin/Editor
* @require controls/editors/Editor
* @require Locale
* @require Ajax
* @require qui/utils/Math
define('package/quiqqer/ckeditor4/bin/Editor', [

Henning Leutz
committed
'qui/QUI',
'Ajax',
'qui/utils/Math',
'css!package/quiqqer/ckeditor4/bin/Editor.css'
], function (require, QUI, Editor, Locale, Ajax, QUIMath, QUIElements, Settings) {
Extends: Editor,
Type : 'package/quiqqer/ckeditor4/bin/Editor',
'$onLoad',
'$onDestroy',
'$onSetContent',
'$onGetContent',
'$onDrop',
'$onResize',
'$onAddCSS',
'$onInstanceReadyListener'
initialize: function (Manager, options) {
this.parent(Manager, options);
onLoad : this.$onLoad,
onResize : this.$onResize,
onDestroy : this.$onDestroy,
onSetContent: this.$onSetContent,
onGetContent: this.$onGetContent,
onDrop : this.$onDrop,
onAddCSS : this.$onAddCSS
/**
* Editor onLoad Event
* if the editor is to be drawn and inserted
*
* @param {Object} data - Editor data
*/

Henning Leutz
committed
if ("CKEDITOR" in window) {
self.$loadInstance(data);
return;
}
require([URL_OPT_DIR + 'ckeditor/ckeditor/ckeditor.js'], function () {

Henning Leutz
committed
// set global events

Henning Leutz
committed
var Editor = QUI.Controls.getById(ev.editor.name);
if (Editor && "$onInstanceReadyListener" in Editor) {
Editor.$onInstanceReadyListener(ev);
}

Henning Leutz
committed
});
// http://docs.ckeditor.com/#!/guide/dev_howtos_dialog_windows
window.CKEDITOR.on('dialogDefinition', function (ev) {

Henning Leutz
committed
var Editor = QUI.Controls.getById(ev.editor.name);

Henning Leutz
committed
Editor.$imageDialog(ev);
Editor.$linkDialog(ev);
});
self.$loadInstance(data);
/**
* Load the CKEditor Instance into an Textarea or DOMNode Element
*
var self = this,
Container = this.getContainer(),
Textarea = false,
size = Container.getSize();
if (!Textarea) {
Textarea = Container.getElement('textarea');
if (window.CKEDITOR.instances[instance]) {
window.CKEDITOR.instances[instance].destroy(true);
// parse the buttons for the ckeditor
var b, g, i, len, blen, glen, group, items,
buttonEntry, lineEntry, groupEntry;
var buttons = data.toolbar,
lines = buttons.lines || [],
toolbar = [];
for (g = 0, glen = lineEntry.length; g < glen; g++) {
for (b = 0, blen = groupEntry.length; b < blen; b++) {
buttonEntry = groupEntry[b];
if (self.getAttribute('width')) {
width = self.getAttribute('width');
if (self.getAttribute('height')) {
height = self.getAttribute('height');
var zIndex = QUIElements.getComputedZIndex(Container);
// parse styles to fckedit styles
var entry, styles = [];
for (i = 0, len = data.styles.length; i < len; i++) {
entry = data.styles[i];
name : entry.text,
element : entry.element,
attributes: entry.attributes
if (!("cssFiles" in data)) {
data.cssFiles = [];
}
URL_OPT_DIR + 'quiqqer/ckeditor4/bin/defaultWysiwyg.css'
Settings.getPlugins().then(function (plugins) {
var extraPlugins = plugins.join(",");
window.CKEDITOR.replace(instance, {
skinName : 'moono-lisa',
customConfig : '',
language : Locale.getCurrent(),
baseHref : URL_DIR,
basePath : URL_DIR,
height : height,
width : width,
toolbar : toolbar,
allowedContent : true,
extraAllowedContent: 'div(*)[*]{*}; iframe(*)[*]{*}; img(*)[*]{*}; script(*)[*]{*}',
stylesSet : styles,
contentsCss : data.cssFiles || [],
bodyClass : data.bodyClass,
// templates_files : [URL_OPT_DIR +'base/bin/pcsgEditorPlugins/templates.php'],
baseFloatZIndex : zIndex,
extraPlugins : extraPlugins
});
if (!Instance || !(name in Instance)) {
return;
}
if (window.CKEDITOR.instances[Instance.name]) {
try {
window.CKEDITOR.instances[Instance.name].destroy(true);
} catch (e) {
window.CKEDITOR.instances[Instance.name] = null;
delete window.CKEDITOR.instances[Instance.name];
window.CKEDITOR.removeListener(
'instanceReady',
this.$onInstanceReadyListener
);
/**
* event : instance ready
* @param instance
*/
$onInstanceReadyListener: function (instance) {
if (typeof instance.editor === 'undefined' ||
typeof instance.editor.name === 'undefined' ||
instance.editor.name !== this.getAttribute('instancename')) {
containerSize = Container.getSize();
// fckeditor resize, setHeight is sooooooooooo mysterious
instance.editor.resize(containerSize.x, containerSize.y);
this.setInstance(instance.editor);
this.fireEvent('loaded', [this, instance.editor]);
$onResize: function () {
var Container = this.getContainer(),
Instance = this.getInstance(),
/**
* Editor onSetContent Event
*
* @param {String} content
$onSetContent: function (content, Editor) {
if (Editor.getInstance()) {
Editor.getInstance().setData(content);
$onGetContent: function (Editor) {
if (Editor.getInstance()) {
Editor.setAttribute('content', Editor.getInstance().getData());
switchToSource: function () {
if (this.getInstance()) {
this.getInstance().setMode('source');
switchToWYSIWYG: function () {
if (this.getInstance()) {
this.getInstance().setMode('wysiwyg');
hideToolbar: function () {
var Toolbar = this.getElm().getElement('.cke_top');
if (Toolbar) {
Toolbar.setStyle('display', 'none');
showToolbar: function () {
var Toolbar = this.getElm().getElement('.cke_top');
if (Toolbar) {
Toolbar.setStyle('display', null);
setHeight: function (height) {
if (this.getInstance()) {
this.getInstance().resize(false, height);
/**
* Set the height of the instance
*
* @param {Number} width
*/
setWidth: function (width) {
if (this.getInstance()) {
this.getInstance().resize(width, false);
/**
* event : on add css
*
* @param {String} file - path to the css file

Henning Leutz
committed
var Instance = this.getInstance();
var Doc = Editor.getDocument(),
Link = Doc.createElement('link');
Link.href = file;
Link.rel = "stylesheet";
Link.type = "text/css";
for (var i = 0, len = params.length; i < len; i++) {
Instance.insertHtml("<img src=" + params[i].url + " />");
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
}
,
// /**
// * Generate the extra plugins option in dependence of the toolbar
// * @param toolbar
// */
// $parseToolbarToPlugins: function (toolbar) {
// var extra = [],
// buttonList = [];
//
// if (typeOf(toolbar) == 'array') {
// buttonList = toolbar.flatten();
// }
//
// for (var i = 0, len = buttonList.length; i < len; i++) {
// switch (buttonList[i]) {
// case 'Templates':
// extra.push('templates');
// break;
//
// case 'Find':
// case 'Replace':
// extra.push('find');
// break;
//
// case 'SelectAll':
// extra.push('selectall');
// break;
//
// case 'Form':
// case 'Checkbox':
// case 'Radio':
// case 'TextField':
// case 'Textarea':
// case 'Select':
// case 'Button':
// case 'ImageButton':
// case 'HiddenField':
// extra.push('forms');
// break;
//
// case 'CreateDiv':
// extra.push('div');
// break;
//
// case 'JustifyLeft':
// case 'JustifyCenter':
// case 'JustifyRight':
// case 'JustifyBlock':
// extra.push('justify');
// break;
//
// case 'BidiLtr':
// case 'BidiRtl':
// extra.push('bidi');
// break;
//
// case 'Language':
// extra.push('language');
// break;
//
// case 'Link':
// case 'Unlink':
// case 'Anchor':
// extra.push('link');
// break;
//
// case 'Flash':
// extra.push('flash');
// break;
//
// case 'Smiley':
// extra.push('smiley');
// break;
//
// case 'PageBreak':
// extra.push('pagebreak');
// break;
//
// case 'Iframe':
// extra.push('iframe');
// break;
//
// case 'Font':
// case 'FontSize':
// extra.push('font');
// break;
//
// case 'BGColor':
// case 'TextColor':
// extra.push('colorbutton');
// break;
// }
// }
//
// //extra.push('wordcount');
//
// extra = extra.unique();
//
//
// return extra.join(',');
// }
// ,

Henning Leutz
committed
* @param {DOMEvent} ev - CKEvent
* @return {DOMEvent} ev (CKEvent)
// Take the dialog name and its definition from the event data.
var self = this,
dialogName = ev.data.name,
dialogDefinition = ev.data.definition;
var UrlGroup = this.getContentElement('info', 'txtUrl')
var UrlInput = UrlGroup.getElement('input[type="text"]');
var HeightInput = this.getContentElement('info', 'txtHeight')
.getElement().$
.getElement('input[type="text"]');
var WidthInput = this.getContentElement('info', 'txtWidth')
.getElement().$
.getElement('input[type="text"]');
Ajax.get('ajax_media_details', function (fileData) {
if (fileData.image_height > 500 ||
fileData.image_width > 500) {
var result = QUIMath.resizeVar(
fileData.image_height,
fileData.image_width,
500
);
HeightInput.value = result.var1;
WidthInput.value = result.var2;
HeightInput.value = fileData.image_height;
WidthInput.value = fileData.image_width;
}
if (!fileData.image_height) {
HeightInput.value = '';
}
if (!fileData.image_width) {
WidthInput.value = '';
}
var LinkGroup = this.getContentElement('Link', 'txtUrl')
var LinkInput = LinkGroup.getElement('input[type="text"]');
events: {
onSubmit: function (Win, data) {
LinkInput.value = data.urls[0];
var Prev = Button.getPrevious();
Prev.setStyles({
* @param {DOMEvent} ev - CKEvent
* @return {DOMEvent} ev - CKEvent
// Take the dialog name and its definition from the event data.
//dialogDefinition.getContents( 'info' ).remove( 'protocol');
Url = dialogDefinition.getContents('info').get('url'),
orgCommit = Url.commit;
Url.commit = function (data) {
orgCommit.call(this, data);
.getContentElement('info', 'protocol')
.getElement()
.$
.getElement('select');
var self = this,
oldOnShow = dialogDefinition.onShow;
dialogDefinition.onShow = function () {
oldOnShow.bind(this)();
var UrlInput = UrlGroup.getElement('input[type="text"]');
Protokoll = this.getContentElement('info', 'protocol')
.getElement()
.$
.getElement('select');
'float': 'left',
width : UrlInput.getSize().x - 100
events: {
onSubmit: function (Win, data) {
UrlInput.value = data.urls[0];
events: {
onSubmit: function (Win, data) {
UrlInput.value = data.url;