// switching view between targets and records
function switchView(view) {
- var targets = findnode('.mkwsTargets');
- var results = findnode('.mkwsResults,.mkwsRecords');
- var blanket = findnode('.mkwsBlanket');
- var motd = findnode('.mkwsMOTD');
+ var targets = widgetNode('Targets');
+ var results = widgetNode('Results') || widgetNode('Records');
+ var blanket = widgetNode('Blanket');
+ var motd = widgetNode('MOTD');
switch(view) {
case 'targets':
mkwsHtmlSwitch();
findnode('.mkwsSearchForm').submit(function() {
- var val = findnode('.mkwsQuery').val();
+ var val = widgetNode('Query').val();
newSearch(val);
return false;
});
// on first page, hide the termlist
- $(document).ready(function() { findnode(".mkwsTermlists").hide(); });
+ $(document).ready(function() { widgetNode("Termlists").hide(); });
var container = findnode(".mkwsMOTDContainer");
if (container.length) {
// Move the MOTD from the provided element down into the container
that.findnode = findnode;
+ // This much simpler and more efficient function should be usable
+ // in place of most uses of findnode.
+ function widgetNode(type) {
+ var w = that.widget(type);
+ return w ? $(w.node) : undefined;
+ }
+
function renderDetails(data, marker) {
var template = loadTemplate("Record");
var details = template(data);
if (template === undefined) {
// Fall back to generic template if there is no team-specific one
- var node = findnode(".mkwsTemplate_" + name);
+ var node = widgetNode("Template_" + name);
if (!node.length) {
- node = findnode(".mkwsTemplate_" + name, "ALL");
+ node = widgetNode("Template_" + name, "ALL");
}
var source = node.html();
that.addWidget = function(w) {
if (!m_widgets[w.type]) {
- m_widgets[w.type] = widget;
+ m_widgets[w.type] = w;
log("Registered '" + w.type + "' widget in team '" + m_teamName + "'");
} else if (typeof(m_widgets[w.type]) !== 'number') {
m_widgets[w.type] = 2;
}
}
+ that.widgetTypes = function() {
+ var keys = [];
+ for (var k in m_widgets) keys.push(k);
+ return keys.sort();
+ }
+
that.widget = function(type) {
return m_widgets[type];
}