This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/initializers/post-decorations.js.es6
Robin Ward 6797a710aa FEATURE: Lazily Load Images as they scroll into the viewport.
This feature uses the Intersection Observer API

https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API

It should be compatible with all modern browsers. Non-Edge IE is *NOT*
supported, so in that particular browser images are loaded by default.
2018-12-12 10:12:49 +11:00

34 lines
1.0 KiB
JavaScript

import highlightSyntax from "discourse/lib/highlight-syntax";
import lightbox from "discourse/lib/lightbox";
import { setupLazyLoading } from "discourse/lib/lazy-load-images";
import { setTextDirections } from "discourse/lib/text-direction";
import { withPluginApi } from "discourse/lib/plugin-api";
export default {
name: "post-decorations",
initialize(container) {
withPluginApi("0.1", api => {
const siteSettings = container.lookup("site-settings:main");
api.decorateCooked(highlightSyntax);
api.decorateCooked(lightbox);
if (siteSettings.support_mixed_text_direction) {
api.decorateCooked(setTextDirections);
}
setupLazyLoading(api);
api.decorateCooked($elem => {
const players = $("audio", $elem);
if (players.length) {
players.on("play", () => {
const postId = parseInt($elem.closest("article").data("post-id"));
if (postId) {
api.preventCloak(postId);
}
});
}
});
});
}
};