Grammalecte  Diff

Differences From Artifact [dcb12b523e]:

To Artifact [bfa5c54a5e]:


1
2
3
4
5

6














7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25









26


27





28



29




30


31




32




33
























































34
35
36
37
38
39
40
// JavaScript
// Panel creator

"use strict";

















function createPanelFrame (sId, sTitle) {
    try {
        let xPanel = createNode("div", {id: sId, className: "grammalecte_panel"});
        let xBar = createNode("div", {className: "grammalecte_title_bar"});
        xBar.appendChild(createCloseButton(xPanel));
        let xTitle = createNode("div", {className: "grammalecte_title"});
        xTitle.appendChild(createLogo());
        xTitle.appendChild(createNode("div", {className: "grammalecte_label", textContent: "Grammalecte · " + sTitle}));
        xBar.appendChild(xTitle);
        xPanel.appendChild(xBar);
        //xPanel.appendChild(createNode("div", {className: "grammalecte_empty_space_under_title_bar"}));
        xPanel.appendChild(createNode("div", {id: sId+"_content", className: "grammalecte_panel_content"}));
        return xPanel;
    }
    catch (e) {
        showError(e);
    }
}










function createCloseButton (xParentNode) {


    let xButton = document.createElement("div");





    xButton.className = "grammalecte_close_button";



    xButton.textContent = "×";




    xButton.onclick = function () {


        xParentNode.style.display = "none";




    }




    return xButton;
























































}


/*
    Common functions
*/
function createNode (sType, oAttr) {





>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

>
>
>
>
>
>
>
>
>
|
>
>
|
>
>
>
>
>
|
>
>
>
|
>
>
>
>
|
>
>
|
>
>
>
>

>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
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
// JavaScript
// Panel creator

"use strict";

console.log("[Content script] Panel creator");


class GrammalectePanel {

    constructor (sId, sTitle, nWidth, nHeight, bMovable=true) {
        this.sId = sId;
        this.sContentId = sId+"_content";
        this.nWidth = nWidth;
        this.nHeight = nHeight;
        this.bMovable = bMovable;
        this.xContentNode = createNode("div", {id: this.sContentId, className: "grammalecte_panel_content"});
        this.xPanelNode = this._createPanel(sTitle);
        this.center();
    }

    _createPanel (sTitle) {
        try {
            let xPanel = createNode("div", {id: this.sId, className: "grammalecte_panel"});
            let xBar = createNode("div", {className: "grammalecte_panel_bar"});
            xBar.appendChild(this._createButtons());
            let xTitle = createNode("div", {className: "grammalecte_panel_title"});
            xTitle.appendChild(createLogo());
            xTitle.appendChild(createNode("div", {className: "grammalecte_panel_label", textContent: "Grammalecte · " + sTitle}));
            xBar.appendChild(xTitle);
            xPanel.appendChild(xBar);
            //xPanel.appendChild(createNode("div", {className: "grammalecte_empty_space_under_title_bar"}));
            xPanel.appendChild(this.xContentNode);
            return xPanel;
        }
        catch (e) {
            showError(e);
        }
    }

    _createButtons () {
        let xButtonLine = createNode("div", {className: "grammalecte_panel_commands"});
        if (this.bMovable) {
            xButtonLine.appendChild(this._createMoveButtonTop());
            xButtonLine.appendChild(this._createMoveButtonLeft());
            xButtonLine.appendChild(this._createMoveButtonMiddle());
            xButtonLine.appendChild(this._createMoveButtonRight());
            xButtonLine.appendChild(this._createMoveButtonBottom());
        }
        xButtonLine.appendChild(this._createCloseButton());
        return xButtonLine;
    }

    _createMoveButtonLeft () {
        let xButton = createNode("div", {className: "grammalecte_move_button", textContent: "‹"});
        xButton.onclick = function () { this.stickToLeft(); }.bind(this);
        return xButton;
    }

    _createMoveButtonMiddle () {
        let xButton = createNode("div", {className: "grammalecte_move_button", textContent: "·"});
        xButton.onclick = function () { this.center(); }.bind(this);
        return xButton;
    }

    _createMoveButtonRight () {
        let xButton = createNode("div", {className: "grammalecte_move_button", textContent: "›"});
        xButton.onclick = function () { this.stickToRight(); }.bind(this);
        return xButton;
    }

    _createMoveButtonTop () {
        let xButton = createNode("div", {className: "grammalecte_move_button", textContent: "^"});
        xButton.onclick = function () { this.stickToTop(); }.bind(this);
        return xButton;
    }

    _createMoveButtonBottom () {
        let xButton = createNode("div", {className: "grammalecte_move_button", textContent: "ˇ"});
        xButton.onclick = function () { this.stickToBottom(); }.bind(this);
        return xButton;
    }

    _createCloseButton () {
        let xButton = createNode("div", {className: "grammalecte_close_button", textContent: "×"});
        xButton.onclick = function () { this.hide(); }.bind(this);  // better than writing “let that = this;” before the function?
        return xButton;
    }

    setContent (xNode) {
        this.xContentNode.appendChild(xNode);
    }

    insertIntoPage () {
        document.body.appendChild(this.xPanelNode);
    }

    show () {
        this.xPanelNode.style.display = "block";
    }

    hide () {
        this.xPanelNode.style.display = "none";
    }

    center () {
        this.xPanelNode.style = `top: 50%; left: 50%; width: ${this.nWidth}px; height: ${this.nHeight}px; margin-top: -${this.nHeight/2}px; margin-left: -${this.nWidth/2}px;`;
    }

    stickToLeft () {
        let nHeight = window.innerHeight-100;
        this.xPanelNode.style = `top: 50%; left: -10px; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px;`;
    }

    stickToRight () {
        let nHeight = window.innerHeight-100;
        this.xPanelNode.style = `top: 50%; right: -10px; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px;`;
    }

    stickToTop () {
        let nWidth = Math.floor(window.innerWidth/2);
        this.xPanelNode.style = `top: -10px; left: 50%; width: ${nWidth}px; height: ${Math.floor(window.innerHeight*0.45)}px; margin-left: -${nWidth/2}px;`;
    }

    stickToBottom () {
        let nWidth = Math.floor(window.innerWidth/2);
        this.xPanelNode.style = `bottom: -10px; left: 50%; width: ${nWidth}px; height: ${Math.floor(window.innerHeight*0.45)}px; margin-left: -${nWidth/2}px;`;
    }

    reduce () {
        // todo
    }

    logInnerHTML () {
        // for debugging
        console.log(this.xPanelNode.innerHTML);
    }
}


/*
    Common functions
*/
function createNode (sType, oAttr) {