Grammalecte  Diff

Differences From Artifact [ada45d4995]:

To Artifact [66d684a48e]:


41
42
43
44
45
46
47
48
49


50
51
52
53
54
55
56
41
42
43
44
45
46
47


48
49
50
51
52
53
54
55
56







-
-
+
+







    });
}
*/


const oGrammalecte = {

    nMenu: 0,
    lMenu: [],
    nButton: 0,
    lButton: [],

    oTFPanel: null,
    oGCPanel: null,

    oMessageBox: null,

    xRightClickedNode: null,
83
84
85
86
87
88
89
90
91


92
93
94
95
96
97
98


99
100
101
102
103
104
105

106
107
108
109
110
111
112
113


114
115
116
117
118
119


120
121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136

137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
83
84
85
86
87
88
89


90
91
92
93
94
95
96


97
98
99
100
101
102
103
104

105
106
107
108
109
110
111


112
113
114
115
116
117


118
119
120
121
122
123
124
125

126



127
128
129
130

131

132
133
134

135
136
137
138
139
140
141
142

143
144
145
146
147
148
149







-
-
+
+





-
-
+
+






-
+






-
-
+
+




-
-
+
+






-
+
-
-
-




-

-
+


-
+







-








    _createButtons: function (oOptions) {
        if (oOptions.hasOwnProperty("ui_options")) {
            this.oOptions = oOptions.ui_options;
            if (this.oOptions.textarea) {
                for (let xNode of document.getElementsByTagName("textarea")) {
                    if (xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && xNode.getAttribute("spellcheck") !== "false") {
                        this.lMenu.push(new GrammalecteButton(this.nMenu, xNode));
                        this.nMenu += 1;
                        this.lButton.push(new GrammalecteButton(this.nButton, xNode));
                        this.nButton += 1;
                    }
                }
            }
            if (this.oOptions.editablenode) {
                for (let xNode of document.querySelectorAll("[contenteditable]")) {
                    this.lMenu.push(new GrammalecteButton(this.nMenu, xNode));
                    this.nMenu += 1;
                    this.lButton.push(new GrammalecteButton(this.nButton, xNode));
                    this.nButton += 1;
                }
            }
        }
    },

    observePage: function () {
        //    When a textarea is added via jascript we add the menu
        // When a textarea is added via jascript we add the menu
        let that = this;
        this.xObserver = new MutationObserver(function (mutations) {
            mutations.forEach(function (mutation) {
                for (let i = 0;  i < mutation.addedNodes.length;  i++){
                    if (mutation.addedNodes[i].tagName == "TEXTAREA") {
                        if (that.oOptions === null || that.oOptions.textarea) {
                            oGrammalecte.lMenu.push(new GrammalecteButton(oGrammalecte.nMenu, mutation.addedNodes[i]));
                            oGrammalecte.nMenu += 1;
                            oGrammalecte.lButton.push(new GrammalecteButton(oGrammalecte.nButton, mutation.addedNodes[i]));
                            oGrammalecte.nButton += 1;
                        }
                    } else if (mutation.addedNodes[i].getElementsByTagName) {
                        if (that.oOptions === null || that.oOptions.textarea) {
                            for (let xNode of mutation.addedNodes[i].getElementsByTagName("textarea")) {
                                oGrammalecte.lMenu.push(new GrammalecteButton(oGrammalecte.nMenu, xNode));
                                oGrammalecte.nMenu += 1;
                                oGrammalecte.lButton.push(new GrammalecteButton(oGrammalecte.nButton, xNode));
                                oGrammalecte.nButton += 1;
                            }
                        }
                    }
                }
            });
        });
        this.xObserver.observe(document.body, {
        this.xObserver.observe(document.body, { childList: true, subtree: true });
            childList: true,
            subtree: true
        });
    },

    rescanPage: function () {
        if (this.oTFPanel !== null) { this.oTFPanel.hide(); }
        //if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); }
        if (this.oGCPanel !== null) { this.oGCPanel.hide(); }
        for (let oMenu of this.lMenu) {
        for (let oMenu of this.lButton) {
            oMenu.deleteNodes();
        }
        this.lMenu.length = 0; // to clear an array
        this.lButton.length = 0; // to clear an array
        this.listenRightClick();
        this.createButtons();
    },

    createTFPanel: function () {
        if (this.oTFPanel === null) {
            this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 595, false);
            //this.oTFPanel.logInnerHTML();
            this.oTFPanel.insertIntoPage();
            window.setTimeout( () => { this.oTFPanel.adjustHeight(); }, 50);
        }
    },

    createGCPanel: function () {
        if (this.oGCPanel === null) {
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
330
331
332
333
334
335
336

337
338
339
340
341
342
343







-







            oGrammalecte.startGCPanel();
            // selected text is sent to the GC worker in the background script.
            break;
        // rescan page command
        case "rescanPage":
            oGrammalecte.rescanPage();
            break;

    }
});


/*
    Other messages from background
*/