Node.js based forum software built for the modern web
Feat: Client-side hooks - replace window.trigger (#9679)
Anton Grigoryev342503e07add
diff --git a/public/src/admin/settings.js b/public/src/admin/settings.jsindex 6732a7bc4f..5b5dee579e 100644--- a/public/src/admin/settings.js+++ b/public/src/admin/settings.js@@ -1,7 +1,7 @@'use strict';-define('admin/settings', ['uploader', 'mousetrap'], function (uploader, mousetrap) {+define('admin/settings', ['uploader', 'mousetrap', 'hooks'], function (uploader, mousetrap, hooks) {var Settings = {};Settings.populateTOC = function () {@@ -87,7 +87,7 @@ define('admin/settings', ['uploader', 'mousetrap'], function (uploader, mousetratype: 'success',});- $(window).trigger('action:admin.settingsSaved');+ hooks.fire('action:admin.settingsSaved');});});@@ -111,7 +111,7 @@ define('admin/settings', ['uploader', 'mousetrap'], function (uploader, mousetra}setTimeout(function () {- $(window).trigger('action:admin.settingsLoaded');+ hooks.fire('action:admin.settingsLoaded');}, 0);};diff --git a/public/src/ajaxify.js b/public/src/ajaxify.jsindex 6c1b81a359..26576dabbd 100644--- a/public/src/ajaxify.js+++ b/public/src/ajaxify.js@@ -92,7 +92,7 @@ ajaxify = window.ajaxify || {};var url = ajaxify.start(window.location.pathname.slice(1) + window.location.search + window.location.hash);ajaxify.updateHistory(url, true);ajaxify.end(url, ajaxify.data.template.name);- $(window).trigger('action:ajaxify.coldLoad');+ hooks.fire('action:ajaxify.coldLoad');};ajaxify.isCold = function () {@@ -179,7 +179,7 @@ ajaxify = window.ajaxify || {};}function renderTemplate(url, tpl_url, data, callback) {- $(window).trigger('action:ajaxify.loadingTemplates', {});+ hooks.fire('action:ajaxify.loadingTemplates', {});require(['translator', 'benchpress'], function (translator, Benchpress) {Benchpress.render(tpl_url, data).then(rendered => translator.translate(rendered))@@ -215,7 +215,7 @@ ajaxify = window.ajaxify || {};// Allow translation strings in title on ajaxify (#5927)title = translator.unescape(title);var data = { title: title };- $(window).trigger('action:ajaxify.updateTitle', data);+ hooks.fire('action:ajaxify.updateTitle', data);translator.translate(data.title, function (translated) {window.document.title = $('<div></div>').html(translated).text();});@@ -299,7 +299,7 @@ ajaxify = window.ajaxify || {};});ajaxify.widgets.render(tpl_url);- $(window).trigger('action:ajaxify.contentLoaded', { url: url, tpl: tpl_url });+ hooks.fire('action:ajaxify.contentLoaded', { url: url, tpl: tpl_url });app.processPage();};@@ -379,7 +379,7 @@ ajaxify = window.ajaxify || {};ajaxify.loadData = function (url, callback) {url = ajaxify.removeRelativePath(url);- $(window).trigger('action:ajaxify.loadingData', { url: url });+ hooks.fire('action:ajaxify.loadingData', { url: url });apiXHR = $.ajax({url: config.relative_path + '/api/' + url,@@ -405,7 +405,7 @@ ajaxify = window.ajaxify || {};ajaxify.data = data;data.config = config;- $(window).trigger('action:ajaxify.dataLoaded', { url: url, data: data });+ hooks.fire('action:ajaxify.dataLoaded', { url: url, data: data });callback(null, data);},@@ -440,6 +440,11 @@ ajaxify = window.ajaxify || {};}());$(document).ready(function () {+ var hooks;+ require(['hooks'], function (_hooks) {+ hooks = _hooks;+ });+$(window).on('popstate', function (ev) {ev = ev.originalEvent;@@ -450,7 +455,7 @@ $(document).ready(function () {}, ev.state.returnPath, config.relative_path + '/' + ev.state.returnPath);} else if (ev.state.url !== undefined) {ajaxify.go(ev.state.url, function () {- $(window).trigger('action:popstate', { url: ev.state.url });+ hooks.fire('action:popstate', { url: ev.state.url });}, true);}}diff --git a/public/src/app.js b/public/src/app.jsindex 816a89b6fd..290dd52c6d 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -18,6 +18,11 @@ app.cacheBuster = null;app.cacheBuster = config['cache-buster'];+ var hooks;+ require(['hooks'], function (_hooks) {+ hooks = _hooks;+ });+$(document).ready(function () {ajaxify.parseData();app.load();@@ -117,7 +122,7 @@ app.cacheBuster = null;unread.initUnreadTopics();}function finishLoad() {- $(window).trigger('action:app.load');+ hooks.fire('action:app.load');app.showMessages();appLoaded = true;}@@ -146,7 +151,7 @@ app.cacheBuster = null;app.logout = function (redirect) {redirect = redirect === undefined ? true : redirect;- $(window).trigger('action:app.logout');+ hooks.fire('action:app.logout');$.ajax(config.relative_path + '/logout', {type: 'POST',@@ -157,7 +162,7 @@ app.cacheBuster = null;app.flags._logout = true;},success: function (data) {- $(window).trigger('action:app.loggedOut', data);+ hooks.fire('action:app.loggedOut', data);if (redirect) {if (data.next) {window.location.href = data.next;@@ -513,7 +518,7 @@ app.cacheBuster = null;quickSearchResults.removeClass('hidden').find('.quick-search-results-container').html('');quickSearchResults.find('.loading-indicator').removeClass('hidden');- $(window).trigger('action:search.quick.start', options);+ hooks.fire('action:search.quick.start', options);options.searchOptions.searchOnly = 1;search.api(options.searchOptions, function (data) {quickSearchResults.find('.loading-indicator').addClass('hidden');@@ -538,7 +543,7 @@ app.cacheBuster = null;'.quick-search-results .quick-search-title, .quick-search-results .snippet');search.highlightMatches(options.searchOptions.term, highlightEls);- $(window).trigger('action:search.quick.complete', {+ hooks.fire('action:search.quick.complete', {data: data,options: options,});@@ -658,7 +663,7 @@ app.cacheBuster = null;require(['search'], function (search) {var data = search.getSearchPreferences();data.term = input.val();- $(window).trigger('action:search.submit', {+ hooks.fire('action:search.submit', {searchOptions: data,searchElements: searchElements,});@@ -711,7 +716,7 @@ app.cacheBuster = null;};app.newTopic = function (cid, tags) {- $(window).trigger('action:composer.topic.new', {+ hooks.fire('action:composer.topic.new', {cid: cid || ajaxify.data.cid || 0,tags: tags || (ajaxify.data.tag ? [ajaxify.data.tag] : []),});diff --git a/public/src/client/account/blocks.js b/public/src/client/account/blocks.jsindex d14901d8a3..0469cf957d 100644--- a/public/src/client/account/blocks.js+++ b/public/src/client/account/blocks.js@@ -3,7 +3,8 @@define('forum/account/blocks', ['forum/account/header','api',-], function (header, api) {+ 'hooks',+], function (header, api, hooks) {var Blocks = {};Blocks.init = function () {@@ -54,7 +55,7 @@ define('forum/account/blocks', [$('#users-container').html(html);$('#users-container').siblings('div.alert')[html.length ? 'hide' : 'show']();});- $(window).trigger('action:user.blocks.toggle', { data: payload });+ hooks.fire('action:user.blocks.toggle', { data: payload });}).fail(function () {ajaxify.go(ajaxify.currentPage);diff --git a/public/src/client/account/topics.js b/public/src/client/account/topics.jsindex 51d052f16e..de005271d9 100644--- a/public/src/client/account/topics.js+++ b/public/src/client/account/topics.js@@ -1,7 +1,11 @@'use strict';-define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'], function (header, infinitescroll) {+define('forum/account/topics', [+ 'forum/account/header',+ 'forum/infinitescroll',+ 'hooks',+], function (header, infinitescroll, hooks) {var AccountTopics = {};var template;@@ -44,7 +48,7 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],html.find('.timeago').timeago();app.createUserTooltips();utils.makeNumbersHumanReadable(html.find('.human-readable-number'));- $(window).trigger('action:topics.loaded', { topics: topics });+ hooks.fire('action:topics.loaded', { topics: topics });callback();});}diff --git a/public/src/client/category.js b/public/src/client/category.jsindex 4d586d5665..62fbc49516 100644--- a/public/src/client/category.js+++ b/public/src/client/category.js@@ -7,7 +7,8 @@ define('forum/category', ['topicList','sort','categorySelector',-], function (infinitescroll, share, navigator, topicList, sort, categorySelector) {+ 'hooks',+], function (infinitescroll, share, navigator, topicList, sort, categorySelector, hooks) {var Category = {};$(window).on('action:ajaxify.start', function (ev, data) {@@ -47,8 +48,8 @@ define('forum/category', [},});- $(window).trigger('action:topics.loaded', { topics: ajaxify.data.topics });- $(window).trigger('action:category.loaded', { cid: ajaxify.data.cid });+ hooks.fire('action:topics.loaded', { topics: ajaxify.data.topics });+ hooks.fire('action:category.loaded', { cid: ajaxify.data.cid });};function handleScrollToTopicIndex() {@@ -134,7 +135,7 @@ define('forum/category', [function loadTopicsAfter(after, direction, callback) {callback = callback || function () {};- $(window).trigger('action:category.loading');+ hooks.fire('action:category.loading');var params = utils.params();infinitescroll.loadMore('categories.loadMore', {cid: ajaxify.data.cid,@@ -143,7 +144,7 @@ define('forum/category', [query: params,categoryTopicSort: config.categoryTopicSort,}, function (data, done) {- $(window).trigger('action:category.loaded');+ hooks.fire('action:category.loaded');callback(data, done);});}diff --git a/public/src/client/chats.js b/public/src/client/chats.jsindex 3f38a118e9..0389834e76 100644--- a/public/src/client/chats.js+++ b/public/src/client/chats.js@@ -10,7 +10,8 @@ define('forum/chats', ['forum/chats/messages','benchpress','composer/autocomplete',-], function (components, translator, mousetrap, recentChats, search, messages, Benchpress, autocomplete) {+ 'hooks',+], function (components, translator, mousetrap, recentChats, search, messages, Benchpress, autocomplete, hooks) {var Chats = {initialised: false,};@@ -35,7 +36,7 @@ define('forum/chats', [}$(document).ready(function () {- $(window).trigger('action:chat.loaded', $('.chats-full'));+ hooks.fire('action:chat.loaded', $('.chats-full'));});Chats.initialised = true;@@ -384,7 +385,7 @@ define('forum/chats', [},};- $(window).trigger('chat:autocomplete:init', data);+ hooks.fire('chat:autocomplete:init', data);if (data.strategies.length) {autocomplete.setup(data);}@@ -429,7 +430,7 @@ define('forum/chats', [ajaxify.data = payload;Chats.setActive();Chats.addEventListeners();- $(window).trigger('action:chat.loaded', $('.chats-full'));+ hooks.fire('action:chat.loaded', $('.chats-full'));messages.scrollToBottom($('.expanded-chat ul.chat-content'));if (history.pushState) {history.pushState({diff --git a/public/src/client/chats/messages.js b/public/src/client/chats/messages.jsindex e6be2d3adf..29ab113e9b 100644--- a/public/src/client/chats/messages.js+++ b/public/src/client/chats/messages.js@@ -1,7 +1,7 @@'use strict';-define('forum/chats/messages', ['components', 'translator', 'benchpress'], function (components, translator, Benchpress) {+define('forum/chats/messages', ['components', 'translator', 'benchpress', 'hooks'], function (components, translator, Benchpress, hooks) {var messages = {};messages.sendMessage = function (roomId, inputEl) {@@ -15,7 +15,7 @@ define('forum/chats/messages', ['components', 'translator', 'benchpress'], functinputEl.val('');inputEl.removeAttr('data-mid');messages.updateRemainingLength(inputEl.parent());- $(window).trigger('action:chat.sent', {+ hooks.fire('action:chat.sent', {roomId: roomId,message: msg,mid: mid,@@ -62,7 +62,7 @@ define('forum/chats/messages', ['components', 'translator', 'benchpress'], functvar element = parent.find('[component="chat/input"]');parent.find('[component="chat/message/length"]').text(element.val().length);parent.find('[component="chat/message/remaining"]').text(config.maximumChatMessageLength - element.val().length);- $(window).trigger('action:chat.updateRemainingLength', {+ hooks.fire('action:chat.updateRemainingLength', {parent: parent,});};@@ -90,7 +90,7 @@ define('forum/chats/messages', ['components', 'translator', 'benchpress'], functmessages.scrollToBottom(chatContentEl);}- $(window).trigger('action:chat.received', {+ hooks.fire('action:chat.received', {messageEl: newMessage,});}@@ -149,7 +149,7 @@ define('forum/chats/messages', ['components', 'translator', 'benchpress'], functinputEl.attr('data-mid', messageId).addClass('editing');inputEl.val(raw).focus();- $(window).trigger('action:chat.prepEdit', {+ hooks.fire('action:chat.prepEdit', {inputEl: inputEl,messageId: messageId,roomId: roomId,diff --git a/public/src/client/compose.js b/public/src/client/compose.jsindex e5df728610..a7890679a5 100644--- a/public/src/client/compose.js+++ b/public/src/client/compose.js@@ -1,14 +1,14 @@'use strict';-define('forum/compose', [], function () {+define('forum/compose', ['hooks'], function (hooks) {var Compose = {};Compose.init = function () {var container = $('.composer');if (container.length) {- $(window).trigger('action:composer.enhance', {+ hooks.fire('action:composer.enhance', {container: container,});}diff --git a/public/src/client/infinitescroll.js b/public/src/client/infinitescroll.jsindex 2f66ce91a8..c8aebb413e 100644--- a/public/src/client/infinitescroll.js+++ b/public/src/client/infinitescroll.js@@ -1,7 +1,7 @@'use strict';-define('forum/infinitescroll', function () {+define('forum/infinitescroll', ['hooks'], function (hooks) {var scroll = {};var callback;var previousScrollTop = 0;@@ -70,7 +70,7 @@ define('forum/infinitescroll', function () {loadingMore = true;var hookData = { method: method, data: data };- $(window).trigger('action:infinitescroll.loadmore', hookData);+ hooks.fire('action:infinitescroll.loadmore', hookData);socket.emit(hookData.method, hookData.data, function (err, data) {if (err) {@@ -90,7 +90,7 @@ define('forum/infinitescroll', function () {loadingMore = true;var url = config.relative_path + '/api' + location.pathname.replace(new RegExp('^' + config.relative_path), '');var hookData = { url: url, data: data };- $(window).trigger('action:infinitescroll.loadmore.xhr', hookData);+ hooks.fire('action:infinitescroll.loadmore.xhr', hookData);$.get(url, data, function (data) {callback(data, function () {diff --git a/public/src/client/login.js b/public/src/client/login.jsindex 0dd0021f6a..0c59cdf2cc 100644--- a/public/src/client/login.js+++ b/public/src/client/login.js@@ -1,7 +1,7 @@'use strict';-define('forum/login', ['jquery-form'], function () {+define('forum/login', ['hooks', 'jquery-form'], function (hooks) {var Login = {_capsState: false,};@@ -26,7 +26,7 @@ define('forum/login', ['jquery-form'], function () {submitEl.addClass('disabled');- $(window).trigger('action:app.login');+ hooks.fire('action:app.login');formEl.ajaxSubmit({headers: {'x-csrf-token': config.csrf_token,@@ -35,7 +35,7 @@ define('forum/login', ['jquery-form'], function () {app.flags._login = true;},success: function (data) {- $(window).trigger('action:app.loggedIn', data);+ hooks.fire('action:app.loggedIn', data);var pathname = utils.urlToLocation(data.next).pathname;var params = utils.params({ url: data.next });params.loggedin = true;diff --git a/public/src/client/search.js b/public/src/client/search.jsindex 7991e41494..d722099cb6 100644--- a/public/src/client/search.js+++ b/public/src/client/search.js@@ -1,7 +1,12 @@'use strict';-define('forum/search', ['search', 'autocomplete', 'storage'], function (searchModule, autocomplete, storage) {+define('forum/search', [+ 'search',+ 'autocomplete',+ 'storage',+ 'hooks',+], function (searchModule, autocomplete, storage, hooks) {var Search = {};Search.init = function () {@@ -51,7 +56,7 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMosearchData.showAs = form.find('#show-as-topics').is(':checked') ? 'topics' : 'posts';}- $(window).trigger('action:search.getSearchDataFromDOM', {+ hooks.fire('action:search.getSearchDataFromDOM', {form: form,data: searchData,});@@ -128,7 +133,7 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo$('#show-as-posts').prop('checked', isPost).parent().toggleClass('active', isPost);}- $(window).trigger('action:search.fillOutForm', {+ hooks.fire('action:search.fillOutForm', {form: formData,});}diff --git a/public/src/client/topic.js b/public/src/client/topic.jsindex d0b57264c8..c6cce374c9 100644--- a/public/src/client/topic.js+++ b/public/src/client/topic.js@@ -44,7 +44,7 @@ define('forum/topic', [Topic.init = function () {var tid = ajaxify.data.tid;currentUrl = ajaxify.currentPage;- $(window).trigger('action:topic.loading');+ hooks.fire('action:topic.loading');app.enterRoom('topic_' + tid);diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.jsindex 5e9a406e87..e3ae6d82f1 100644--- a/public/src/client/topic/events.js+++ b/public/src/client/topic/events.js@@ -10,7 +10,8 @@ define('forum/topic/events', ['components','translator','benchpress',-], function (postTools, threadTools, posts, images, components, translator, Benchpress) {+ 'hooks',+], function (postTools, threadTools, posts, images, components, translator, Benchpress, hooks) {var Events = {};var events = {@@ -150,11 +151,11 @@ define('forum/topic/events', [app.parseAndTranslate('partials/topic/post-editor', editData, function (html) {editorEl.replaceWith(html);$('[data-pid="' + data.post.pid + '"] [component="post/editor"] .timeago').timeago();- $(window).trigger('action:posts.edited', data);+ hooks.fire('action:posts.edited', data);});});} else {- $(window).trigger('action:posts.edited', data);+ hooks.fire('action:posts.edited', data);}if (data.topic.tags && tagsUpdated(data.topic.tags)) {diff --git a/public/src/client/topic/move.js b/public/src/client/topic/move.jsindex 624c7aeb28..6bacc9fa3f 100644--- a/public/src/client/topic/move.js+++ b/public/src/client/topic/move.js@@ -1,7 +1,7 @@'use strict';-define('forum/topic/move', ['categorySelector', 'alerts'], function (categorySelector, alerts) {+define('forum/topic/move', ['categorySelector', 'alerts', 'hooks'], function (categorySelector, alerts, hooks) {var Move = {};var modal;var selectedCategory;@@ -85,7 +85,7 @@ define('forum/topic/move', ['categorySelector', 'alerts'], function (categorySel}function moveTopics(data) {- $(window).trigger('action:topic.move', data);+ hooks.fire('action:topic.move', data);socket.emit(!data.tids ? 'topics.moveAll' : 'topics.move', data, function (err) {if (err) {diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.jsindex df739609ba..0323663f81 100644--- a/public/src/client/topic/postTools.js+++ b/public/src/client/topic/postTools.js@@ -9,7 +9,8 @@ define('forum/topic/postTools', ['forum/topic/votes','api','bootbox',-], function (share, navigator, components, translator, votes, api, bootbox) {+ 'hooks',+], function (share, navigator, components, translator, votes, api, bootbox, hooks) {var PostTools = {};var staleReplyAnyway = false;@@ -50,7 +51,7 @@ define('forum/topic/postTools', [require(['clipboard'], function (clipboard) {new clipboard('[data-clipboard-text]');});- $(window).trigger('action:post.tools.load');+ hooks.fire('action:post.tools.load');});});});@@ -98,7 +99,7 @@ define('forum/topic/postTools', [$('.topic').on('click', '[component="topic/reply-as-topic"]', function () {translator.translate('[[topic:link_back, ' + ajaxify.data.titleRaw + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) {- $(window).trigger('action:composer.topic.new', {+ hooks.fire('action:composer.topic.new', {cid: ajaxify.data.cid,body: body,});@@ -155,7 +156,7 @@ define('forum/topic/postTools', [var postEditDuration = parseInt(ajaxify.data.postEditDuration, 10);if (checkDuration(postEditDuration, timestamp, 'post-edit-duration-expired')) {- $(window).trigger('action:composer.post.edit', {+ hooks.fire('action:composer.post.edit', {pid: getData(btn, 'data-pid'),});}@@ -258,10 +259,11 @@ define('forum/topic/postTools', [}var toPid = button.is('[component="post/reply"]') ? getData(button, 'data-pid') : null;+ var isQuoteToPid = !toPid || !selectedNode.pid || toPid === selectedNode.pid;- if (selectedNode.text && (!toPid || !selectedNode.pid || toPid === selectedNode.pid)) {+ if (selectedNode.text && isQuoteToPid) {username = username || selectedNode.username;- $(window).trigger('action:composer.addQuote', {+ hooks.fire('action:composer.addQuote', {tid: tid,pid: toPid,topicName: ajaxify.data.titleRaw,@@ -270,7 +272,7 @@ define('forum/topic/postTools', [selectedPid: selectedNode.pid,});} else {- $(window).trigger('action:composer.post.new', {+ hooks.fire('action:composer.post.new', {tid: tid,pid: toPid,topicName: ajaxify.data.titleRaw,@@ -288,7 +290,7 @@ define('forum/topic/postTools', [var toPid = getData(button, 'data-pid');function quote(text) {- $(window).trigger('action:composer.addQuote', {+ hooks.fire('action:composer.addQuote', {tid: tid,pid: toPid,username: username,@@ -351,7 +353,7 @@ define('forum/topic/postTools', [return app.alertError(err);}var type = method === 'put' ? 'bookmark' : 'unbookmark';- $(window).trigger('action:post.' + type, { pid: pid });+ hooks.fire('action:post.' + type, { pid: pid });});return false;}@@ -440,7 +442,7 @@ define('forum/topic/postTools', [className: 'btn-primary',callback: function () {translator.translate('[[topic:link_back, ' + ajaxify.data.title + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) {- $(window).trigger('action:composer.topic.new', {+ hooks.fire('action:composer.topic.new', {cid: ajaxify.data.cid,body: body,fromStaleTopic: true,diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.jsindex 3f841eac4f..89d3956a4e 100644--- a/public/src/client/topic/posts.js+++ b/public/src/client/topic/posts.js@@ -200,7 +200,7 @@ define('forum/topic/posts', [before = repliesSelector.first();}- $(window).trigger('action:posts.loading', { posts: data.posts, after: after, before: before });+ hooks.fire('action:posts.loading', { posts: data.posts, after: after, before: before });app.parseAndTranslate('topic', 'posts', Object.assign({}, ajaxify.data, data), function (html) {html = html.filter(function () {diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.jsindex 1ba9efeae6..f49d1f9b62 100644--- a/public/src/client/topic/threadTools.js+++ b/public/src/client/topic/threadTools.js@@ -7,7 +7,8 @@ define('forum/topic/threadTools', ['handleBack','forum/topic/posts','api',-], function (components, translator, handleBack, posts, api) {+ 'hooks',+], function (components, translator, handleBack, posts, api, hooks) {var ThreadTools = {};ThreadTools.init = function (tid, topicContainer) {@@ -151,7 +152,7 @@ define('forum/topic/threadTools', [timeout: 5000,});- $(window).trigger('action:topics.changeWatching', { tid: tid, type: type });+ hooks.fire('action:topics.changeWatching', { tid: tid, type: type });}, () => {app.alert({type: 'danger',@@ -180,7 +181,7 @@ define('forum/topic/threadTools', [}app.parseAndTranslate('partials/topic/topic-menu-list', data, function (html) {dropdownMenu.html(html);- $(window).trigger('action:topic.tools.load', {+ hooks.fire('action:topic.tools.load', {element: dropdownMenu,});});diff --git a/public/src/client/topic/votes.js b/public/src/client/topic/votes.jsindex e2f15008a9..797d27dee4 100644--- a/public/src/client/topic/votes.js+++ b/public/src/client/topic/votes.js@@ -2,8 +2,8 @@define('forum/topic/votes', [- 'components', 'translator', 'benchpress', 'api',-], function (components, translator, Benchpress, api) {+ 'components', 'translator', 'benchpress', 'api', 'hooks',+], function (components, translator, Benchpress, api, hooks) {var Votes = {};Votes.addVoteHandler = function () {@@ -70,7 +70,7 @@ define('forum/topic/votes', [}return app.alertError(err.message);}- $(window).trigger('action:post.toggleVote', {+ hooks.fire('action:post.toggleVote', {pid: pid,delta: delta,unvote: method === 'del',diff --git a/public/src/modules/categoryFilter.js b/public/src/modules/categoryFilter.jsindex ee14041fe3..25b9a80a96 100644--- a/public/src/modules/categoryFilter.js+++ b/public/src/modules/categoryFilter.js@@ -1,6 +1,6 @@'use strict';-define('categoryFilter', ['categorySearch', 'api'], function (categorySearch, api) {+define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categorySearch, api, hooks) {var categoryFilter = {};categoryFilter.init = function (el, options) {@@ -10,7 +10,8 @@ define('categoryFilter', ['categorySearch', 'api'], function (categorySearch, apoptions = options || {};options.states = options.states || ['watching', 'notwatching', 'ignoring'];options.template = 'partials/category-filter';- $(window).trigger('action:category.filter.options', { el: el, options: options });++ hooks.fire('action:category.filter.options', { el: el, options: options });categorySearch.init(el, options);diff --git a/public/src/modules/categorySelector.js b/public/src/modules/categorySelector.jsindex dcf9505392..3117857999 100644--- a/public/src/modules/categorySelector.js+++ b/public/src/modules/categorySelector.js@@ -1,8 +1,8 @@'use strict';define('categorySelector', [- 'categorySearch', 'bootbox',-], function (categorySearch, bootbox) {+ 'categorySearch', 'bootbox', 'hooks',+], function (categorySearch, bootbox, hooks) {var categorySelector = {};categorySelector.init = function (el, options) {@@ -14,7 +14,7 @@ define('categorySelector', [options.states = options.states || ['watching', 'notwatching', 'ignoring'];options.template = 'partials/category-selector';- $(window).trigger('action:category.selector.options', { el: el, options: options });+ hooks.fire('action:category.selector.options', { el: el, options: options });categorySearch.init(el, options);diff --git a/public/src/modules/chat.js b/public/src/modules/chat.jsindex 680022049e..ff703a85a9 100644--- a/public/src/modules/chat.js+++ b/public/src/modules/chat.js@@ -4,7 +4,8 @@ define('chat', ['components','taskbar','translator',-], function (components, taskbar, translator) {+ 'hooks',+], function (components, taskbar, translator, hooks) {var module = {};var newMessage = false;@@ -123,7 +124,7 @@ define('chat', [taskbar.update('chat', modal.attr('data-uuid'), {title: newTitle,});- $(window).trigger('action:chat.renamed', Object.assign(data, {+ hooks.fire('action:chat.renamed', Object.assign(data, {modal: modal,}));};@@ -249,7 +250,7 @@ define('chat', [isSelf: data.isSelf,}, function () {taskbar.toggleNew(chatModal.attr('data-uuid'), !data.isSelf);- $(window).trigger('action:chat.loaded', chatModal);+ hooks.fire('action:chat.loaded', chatModal);if (typeof callback === 'function') {callback(chatModal);@@ -275,7 +276,7 @@ define('chat', [module.disableMobileBehaviour(chatModal);}- $(window).trigger('action:chat.closed', {+ hooks.fire('action:chat.closed', {uuid: uuid,modal: chatModal,});@@ -352,7 +353,7 @@ define('chat', [taskbar.minimize('chat', uuid);clearInterval(chatModal.attr('intervalId'));chatModal.attr('intervalId', 0);- $(window).trigger('action:chat.minimized', {+ hooks.fire('action:chat.minimized', {uuid: uuid,modal: chatModal,});diff --git a/public/src/modules/flags.js b/public/src/modules/flags.jsindex 12ab3d419e..244589a3a2 100644--- a/public/src/modules/flags.js+++ b/public/src/modules/flags.js@@ -48,7 +48,7 @@ define('flags', ['hooks', 'components', 'api'], function (hooks, components, api});flagModal.modal('show');- $(window).trigger('action:flag.showModal', {+ hooks.fire('action:flag.showModal', {modalEl: flagModal,type: data.type,id: data.id,@@ -84,7 +84,7 @@ define('flags', ['hooks', 'components', 'api'], function (hooks, components, apipostEl.find('[component="post/flag"]').addClass('hidden').parent().attr('hidden', '');postEl.find('[component="post/already-flagged"]').removeClass('hidden').parent().attr('hidden', null);}- $(window).trigger('action:flag.create', { flagId: flagId, data: data });+ hooks.fire('action:flag.create', { flagId: flagId, data: data });});}diff --git a/public/src/modules/search.js b/public/src/modules/search.jsindex 57056d2124..536bebbe5d 100644--- a/public/src/modules/search.js+++ b/public/src/modules/search.js@@ -1,7 +1,7 @@'use strict';-define('search', ['navigator', 'translator', 'storage'], function (nav, translator, storage) {+define('search', ['navigator', 'translator', 'storage', 'hooks'], function (nav, translator, storage, hooks) {var Search = {current: {},};@@ -90,7 +90,7 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translatquery.searchOnly = data.searchOnly;}- $(window).trigger('action:search.createQueryString', {+ hooks.fire('action:search.createQueryString', {query: query,data: data,});diff --git a/public/src/modules/share.js b/public/src/modules/share.jsindex e8d4633e08..946135e986 100644--- a/public/src/modules/share.js+++ b/public/src/modules/share.js@@ -1,7 +1,7 @@'use strict';-define('share', function () {+define('share', ['hooks'], function (hooks) {var module = {};module.addShareHandlers = function (name) {@@ -9,7 +9,7 @@ define('share', function () {function openShare(url, urlToPost, width, height) {window.open(url + encodeURIComponent(baseUrl + config.relative_path + urlToPost), '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no');- $(window).trigger('action:share.open', {+ hooks.fire('action:share.open', {url: url,urlToPost: urlToPost,});@@ -43,7 +43,7 @@ define('share', function () {return openShare('https://plus.google.com/share?url=', getPostUrl($(this)), 500, 570);});- $(window).trigger('action:share.addHandlers', { openShare: openShare });+ hooks.fire('action:share.addHandlers', { openShare: openShare });};function addHandler(selector, callback) {diff --git a/public/src/modules/taskbar.js b/public/src/modules/taskbar.jsindex a16e4d8f5c..1c8b2165bb 100644--- a/public/src/modules/taskbar.js+++ b/public/src/modules/taskbar.js@@ -1,7 +1,7 @@'use strict';-define('taskbar', ['benchpress', 'translator'], function (Benchpress, translator) {+define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, translator, hooks) {var taskbar = {};taskbar.init = function () {@@ -89,7 +89,7 @@ define('taskbar', ['benchpress', 'translator'], function (Benchpress, translatorelement: element,};- $(window).trigger('filter:taskbar.push', data);+ hooks.fire('filter:taskbar.push', data);if (!element.length && data.module) {createTaskbarItem(data, callback);@@ -116,7 +116,7 @@ define('taskbar', ['benchpress', 'translator'], function (Benchpress, translatorbtnEl.toggleClass('new', state);if (!silent) {- $(window).trigger('action:taskbar.toggleNew', uuid);+ hooks.fire('action:taskbar.toggleNew', uuid);}};@@ -175,7 +175,7 @@ define('taskbar', ['benchpress', 'translator'], function (Benchpress, translatordata.element = taskbarEl;taskbarEl.data(data);- $(window).trigger('action:taskbar.pushed', data);+ hooks.fire('action:taskbar.pushed', data);callback(taskbarEl);});}diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.jsindex c4ee45e66a..b85e04aef9 100644--- a/public/src/modules/topicList.js+++ b/public/src/modules/topicList.js@@ -72,7 +72,7 @@ define('topicList', [TopicList.loadMoreTopics(1);});- $(window).trigger('action:topics.loaded', { topics: ajaxify.data.topics });+ hooks.fire('action:topics.loaded', { topics: ajaxify.data.topics });};function findTopicListElement() {@@ -277,7 +277,7 @@ define('topicList', [html.find('.timeago').timeago();app.createUserTooltips(html);utils.makeNumbersHumanReadable(html.find('.human-readable-number'));- $(window).trigger('action:topics.loaded', { topics: topics, template: templateName });+ hooks.fire('action:topics.loaded', { topics: topics, template: templateName });callback();});}diff --git a/public/src/modules/translator.js b/public/src/modules/translator.jsindex da6335a20b..2205d9b64b 100644--- a/public/src/modules/translator.js+++ b/public/src/modules/translator.js@@ -9,8 +9,10 @@namespace: namespace,data: data,};- $(window).trigger('action:translator.loadClient', payload);- resolve(payload.promise ? Promise.resolve(payload.promise) : data);+ require(['hooks'], function (hooks) {+ hooks.fire('action:translator.loadClient', payload);+ resolve(payload.promise ? Promise.resolve(payload.promise) : data);+ });}).fail(function (jqxhr, textStatus, error) {reject(new Error(textStatus + ', ' + error));});diff --git a/public/src/sockets.js b/public/src/sockets.jsindex 6c4c4b62c3..c80aec205d 100644--- a/public/src/sockets.js+++ b/public/src/sockets.js@@ -7,6 +7,11 @@ socket = window.socket;(function () {var reconnecting = false;+ var hooks;+ require(['hooks'], function (_hooks) {+ hooks = _hooks;+ });+var ioParams = {reconnectionAttempts: config.maxReconnectionAttempts,reconnectionDelay: config.reconnectionDelay,@@ -124,7 +129,7 @@ socket = window.socket;function onConnect() {if (!reconnecting) {- $(window).trigger('action:connected');+ hooks.fire('action:connected');}if (reconnecting) {@@ -140,7 +145,7 @@ socket = window.socket;socket.emit('meta.reconnected');- $(window).trigger('action:reconnected');+ hooks.fire('action:reconnected');setTimeout(function () {reconnectEl.removeClass('active').addClass('hide');@@ -204,7 +209,7 @@ socket = window.socket;}}, 2000);- $(window).trigger('action:disconnected');+ hooks.fire('action:disconnected');}function onEventBanned(data) {diff --git a/public/src/widgets.js b/public/src/widgets.jsindex 152ba80c6d..a23155e56e 100644--- a/public/src/widgets.js+++ b/public/src/widgets.js@@ -48,6 +48,8 @@}});- $(window).trigger('action:widgets.loaded', {});+ require(['hooks'], function (hooks) {+ hooks.fire('action:widgets.loaded', {});+ });};}(ajaxify || {}));