DEV: Remove `after-transition` function (#21142)

All supported browsers use `transitionend` event now, so this code is not necessary and makes it difficult to use that event in tests (you'd have to trigger all variants to cover the bases)

That function was used only in core (no hits in all-the*) in two places, so I think it's rather safe to just trash it without deprecating it first.

(History Corner – this helper was originally added in the initial commit of Discourse! 1839614bcc/app/assets/javascripts/discourse/components/transition_helper.js.coffee)
This commit is contained in:
Jarek Radosz 2023-04-18 20:45:20 +02:00 committed by GitHub
parent e2f65cd170
commit 0650504bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 54 deletions

View File

@ -7,7 +7,6 @@ import discourseComputed, {
import Component from "@ember/component"; import Component from "@ember/component";
import Composer from "discourse/models/composer"; import Composer from "discourse/models/composer";
import KeyEnterEscape from "discourse/mixins/key-enter-escape"; import KeyEnterEscape from "discourse/mixins/key-enter-escape";
import afterTransition from "discourse/lib/after-transition";
import discourseDebounce from "discourse-common/lib/debounce"; import discourseDebounce from "discourse-common/lib/debounce";
import { headerOffset } from "discourse/lib/offset-calculator"; import { headerOffset } from "discourse/lib/offset-calculator";
import positioningWorkaround from "discourse/lib/safari-hacks"; import positioningWorkaround from "discourse/lib/safari-hacks";
@ -181,7 +180,7 @@ export default Component.extend(KeyEnterEscape, {
}; };
triggerOpen(); triggerOpen();
afterTransition($(this.element), () => { this.element.addEventListener("transitionend", () => {
triggerOpen(); triggerOpen();
}); });

View File

@ -1,4 +1,3 @@
import afterTransition from "discourse/lib/after-transition";
import { propertyEqual } from "discourse/lib/computed"; import { propertyEqual } from "discourse/lib/computed";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
@ -412,25 +411,27 @@ export default Component.extend(KeyEnterEscape, {
this.editPost(postModel); this.editPost(postModel);
afterTransition(document.querySelector("#reply-control"), () => { document
const textarea = document.querySelector(".d-editor-input"); .querySelector("#reply-control")
if (!textarea || this.isDestroyed || this.isDestroying) { ?.addEventListener("transitionend", () => {
return; 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 // 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 // we add 1 to be at the beginning of next line, unless we start from top
setCaretPosition( setCaretPosition(
textarea, textarea,
rows.slice(0, bestIndex).join("\n").length + rows.slice(0, bestIndex).join("\n").length +
(bestIndex > 0 ? 1 : 0) (bestIndex > 0 ? 1 : 0)
); );
// ensures we correctly scroll to caret and reloads composer // ensures we correctly scroll to caret and reloads composer
// if we do another selection/edit // if we do another selection/edit
textarea.blur(); textarea.blur();
textarea.focus(); textarea.focus();
}); });
} }
); );
} }

View File

@ -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);
});
}