Grammalecte  Check-in [5bc013ac26]

Overview
Comment:Auto Add button in tinymce zone
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | comunicate
Files: files | file ages | folders
SHA3-256: 5bc013ac26e2c50bd6277d30666743e5094279795e123155d26853fee1a46f27
User & Date: IllusionPerdu on 2018-11-07 22:52:52
Other Links: branch diff | manifest | tags
Context
2018-11-07
23:57
Auto add fix if they are not button defined before check-in: 13ca4224a8 user: IllusionPerdu tags: comunicate
22:52
Auto Add button in tinymce zone check-in: 5bc013ac26 user: IllusionPerdu tags: comunicate
11:59
Oups forgettent to change variable name check-in: 7eb5a85846 user: IllusionPerdu tags: comunicate
Changes

Modified gc_lang/fr/webext/content_scripts/event.js from [8e71634c5b] to [e6245afd69].

22
23
24
25
26
27
28
































































29
30
31
32
33
34
35
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    document.dispatchEvent(eventGrammalecte);
    return dataToSend.IdAction;
}

// On informe la page qu'il y a Grammalecte ;)
var customAPILoaded = new CustomEvent('GrammalecteIsLoaded');
document.dispatchEvent(customAPILoaded);

// Gros Hack : Auto add a button in tinymce ;)
// Page to test v4 https://www.quackit.com/html/html_editors/tinymce_editor.cfm
// Page to test v3 http://www.imathas.com/editordemo/demo.html
if (typeof tinymce !== "undefined" && tinymce.majorVersion && tinymce.majorVersion >= 3 && tinymce.majorVersion <= 5) {
    //console.log("Have TinyMCE");
    let TinyOnEditor = function(event, editor = null) {
        let xEditorAdd = editor || event.editor;
        let bIsAdded = false;

        if ( tinymce.majorVersion >= 4 ){
            let aBtn = ["toolbar3", "toolbar2", "toolbar1", "toolbar"];
            let nBtn = aBtn.length;
            let iBtn = 0;
            for (let eBtn of aBtn){
                if ((!bIsAdded && typeof xEditorAdd.settings[eBtn] !== "undefined") || iBtn == nBtn){
                    bIsAdded = true;
                    xEditorAdd.settings[eBtn] = (xEditorAdd.settings[eBtn] + " Grammalecte").trim()
                }
                iBtn++;
            }
        } else if ( tinymce.majorVersion >= 3 ){
            let aBtn = ["theme_advanced_buttons3", "theme_advanced_buttons2", "theme_advanced_buttons1"];
            let nBtn = aBtn.length;
            let iBtn = 0;
            for (let eBtn of aBtn){
                if ((!bIsAdded && typeof xEditorAdd.settings[eBtn] !== "undefined") || iBtn == nBtn){
                    bIsAdded = true;
                    xEditorAdd.settings[eBtn] = (xEditorAdd.settings[eBtn] + ",Grammalecte").trim()
                }
                iBtn++;
            }
        }

        xEditorAdd.addButton("Grammalecte", {
            text: "",
            icon: false,
            image:
                "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAC8UlEQVQ4jX3TbUgTcRwH8P89ddu5u9tt082aZmpFEU4tFz0QGTUwCi0heniR9MSUIKRaD0RvIlKigsooo+iNFa0XJYuwIjEK19OcDtPElsG0ktyp591t7u7+vUh7MPX3+vf5/n8/+P0BmKJIPUUVlh2rdVVeesWlzEybqg+bFOsoylnqPmNavGFfknV2Omu2Lvja3vxAURKJib3opHizu8riLK6gjRyuKgmoSoMRFENRUqfXTzvBGK62LC2uoFkOl4RhjQ8+qWt7dPNE3sbdp+2LXbsGe9qb4rIo/BfwFy6nWQ4ThWGNDzbcfu29dMDh2nHU7CypYNLmzTda0/L5cNuzmDQi/A4Y27k6eQxLI79wS/11D0AAMNvs6XT6ojVJjJEgTbMy2BT77xBMp09KcpaWV1uc41jQoi0NdUHfjeOO9WWn7AVF7s7n986SithPJGeupBh2PCSP/xxqxAp3eq6wuUV7Wc6MSZIEhA8vHjbfOe/OcW3zmAuKy+nUzAyD2bow8ODaEROFq8AyZ5WBYdEZXGqGxZ61HJV+9HYCJRbTNA0QBA40HWunaKN5dKg/DBKxeCIe09Th/m4MJwiMSZmLEzMQAABQRuNqgu8NYX3doTcMpvCkLbtQZ2AJkrPOZG1zlnY13T+Hy9EehY90h57eqcorcZ/lctZuMzAsOjLEqwNv66/6vZcPYRBC+C3cGaBxhSet2av1BpYgTTY7k5y2JPT41slIR6Axv8R9nnOs+4Pf+2r992uOxGVJwgAAAEINfgt3BGgsESWtWas1iGDyl+CT/u7WpvxNFRc4x7qtBoZFhSFejb7z1fq9NYfjsiT+cwcQavBruCOgU4SIGo18amuoq3Js3FNlynVtH385+s53ze+t8cRkURx3yMTTRBAEQVAUXbFlf3XystJKA2NExeFBdWASDAAA+MQACCEEmqbJ0b6PMC7JwhDU8YFHV5u9NZ64LErT/oW/63tPV6uJwmKoOND78u7Fg5NhAAD4CVbzY9cwrWQrAAAAAElFTkSuQmCC",
            onclick: function(e) {
                //console.log( editorAdd.getContent() );
                //console.log( editorAdd.getBody().innerText )
                let sText = xEditorAdd.getBody().innerText;
                sendToGrammalecte({ spellcheck: sText });
            }
        });
    };
    if ( tinymce.majorVersion >= 4 ){
        tinymce.on("AddEditor", TinyOnEditor);
    } else if ( tinymce.majorVersion >= 3 ){
        tinymce.onAddEditor.add(TinyOnEditor);
    }

    for (var i = tinymce.editors.length - 1; i > -1; i--) {
        let idTiny = tinymce.editors[i].id;
        if ( tinymce.majorVersion >= 4 ){
            tinymce.execCommand("mceRemoveEditor", true, idTiny);
            tinymce.execCommand("mceAddEditor", true, idTiny);
        } else if ( tinymce.majorVersion >= 3 ){
            tinymce.execCommand("mceRemoveControl", true, idTiny);
            tinymce.execCommand("mceAddControl", true, idTiny);
        }
    }
}

/* // ! In the webpage script :
document.addEventListener('GrammalecteIsLoaded', function() {
    // Le gestionnaire d'évènement est prêt!
    // La page web peut effectuer des actions
    ...
});