Created
March 10, 2017 11:32
-
-
Save briedis/d7c562ede66ba66c800e0554bd0e753b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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