PluginAPI for more stable backwards compatibility going forward
This commit is contained in:
parent
81ee8f760a
commit
9b8871d7dd
|
@ -1,11 +1,13 @@
|
||||||
import { decorateCooked } from 'discourse/lib/plugin-api';
|
|
||||||
import highlightSyntax from 'discourse/lib/highlight-syntax';
|
import highlightSyntax from 'discourse/lib/highlight-syntax';
|
||||||
import lightbox from 'discourse/lib/lightbox';
|
import lightbox from 'discourse/lib/lightbox';
|
||||||
|
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "post-decorations",
|
name: "post-decorations",
|
||||||
initialize: function(container) {
|
initialize() {
|
||||||
decorateCooked(container, highlightSyntax);
|
const api = getPluginApi('0.1');
|
||||||
decorateCooked(container, lightbox);
|
|
||||||
|
api.decorateCooked(highlightSyntax);
|
||||||
|
api.decorateCooked(lightbox);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,31 @@ function decorate(klass, evt, cb) {
|
||||||
klass.reopen(mixin);
|
klass.reopen(mixin);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decorateCooked(container, cb) {
|
export function decorateCooked() {
|
||||||
addDecorator(cb);
|
console.warn('`decorateCooked` has been removed. Use `getPluginApi(version).decorateCooked` instead');
|
||||||
decorate(ComposerEditor, 'previewRefreshed', cb);
|
|
||||||
decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PluginApi {
|
||||||
|
constructor(version, container) {
|
||||||
|
this.version = version;
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
decorateCooked(cb) {
|
||||||
|
addDecorator(cb);
|
||||||
|
decorate(ComposerEditor, 'previewRefreshed', cb);
|
||||||
|
decorate(this.container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _pluginv01;
|
||||||
|
|
||||||
|
export function getPluginApi(version) {
|
||||||
|
if (version === "0.1") {
|
||||||
|
if (!_pluginv01) {
|
||||||
|
_pluginv01 = new PluginApi(version, Discourse.__container__);
|
||||||
|
}
|
||||||
|
return _pluginv01;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { decorateCooked } from "discourse/lib/plugin-api";
|
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "apply-details",
|
name: "apply-details",
|
||||||
|
|
||||||
initialize(container) {
|
initialize() {
|
||||||
decorateCooked(container, $elem => $("details", $elem).details());
|
const api = getPluginApi('0.1');
|
||||||
|
api.decorateCooked($elem => $("details", $elem).details());
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
/**
|
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||||
Apply lazyYT when the app boots
|
|
||||||
**/
|
|
||||||
import { decorateCooked } from 'discourse/lib/plugin-api';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "apply-lazyYT",
|
name: "apply-lazyYT",
|
||||||
initialize: function(container) {
|
initialize() {
|
||||||
decorateCooked(container, function($elem) {
|
const api = getPluginApi('0.1');
|
||||||
$('.lazyYT', $elem).lazyYT();
|
api.decorateCooked($elem => $('.lazyYT', $elem).lazyYT());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue