Files
NodeBB/public/src/modules/components.js
gasoved b0a24d6dd5 refactor: var to const and let (#9885)
* refactor: var to const and let

* fix: missed global bootbox usage

* refactor: align with eslint expectations
2021-10-12 10:26:18 -04:00

74 lines
2.3 KiB
JavaScript

'use strict';
define('components', function () {
const components = {};
components.core = {
'topic/teaser': function (tid) {
if (tid) {
return $('[component="category/topic"][data-tid="' + tid + '"] [component="topic/teaser"]');
}
return $('[component="topic/teaser"]');
},
topic: function (name, value) {
return $('[component="topic"][data-' + name + '="' + value + '"]');
},
post: function (name, value) {
return $('[component="post"][data-' + name + '="' + value + '"]');
},
'post/content': function (pid) {
return $('[component="post"][data-pid="' + pid + '"] [component="post/content"]');
},
'post/header': function (pid) {
return $('[component="post"][data-pid="' + pid + '"] [component="post/header"]');
},
'post/anchor': function (index) {
return $('[component="post"][data-index="' + index + '"] [component="post/anchor"]');
},
'post/vote-count': function (pid) {
return $('[component="post"][data-pid="' + pid + '"] [component="post/vote-count"]');
},
'post/bookmark-count': function (pid) {
return $('[component="post"][data-pid="' + pid + '"] [component="post/bookmark-count"]');
},
'user/postcount': function (uid) {
return $('[component="user/postcount"][data-uid="' + uid + '"]');
},
'user/reputation': function (uid) {
return $('[component="user/reputation"][data-uid="' + uid + '"]');
},
'category/topic': function (name, value) {
return $('[component="category/topic"][data-' + name + '="' + value + '"]');
},
'categories/category': function (name, value) {
return $('[component="categories/category"][data-' + name + '="' + value + '"]');
},
'chat/message': function (messageId) {
return $('[component="chat/message"][data-mid="' + messageId + '"]');
},
'chat/message/body': function (messageId) {
return $('[component="chat/message"][data-mid="' + messageId + '"] [component="chat/message/body"]');
},
'chat/recent/room': function (roomid) {
return $('[component="chat/recent/room"][data-roomid="' + roomid + '"]');
},
};
components.get = function () {
const args = Array.prototype.slice.call(arguments, 1);
if (components.core[arguments[0]] && args.length) {
return components.core[arguments[0]].apply(this, args);
}
return $('[component="' + arguments[0] + '"]');
};
return components;
});