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, QUIStringUtils, 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
const Editor = QUI.Controls.getById(ev.editor.name);

Henning Leutz
committed
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) {
const Editor = QUI.Controls.getById(ev.editor.name);

Henning Leutz
committed
Editor.$imageDialog(ev);

Henning Leutz
committed
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
*
$loadInstance: function (data) {
if (typeof window.CKEDITOR === 'undefined') {
const self = this,
Container = this.getContainer();
let Textarea = false,
size = Container.getSize();
if (!Textarea) {
Textarea = Container.getElement('textarea');
if (window.CKEDITOR.instances[instance]) {
window.CKEDITOR.instances[instance].destroy(true);
const 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');
const zIndex = QUIElements.getComputedZIndex(Container);
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) {

Florian Bogner
committed
plugins = self.$parseToolbarToPlugins(toolbar).concat(plugins);
plugins = plugins.unique();
const pluginPath = config.pluginPath;
const extraPlugins = plugins.join(",");
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: 'figure(*)[*]{*}; figcaption; 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;
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')) {
const Container = this.getContainer(),
containerSize = Container.getSize();
// fckeditor resize, setHeight is sooooooooooo mysterious
instance.editor.resize(containerSize.x, containerSize.y);
this.fireEvent('loaded', [
this,
instance.editor
]);
const Container = this.getContainer(),
Instance = this.getInstance(),
containerSize = Container.getSize();
/**
* 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');
const Toolbar = this.getElm().getElement('.cke_top');
if (Toolbar) {
Toolbar.setStyle('display', 'none');
const 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
const Doc = Editor.getDocument(),
Link = Doc.createElement('link');
for (let 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) {
buttonList = [];
buttonList = toolbar.flatten();
}
for (let i = 0, len = buttonList.length; i < len; i++) {
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
569
570
571
572
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');
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
642
643
644
645
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.
const self = this,
dialogName = ev.data.name,
dialogDefinition = ev.data.definition;
if (dialogName !== 'image') {
const UrlGroup = this.getContentElement('info', 'txtUrl')
.getElement().$;
const UrlInput = UrlGroup.getElement('input[type="text"]');
/*
let HeightInput = this.getContentElement('info', 'txtHeight')
.getElement().$
.getElement('input[type="text"]');
const WidthInput = this.getContentElement('info', 'txtWidth')
.getElement().$
.getElement('input[type="text"]');
UrlGroup.getElement('label').setStyles({
'float': 'left',
'width': '100%'
});
let fileId = false;
if (UrlInput.value !== '') {
let urlParams = QUIStringUtils.getUrlParams(UrlInput.value);
if (typeof urlParams.project !== 'undefined' &&
typeof urlParams.id !== 'undefined' &&
urlParams.project === self.$Project.getName()) {
fileId = urlParams.id;
}
}
Ajax.get('ajax_media_details', function (fileData) {
if (fileData.image_height > 500 ||
fileData.image_width > 500) {
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 = '';
}
const LinkGroup = this.getContentElement('Link', 'txtUrl').getElement().$;
const LinkInput = LinkGroup.getElement('input[type="text"]');
events: {
onSubmit: function (Win, data) {
LinkInput.value = data.urls[0];
$image2Dialog: function (ev) {
// Take the dialog name and its definition from the event data.
const self = this,
dialogName = ev.data.name,
dialogDefinition = ev.data.definition;
/**
* Image dialog
*/
if (dialogName !== 'image2') {
return ev;
}
// Get a reference to the "Link Info" tab.
dialogDefinition.onShow = function () {
oldOnShow.bind(this)();
const UrlGroup = this.getContentElement('info', 'src')
.getElement().$;
/*
let HeightInput = this.getContentElement('info', 'height')
.getElement().$
.getElement('input[type="text"]');
const WidthInput = this.getContentElement('info', 'width')
.getElement().$
.getElement('input[type="text"]');
const UrlInput = UrlGroup.getElement('input[type="text"]');
if (!UrlGroup.getElement('.qui-button')) {
new Element('button', {
'class': 'qui-button',
html : '<span class="fa fa-picture-o"></span>',
styles : {
margin: 0
},
events : {
click: function () {
let fileId = false;
if (UrlInput.value !== '') {
let urlParams = QUIStringUtils.getUrlParams(UrlInput.value);
if (typeof urlParams.project !== 'undefined' &&
typeof urlParams.id !== 'undefined' &&
urlParams.project === self.$Project.getName()) {
fileId = urlParams.id;
}
}
events: {
onSubmit: function (Win, data) {
UrlInput.value = data.url;
Ajax.get('ajax_media_details', function (fileData) {
if (fileData.image_height > 500 ||
fileData.image_width > 500) {
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
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;
} else {
// HeightInput.value = fileData.image_height;
WidthInput.value = fileData.image_width;
}
// if (!fileData.image_height) {
// HeightInput.value = '';
// }
if (!fileData.image_width) {
WidthInput.value = '';
}
}, {
project: data.project,
fileid : data.id
});
}
}
});
}
}
}).inject(UrlGroup);
UrlInput.setStyle('float', 'left');
UrlInput.setStyle('width', 'calc(100% - 35px)');
UrlInput.setStyle('lineHeight', 20);
}
console.log(UrlInput);
};
},
* @param {DOMEvent} ev - CKEvent
* @return {DOMEvent} ev - CKEvent
// Take the dialog name and its definition from the event data.
//dialogDefinition.getContents( 'info' ).remove( 'protocol');
const dialogDefinition = ev.data.definition,
Url = dialogDefinition.getContents('info').get('url'),
orgCommit = Url.commit;
Url.commit = function (data) {
orgCommit.call(this, data);
.getContentElement('info', 'protocol')
.getElement()
.$
.getElement('select');
const self = this,
oldOnShow = dialogDefinition.onShow;

Jan Wennrich
committed
self.$turnLinkRelInputToSelect(dialogDefinition);
dialogDefinition.onShow = function () {
oldOnShow.bind(this)();
const UrlGroup = this.getContentElement('info', 'url')
.getElement()
const UrlInput = UrlGroup.getElement('input[type="text"]');
Protokoll = this.getContentElement('info', 'protocol')
.getElement()
.$
.getElement('select');
'float': 'left',
width : UrlInput.getSize().x - 100