Update Polls plugin to work with new Plugin API

This commit is contained in:
Robin Ward
2016-02-18 15:17:53 -05:00
parent f6aa1ac37a
commit 6935925f10
5 changed files with 136 additions and 95 deletions

View File

@ -4,6 +4,7 @@ import { addPosterIcon } from 'discourse/widgets/poster-name';
import { addButton } from 'discourse/widgets/post-menu';
import { includeAttributes } from 'discourse/lib/transform-post';
import { addToolbarCallback } from 'discourse/components/d-editor';
import { addWidgetCleanCallback } from 'discourse/components/mount-widget';
let _decorateId = 0;
function decorate(klass, evt, cb) {
@ -29,23 +30,31 @@ class PluginApi {
}
/**
* decorateCooked(callback)
* decorateCooked(callback, options)
*
* Used for decorating the `cooked` content of a post after it is rendered using
* jQuery.
*
* `callback` will be called when it is time to decorate with a jQuery selector.
*
* Use `options.onlyStream` if you only want to decorate posts within a topic,
* and not in other places like the user stream.
*
* For example, to add a yellow background to all posts you could do this:
*
* ```
* api.decorateCooked($elem => $elem.css({ backgroundColor: 'yellow' }));
* ```
**/
decorateCooked(cb) {
addDecorator(cb);
decorate(ComposerEditor, 'previewRefreshed', cb);
decorate(this.container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
decorateCooked(callback, opts) {
opts = opts || {};
addDecorator(callback);
if (!opts.onlyStream) {
decorate(ComposerEditor, 'previewRefreshed', callback);
decorate(this.container.lookupFactory('view:user-stream'), 'didInsertElement', callback);
}
}
/**
@ -91,6 +100,10 @@ class PluginApi {
addToolbarCallback(callback);
}
cleanupStream(fn) {
addWidgetCleanCallback('post-stream', fn);
}
}
let _pluginv01;