mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 09:20:32 +01:00
Feat: Client-side hooks - replace window.trigger (#9679)
* feat/clientside-hooks: replace window.trigger with hooks.fire * feat(clientside-hooks): Move hooks require to the top * fix: simplifying complex logical expression * fix: client-side hook for translator - post-review fixes
This commit is contained in:
@@ -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, mousetra
|
||||
type: '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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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] : []),
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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'], funct
|
||||
inputEl.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'], funct
|
||||
var 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'], funct
|
||||
messages.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'], funct
|
||||
inputEl.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,
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 (searchMo
|
||||
searchData.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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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, ap
|
||||
options = 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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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, api
|
||||
postEl.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 });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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, translat
|
||||
query.searchOnly = data.searchOnly;
|
||||
}
|
||||
|
||||
$(window).trigger('action:search.createQueryString', {
|
||||
hooks.fire('action:search.createQueryString', {
|
||||
query: query,
|
||||
data: data,
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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, translator
|
||||
element: 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, translator
|
||||
btnEl.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, translator
|
||||
data.element = taskbarEl;
|
||||
|
||||
taskbarEl.data(data);
|
||||
$(window).trigger('action:taskbar.pushed', data);
|
||||
hooks.fire('action:taskbar.pushed', data);
|
||||
callback(taskbarEl);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
namespace: namespace,
|
||||
data: data,
|
||||
};
|
||||
$(window).trigger('action:translator.loadClient', payload);
|
||||
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));
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -48,6 +48,8 @@
|
||||
}
|
||||
});
|
||||
|
||||
$(window).trigger('action:widgets.loaded', {});
|
||||
require(['hooks'], function (hooks) {
|
||||
hooks.fire('action:widgets.loaded', {});
|
||||
});
|
||||
};
|
||||
}(ajaxify || {}));
|
||||
|
||||
Reference in New Issue
Block a user