5118 Create Javascript hook mechanism

This commit is contained in:
Pascal Deklerck 2018-06-07 22:23:30 +02:00
parent b53e74d989
commit d488512ca0
3 changed files with 33 additions and 0 deletions

12
view/js/addon-hooks.js Normal file
View file

@ -0,0 +1,12 @@
var addon_hooks={};
function Addon_registerHook( type, hookfnstr )
{
if (!addon_hooks.hasOwnProperty(type)) {
addon_hooks[type]=[];
}
addon_hooks[type].push( hookfnstr );
console.log("addon_hooks type "+type+" has "+addon_hooks[type].length+" hooks registered");
}

View file

@ -395,6 +395,19 @@ function NavUpdate() {
timer = setTimeout(NavUpdate, updateInterval);
}
function callAddonHooks(typeOfHook) {
if (typeof addon_hooks !== 'undefined') {
var myTypeOfHooks = addon_hooks[typeOfHook];
if (typeof myTypeOfHooks !== 'undefined') {
for (addon_hook_idx = 0; addon_hook_idx < myTypeOfHooks.length; addon_hook_idx++) {
var hookfnstr = myTypeOfHooks[addon_hook_idx];
var hookfn = window[hookfnstr];
if (typeof hookfn === "function") hookfn();
}
}
}
}
function liveUpdate(src) {
if ((src == null) || stopped || !profile_uid) {
$('.like-rotator').hide(); return;
@ -460,6 +473,8 @@ function liveUpdate(src) {
prev = ident;
});
callAddonHooks("postprocess");
$('.like-rotator').hide();
if (commentBusy) {
commentBusy = false;
@ -469,7 +484,9 @@ function liveUpdate(src) {
$(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl");
/* autocomplete bbcode */
$(".comment-edit-form textarea").bbco_autocomplete('bbcode');
});
}
function imgbright(node) {

View file

@ -44,6 +44,10 @@
<script type="text/javascript" src="view/asset/perfect-scrollbar/js/perfect-scrollbar.jquery.min.js" ></script>
<script type="text/javascript" src="view/js/acl.js" ></script>
<script type="text/javascript" src="view/asset/base64/base64.min.js" ></script>
<script type="text/javascript" src="view/js/addon-hooks.js" ></script>
{{foreach $addon_hooks as $addon_hook}}
<script type="text/javascript" src="addon/{{$addon_hook}}/{{$addon_hook}}.js"></script>
{{/foreach}}
<script type="text/javascript" src="view/js/main.js" ></script>
<script>