I am still trying to make my first widget, which is still a clock button
for my top menu. So here is what I have so far. I put the following in a
tiddler with title: $:/core/modules/widgets/clock.js, Type:
application/javascript and added a filed module-type: widget. In another
tiddler I put <$clock> but all still get Undefined widget 'clock'. What am
I missing?
/*\
title: $:/core/modules/widgets/clock.js
type: application/javascript
module-type: widget
A widget to display a clock
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/clock.js").widget;
var ClockWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
ClockWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
ClockWidget.prototype.render = function(parent,nextSibling) {
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
var domNode = this.document.createElement('p');
domNode.setAttribute("id","tw-clockbutton");
parent.insertBefore(domNode,nextSibling);
this.renderChildren(domNode,null);
this.domNodes.push(domNode);
};
/*
Compute the internal state of the widget
*/
ClockWidget.prototype.execute = function() {
var myVar=setInterval(function(){myTimer()},1000);
};
ClockWidget.prototype.myTimer = function() {
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("tw-clockbutton").innerHTML=t;
};
/*
Selectively refreshes the widget if needed. Returns true if the widget or
any of its children needed re-rendering
*/
ClockWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes(),
hasChangedAttributes = $tw.utils.count(changedAttributes) > 0;
if(hasChangedAttributes) {
// Update our attributes
this.assignAttributes(this.domNodes[0]);
}
return this.refreshChildren(changedTiddlers) || hasChangedAttributes;
};
exports.clock = ClockWidget;
})();
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/groups/opt_out.