From 5e2a27a1828a14471587ba04601b05d76e411aa5 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 2 Nov 2020 15:43:30 -0500 Subject: [PATCH] Replace `setClassPresence(x, ...)` with `x.classList.toggle(...)` --- src/static/js/ace2_inner.js | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 928b15c1..789f7395 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -556,7 +556,7 @@ function Ace2Inner(){ { doesWrap = newVal; var dwClass = "doesWrap"; - setClassPresence(root, "doesWrap", doesWrap); + root.classList.toggle('doesWrap', doesWrap); scheduler.setTimeout(function() { inCallStackIfNecessary("setWraps", function() @@ -618,7 +618,7 @@ function Ace2Inner(){ { setDesignMode(true); } - setClassPresence(root, "static", !isEditable); + root.classList.toggle('static', !isEditable); } function enforceEditability() @@ -890,25 +890,17 @@ function Ace2Inner(){ // @param value the value to set to editorInfo.ace_setProperty = function(key, value) { - - // Convinience function returning a setter for a class on an element - var setClassPresenceNamed = function(element, cls){ - return function(value){ - setClassPresence(element, cls, !! value) - } - }; - // These properties are exposed var setters = { wraps: setWraps, - showsauthorcolors: setClassPresenceNamed(root, "authorColors"), - showsuserselections: setClassPresenceNamed(root, "userSelections"), + showsauthorcolors: (val) => root.classList.toggle('authorColors', !!val), + showsuserselections: (val) => root.classList.toggle('userSelections', !!val), showslinenumbers : function(value){ hasLineNumbers = !! value; - setClassPresence(sideDiv.parentNode, "line-numbers-hidden", !hasLineNumbers); + sideDiv.parentNode.classList.toggle('line-numbers-hidden', !hasLineNumbers); fixView(); }, - grayedout: setClassPresenceNamed(outerWin.document.body, "grayedout"), + grayedout: (val) => outerWin.document.body.classList.toggle('grayedout', !!val), dmesg: function(){ dmesg = window.dmesg = value; }, userauthor: function(value){ thisAuthor = String(value); @@ -917,8 +909,8 @@ function Ace2Inner(){ styled: setStyled, textface: setTextFace, rtlistrue: function(value) { - setClassPresence(root, "rtl", value) - setClassPresence(root, "ltr", !value) + root.classList.toggle('rtl', value); + root.classList.toggle('ltr', !value); document.documentElement.dir = value? 'rtl' : 'ltr' } }; @@ -4916,12 +4908,6 @@ function Ace2Inner(){ elem.className = array.join(' '); } - function setClassPresence(elem, className, present) - { - if (present) $(elem).addClass(className); - else $(elem).removeClass(className); - } - function focus() { window.focus(); @@ -5335,8 +5321,8 @@ function Ace2Inner(){ if (browser.firefox) $(root).addClass("mozilla"); if (browser.safari) $(root).addClass("safari"); if (browser.msie) $(root).addClass("msie"); - setClassPresence(root, "authorColors", true); - setClassPresence(root, "doesWrap", doesWrap); + root.classList.toggle('authorColors', true); + root.classList.toggle('doesWrap', doesWrap); initDynamicCSS();