From 7c373edf4d86c704320743614c696a44ef363858 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 14 Jun 2015 23:14:00 +0200 Subject: [PATCH] implement javascript callbacks (no remove yet) --- js/util.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/js/util.js b/js/util.js index 54959bed73..b0274a91ba 100644 --- a/js/util.js +++ b/js/util.js @@ -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}); }, },