From a06045adf033a232c12cfdce1ebcc8fdaedcc3eb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 24 Apr 2013 19:51:57 +0400 Subject: add missing pluginhost source --- js/PluginHost.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 js/PluginHost.js (limited to 'js/PluginHost.js') diff --git a/js/PluginHost.js b/js/PluginHost.js new file mode 100644 index 000000000..a3a31ce9c --- /dev/null +++ b/js/PluginHost.js @@ -0,0 +1,30 @@ +// based on http://www.velvetcache.org/2010/08/19/a-simple-javascript-hooks-system + +var PluginHost = { + HOOK_ARTICLE_RENDERED: 1, + HOOK_ARTICLE_RENDERED_CDM: 2, + HOOK_ARTICLE_SET_ACTIVE: 3, + HOOK_FEED_SET_ACTIVE: 4, + HOOK_FEED_LOADED: 5, + hooks: [], + register: function (name, callback) { + if (typeof(this.hooks[name]) == 'undefined') + this.hooks[name] = []; + + this.hooks[name].push(callback); + }, + run: function (name, args) { + console.warn('PluginHost::run ' + name); + + if (typeof(this.hooks[name]) != 'undefined') + for (i = 0; i < this.hooks[name].length; i++) + if (!this.hooks[name][i](args)) break; + } +}; + +/* PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED, + function (args) { console.log('ARTICLE_RENDERED: ' + args); return true; }); + +PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, + function (args) { console.log('ARTICLE_RENDERED_CDM: ' + args); return true; }); */ + -- cgit v1.2.3-54-g00ecf From 2779e22bf5eb8eab0af91138e0d613f604a60a1a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 25 Apr 2013 10:09:40 +0400 Subject: js: add collapsed and expanded hooks --- js/PluginHost.js | 2 ++ js/viewfeed.js | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'js/PluginHost.js') diff --git a/js/PluginHost.js b/js/PluginHost.js index a3a31ce9c..de4c57b60 100644 --- a/js/PluginHost.js +++ b/js/PluginHost.js @@ -6,6 +6,8 @@ var PluginHost = { HOOK_ARTICLE_SET_ACTIVE: 3, HOOK_FEED_SET_ACTIVE: 4, HOOK_FEED_LOADED: 5, + HOOK_ARTICLE_EXPANDED: 6, + HOOK_ARTICLE_COLLAPSED: 7, hooks: [], register: function (name, callback) { if (typeof(this.hooks[name]) == 'undefined') diff --git a/js/viewfeed.js b/js/viewfeed.js index 96919dc01..da869d92a 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1416,6 +1416,8 @@ function cdmCollapseArticle(event, id) { } if (event) Event.stop(event); + + PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id); } } catch (e) { @@ -1503,6 +1505,8 @@ function cdmExpandArticle(id, noexpand) { toggleSelected(id); $("RROW-" + id).addClassName("active"); + PluginHost.run(PluginHost.HOOK_ARTICLE_EXPANDED, id); + } catch (e) { exception_error("cdmExpandArticle", e); } -- cgit v1.2.3-54-g00ecf From 8ceea119a8287568439a2a9d167b333f74a47e21 Mon Sep 17 00:00:00 2001 From: supahgreg Date: Sat, 27 Apr 2013 11:01:54 -0500 Subject: Add JS PluginHost.HOOK_PARAMS_LOADED and PluginHost.HOOK_RUNTIME_INFO_LOADED to notify when interesting info has been created/updated. --- js/PluginHost.js | 2 ++ js/functions.js | 3 +++ js/tt-rss.js | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) (limited to 'js/PluginHost.js') diff --git a/js/PluginHost.js b/js/PluginHost.js index de4c57b60..668d215f9 100644 --- a/js/PluginHost.js +++ b/js/PluginHost.js @@ -8,6 +8,8 @@ var PluginHost = { HOOK_FEED_LOADED: 5, HOOK_ARTICLE_EXPANDED: 6, HOOK_ARTICLE_COLLAPSED: 7, + HOOK_PARAMS_LOADED: 8, + HOOK_RUNTIME_INFO_LOADED: 9, hooks: [], register: function (name, callback) { if (typeof(this.hooks[name]) == 'undefined') diff --git a/js/functions.js b/js/functions.js index 87c52b709..8691c1ee5 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1277,6 +1277,9 @@ function backend_sanity_check_callback(transport) { } init_params = params; + + // PluginHost might not be available on non-index pages + window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params); } sanity_check_done = true; diff --git a/js/tt-rss.js b/js/tt-rss.js index a7518959c..2a741ab2d 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -753,6 +753,8 @@ function parse_runtime_info(data) { init_params[k] = v; notify(''); } + + PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); } function collapse_feedlist() { @@ -992,7 +994,7 @@ function handle_rpc_json(transport, scheduled_call) { if (counters) parse_counters(counters, scheduled_call); - var runtime_info = reply['runtime-info'];; + var runtime_info = reply['runtime-info']; if (runtime_info) parse_runtime_info(runtime_info); -- cgit v1.2.3-54-g00ecf