Skip to content

Instantly share code, notes, and snippets.

@briedis
Created March 10, 2017 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briedis/d7c562ede66ba66c800e0554bd0e753b to your computer and use it in GitHub Desktop.
Save briedis/d7c562ede66ba66c800e0554bd0e753b to your computer and use it in GitHub Desktop.
(function () {
'use strict';
var List = Class({
/**
* @type {Array<string>}
*/
_items: [],
/**
* @type {Object<HTMLElement>}
*/
_itemNodes: {},
/**
* @param {Array<string>} items
* @private
*/
__construct: function (items) {
this._items = items;
this.node = mkE({tag: 'div'});
this._render();
},
/**
* @private
*/
_render: function () {
mkE.clearNode(this.node);
for (var i in this._items) {
var item = this._items[i];
var itemNode = mkE({
tag: 'a',
text: item
}).append(this.node);
this._itemNodes[item] = node;
}
},
/**
* @param {Array<string>} items
* @public
*/
activate: function (items) {
for (var i in items) {
mkE.addClassName(this._itemNodes[items[i]], 'active');
}
}
}, mkE.Base);
var list = new List(['one', 'two', 'three']);
list.append(document.body);
list.activate(['one', 'two']);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment