]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
implement javascript callbacks (no remove yet)
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 14 Jun 2015 21:14:00 +0000 (23:14 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 14 Jun 2015 21:14:00 +0000 (23:14 +0200)
js/util.js

index 54959bed73ed44ac541defbad1e6e8c6fe04b5d4..b0274a91bad4dfc6b1d75f77be76f8129696697e 100644 (file)
@@ -60,6 +60,13 @@ var SN = { // StatusNet
     V: {    // Variables
     },
 
+    /**
+     * list of callbacks, categorized into _callbacks['event_name'] = [ callback_function_1, callback_function_2 ]
+     *
+     * @access private
+     */
+    _callbacks: {},
+
     /**
      * Map of localized message strings exported to script from the PHP
      * side via Action::getScriptMessages().
@@ -1394,6 +1401,23 @@ var SN = { // StatusNet
                     .text(text)
             );
         },
+
+        addCallback: function (ename, callback) {
+            // initialize to array if it's undefined
+            if (typeof SN._callbacks[ename] === 'undefined') {
+                SN._callbacks[ename] = [];
+            }
+            SN._callbacks[ename].push(callback);
+        },
+
+        runCallbacks: function (ename, data) {
+            if (typeof SN._callbacks[ename] === 'undefined') {
+                return;
+            }
+            for (cbname in SN._callbacks[ename]) {
+                SN._callbacks[ename][cbname](data);
+            }
+        }
     },
 
     E: {    /* Events */
@@ -1454,6 +1478,8 @@ var SN = { // StatusNet
             form.find('[name=inreplyto]').val('');
             form.find('.attach-status').remove();
             SN.U.FormNoticeEnhancements(form);
+
+            SN.U.runCallbacks('notice_posted', {"notice": notice});
         }, 
     },