Index: gc_lang/fr/webext/content_scripts/content_modifier.js ================================================================== --- gc_lang/fr/webext/content_scripts/content_modifier.js +++ gc_lang/fr/webext/content_scripts/content_modifier.js @@ -72,11 +72,11 @@ }; let xGCButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Corriger"}); xGCButton.onclick = function() { createGCPanel(); oGCPanel.startWaitIcon(); - oGCPanelContent.start(xTextArea); + oGCPanel.start(xTextArea); xPort.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: xTextArea.value, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sTextAreaId: xTextArea.id} }); @@ -109,42 +109,41 @@ } function createTFPanel (xTextArea) { console.log("Formateur de texte"); if (oTFPanel !== null) { + oTFPanel.setTextArea(xTextArea); oTFPanel.show(); } else { // create the panel - oTFPanel = new GrammalectePanel("grammalecte_tf_panel", "Formateur de texte", 800, 600, false); + oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 800, 600, false); oTFPanel.logInnerHTML(); - oTFPanel.setContentNode(createTextFormatter(xTextArea)); + oTFPanel.setTextArea(xTextArea); oTFPanel.insertIntoPage(); } } function createLxgPanel () { console.log("Lexicographe"); if (oLxgPanel !== null) { - oLxgPanelContent.clear(); + oLxgPanel.clear(); oLxgPanel.show(); } else { // create the panel - oLxgPanel = new GrammalectePanel("grammalecte_lxg_panel", "Lexicographe", 500, 700); - oLxgPanel.setContentNode(oLxgPanelContent.init()); + oLxgPanel = new GrammalecteLexicographer("grammalecte_lxg_panel", "Lexicographe", 500, 700); oLxgPanel.insertIntoPage(); } } function createGCPanel () { console.log("Correction grammaticale"); if (oGCPanel !== null) { - oGCPanelContent.clear(); + oGCPanel.clear(); oGCPanel.show(); } else { // create the panel - oGCPanel = new GrammalectePanel("grammalecte_gc_panel", "Grammalecte", 500, 700); - oGCPanel.setContentNode(oGCPanelContent.init()); + oGCPanel = new GrammalecteGrammarChecker("grammalecte_gc_panel", "Grammalecte", 500, 700); oGCPanel.insertIntoPage(); } } @@ -176,23 +175,23 @@ nTadId = result; break; case "parseAndSpellcheck": console.log("[content script] received: parseAndSpellcheck"); if (!bEnd) { - oGCPanelContent.addParagraphResult(result); + oGCPanel.addParagraphResult(result); } else { oGCPanel.stopWaitIcon(); } break; case "parseAndSpellcheck1": console.log("[content script] received: parseAndSpellcheck1"); - oGCPanelContent.refreshParagraph(dInfo.sParagraphId, result); + oGCPanel.refreshParagraph(dInfo.sParagraphId, result); break; case "getListOfTokens": console.log("[content script] received: getListOfTokens"); if (!bEnd) { - oLxgPanelContent.addListOfTokens(result); + oLxgPanel.addListOfTokens(result); } else { oLxgPanel.stopWaitIcon(); } break; default: Index: gc_lang/fr/webext/content_scripts/gc_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/gc_content.js +++ gc_lang/fr/webext/content_scripts/gc_content.js @@ -5,80 +5,74 @@ function onGrammalecteGCPanelClick (xEvent) { try { let xElem = xEvent.target; if (xElem.id) { if (xElem.id.startsWith("grammalecte_sugg")) { - oGCPanelContent.applySuggestion(xElem.id); + oGCPanel.applySuggestion(xElem.id); } else if (xElem.id === "grammalecte_tooltip_ignore") { - oGCPanelContent.ignoreError(xElem.id); + oGCPanel.ignoreError(xElem.id); } else if (xElem.id.startsWith("grammalecte_check")) { - oGCPanelContent.recheckParagraph(parseInt(xElem.id.slice(17))); + oGCPanel.recheckParagraph(parseInt(xElem.id.slice(17))); } else if (xElem.id.startsWith("grammalecte_hide")) { xElem.parentNode.parentNode.style.display = "none"; } else if (xElem.tagName === "U" && xElem.id.startsWith("grammalecte_err") && xElem.className !== "corrected" && xElem.className !== "ignored") { - oGCPanelContent.oTooltip.show(xElem.id); + oGCPanel.oTooltip.show(xElem.id); } else if (xElem.id === "grammalecte_tooltip_url") { - oGCPanelContent.openURL(xElem.getAttribute("href")); + oGCPanel.openURL(xElem.getAttribute("href")); } else { - oGCPanelContent.oTooltip.hide(); + oGCPanel.oTooltip.hide(); } } else if (xElem.tagName === "A") { - oGCPanelContent.openURL(xElem.getAttribute("href")); + oGCPanel.openURL(xElem.getAttribute("href")); } else { - oGCPanelContent.oTooltip.hide(); + oGCPanel.oTooltip.hide(); } } catch (e) { showError(e); } } -const oGCPanelContent = { +class GrammalecteGrammarChecker extends GrammalectePanel { /* KEYS for identifiers: grammalecte_paragraph{Id} : [paragraph number] grammalecte_check{Id} : [paragraph number] grammalecte_hide{Id} : [paragraph number] grammalecte_error{Id} : [paragraph number]-[error_number] grammalecte_sugg{Id} : [paragraph number]-[error_number]--[suggestion_number] */ - bInitDone: false, - - xContentNode: null, - xParagraphList: null, - - aIgnoredErrors: new Set(), - - init: function () { + constructor (...args) { + super(...args); + this.aIgnoredErrors = new Set(); this.xContentNode = createNode("div", {id: "grammalecte_gc_panel_content"}); this.xParagraphList = createNode("div", {id: "grammalecte_paragraph_list"}); this.xContentNode.appendChild(this.xParagraphList); this.xContentNode.addEventListener("click", onGrammalecteGCPanelClick, false); - this.oTooltip.init(); - this.xContentNode.appendChild(this.oTooltip.xTooltip); - this.bInitDone = true; - return this.xContentNode; - }, + this.oTooltip = new GrammalecteTooltip(this.xContentNode); + this.xPanelContent.appendChild(this.xContentNode); + this.oTAC = new GrammalecteTextAreaControl(); + } - start: function (xTextArea=null) { + start (xTextArea=null) { this.clear(); if (xTextArea) { this.oTAC.setTextArea(xTextArea); } - }, + } - clear: function () { + clear () { while (this.xParagraphList.firstChild) { this.xParagraphList.removeChild(this.xParagraphList.firstChild); } this.aIgnoredErrors.clear(); - }, + } - addParagraphResult: function (oResult) { + addParagraphResult (oResult) { try { if (oResult) { let xNodeDiv = createNode("div", {className: "grammalecte_paragraph_block"}); // actions let xActionsBar = createNode("div", {className: "grammalecte_paragraph_actions"}); @@ -101,13 +95,13 @@ } } catch (e) { showError(e); } - }, + } - recheckParagraph: function (iParaNum) { + recheckParagraph (iParaNum) { let sParagraphId = "grammalecte_paragraph" + iParaNum; let xParagraph = document.getElementById(sParagraphId); this.blockParagraph(xParagraph); let sText = this.purgeText(xParagraph.textContent); xPort.postMessage({ @@ -115,13 +109,13 @@ dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sParagraphId: sParagraphId} }); this.oTAC.setParagraph(iParaNum, sText); this.oTAC.write(); - }, + } - refreshParagraph: function (sParagraphId, oResult) { + refreshParagraph (sParagraphId, oResult) { try { let xParagraph = document.getElementById(sParagraphId); xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph"; xParagraph.textContent = ""; this._tagParagraph(xParagraph, oResult.sParagraph, sParagraphId.slice(21), oResult.aGrammErr, oResult.aSpellErr); @@ -128,17 +122,17 @@ this.freeParagraph(xParagraph); } catch (e) { showError(e); } - }, + } - _tagParagraph: function (xParagraph, sParagraph, iParaNum, aSpellErr, aGrammErr) { + _tagParagraph (xParagraph, sParagraph, iParaNum, aSpellErr, aGrammErr) { try { if (aGrammErr.length === 0 && aSpellErr.length === 0) { xParagraph.textContent = sParagraph; - return + return; } aGrammErr.push(...aSpellErr); aGrammErr.sort(function (a, b) { if (a["nStart"] < b["nStart"]) return -1; @@ -168,13 +162,13 @@ } } catch (e) { showError(e); } - }, + } - _createError: function (sUnderlined, oErr) { + _createError (sUnderlined, oErr) { let xNodeErr = document.createElement("u"); xNodeErr.id = "grammalecte_err" + oErr['sErrorId']; xNodeErr.textContent = sUnderlined; xNodeErr.dataset.error_id = oErr['sErrorId']; xNodeErr.dataset.ignored_key = oErr['sIgnoredKey']; @@ -188,21 +182,23 @@ } xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|"); } xNodeErr.className = (this.aIgnoredErrors.has(xNodeErr.dataset.ignored_key)) ? "ignored" : "error " + oErr['sType']; return xNodeErr; - }, + } - blockParagraph: function (xParagraph) { + blockParagraph (xParagraph) { xParagraph.contentEditable = "false"; - }, + document.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "Analyse…"; + } - freeParagraph: function (xParagraph) { + freeParagraph (xParagraph) { xParagraph.contentEditable = "true"; - }, + document.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "Réanalyser"; + } - applySuggestion: function (sNodeSuggId) { // sugg + applySuggestion (sNodeSuggId) { // sugg try { console.log(sNodeSuggId); let sErrorId = document.getElementById(sNodeSuggId).dataset.error_id; //let sParaNum = sErrorId.slice(0, sErrorId.indexOf("-")); console.log("grammalecte_err"+sErrorId); @@ -214,13 +210,13 @@ this.recheckParagraph(parseInt(sErrorId.slice(0, sErrorId.indexOf("-")))); } catch (e) { showError(e); } - }, + } - ignoreError: function (sIgnoreButtonId) { // ignore + ignoreError (sIgnoreButtonId) { // ignore try { console.log(sIgnoreButtonId); let sErrorId = document.getElementById(sIgnoreButtonId).dataset.error_id; console.log("grammalecte_err"+sErrorId); let xNodeErr = document.getElementById("grammalecte_err" + sErrorId); @@ -229,27 +225,27 @@ this.oTooltip.hide(); } catch (e) { showError(e); } - }, + } - purgeText: function (sText) { + purgeText (sText) { return sText.replace(/ /g, " ").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); - }, + } - addSummary: function () { + addSummary () { // todo - }, + } - addMessage: function (sMessage) { + addMessage (sMessage) { let xNode = createNode("div", {className: "grammalecte_gc_panel_message", textContent: sMessage}); this.xParagraphList.appendChild(xNode); - }, + } - copyToClipboard: function () { - startWaitIcon(); + copyToClipboard () { + this.startWaitIcon(); try { let xClipboardButton = document.getElementById("grammalecte_clipboard_button"); xClipboardButton.textContent = "copie en cours…"; let sText = ""; for (let xNode of document.getElementById("grammalecte_paragraph_list").getElementsByClassName("grammalecte_paragraph")) { @@ -260,47 +256,44 @@ window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 3000); } catch (e) { console.log(e.lineNumber + ": " +e.message); } - stopWaitIcon(); + this.stopWaitIcon(); } } -oGCPanelContent.oTooltip = { - - xTooltip: null, - - xTooltipArrow: createNode("img", { - id: "grammalecte_tooltip_arrow", - src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAECAYAAACzzX7wAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwQAADsEBuJFr7QAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNkRpr/UAAAAlSURBVBhXY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQCF/8HAGUkScGH4cM8AAAAAElFTkSuQmCC", - alt: "^" - }), - - xTooltipSuggBlock: null, - - init: function () { +class GrammalecteTooltip { + + constructor (xContentNode) { this.xTooltip = createNode("div", {id: "grammalecte_tooltip"}); + this.xTooltipArrow = createNode("img", { + id: "grammalecte_tooltip_arrow", + src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAECAYAAACzzX7wAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwQAADsEBuJFr7QAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNkRpr/UAAAAlSURBVBhXY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQCF/8HAGUkScGH4cM8AAAAAElFTkSuQmCC", + alt: "^" + }); + this.xTooltipSuggBlock = createNode("div", {id: "grammalecte_tooltip_sugg_block"}); let xMessageBlock = createNode("div", {id: "grammalecte_tooltip_message_block"}); xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_rule_id"})); xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_message", textContent: "Erreur."})); xMessageBlock.appendChild(createNode("a", {id: "grammalecte_tooltip_ignore", href: "#", onclick: "return false;", textContent: "Ignorer"})); xMessageBlock.appendChild(createNode("a", {id: "grammalecte_tooltip_url", href: "#", onclick: "return false;", textContent: "Voulez-vous en savoir plus ?…"})); this.xTooltip.appendChild(xMessageBlock); this.xTooltip.appendChild(createNode("div", {id: "grammalecte_tooltip_sugg_title", textContent: "SUGGESTIONS :"})); - this.xTooltipSuggBlock = createNode("div", {id: "grammalecte_tooltip_sugg_block"}); this.xTooltip.appendChild(this.xTooltipSuggBlock); - }, + xContentNode.appendChild(this.xTooltip); + xContentNode.appendChild(this.xTooltipArrow); + } - show: function (sNodeErrorId) { // err + show (sNodeErrorId) { // err try { let xNodeErr = document.getElementById(sNodeErrorId); let nLimit = 500 - 330; // paragraph width - tooltip width - this.xTooltipArrow.style.top = (xNodeErr.offsetTop + 16) + "px" - this.xTooltipArrow.style.left = (xNodeErr.offsetLeft + Math.floor((xNodeErr.offsetWidth / 2))-4) + "px" // 4 is half the width of the arrow. + this.xTooltipArrow.style.top = (xNodeErr.offsetTop + 16) + "px"; + this.xTooltipArrow.style.left = (xNodeErr.offsetLeft + Math.floor((xNodeErr.offsetWidth / 2))-4) + "px"; // 4 is half the width of the arrow. this.xTooltip.style.top = (xNodeErr.offsetTop + 20) + "px"; this.xTooltip.style.left = (xNodeErr.offsetLeft > nLimit) ? nLimit + "px" : xNodeErr.offsetLeft + "px"; if (xNodeErr.dataset.error_type === "grammar") { // grammar error if (xNodeErr.dataset.gc_message.includes(" ##")) { @@ -331,11 +324,10 @@ } else { xGCSugg.textContent = "Aucune."; } } this.xTooltipArrow.style.display = "block"; - this.xTooltipArrow.style.border = "10px solid hsl(0, 0%, 0%)"; this.xTooltip.style.display = "block"; if (xNodeErr.dataset.error_type === "spelling") { // spelling mistake document.getElementById("grammalecte_tooltip_message").textContent = "Mot inconnu du dictionnaire."; document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id; @@ -348,31 +340,31 @@ } } catch (e) { showError(e); } - }, + } - setTooltipColor: function (bBlue) { + setTooltipColor () { // todo - }, + } hide () { this.xTooltipArrow.style.display = "none"; this.xTooltip.style.display = "none"; - }, + } - _createSuggestion: function (sErrId, iSugg, sSugg) { + _createSuggestion (sErrId, iSugg, sSugg) { let xNodeSugg = document.createElement("a"); xNodeSugg.id = "grammalecte_sugg" + sErrId + "--" + iSugg.toString(); xNodeSugg.className = "sugg"; xNodeSugg.dataset.error_id = sErrId; xNodeSugg.textContent = sSugg; return xNodeSugg; - }, + } - setSpellSuggestionsFor: function (sWord, sSuggestions, sErrId) { + setSpellSuggestionsFor (sWord, sSuggestions, sErrId) { // spell checking suggestions try { // console.log("setSuggestionsFor: " + sWord + " > " + sSuggestions + " // " + sErrId); let xSuggBlock = document.getElementById("grammalecte_tooltip_sugg_block"); xSuggBlock.textContent = ""; @@ -395,37 +387,37 @@ } } } -oGCPanelContent.oTAC = { - // Text area control - - _xTextArea: null, - - _dParagraph: new Map(), - - setTextArea: function (xNode) { +class GrammalecteTextAreaControl { + + constructor () { + this._xTextArea = null; + this._dParagraph = new Map(); + } + + setTextArea (xNode) { this.clear(); this._xTextArea = xNode; this._xTextArea.disabled = true; this._loadText(); - }, + } - clear: function () { + clear () { if (this._xTextArea !== null) { this._xTextArea.disabled = false; this._xTextArea = null; } this._dParagraph.clear(); - }, + } setParagraph (iParagraph, sText) { if (this._xTextArea !== null) { this._dParagraph.set(iParagraph, sText); } - }, + } _loadText () { let sText = this._xTextArea.value; let i = 0; let iStart = 0; @@ -436,17 +428,17 @@ i++; iStart = iEnd+1; } this._dParagraph.set(i, sText.slice(iStart)); console.log("Paragraphs number: " + (i+1)); - }, + } - write: function () { + write () { if (this._xTextArea !== null) { let sText = ""; this._dParagraph.forEach(function (val, key) { sText += val + "\n"; }); this._xTextArea.value = sText.slice(0,-1); } } } Index: gc_lang/fr/webext/content_scripts/lxg_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/lxg_content.js +++ gc_lang/fr/webext/content_scripts/lxg_content.js @@ -1,37 +1,36 @@ // JavaScript "use strict"; -const oLxgPanelContent = { - - _xContentNode: createNode("div", {id: "grammalecte_lxg_panel_content"}), - - _nCount: 0, - - init: function () { - return this._xContentNode; - }, - - clear: function () { +class GrammalecteLexicographer extends GrammalectePanel { + + constructor (...args) { + super(...args); + this._nCount = 0; + this._xContentNode = createNode("div", {id: "grammalecte_lxg_panel_content"}); + this.xPanelContent.appendChild(this._xContentNode); + } + + clear () { this._nCount = 0; while (this._xContentNode.firstChild) { this._xContentNode.removeChild(this._xContentNode.firstChild); } - }, + } - addSeparator: function (sText) { + addSeparator (sText) { if (this._xContentNode.textContent !== "") { this._xContentNode.appendChild(createNode("div", {className: "grammalecte_lxg_separator", textContent: sText})); } - }, + } - addMessage: function (sClass, sText) { + addMessage (sClass, sText) { this._xContentNode.appendChild(createNode("div", {className: sClass, textContent: sText})); - }, + } - addListOfTokens: function (lTokens) { + addListOfTokens (lTokens) { try { if (lTokens) { this._nCount += 1; let xNodeDiv = createNode("div", {className: "grammalecte_lxg_list_of_tokens"}); xNodeDiv.appendChild(createNode("div", {className: "num", textContent: this._nCount})); @@ -42,13 +41,13 @@ } } catch (e) { showError(e); } - }, + } - _createTokenNode: function (oToken) { + _createTokenNode (oToken) { let xTokenNode = createNode("div", {className: "grammalecte_token"}); xTokenNode.appendChild(createNode("b", {className: oToken.sType, textContent: oToken.sValue})); xTokenNode.appendChild(createNode("s", {textContent: " : "})); if (oToken.aLabel.length === 1) { xTokenNode.appendChild(document.createTextNode(oToken.aLabel[0])); @@ -58,13 +57,13 @@ xTokenList.appendChild(createNode("li", {textContent: sLabel})); } xTokenNode.appendChild(xTokenList); } return xTokenNode; - }, + } - setHidden: function (sClass, bHidden) { + setHidden (sClass, bHidden) { for (let xNode of document.getElementsByClassName(sClass)) { xNode.hidden = bHidden; } } } Index: gc_lang/fr/webext/content_scripts/panels_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/panels_content.js +++ gc_lang/fr/webext/content_scripts/panels_content.js @@ -12,11 +12,11 @@ this.sId = sId; this.sContentId = sId+"_content"; this.nWidth = nWidth; this.nHeight = nHeight; this.bMovable = bMovable; - this.xContentNode = createNode("div", {className: "grammalecte_panel_content"}); + this.xPanelContent = createNode("div", {className: "grammalecte_panel_content"}); this.xWaitIcon = this._createWaitIcon(); this.xPanelNode = this._createPanel(sTitle); this.center(); } @@ -28,11 +28,11 @@ let xTitle = createNode("div", {className: "grammalecte_panel_title"}); xTitle.appendChild(createLogo()); xTitle.appendChild(createNode("div", {className: "grammalecte_panel_label", textContent: sTitle})); xBar.appendChild(xTitle); xPanel.appendChild(xBar); - xPanel.appendChild(this.xContentNode); + xPanel.appendChild(this.xPanelContent); return xPanel; } catch (e) { showError(e); } @@ -70,11 +70,11 @@ xButton.onclick = function () { this.hide(); }.bind(this); // better than writing “let that = this;” before the function? return xButton; } setContentNode (xNode) { - this.xContentNode.appendChild(xNode); + this.xPanelContent.appendChild(xNode); } insertIntoPage () { document.body.appendChild(this.xPanelNode); } @@ -126,10 +126,14 @@ } stopWaitIcon () { this.xWaitIcon.style.visibility = "hidden"; } + + openURL (sURL) { + // todo + } } /* Common functions Index: gc_lang/fr/webext/content_scripts/tf_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/tf_content.js +++ gc_lang/fr/webext/content_scripts/tf_content.js @@ -1,149 +1,168 @@ // JavaScript // Text formatter "use strict"; -function createTextFormatter (xTextArea) { - let xTFNode = document.createElement("div"); - try { - // Options - let xOptions = createNode("div", {id: "grammalecte_tf_options"}); - let xColumn1 = createNode("div", {className: "grammalecte_tf_column"}); - let xSSP = createFieldset("group_ssp", true, "Espaces surnuméraires"); - xSSP.appendChild(createOptionInputAndLabel("o_start_of_paragraph", true, "En début de paragraphe")); - xSSP.appendChild(createOptionInputAndLabel("o_end_of_paragraph", true, "En fin de paragraphe")); - xSSP.appendChild(createOptionInputAndLabel("o_between_words", true, "Entre les mots")); - xSSP.appendChild(createOptionInputAndLabel("o_before_punctuation", true, "Avant les points (.), les virgules (,)")); - xSSP.appendChild(createOptionInputAndLabel("o_within_parenthesis", true, "À l’intérieur des parenthèses")); - xSSP.appendChild(createOptionInputAndLabel("o_within_square_brackets", true, "À l’intérieur des crochets")); - xSSP.appendChild(createOptionInputAndLabel("o_within_quotation_marks", true, "À l’intérieur des guillemets “ et ”")); - let xSpace = createFieldset("group_space", true, "Espaces manquants"); - xSpace.appendChild(createOptionInputAndLabel("o_add_space_after_punctuation", true, "Après , ; : ? ! . …")); - xSpace.appendChild(createOptionInputAndLabel("o_add_space_around_hyphens", true, "Autour des tirets d’incise")); - let xNBSP = createFieldset("group_nbsp", true, "Espaces insécables"); - xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_before_punctuation", true, "Avant : ; ? et !")); - xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_within_quotation_marks", true, "Avec les guillemets « et »")); - xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_before_symbol", true, "Avant % ‰ € $ £ ¥ ˚C")); - xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_within_numbers", true, "À l’intérieur des nombres")); - xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_before_units", true, "Avant les unités de mesure")); - let xDelete = createFieldset("group_delete", true, "Suppressions"); - xDelete.appendChild(createOptionInputAndLabel("o_erase_non_breaking_hyphens", true, "Tirets conditionnels")); - let xColumn2 = createNode("div", {className: "grammalecte_tf_column"}); - let xTypo = createFieldset("group_typo", true, "Signes typographiques"); - xTypo.appendChild(createOptionInputAndLabel("o_ts_apostrophe", true, "Apostrophe (’)")); - xTypo.appendChild(createOptionInputAndLabel("o_ts_ellipsis", true, "Points de suspension (…)")); - xTypo.appendChild(createOptionInputAndLabel("o_ts_dash_middle", true, "Tirets d’incise :")); - xTypo.appendChild(createRadioBoxHyphens("hyphen1", "o_ts_m_dash_middle", "o_ts_n_dash_middle", false)); - xTypo.appendChild(createOptionInputAndLabel("o_ts_dash_start", true, "Tirets en début de paragraphe :")); - xTypo.appendChild(createRadioBoxHyphens("hyphen2", "o_ts_m_dash_start", "o_ts_n_dash_start", true)); - xTypo.appendChild(createOptionInputAndLabel("o_ts_quotation_marks", true, "Modifier les guillemets droits (\" et ')")); - xTypo.appendChild(createOptionInputAndLabel("o_ts_units", true, "Points médians des unités (N·m, Ω·m…)")); - xTypo.appendChild(createOptionInputAndLabel("o_ts_spell", true, "Ligatures (cœur…) et diacritiques (ça, État…)")); - xTypo.appendChild(createRadioBoxLigatures()); - xTypo.appendChild(createLigaturesSelection()); - let xMisc = createFieldset("group_misc", true, "Divers"); - xMisc.appendChild(createOptionInputAndLabel("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)")); - xMisc.appendChild(createOptionInputAndLabel("o_etc", true, "Et cætera, etc.")); - xMisc.appendChild(createOptionInputAndLabel("o_missing_hyphens", true, "Traits d’union manquants")); - xMisc.appendChild(createOptionInputAndLabel("o_ma_word", true, "Apostrophes manquantes")); - let xStruct = createFieldset("group_struct", false, "Restructuration [!]"); - xStruct.appendChild(createOptionInputAndLabel("o_remove_hyphens_at_end_of_paragraphs", false, "Enlever césures en fin de ligne/paragraphe [!]")); - xStruct.appendChild(createOptionInputAndLabel("o_merge_contiguous_paragraphs", false, "Fusionner les paragraphes contigus [!]")); - xColumn1.appendChild(xSSP); - xColumn1.appendChild(xSpace); - xColumn1.appendChild(xNBSP); - xColumn1.appendChild(xDelete); - xColumn2.appendChild(xTypo); - xColumn2.appendChild(xMisc); - xColumn2.appendChild(xStruct); - xOptions.appendChild(xColumn1); - xOptions.appendChild(xColumn2); - // Actions - let xActions = createNode("div", {id: "grammalecte_tf_actions"}); - xActions.appendChild(createNode("div", {id: "grammalecte_tf_reset", textContent: "Par défaut", className: "grammalecte_button", style: "background-color: hsl(210, 50%, 50%)"})); - xActions.appendChild(createNode("progress", {id: "grammalecte_tf_progressbar"})); - xActions.appendChild(createNode("span", {id: "grammalecte_tf_time_res"})); - xActions.appendChild(createNode("div", {id: "grammalecte_tf_apply", textContent: "Appliquer", className: "grammalecte_button", style: "background-color: hsl(180, 50%, 50%)"})); - //xActions.appendChild(createNode("div", {id: "grammalecte_infomsg", textContent: "blabla"})); - // create result - xTFNode.appendChild(xOptions); - xTFNode.appendChild(xActions); - } - catch (e) { - //console.error(e); - showError(e); - } - return xTFNode; -} - - -/* - Common options -*/ -function createFieldset (sId, bDefault, sLabel) { - let xFieldset = createNode("fieldset", {id: sId, className: "groupblock"}); - let xLegend = document.createElement("legend"); - xLegend.appendChild(createNode("input", {type: "checkbox", id: "o_"+sId, className: "option"}, {default: bDefault})); - xLegend.appendChild(createNode("label", {htmlFor: "o_"+sId, textContent: sLabel})); - xFieldset.appendChild(xLegend); - return xFieldset; -} - -function createOptionInputAndLabel (sId, bDefault, sLabel) { - let xOption = createNode("div", {className: "blockopt underline"}); - xOption.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); - xOption.appendChild(createNode("label", {htmlFor: sId, textContent: sLabel, className: "opt_lbl largew"})); - xOption.appendChild(createNode("div", {id: "res_"+sId, className: "grammalecte_tf_result", textContent: "9999"})); - return xOption; -} - - -/* - Hyphens -*/ -function createRadioBoxHyphens (sName, sIdEmDash, sIdEnDash, bDefaultEmDash) { - let xLine = createNode("div", {className: "blockopt"}); - xLine.appendChild(createNode("input", {type: "radio", id: sIdEmDash, name: sName, className:"option"}, {default: bDefaultEmDash})); - xLine.appendChild(createNode("label", {htmlFor: sIdEmDash, className: "opt_lbl", textContent: "cadratin (—)"})); - xLine.appendChild(createNode("input", {type: "radio", id: sIdEnDash, name: sName, className:"option"}, {default: !bDefaultEmDash})); - xLine.appendChild(createNode("label", {htmlFor: sIdEnDash, className: "opt_lbl", textContent: "demi-cadratin (–)"})); - return xLine; -} - - -/* - Ligatures -*/ -function createRadioBoxLigatures () { - let xLine = createNode("div", {className: "blockopt underline"}); - xLine.appendChild(createOptionInputAndLabel("o_ts_ligature", true, "Ligatures")); - xLine.appendChild(createNode("input", {type: "radio", id: "o_ts_ligature_do", name: "liga", className:"option"}, {default: false})); - xLine.appendChild(createNode("label", {htmlFor: "o_ts_ligature_do", className: "opt_lbl", textContent: "faire"})); - xLine.appendChild(createNode("input", {type: "radio", id: "o_ts_ligature_undo", name: "liga", className:"option"}, {default: true})); - xLine.appendChild(createNode("label", {htmlFor: "o_ts_ligature_undo", className: "opt_lbl", textContent: "défaire"})); - return xLine; -} - -function createLigaturesSelection () { - let xLine = createNode("div", {className: "blockopt"}); - xLine.appendChild(createLigatureCheckboxAndLabel("o_ts_ligature_ff", "ff", true)); - xLine.appendChild(createLigatureCheckboxAndLabel("o_ts_ligature_fi", "fi", true)); - xLine.appendChild(createLigatureCheckboxAndLabel("o_ts_ligature_ffi", "ffi", true)); - xLine.appendChild(createLigatureCheckboxAndLabel("o_ts_ligature_fl", "fl", true)); - xLine.appendChild(createLigatureCheckboxAndLabel("o_ts_ligature_ffl", "ffl", true)); - xLine.appendChild(createLigatureCheckboxAndLabel("o_ts_ligature_ft", "ft", true)); - xLine.appendChild(createLigatureCheckboxAndLabel("o_ts_ligature_st", "st", false)); - return xLine; -} - -function createLigatureCheckboxAndLabel (sId, sLabel, bDefault) { - let xInlineBlock = createNode("div", {style: "display: inline-block;"}); - xInlineBlock.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); - xInlineBlock.appendChild(createNode("label", {htmlFor: sId, className: "opt_lbl", textContent: sLabel})); - return xInlineBlock; -} + +class GrammalecteTextFormatter extends GrammalectePanel { + + constructor (...args) { + super(...args); + this.xTFNode = this._createTextFormatter(); + this.xPanelContent.appendChild(this.xTFNode); + this.xTextArea = null; + } + + setTextArea (xTextArea) { + this.xTextArea = xTextArea; + } + + _createTextFormatter () { + let xTFNode = document.createElement("div"); + try { + // Options + let xOptions = createNode("div", {id: "grammalecte_tf_options"}); + let xColumn1 = createNode("div", {className: "grammalecte_tf_column"}); + let xSSP = this._createFieldset("group_ssp", true, "Espaces surnuméraires"); + xSSP.appendChild(this._createSimpleOption("o_start_of_paragraph", true, "En début de paragraphe")); + xSSP.appendChild(this._createSimpleOption("o_end_of_paragraph", true, "En fin de paragraphe")); + xSSP.appendChild(this._createSimpleOption("o_between_words", true, "Entre les mots")); + xSSP.appendChild(this._createSimpleOption("o_before_punctuation", true, "Avant les points (.), les virgules (,)")); + xSSP.appendChild(this._createSimpleOption("o_within_parenthesis", true, "À l’intérieur des parenthèses")); + xSSP.appendChild(this._createSimpleOption("o_within_square_brackets", true, "À l’intérieur des crochets")); + xSSP.appendChild(this._createSimpleOption("o_within_quotation_marks", true, "À l’intérieur des guillemets “ et ”")); + let xSpace = this._createFieldset("group_space", true, "Espaces manquants"); + xSpace.appendChild(this._createSimpleOption("o_add_space_after_punctuation", true, "Après , ; : ? ! . …")); + xSpace.appendChild(this._createSimpleOption("o_add_space_around_hyphens", true, "Autour des tirets d’incise")); + let xNBSP = this._createFieldset("group_nbsp", true, "Espaces insécables"); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_punctuation", true, "Avant : ; ? et !")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_within_quotation_marks", true, "Avec les guillemets « et »")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_symbol", true, "Avant % ‰ € $ £ ¥ ˚C")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_within_numbers", true, "À l’intérieur des nombres")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_units", true, "Avant les unités de mesure")); + let xDelete = this._createFieldset("group_delete", true, "Suppressions"); + xDelete.appendChild(this._createSimpleOption("o_erase_non_breaking_hyphens", true, "Tirets conditionnels")); + let xColumn2 = createNode("div", {className: "grammalecte_tf_column"}); + let xTypo = this._createFieldset("group_typo", true, "Signes typographiques"); + xTypo.appendChild(this._createSimpleOption("o_ts_apostrophe", true, "Apostrophe (’)")); + xTypo.appendChild(this._createSimpleOption("o_ts_ellipsis", true, "Points de suspension (…)")); + xTypo.appendChild(this._createSimpleOption("o_ts_dash_middle", true, "Tirets d’incise :")); + xTypo.appendChild(this._createRadioBoxHyphens("hyphen1", "o_ts_m_dash_middle", "o_ts_n_dash_middle", false)); + xTypo.appendChild(this._createSimpleOption("o_ts_dash_start", true, "Tirets en début de paragraphe :")); + xTypo.appendChild(this._createRadioBoxHyphens("hyphen2", "o_ts_m_dash_start", "o_ts_n_dash_start", true)); + xTypo.appendChild(this._createSimpleOption("o_ts_quotation_marks", true, "Modifier les guillemets droits (\" et ')")); + xTypo.appendChild(this._createSimpleOption("o_ts_units", true, "Points médians des unités (N·m, Ω·m…)")); + xTypo.appendChild(this._createSimpleOption("o_ts_spell", true, "Ligatures (cœur…) et diacritiques (ça, État…)")); + xTypo.appendChild(this._createRadioBoxLigatures()); + xTypo.appendChild(this._createLigaturesSelection()); + let xMisc = this._createFieldset("group_misc", true, "Divers"); + xMisc.appendChild(this._createSimpleOption("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)")); + xMisc.appendChild(this._createSimpleOption("o_etc", true, "Et cætera, etc.")); + xMisc.appendChild(this._createSimpleOption("o_missing_hyphens", true, "Traits d’union manquants")); + xMisc.appendChild(this._createSimpleOption("o_ma_word", true, "Apostrophes manquantes")); + let xStruct = this._createFieldset("group_struct", false, "Restructuration [!]"); + xStruct.appendChild(this._createSimpleOption("o_remove_hyphens_at_end_of_paragraphs", false, "Enlever césures en fin de ligne/paragraphe [!]")); + xStruct.appendChild(this._createSimpleOption("o_merge_contiguous_paragraphs", false, "Fusionner les paragraphes contigus [!]")); + xColumn1.appendChild(xSSP); + xColumn1.appendChild(xSpace); + xColumn1.appendChild(xNBSP); + xColumn1.appendChild(xDelete); + xColumn2.appendChild(xTypo); + xColumn2.appendChild(xMisc); + xColumn2.appendChild(xStruct); + xOptions.appendChild(xColumn1); + xOptions.appendChild(xColumn2); + // Actions + let xActions = createNode("div", {id: "grammalecte_tf_actions"}); + xActions.appendChild(createNode("div", {id: "grammalecte_tf_reset", textContent: "Par défaut", className: "grammalecte_button", style: "background-color: hsl(210, 50%, 50%)"})); + xActions.appendChild(createNode("progress", {id: "grammalecte_tf_progressbar"})); + xActions.appendChild(createNode("span", {id: "grammalecte_tf_time_res"})); + xActions.appendChild(createNode("div", {id: "grammalecte_tf_apply", textContent: "Appliquer", className: "grammalecte_button", style: "background-color: hsl(180, 50%, 50%)"})); + //xActions.appendChild(createNode("div", {id: "grammalecte_infomsg", textContent: "blabla"})); + // create result + xTFNode.appendChild(xOptions); + xTFNode.appendChild(xActions); + } + catch (e) { + //console.error(e); + showError(e); + } + return xTFNode; + } + + /* + Common options + */ + _createFieldset (sId, bDefault, sLabel) { + let xFieldset = createNode("fieldset", {id: sId, className: "groupblock"}); + let xLegend = document.createElement("legend"); + xLegend.appendChild(createNode("input", {type: "checkbox", id: "o_"+sId, className: "option"}, {default: bDefault})); + xLegend.appendChild(createNode("label", {htmlFor: "o_"+sId, textContent: sLabel})); + xFieldset.appendChild(xLegend); + return xFieldset; + } + + _createSimpleOption (sId, bDefault, sLabel) { + let xOption = createNode("div", {className: "blockopt underline"}); + xOption.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); + xOption.appendChild(createNode("label", {htmlFor: sId, textContent: sLabel, className: "opt_lbl largew"})); + xOption.appendChild(createNode("div", {id: "res_"+sId, className: "grammalecte_tf_result", textContent: "9999"})); + return xOption; + } + + + /* + Hyphens + */ + _createRadioBoxHyphens (sName, sIdEmDash, sIdEnDash, bDefaultEmDash) { + let xLine = createNode("div", {className: "blockopt"}); + xLine.appendChild(createNode("input", {type: "radio", id: sIdEmDash, name: sName, className:"option"}, {default: bDefaultEmDash})); + xLine.appendChild(createNode("label", {htmlFor: sIdEmDash, className: "opt_lbl", textContent: "cadratin (—)"})); + xLine.appendChild(createNode("input", {type: "radio", id: sIdEnDash, name: sName, className:"option"}, {default: !bDefaultEmDash})); + xLine.appendChild(createNode("label", {htmlFor: sIdEnDash, className: "opt_lbl", textContent: "demi-cadratin (–)"})); + return xLine; + } + + + /* + Ligatures + */ + _createRadioBoxLigatures () { + let xLine = createNode("div", {className: "blockopt underline"}); + xLine.appendChild(this._createSimpleOption("o_ts_ligature", true, "Ligatures")); + xLine.appendChild(createNode("input", {type: "radio", id: "o_ts_ligature_do", name: "liga", className:"option"}, {default: false})); + xLine.appendChild(createNode("label", {htmlFor: "o_ts_ligature_do", className: "opt_lbl", textContent: "faire"})); + xLine.appendChild(createNode("input", {type: "radio", id: "o_ts_ligature_undo", name: "liga", className:"option"}, {default: true})); + xLine.appendChild(createNode("label", {htmlFor: "o_ts_ligature_undo", className: "opt_lbl", textContent: "défaire"})); + return xLine; + } + + _createLigaturesSelection () { + let xLine = createNode("div", {className: "blockopt"}); + xLine.appendChild(this._createLigatureCheckboxAndLabel("o_ts_ligature_ff", "ff", true)); + xLine.appendChild(this._createLigatureCheckboxAndLabel("o_ts_ligature_fi", "fi", true)); + xLine.appendChild(this._createLigatureCheckboxAndLabel("o_ts_ligature_ffi", "ffi", true)); + xLine.appendChild(this._createLigatureCheckboxAndLabel("o_ts_ligature_fl", "fl", true)); + xLine.appendChild(this._createLigatureCheckboxAndLabel("o_ts_ligature_ffl", "ffl", true)); + xLine.appendChild(this._createLigatureCheckboxAndLabel("o_ts_ligature_ft", "ft", true)); + xLine.appendChild(this._createLigatureCheckboxAndLabel("o_ts_ligature_st", "st", false)); + return xLine; + } + + _createLigatureCheckboxAndLabel (sId, sLabel, bDefault) { + let xInlineBlock = createNode("div", {style: "display: inline-block;"}); + xInlineBlock.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); + xInlineBlock.appendChild(createNode("label", {htmlFor: sId, className: "opt_lbl", textContent: sLabel})); + return xInlineBlock; + } +} + + + + + let sTFinnerHTML = ' \ \
\
\