mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 09:03:44 +08:00
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:
parent
e2f65cd170
commit
0650504bf5
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user