diff --git a/app/assets/javascripts/discourse/app/components/composer-body.js b/app/assets/javascripts/discourse/app/components/composer-body.js index 0827c1f3ad4..2d9414dec42 100644 --- a/app/assets/javascripts/discourse/app/components/composer-body.js +++ b/app/assets/javascripts/discourse/app/components/composer-body.js @@ -7,7 +7,6 @@ import discourseComputed, { import Component from "@ember/component"; import Composer from "discourse/models/composer"; import KeyEnterEscape from "discourse/mixins/key-enter-escape"; -import afterTransition from "discourse/lib/after-transition"; import discourseDebounce from "discourse-common/lib/debounce"; import { headerOffset } from "discourse/lib/offset-calculator"; import positioningWorkaround from "discourse/lib/safari-hacks"; @@ -181,7 +180,7 @@ export default Component.extend(KeyEnterEscape, { }; triggerOpen(); - afterTransition($(this.element), () => { + this.element.addEventListener("transitionend", () => { triggerOpen(); }); diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.js index ee429bf5b2a..2c973bb1e69 100644 --- a/app/assets/javascripts/discourse/app/components/quote-button.js +++ b/app/assets/javascripts/discourse/app/components/quote-button.js @@ -1,4 +1,3 @@ -import afterTransition from "discourse/lib/after-transition"; import { propertyEqual } from "discourse/lib/computed"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; @@ -412,25 +411,27 @@ export default Component.extend(KeyEnterEscape, { this.editPost(postModel); - afterTransition(document.querySelector("#reply-control"), () => { - const textarea = document.querySelector(".d-editor-input"); - if (!textarea || this.isDestroyed || this.isDestroying) { - return; - } + document + .querySelector("#reply-control") + ?.addEventListener("transitionend", () => { + const textarea = document.querySelector(".d-editor-input"); + if (!textarea || this.isDestroyed || this.isDestroying) { + return; + } - // best index brings us to one row before as slice start from 1 - // we add 1 to be at the beginning of next line, unless we start from top - setCaretPosition( - textarea, - rows.slice(0, bestIndex).join("\n").length + - (bestIndex > 0 ? 1 : 0) - ); + // best index brings us to one row before as slice start from 1 + // we add 1 to be at the beginning of next line, unless we start from top + setCaretPosition( + textarea, + rows.slice(0, bestIndex).join("\n").length + + (bestIndex > 0 ? 1 : 0) + ); - // ensures we correctly scroll to caret and reloads composer - // if we do another selection/edit - textarea.blur(); - textarea.focus(); - }); + // ensures we correctly scroll to caret and reloads composer + // if we do another selection/edit + textarea.blur(); + textarea.focus(); + }); } ); } diff --git a/app/assets/javascripts/discourse/app/lib/after-transition.js b/app/assets/javascripts/discourse/app/lib/after-transition.js deleted file mode 100644 index 70edaaf8436..00000000000 --- a/app/assets/javascripts/discourse/app/lib/after-transition.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - CSS transitions are a PITA, often we need to queue some js after a transition, this helper ensures - it happens after the transition. - - SO: http://stackoverflow.com/questions/9943435/css3-animation-end-techniques -**/ -let dummy = document.createElement("div"), - eventNameHash = { - webkit: "webkitTransitionEnd", - Moz: "transitionend", - O: "oTransitionEnd", - ms: "MSTransitionEnd", - }; - -let transitionEnd = (function () { - let retValue; - retValue = "transitionend"; - Object.keys(eventNameHash).some(function (vendor) { - if (vendor + "TransitionProperty" in dummy.style) { - retValue = eventNameHash[vendor]; - return true; - } - }); - return retValue; -})(); - -export default function (element, callback) { - return $(element).on(transitionEnd, (event) => { - if (event.target !== event.currentTarget) { - return; - } - return callback(event); - }); -}