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'
/**
* Control Constructor
* @param Manager
* @param options
*/
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);
Editor.$html5AudioDialog(ev);
Editor.$html5VideoDialog(ev);

Henning Leutz
committed
});
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'
data.cssFiles.push(
URL_OPT_DIR + 'quiqqer/quiqqer/bin/css/fonts/font-awesome.min.css'
);

Florian Bogner
committed
Settings.getConfig().then(function (config) {
var plugins = config.plugins;

Florian Bogner
committed
plugins = self.$parseToolbarToPlugins(toolbar).concat(plugins);
plugins = plugins.unique();
var pluginPath = config.pluginPath;
var i, len, pluginName;
for (i = 0, len = plugins.length; i < len; i++) {
pluginName = plugins[i];
if (!window.CKEDITOR.plugins.get(pluginName)) {
window.CKEDITOR.plugins.addExternal(
pluginName,
pluginPath + "/bin/" + pluginName + "/",
""
);
skinName : 'moono-lisa',
customConfig : '',
language : Locale.getCurrent(),
baseHref : URL_DIR,
basePath : URL_DIR,
height : height,
width : width,
toolbar : toolbar,
allowedContent : true,
extraAllowedContent: 'iframe(*)[*]{*}; img(*)[*]{*}; script(*)[*]{*}; ins(*)[*]{*}',
protectedSource : [/<ins[\s|\S]+?<\/ins>/g],
stylesSet : styles,
contentsCss : data.cssFiles || [],
bodyClass : data.bodyClass,
// templates_files : [URL_OPT_DIR +'base/bin/pcsgEditorPlugins/templates.php'],
baseFloatZIndex: zIndex,
extraPlugins : extraPlugins,

Florian Bogner
committed
//removePlugins : 'scayt',
disableNativeSpellChecker: config.disableNativeSpellChecker,
autoGrow_onStartup : false,
resize_enabled : false
// because of font awesome
window.CKEDITOR.dtd.$removeEmpty.span = false;
window.CKEDITOR.dtd.$removeEmpty.i = false;
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 + " />");
/**
* Generate the extra plugins option in dependence of the toolbar
* @param toolbar
*
* @return Array
*/
$parseToolbarToPlugins: function (toolbar) {
var extra = [],
buttonList = [];
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
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
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;
case 'Code':
extra.push('codetag');
break;
case 'Image':
extra.push('image');
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
break;
case 'Zoom':
extra.push('zoom');
break;
case 'Youtube':
extra.push('youtube');
break;
case 'Videodetector':
extra.push('videodetector');
break;
case 'Tweetabletext':
extra.push('tweetabletext');
break;
case 'Createtoken':
extra.push('token');
break;
case 'TransformTextSwitcher':
case 'TransformTextToLowercase':
case 'TransformTextToUppercase':
case 'TransformTextCapitalize':
extra.push('texttransform');
break;
case 't2s_button':
extra.push('text2speech');
break;
case 'Symbol':
extra.push('symbol');
break;
case 'pre':
extra.push('pre');
break;
case 'pbckeditor':
extra.push('pbckeditor');
break;
case 'page2images':
extra.push('page2images');
break;
case 'Markdown':
extra.push('markdown');
break;
case 'Loremipsum':
extra.push('loremipsum');
break;
case 'inserthtml4x':
extra.push('inserthtml4x');
break;
case 'Html5Video':
extra.push('html5video');
break;
case 'Html5Audio':
extra.push('html5audio');
break;
case 'EqnEditor':
extra.push('eqneditor');
break;
case 'cssanim':
extra.push('cssanim');
break;
case 'WebSpeechEnabled':
case 'WebSpeechSettings':
extra.push('ckwebspeech');
break;
case 'base64image':
extra.push('base64image');
break;
case 'AutoCorrect':
extra.push('autocorrect');
break;
}
}
return extra;
},
* @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;
if (dialogName !== 'image') {
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"]');
UrlGroup.getElement('label').setStyles({
'float': 'left',
'width': '100%'
});
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
);
// es darf keine image height gesetzt
// da das Bild sonst im mobile view sich verzieht
// 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({
* @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;

Jan Wennrich
committed
self.$turnLinkRelInputToSelect(dialogDefinition);
dialogDefinition.onShow = function () {
oldOnShow.bind(this)();
.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;
return ev;
},
/**
* Extends the Html5Audio Dialog
*
* @param {DOMEvent} ev - CKEvent
* @return {DOMEvent} ev - CKEvent
*/
$html5AudioDialog: function (ev) {
var dialogname = ev.data.name,
dialogDefinition = ev.data.definition,
Button = null;
if (dialogname !== "html5audio") {
return ev;
}
var self = this;
var oldOnShow = dialogDefinition.onShow || function () {
};
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
dialogDefinition.onShow = function () {
oldOnShow.bind(this)();
var UrlGroup = this.getContentElement("info", "url").getElement().$;
if (UrlGroup.getElement('.qui-button')) {
return;
}
var UrlInput = UrlGroup.getElement('input[type="text"]');
Button = new Element('button', {
'class': 'qui-button',
html : '<span class="fa fa-picture-o"></span>',
events : {
click: function () {
self.openMedia({
events: {
onSubmit: function (Win, data) {
UrlInput.value = data.url;
}
}
});
}
},
style : {
float: "left"
}
}).inject(UrlGroup);
var Label = UrlGroup.getElement("label");
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
Label.setStyles({
width : "100%",
display: "block"
});
Button.getPrevious().setStyles({
'width': '85%',
float : "left"
});
};
return ev;
},
$html5VideoDialog: function (ev) {
var dialogname = ev.data.name,
dialogDefinition = ev.data.definition,
Button = null;
if (dialogname !== "html5video") {
return ev;
}
var self = this;
var oldOnShow = dialogDefinition.onShow || function () {
};
dialogDefinition.onShow = function () {
oldOnShow.bind(this)();
var UrlGroup = this.getContentElement("info", "url").getElement().$;
if (UrlGroup.getElement('.qui-button')) {
return;
}
var UrlInput = UrlGroup.getElement('input[type="text"]');
Button = new Element('button', {
'class': 'qui-button',
html : '<span class="fa fa-picture-o"></span>',