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);

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
*
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: '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;
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 = [];
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
569
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');
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
642
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({
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
$image2Dialog: function (ev) {
// Take the dialog name and its definition from the event data.
var self = this,
dialogName = ev.data.name,
dialogDefinition = ev.data.definition;
/**
* Image dialog
*/
if (dialogName !== 'image2') {
return ev;
}
var oldOnShow = dialogDefinition.onShow;
// Get a reference to the "Link Info" tab.
dialogDefinition.onShow = function () {
var Button;
oldOnShow.bind(this)();
console.log(this);
// image button
var UrlGroup = this.getContentElement('info', 'src')
.getElement().$;
var HeightInput = this.getContentElement('info', 'height')
.getElement().$
.getElement('input[type="text"]');
var WidthInput = this.getContentElement('info', 'width')
.getElement().$
.getElement('input[type="text"]');
console.log('#############');
console.log(UrlGroup);
var 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 () {
self.openMedia({
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) {
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;
} 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');
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
*