Passed
Push — main ( fac3c3...502827 )
by Stefan
02:24
created

script/FormCKEdit.js   A

Complexity

Total Complexity 18
Complexity/F 3

Size

Lines of Code 91
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 18
eloc 61
mnd 12
bc 12
fnc 6
dl 0
loc 91
rs 10
bpm 2
cpm 3
noi 7
c 0
b 0
f 0
1
function loadEditor()
2
{
3
    var oEditor = null;
0 ignored issues
show
Unused Code introduced by
The assignment to oEditor seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
4
    
5
    var oTA = document.getElementById(g_oConfigFromPHP.CKEditor.editorID);
0 ignored issues
show
Bug introduced by
The variable g_oConfigFromPHP seems to be never declared. If this is a global, consider adding a /** global: g_oConfigFromPHP */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
6
    if (!oTA) {
7
        displayJSError('Element [' + g_oConfigFromPHP.CKEditor.editorID + 'to be replaced by CKEditor not exists!', 'error');
8
        return;
9
    }
10
    // get initial size of textarea to replace
11
    var iHeight = oTA.offsetHeight;
12
    var iWidth = oTA.offsetWidth;
13
    oEditor = CKEDITOR.replace(g_oConfigFromPHP.CKEditor.editorID, g_oConfigFromPHP.CKEditor.editorOptions);
0 ignored issues
show
Bug introduced by
The variable CKEDITOR seems to be never declared. If this is a global, consider adding a /** global: CKEDITOR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
14
15
    // custom buttons
16
    if (Array.isArray(g_oConfigFromPHP.CKEditor.customButtons)) {
17
        let length = g_oConfigFromPHP.CKEditor.customButtons.length;
18
        for (let i = 0; i < length; i++) {
19
            let btn = g_oConfigFromPHP.CKEditor.customButtons[i];
20
            
21
            var exec = window[btn.func];
22
            if (typeof exec === "function") {
23
                oEditor.addCommand('cmd_' + btn.func, {exec: function(oEditor) {window[btn.func](oEditor);}});
24
                oEditor.ui.addButton(btn.func, {label: btn.name, command: 'cmd_' + btn.func, icon: btn.icon});
25
            } else {
26
                displayJSError('Handler for Custom Button [' + btn.func + '] is not defined!', 'error');
27
            }
28
        }
29
    }
30
31
    // resize to desired size
32
    CKEDITOR.on('instanceReady', function(event) {event.editor.resize(iWidth, iHeight);});
33
34
    if (g_oConfigFromPHP.CKEditor.editorData !== undefined) {
35
        oEditor.setData(g_oConfigFromPHP.CKEditor.editorData);
36
    }
37
38
    if (g_oConfigFromPHP.RichFilemanager === undefined) {
39
        return;
40
    }
41
    // check filemanager...
42
    CKEDITOR.on('dialogDefinition', function (event) {
43
        var editor = event.editor;
44
        var dialogDefinition = event.data.definition;
45
        var dialogName = event.data.name;
46
        var cleanUpFuncRef = CKEDITOR.tools.addFunction(function () {
0 ignored issues
show
Bug introduced by
The variable CKEDITOR seems to be never declared. If this is a global, consider adding a /** global: CKEDITOR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
47
            let oIFrame = document.getElementById('fm-iframeCKE');
48
            if (oIFrame) {
49
                oIFrame.remove();
50
            }
51
            document.body.style.overflowY = 'scroll';
52
        });
53
            
54
        var tabCount = dialogDefinition.contents.length;
55
        for (var i = 0; i < tabCount; i++) {
56
            var dialogTab = dialogDefinition.contents[i];
57
            if (!(dialogTab && typeof dialogTab.get === 'function')) {
58
                continue;
59
            }
60
                
61
            var browseButton = dialogTab.get('browse');
62
            if (browseButton !== null) {
63
                browseButton.hidden = false;
64
                var params = 
65
                    '?CKEditorFuncNum=' + CKEDITOR.instances[event.editor.name]._.filebrowserFn +
66
                    '&CKEditorCleanUpFuncNum=' + cleanUpFuncRef +
67
                    '&langCode=' + g_oConfigFromPHP.RichFilemanager.language +
0 ignored issues
show
Bug introduced by
The variable g_oConfigFromPHP seems to be never declared. If this is a global, consider adding a /** global: g_oConfigFromPHP */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
68
                    '&CKEditor=' + event.editor.name;
69
                    
70
                if (dialogName == 'link') {
71
                    params += '&expandedFolder=' + g_oConfigFromPHP.RichFilemanager.expandFolder.browseLinkURL;
72
                } else if (dialogTab.id == 'info') {
73
                    params += '&expandedFolder=' + g_oConfigFromPHP.RichFilemanager.expandFolder.browseImageURL;
74
                } else {
75
                    params += '&expandedFolder=' + g_oConfigFromPHP.RichFilemanager.expandFolder.browseImageLinkURL;
76
                }
77
                browseButton.filebrowser.params = params;
78
                browseButton.onClick = function (dialog, i) {
0 ignored issues
show
Unused Code introduced by
The parameter i is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
79
                    editor._.filebrowserSe = this;
80
                    
81
                    let oIFrame = document.createElement('iframe');
82
                    oIFrame.id = 'fm-iframeCKE';
83
                    oIFrame.className = 'fm-modal';
84
                    oIFrame.src = g_oConfigFromPHP.RichFilemanager.Path + dialog.sender.filebrowser.params;
0 ignored issues
show
Bug introduced by
The variable g_oConfigFromPHP seems to be never declared. If this is a global, consider adding a /** global: g_oConfigFromPHP */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
85
                    document.body.append(oIFrame);
86
                    document.body.style.overflowY = 'hidden';
87
                }
88
            }
89
        }
90
    });
91
}
92