You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/public/src/modules/categorySelector.js

34 lines
830 B
JavaScript

8 years ago
'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;
});