MediaWiki:Chat-js.js

// Chat-js prototype // Please *reject* if reviewed - this is still in construction.
 * (function (window, $, mw) {

// Variables and double-run protection window.dev = window.dev || {}; if (window.dev.chat) { return; }

// Event for chat initialisation var $loaded = $.Deferred;

// Import our styles var styles = $(importArticles({ type: 'style', article: 'u:dev:MediaWiki:Chat-js.css' }));

// Chat-js bootstrapper function boot { $.when(dev.chat.$loaded).then(function(chat) {           mw.hook('dev.chat.init').fire(chat);        }); // Chat bootstrapper if (typeof window.mainRoom !== 'undefined') { _main(window.dev.chat); } else { init.observe(user, { childList: true }); }   }

// Chat initialisation // When Chat is first rendered, .ChatHeader .User is populated. // The initial render will trigger this MutationObserver callback. var _init = new MutationObserver(function {       if (typeof window.mainRoom !== 'undefined') {            main(window.dev.chat);            init.disconnect;        }    }); var _user = document.querySelector('#ChatHeader .User'); // Chat-js event logic function _main(chat) { ui.$toolbar .insertBefore('.ChatHeader .User'); $loaded.resolve(chat); }

// UI cache for cross-script button creation var ui = { $toolbar: $(' ', {               'class': 'toolbar wds-button-group'            }), $buttons: {}, };

// Button creation utility function _button(btn) { var bc = btn || {}, t = bc.text || s.replace(/[a-z]/g, '' ), $b = $(' ', {               'class': 'wds-button wds-is-secondary wds-is-squished'            }); if (!ui.$buttons.hasOwnProperty(t)) { if (t.length > 0) { $b.text(t); }           if (bc.cls) { $b.addClass(bc.cls); }           if (typeof bc.handler === 'function') { $b.click(bc.handler); }           $b.appendTo(ui.$toolbar); ui.$buttons[t] = $b; return $b; }   }

// Expose global variable window.dev.chat = { button: _button };

// Library bootloader mw.loader.using('mediawiki.util', _boot);

}(this, jQuery, mediaWiki));