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) {
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
*
$loadInstance: function (data) {
if (typeof window.CKEDITOR === 'undefined') {
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 (buttonEntry.type == 'seperator') {
group.push('-');
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'
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'],

Henning Leutz
committed
baseFloatZIndex : zIndex,
extraPlugins : self.$parseToolbarToPlugins(toolbar)
});
},
/**
* Editor onDestroy Event
*
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);
}
},
/**
* Editor onGetContent Event
*
$onGetContent: function (Editor) {
if (Editor.getInstance()) {
Editor.setAttribute('content', Editor.getInstance().getData());
this.getInstance().focus();
}
},
/**
* Switch to source mode
*/
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);
}
},
/**
* Set the height of the instance
*
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 + " />");

Henning Leutz
committed
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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
/**
* 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 = extra.unique();
return extra.join(',');
},
* @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')
.getElement()
.$;
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')
.getElement()
.$;
var LinkInput = LinkGroup.getElement('input[type="text"]');
events: {
onSubmit: function (Win, data) {
LinkInput.value = data.urls[0];
var Prev = Button.getPrevious();
Prev.setStyles({
return ev;
},
/**
* edit the link dialog
*
* @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 UrlGroup = this.getContentElement('info', 'url')
.getElement()
.$;
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;