Skip to content

Instantly share code, notes, and snippets.

@rla
Created August 4, 2012 20:53
Show Gist options
  • Save rla/3259850 to your computer and use it in GitHub Desktop.
Save rla/3259850 to your computer and use it in GitHub Desktop.
Example JS client-side module
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