PERF: Refactor lightbox decorator to use querySelectorAll (#10158)
Previously we were using `$elem.find(...).not($elem.find(...))`. This took approximately 2ms on my machine with a test post. This commit switches to using a native querySelectorAll method, which takes less than 0.5ms on the same test post.
This commit is contained in:
parent
6bab2acc9f
commit
95153356ea
|
@ -86,7 +86,7 @@ export default Component.extend(UploadMixin, {
|
||||||
},
|
},
|
||||||
|
|
||||||
_applyLightbox() {
|
_applyLightbox() {
|
||||||
if (this.imageUrl) next(() => lightbox($(this.element)));
|
if (this.imageUrl) next(() => lightbox(this.element));
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default {
|
||||||
api.decorateCooked(highlightSyntax, {
|
api.decorateCooked(highlightSyntax, {
|
||||||
id: "discourse-syntax-highlighting"
|
id: "discourse-syntax-highlighting"
|
||||||
});
|
});
|
||||||
api.decorateCooked(lightbox, { id: "discourse-lightbox" });
|
api.decorateCookedElement(lightbox, { id: "discourse-lightbox" });
|
||||||
if (siteSettings.support_mixed_text_direction) {
|
if (siteSettings.support_mixed_text_direction) {
|
||||||
api.decorateCooked(setTextDirections, {
|
api.decorateCooked(setTextDirections, {
|
||||||
id: "discourse-text-direction"
|
id: "discourse-text-direction"
|
||||||
|
|
|
@ -6,18 +6,16 @@ import { isAppWebview, postRNWebviewMessage } from "discourse/lib/utilities";
|
||||||
import { spinnerHTML } from "discourse/helpers/loading-spinner";
|
import { spinnerHTML } from "discourse/helpers/loading-spinner";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
|
|
||||||
export default function($elem) {
|
export default function(elem) {
|
||||||
if (!$elem) {
|
if (!elem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadScript("/javascripts/jquery.magnific-popup.min.js").then(function() {
|
loadScript("/javascripts/jquery.magnific-popup.min.js").then(function() {
|
||||||
const spoilers = $elem.find(".spoiler a.lightbox, .spoiled a.lightbox");
|
const lightboxes = elem.querySelectorAll(
|
||||||
|
"*:not(.spoiler):not(.spoiled) a.lightbox"
|
||||||
$elem
|
);
|
||||||
.find("a.lightbox")
|
$(lightboxes).magnificPopup({
|
||||||
.not(spoilers)
|
|
||||||
.magnificPopup({
|
|
||||||
type: "image",
|
type: "image",
|
||||||
closeOnContentClick: false,
|
closeOnContentClick: false,
|
||||||
removalDelay: 300,
|
removalDelay: 300,
|
||||||
|
|
Loading…
Reference in New Issue