it works. Thank you. 

пятница, 28 ноября 2014 г., 21:44:22 UTC+3 пользователь Mark S. написал:
>
> I don't believe you can currently add things in TW5
>
> Here's a widget I put together in a few minutes based on an existing 
> widget. Be sure to back up and save your data before using. There shouldn't 
> be anything dangerous here since it doesn't modify the store ... but who 
> knows?
>
> Use like
>
>    *<$addup val1="20" val2="80" />*
>
> You can have up to 5 *valx* attributes
>
> To import this code into your own TW, just find an existing plugin (e.g. 
> $:/core/modules/widgets/button.js), 
> clone it, rename the clone to $:/core/modules/widgets/addup.js and 
> replace the code with the code that follows or if that doesn't work, with 
> the code in the attached file. Reload the TW to activate the plugin.
>
>   
>
>
> /*\
> title: $:/core/modules/widgets/addup.js
> type: application/javascript
> module-type: widget
>
> Sum up to 5 variables widget
>
> \*/
> (function(){
>
> /*jslint node: true, browser: true */
> /*global $tw: false */
> "use strict";
>
> var Widget = require("$:/core/modules/widgets/widget.js").widget;
>
> var AddUpWidget = function(parseTreeNode,options) {
>     this.initialise(parseTreeNode,options);
> };
>
> /*
> Inherit from the base widget class
> */
> AddUpWidget.prototype = new Widget();
>
> /*
> Render this widget into the DOM
> */
> AddUpWidget.prototype.render = function(parent,nextSibling) {
>     this.parentDomNode = parent;
>     this.computeAttributes();
>     this.execute();
>     var textNode = this.document.createTextNode(this.currentSum);
>     parent.insertBefore(textNode,nextSibling);
>     this.domNodes.push(textNode);
> };
>
> /*
> Compute the internal state of the widget
> */
> AddUpWidget.prototype.execute = function() {
>     // Get parameters from our attributes
>     //this.filter = this.getAttribute("filter");
>     this.val1 = this.getAttribute("val1","0") ;
>     this.val2 = this.getAttribute("val2","0") ;
>     this.val3 = this.getAttribute("val3","0") ;
>     this.val4 = this.getAttribute("val4","0") ;
>     this.val5 = this.getAttribute("val5","0") ;
>
>     // Execute the math
>     this.currentSum= 
> Number(this.val1)+Number(this.val2)+Number(this.val3)+
>     Number(this.val4)+Number(this.val5) ;
>
>
> };
>
> /*
> Selectively refreshes the widget if needed. Returns true if the widget or 
> any of its children needed re-rendering
> */
> AddUpWidget.prototype.refresh = function(changedTiddlers) {
>     // Re-execute the filter to get the count
>     this.computeAttributes();
>     var oldCount = this.currentSum;
>     this.execute();
>     if(this.currentSum !== oldCount) {
>         // Regenerate and rerender the widget and replace the existing DOM 
> node
>         this.refreshSelf();
>         return true;
>     } else {
>         return false;
>     }
>
> };
>
> exports.addup = AddUpWidget;
>
> })();
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" 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/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

Reply via email to