2013-01-03 22:36:51 +00:00
|
|
|
/*\
|
2013-05-31 12:23:25 +00:00
|
|
|
title: $:/core/modules/widgets/setstyle.js
|
2013-01-03 22:36:51 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: widget
|
|
|
|
|
|
|
|
Implements the setstyle widget.
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var SetStyleWidget = function(renderer) {
|
|
|
|
// Save state
|
|
|
|
this.renderer = renderer;
|
|
|
|
// Generate child nodes
|
|
|
|
this.generate();
|
|
|
|
};
|
|
|
|
|
|
|
|
SetStyleWidget.prototype.generate = function() {
|
|
|
|
// Get the parameters from the attributes
|
|
|
|
this.name = this.renderer.getAttribute("name");
|
|
|
|
this.value = this.renderer.getAttribute("value");
|
|
|
|
this["class"] = this.renderer.getAttribute("class");
|
|
|
|
// Set up the element
|
|
|
|
this.tag = this.renderer.parseTreeNode.isBlock ? "div" : "span";
|
|
|
|
this.attributes = {
|
|
|
|
style: this.name + ":" + this.value
|
|
|
|
};
|
|
|
|
if(this["class"]) {
|
|
|
|
this.attributes["class"] = this["class"];
|
|
|
|
}
|
2013-05-15 16:32:17 +00:00
|
|
|
this.children = this.renderer.renderTree.createRenderers(this.renderer,this.renderer.parseTreeNode.children);
|
2013-01-03 22:36:51 +00:00
|
|
|
};
|
|
|
|
|
2013-06-02 22:18:54 +00:00
|
|
|
SetStyleWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|
|
|
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed
|
|
|
|
if(changedAttributes.name || changedAttributes.value || changedAttributes["class"]) {
|
|
|
|
// Regenerate and rerender the widget and replace the existing DOM node
|
|
|
|
this.generate();
|
|
|
|
var oldDomNode = this.renderer.domNode,
|
|
|
|
newDomNode = this.renderer.renderInDom();
|
|
|
|
oldDomNode.parentNode.replaceChild(newDomNode,oldDomNode);
|
|
|
|
} else {
|
|
|
|
// We don't need to refresh ourselves, so just refresh any child nodes
|
|
|
|
$tw.utils.each(this.children,function(node) {
|
|
|
|
if(node.refreshInDom) {
|
|
|
|
node.refreshInDom(changedTiddlers);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-03 22:36:51 +00:00
|
|
|
exports.setstyle = SetStyleWidget;
|
|
|
|
|
|
|
|
})();
|