DEV: remove old code, refactor jQuery call

DEV: remove old code, refactor jQuery call

diff --git a/app/assets/javascripts/discourse/components/d-editor-modal.js.es6 b/app/assets/javascripts/discourse/components/d-editor-modal.js.es6
deleted file mode 100644
index 4085b8c..0000000
--- a/app/assets/javascripts/discourse/components/d-editor-modal.js.es6
+++ /dev/null
@@ -1,61 +0,0 @@
-import { observes, on } from "ember-addons/ember-computed-decorators";
-
-export default Ember.Component.extend({
-  classNameBindings: [":d-editor-modal", "hidden"],
-
-  @observes("hidden")
-  _hiddenChanged() {
-    if (!this.hidden) {
-      Ember.run.scheduleOnce("afterRender", () => {
-        const $modal = $(this.element);
-        const $parent = $(this.element).closest(".d-editor");
-        const w = $parent.width();
-        const h = $parent.height();
-        const dir = $("html").css("direction") === "rtl" ? "right" : "left";
-        const offset = w / 2 - $modal.outerWidth() / 2;
-        $modal.css(dir, offset + "px");
-        parent
-          .$(".d-editor-overlay")
-          .removeClass("hidden")
-          .css({ width: w, height: h });
-        this.$("input:eq(0)").focus();
-      });
-    } else {
-      parent.$(".d-editor-overlay").addClass("hidden");
-    }
-  },
-
-  @on("didInsertElement")
-  _listenKeys() {
-    $(this.element).on("keydown.d-modal", key => {
-      if (this.hidden) {
-        return;
-      }
-
-      if (key.keyCode === 27) {
-        this.send("cancel");
-        return false;
-      }
-      if (key.keyCode === 13) {
-        this.send("ok");
-        return false;
-      }
-    });
-  },
-
-  @on("willDestroyElement")
-  _stopListening() {
-    $(this.element).off("keydown.d-modal");
-  },
-
-  actions: {
-    ok() {
-      this.set("hidden", true);
-      this.okAction();
-    },
-
-    cancel() {
-      this.set("hidden", true);
-    }
-  }
-});
diff --git a/app/assets/javascripts/discourse/components/d-modal.js.es6 b/app/assets/javascripts/discourse/components/d-modal.js.es6
index f3ed9bc..8c46fc4 100644
--- a/app/assets/javascripts/discourse/components/d-modal.js.es6
+++ b/app/assets/javascripts/discourse/components/d-modal.js.es6
@@ -51,7 +51,7 @@ export default Ember.Component.extend({
   triggerClickOnEnter(e) {
     // skip when in a form or a textarea element
     if (
-      $(e.target).parents("form").length > 0 ||
+      e.target.closest("form") ||
       (document.activeElement && document.activeElement.nodeName === "TEXTAREA")
     ) {
       return false;
diff --git a/app/assets/javascripts/discourse/templates/components/d-editor-modal.hbs b/app/assets/javascripts/discourse/templates/components/d-editor-modal.hbs
deleted file mode 100644
index 9c1426e..0000000
--- a/app/assets/javascripts/discourse/templates/components/d-editor-modal.hbs
+++ /dev/null
@@ -1,8 +0,0 @@
-{{#unless hidden}}
-  {{yield}}
-
-  <div class="controls">
-    {{d-button class="btn-primary" label="composer.modal_ok" action=(action "ok")}}
-    {{d-button class="btn-danger" label="composer.modal_cancel" action=(action "cancel")}}
-  </div>
-{{/unless}}

GitHub sha: 04452e74

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: