Created
August 4, 2012 20:53
-
-
Save rla/3259850 to your computer and use it in GitHub Desktop.
Example JS client-side module
This file contains 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
var kam = kam || {}; | |
kam.group = function() { | |
var exports = {}; | |
var Widget = kam.widget.Widget; | |
// Group groups items into box-like widget. | |
// Has title area. | |
function Group(title) { | |
Widget.call(this, 'group'); | |
this.title = title; | |
this.contents = []; | |
} | |
kam.util.inherits(Group, Widget); | |
exports.Group = Group; | |
// Adds new item to groupbox. | |
Group.prototype.add = function(item) { | |
this.contents.push(item); | |
}; | |
Group.prototype.make = function() { | |
var box = this.makeStyled(); | |
if (this.title) { | |
var title = document.createElement('div'); | |
title.className = 'group-title'; | |
title.innerHTML = this.title; | |
box.appendChild(title); | |
} | |
for (var i = 0; i < this.contents.length; i++) { | |
box.appendChild(this.contents[i].make()); | |
} | |
return box; | |
}; | |
return exports; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment