2013-04-24 15:51:57 +00:00
|
|
|
// based on http://www.velvetcache.org/2010/08/19/a-simple-javascript-hooks-system
|
|
|
|
|
2020-06-04 20:27:22 +00:00
|
|
|
|
|
|
|
/* exported PluginHost */
|
2020-06-04 16:50:13 +00:00
|
|
|
const PluginHost = {
|
2013-04-24 15:51:57 +00:00
|
|
|
HOOK_ARTICLE_RENDERED: 1,
|
|
|
|
HOOK_ARTICLE_RENDERED_CDM: 2,
|
|
|
|
HOOK_ARTICLE_SET_ACTIVE: 3,
|
|
|
|
HOOK_FEED_SET_ACTIVE: 4,
|
|
|
|
HOOK_FEED_LOADED: 5,
|
2013-04-25 06:09:40 +00:00
|
|
|
HOOK_ARTICLE_EXPANDED: 6,
|
|
|
|
HOOK_ARTICLE_COLLAPSED: 7,
|
2013-04-27 16:01:54 +00:00
|
|
|
HOOK_PARAMS_LOADED: 8,
|
|
|
|
HOOK_RUNTIME_INFO_LOADED: 9,
|
2013-06-28 04:30:35 +00:00
|
|
|
HOOK_FLOATING_TITLE: 10,
|
2018-12-08 17:06:07 +00:00
|
|
|
HOOK_INIT_COMPLETE: 11,
|
2018-12-08 17:08:57 +00:00
|
|
|
HOOK_HEADLINE_RENDERED: 12,
|
2019-05-06 06:49:04 +00:00
|
|
|
HOOK_COUNTERS_RECEIVED: 13,
|
2019-05-06 06:50:46 +00:00
|
|
|
HOOK_COUNTERS_PROCESSED: 14,
|
2021-03-09 14:01:22 +00:00
|
|
|
HOOK_HEADLINE_MUTATIONS: 15,
|
|
|
|
HOOK_HEADLINE_MUTATIONS_SYNCED: 16,
|
2021-03-11 19:55:14 +00:00
|
|
|
HOOK_HEADLINES_RENDERED: 17,
|
2021-03-12 09:29:26 +00:00
|
|
|
HOOK_HEADLINES_SCROLL_HANDLER: 18,
|
2013-04-24 15:51:57 +00:00
|
|
|
hooks: [],
|
|
|
|
register: function (name, callback) {
|
|
|
|
if (typeof(this.hooks[name]) == 'undefined')
|
|
|
|
this.hooks[name] = [];
|
|
|
|
|
|
|
|
this.hooks[name].push(callback);
|
|
|
|
},
|
|
|
|
run: function (name, args) {
|
2021-03-09 14:01:22 +00:00
|
|
|
//console.warn('PluginHost.run', name);
|
2013-04-24 15:51:57 +00:00
|
|
|
|
|
|
|
if (typeof(this.hooks[name]) != 'undefined')
|
2018-12-08 18:14:40 +00:00
|
|
|
for (let i = 0; i < this.hooks[name].length; i++) {
|
|
|
|
this.hooks[name][i](args);
|
|
|
|
}
|
2019-05-07 14:34:15 +00:00
|
|
|
},
|
|
|
|
unregister: function (name, callback) {
|
2020-06-04 20:27:22 +00:00
|
|
|
for (let i = 0; i < this.hooks[name].length; i++)
|
2019-05-07 14:34:15 +00:00
|
|
|
if (this.hooks[name][i] == callback)
|
|
|
|
this.hooks[name].splice(i, 1);
|
2013-04-24 15:51:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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; }); */
|
|
|
|
|