REFACTOR: refactor js files

REFACTOR: refactor js files

diff --git a/assets/javascripts/discourse/initializers/checklist.js.es6 b/assets/javascripts/discourse/initializers/checklist.js.es6
index 1fd4665..9befebb 100644
--- a/assets/javascripts/discourse/initializers/checklist.js.es6
+++ b/assets/javascripts/discourse/initializers/checklist.js.es6
@@ -16,53 +16,52 @@ export function checklistSyntax($elem, post) {
     return;
   }
 
-  var boxes = $elem.find(".chcklst-box"),
-    viewPost = post.getModel();
+  const $boxes = $elem.find(".chcklst-box");
+  const postModel = post.getModel();
 
-  if (!viewPost.can_edit) {
+  if (!postModel.can_edit) {
     return;
   }
 
-  boxes.each(function(idx, val) {
-    $(val).click(function(ev) {
-      var elem = $(ev.currentTarget),
-        new_value = elem.hasClass("checked") ? "[ ]" : "[\\*]";
+  $boxes.each((idx, val) => {
+    $(val).click(ev => {
+      const $box = $(ev.currentTarget);
+      const newValue = $box.hasClass("checked") ? "[ ]" : "[\\*]";
 
-      elem.after(iconHTML("spinner", { class: "fa-spin" }));
-      elem.hide();
+      $box.after(iconHTML("spinner", { class: "fa-spin" })).hide();
 
-      const endpoint = Discourse.getURL(`/posts/${viewPost.id}`);
-      AjaxLib.ajax(endpoint, { type: "GET", cache: false }).then(
-        function(result) {
-          var nth = -1, // make the first run go to index = 0
-            new_raw = result.raw.replace(/\[(\s|\_|\-|\x|\\?\*)?\]/gi, function(
-              match
-            ) {
-              nth += 1;
-              return nth === idx ? new_value : match;
-            });
+      const endpoint = Discourse.getURL(`/posts/${postModel.id}`);
+      AjaxLib.ajax(endpoint, { type: "GET", cache: false }).then(result => {
+        // make the first run go to index = 0
+        let nth = -1;
+        const newRaw = result.raw.replace(
+          /\[(\s|\_|\-|\x|\\?\*)?\]/gi,
+          match => {
+            nth += 1;
+            return nth === idx ? newValue : match;
+          }
+        );
 
-          var props = {
-            raw: new_raw,
-            edit_reason: I18n.t("checklist.edit_reason")
-          };
+        const props = {
+          raw: newRaw,
+          edit_reason: I18n.t("checklist.edit_reason")
+        };
 
-          if (TextLib.cookAsync) {
-            TextLib.cookAsync(new_raw).then(cooked => {
-              props.cooked = cooked.string;
-              viewPost.save(props);
-            });
-          } else {
-            props.cooked = TextLib.cook(new_raw).string;
-            viewPost.save(props);
-          }
+        if (TextLib.cookAsync) {
+          TextLib.cookAsync(newRaw).then(cooked => {
+            props.cooked = cooked.string;
+            postModel.save(props);
+          });
+        } else {
+          props.cooked = TextLib.cook(newRaw).string;
+          postModel.save(props);
         }
-      );
+      });
     });
   });
 
   // confirm the feature is enabled by showing the click-ability
-  boxes.css({ cursor: "pointer" });
+  $boxes.css({ cursor: "pointer" });
 }
 
 export default {
diff --git a/assets/javascripts/lib/discourse-markdown/checklist.js.es6 b/assets/javascripts/lib/discourse-markdown/checklist.js.es6
index 91e1790..d8526ae 100644
--- a/assets/javascripts/lib/discourse-markdown/checklist.js.es6
+++ b/assets/javascripts/lib/discourse-markdown/checklist.js.es6
@@ -18,24 +18,25 @@ function getClasses(str) {
 }
 
 function addCheckbox(result, content, match, state) {
-  let classes = getClasses(match[1]);
-  let token = new state.Token("check_open", "span", 1);
-  token.attrs = [["class", `chcklst-box ${classes}`]];
-  result.push(token);
+  const classes = getClasses(match[1]);
 
-  token = new state.Token("check_close", "span", -1);
-  result.push(token);
+  const checkOpenToken = new state.Token("check_open", "span", 1);
+  checkOpenToken.attrs = [["class", `chcklst-box ${classes}`]];
+  result.push(checkOpenToken);
+
+  const checkCloseToken = new state.Token("check_close", "span", -1);
+  result.push(checkCloseToken);
 }
 
 function applyCheckboxes(content, state) {
-  let result = null,
-    pos = 0,
-    match;
+  let match;
+  let result = null;
+  let pos = 0;
 
   while ((match = REGEX.exec(content))) {
     if (match.index > pos) {
       result = result || [];
-      let token = new state.Token("text", "", 0);
+      const token = new state.Token("text", "", 0);
       token.content = content.slice(pos, match.index);
       result.push(token);
     }
@@ -47,7 +48,7 @@ function applyCheckboxes(content, state) {
   }
 
   if (result && pos < content.length) {
-    let token = new state.Token("text", "", 0);
+    const token = new state.Token("text", "", 0);
     token.content = content.slice(pos);
     result.push(token);
   }
@@ -78,7 +79,7 @@ function processChecklist(state) {
       nesting += token.nesting;
 
       if (token.type === "text" && nesting === 0) {
-        let processed = applyCheckboxes(token.content, state);
+        const processed = applyCheckboxes(token.content, state);
         if (processed) {
           blockTokens[j].children = tokens = state.md.utils.arrayReplaceAt(
             tokens,
@@ -105,7 +106,7 @@ export function setup(helper) {
     "span.chcklst-box checked fa fa-check-square-o fa-fw"
   ]);
 
-  helper.registerPlugin(md => {
-    md.core.ruler.push("checklist", processChecklist);
-  });
+  helper.registerPlugin(md =>
+    md.core.ruler.push("checklist", processChecklist)
+  );
 }

GitHub sha: d4cdb3d7