mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +01:00
34 lines
830 B
JavaScript
34 lines
830 B
JavaScript
'use strict';
|
|
|
|
|
|
define('categorySelector', function () {
|
|
var categorySelector = {};
|
|
var selectedCategory;
|
|
var el;
|
|
categorySelector.init = function (_el, callback) {
|
|
callback = callback || function () {};
|
|
el = _el;
|
|
el.on('click', '[data-cid]', function () {
|
|
var categoryEl = $(this);
|
|
categorySelector.selectCategory(categoryEl.attr('data-cid'));
|
|
callback(selectedCategory);
|
|
});
|
|
};
|
|
|
|
categorySelector.getSelectedCategory = function () {
|
|
return selectedCategory;
|
|
};
|
|
|
|
categorySelector.selectCategory = function (cid) {
|
|
var categoryEl = el.find('[data-cid="' + cid + '"]');
|
|
selectedCategory = {
|
|
cid: cid,
|
|
name: categoryEl.attr('data-name'),
|
|
};
|
|
el.find('[component="category-selector-selected"]').html(categoryEl.find('[component="category-markup"]').html());
|
|
};
|
|
|
|
return categorySelector;
|
|
});
|
|
|