]> git.mxchange.org Git - friendica.git/commitdiff
5118 Create Javascript hook mechanism
authorPascal Deklerck <pascal.deklerck@gmail.com>
Thu, 7 Jun 2018 20:23:30 +0000 (22:23 +0200)
committerPascal Deklerck <pascal.deklerck@gmail.com>
Thu, 7 Jun 2018 20:23:30 +0000 (22:23 +0200)
view/js/addon-hooks.js [new file with mode: 0644]
view/js/main.js
view/templates/head.tpl

diff --git a/view/js/addon-hooks.js b/view/js/addon-hooks.js
new file mode 100644 (file)
index 0000000..b00285c
--- /dev/null
@@ -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");
+}
index 475e81087013ae2985bbd58cdc4f6919a8b712a3..f0bab12806ac18e9ecac4203f18bc600c1cc502c 100644 (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) {
index c58b2b8290d074d5fa4012b5507eb4a5ef0bf272..75a676a91ebe279fa55879ca8b288797a80fee15 100644 (file)
 <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>