mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
PluginAPI for more stable backwards compatibility going forward
This commit is contained in:
parent
81ee8f760a
commit
9b8871d7dd
4 changed files with 41 additions and 19 deletions
|
@ -1,11 +1,13 @@
|
|||
import { decorateCooked } from 'discourse/lib/plugin-api';
|
||||
import highlightSyntax from 'discourse/lib/highlight-syntax';
|
||||
import lightbox from 'discourse/lib/lightbox';
|
||||
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
export default {
|
||||
name: "post-decorations",
|
||||
initialize: function(container) {
|
||||
decorateCooked(container, highlightSyntax);
|
||||
decorateCooked(container, lightbox);
|
||||
initialize() {
|
||||
const api = getPluginApi('0.1');
|
||||
|
||||
api.decorateCooked(highlightSyntax);
|
||||
api.decorateCooked(lightbox);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,8 +8,31 @@ function decorate(klass, evt, cb) {
|
|||
klass.reopen(mixin);
|
||||
}
|
||||
|
||||
export function decorateCooked(container, cb) {
|
||||
addDecorator(cb);
|
||||
decorate(ComposerEditor, 'previewRefreshed', cb);
|
||||
decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
|
||||
export function decorateCooked() {
|
||||
console.warn('`decorateCooked` has been removed. Use `getPluginApi(version).decorateCooked` instead');
|
||||
}
|
||||
|
||||
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 {
|
||||
name: "apply-details",
|
||||
|
||||
initialize(container) {
|
||||
decorateCooked(container, $elem => $("details", $elem).details());
|
||||
initialize() {
|
||||
const api = getPluginApi('0.1');
|
||||
api.decorateCooked($elem => $("details", $elem).details());
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
/**
|
||||
Apply lazyYT when the app boots
|
||||
**/
|
||||
import { decorateCooked } from 'discourse/lib/plugin-api';
|
||||
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
export default {
|
||||
name: "apply-lazyYT",
|
||||
initialize: function(container) {
|
||||
decorateCooked(container, function($elem) {
|
||||
$('.lazyYT', $elem).lazyYT();
|
||||
});
|
||||
initialize() {
|
||||
const api = getPluginApi('0.1');
|
||||
api.decorateCooked($elem => $('.lazyYT', $elem).lazyYT());
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue