2012-12-14 17:38:46 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/widgetbase.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: global
|
|
|
|
|
|
|
|
Base class for widgets
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
This constructor is always overridden with a blank constructor, and so shouldn't be used
|
|
|
|
*/
|
|
|
|
var WidgetBase = function() {
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
To be overridden by individual widgets
|
|
|
|
*/
|
|
|
|
WidgetBase.prototype.init = function(renderer) {
|
|
|
|
this.renderer = renderer;
|
|
|
|
};
|
|
|
|
|
2012-12-14 17:51:14 +00:00
|
|
|
/*
|
|
|
|
Default render() method just renders child nodes
|
|
|
|
*/
|
|
|
|
WidgetBase.prototype.render = function(type) {
|
|
|
|
var output = [];
|
|
|
|
$tw.utils.each(this.children,function(node) {
|
|
|
|
if(node.render) {
|
|
|
|
output.push(node.render(type));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return output.join("");
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Default renderInDom() method just renders child nodes
|
|
|
|
*/
|
|
|
|
WidgetBase.prototype.renderInDom = function(parentElement) {
|
|
|
|
this.parentElement = parentElement;
|
|
|
|
// Render any child nodes
|
|
|
|
$tw.utils.each(this.children,function(node) {
|
|
|
|
if(node.renderInDom) {
|
|
|
|
parentElement.appendChild(node.renderInDom());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2012-12-14 17:38:46 +00:00
|
|
|
exports.WidgetBase = WidgetBase;
|
|
|
|
|
|
|
|
})();
|