From 513f570936723e912ab79ba10a3b6b23558be803 Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Tue, 17 Jan 2017 00:39:23 +1300 Subject: [PATCH 1/4] Add reopenWidget method --- .../javascripts/discourse/widgets/widget.js.es6 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/assets/javascripts/discourse/widgets/widget.js.es6 b/app/assets/javascripts/discourse/widgets/widget.js.es6 index f3f5d95356a..45bdac06245 100644 --- a/app/assets/javascripts/discourse/widgets/widget.js.es6 +++ b/app/assets/javascripts/discourse/widgets/widget.js.es6 @@ -125,6 +125,17 @@ export function createWidget(name, opts) { return result; } +export function reopenWidget(name, opts) { + let existing = _registry[name] + if (!existing) { + console.error(`Could not find widget ${name} in registry`); + return + } + + Object.keys(opts).forEach(k => existing.prototype[k] = opts[k]) + return existing +} + export default class Widget { constructor(attrs, register, opts) { opts = opts || {}; From 646b49e5ae5c8d5232e9cafe4b9171e2ceb7b6c2 Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Tue, 17 Jan 2017 08:19:29 +1300 Subject: [PATCH 2/4] Expose reopenWidget through plugin api --- .../javascripts/discourse/lib/plugin-api.js.es6 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index b8beb0020d9..62c984447fa 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -5,7 +5,7 @@ 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'; -import { createWidget, decorateWidget, changeSetting } from 'discourse/widgets/widget'; +import { createWidget, reopenWidget, decorateWidget, changeSetting } from 'discourse/widgets/widget'; import { onPageChange } from 'discourse/lib/page-tracker'; import { preventCloak } from 'discourse/widgets/post-stream'; import { h } from 'virtual-dom'; @@ -307,6 +307,16 @@ class PluginApi { return createWidget(name, args); } + /** + * Exposes the widget update ability to plugins. Updates the widget + * registry for the given widget name to include the properties on args + * See `reopenWidget` in `discourse/widgets/widget` from more ifo. + **/ + + reopenWidget(name, args) { + return reopenWidget(name, args); + } + /** * Adds a property that can be summed for calculating the flag counter **/ From 1d8882a1dd6a9c60841fd22c88705f153ff493c1 Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Tue, 17 Jan 2017 08:20:57 +1300 Subject: [PATCH 3/4] oops semicolons --- app/assets/javascripts/discourse/widgets/widget.js.es6 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/widget.js.es6 b/app/assets/javascripts/discourse/widgets/widget.js.es6 index 45bdac06245..4eddd1867cb 100644 --- a/app/assets/javascripts/discourse/widgets/widget.js.es6 +++ b/app/assets/javascripts/discourse/widgets/widget.js.es6 @@ -126,14 +126,14 @@ export function createWidget(name, opts) { } export function reopenWidget(name, opts) { - let existing = _registry[name] + let existing = _registry[name]; if (!existing) { console.error(`Could not find widget ${name} in registry`); return } - Object.keys(opts).forEach(k => existing.prototype[k] = opts[k]) - return existing + Object.keys(opts).forEach(k => existing.prototype[k] = opts[k]); + return existing; } export default class Widget { From 816a030f78dcd4092aa8c4382fd7dab5f71c9c7c Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Wed, 1 Feb 2017 11:05:47 +1300 Subject: [PATCH 4/4] Bump plugin api to 0.7 --- app/assets/javascripts/discourse/lib/plugin-api.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index 62c984447fa..9544d849577 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -367,7 +367,7 @@ class PluginApi { let _pluginv01; function getPluginApi(version) { version = parseFloat(version); - if (version <= 0.6) { + if (version <= 0.7) { if (!_pluginv01) { _pluginv01 = new PluginApi(version, Discourse.__container__); }