kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Refine refreshing of tiddler widget
We need to refresh if there is a change in the state that we copy to variables.print-window-tiddler
rodzic
d2ab7c5986
commit
9bbd599f5c
|
@ -37,18 +37,35 @@ TiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||||
Compute the internal state of the widget
|
Compute the internal state of the widget
|
||||||
*/
|
*/
|
||||||
TiddlerWidget.prototype.execute = function() {
|
TiddlerWidget.prototype.execute = function() {
|
||||||
// Get our parameters
|
this.tiddlerState = this.computeTiddlerState();
|
||||||
this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
this.setVariable("currentTiddler",this.tiddlerState.currentTiddler);
|
||||||
// Set context variables
|
this.setVariable("missingTiddlerClass",this.tiddlerState.missingTiddlerClass);
|
||||||
this.setVariable("currentTiddler",this.tiddlerTitle);
|
this.setVariable("shadowTiddlerClass",this.tiddlerState.shadowTiddlerClass);
|
||||||
this.setVariable("missingTiddlerClass",(this.wiki.tiddlerExists(this.tiddlerTitle) || this.wiki.isShadowTiddler(this.tiddlerTitle)) ? "tc-tiddler-exists" : "tc-tiddler-missing");
|
this.setVariable("systemTiddlerClass",this.tiddlerState.systemTiddlerClass);
|
||||||
this.setVariable("shadowTiddlerClass",this.wiki.isShadowTiddler(this.tiddlerTitle) ? "tc-tiddler-shadow" : "");
|
this.setVariable("tiddlerTagClasses",this.tiddlerState.tiddlerTagClasses);
|
||||||
this.setVariable("systemTiddlerClass",this.wiki.isSystemTiddler(this.tiddlerTitle) ? "tc-tiddler-system" : "");
|
|
||||||
this.setVariable("tiddlerTagClasses",this.getTagClasses());
|
|
||||||
// Construct the child widgets
|
// Construct the child widgets
|
||||||
this.makeChildWidgets();
|
this.makeChildWidgets();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Compute the tiddler state flags
|
||||||
|
*/
|
||||||
|
TiddlerWidget.prototype.computeTiddlerState = function() {
|
||||||
|
// Get our parameters
|
||||||
|
this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||||
|
// Compute the state
|
||||||
|
var state = {
|
||||||
|
currentTiddler: this.tiddlerTitle || "",
|
||||||
|
missingTiddlerClass: (this.wiki.tiddlerExists(this.tiddlerTitle) || this.wiki.isShadowTiddler(this.tiddlerTitle)) ? "tc-tiddler-exists" : "tc-tiddler-missing",
|
||||||
|
shadowTiddlerClass: this.wiki.isShadowTiddler(this.tiddlerTitle) ? "tc-tiddler-shadow" : "",
|
||||||
|
systemTiddlerClass: this.wiki.isSystemTiddler(this.tiddlerTitle) ? "tc-tiddler-system" : "",
|
||||||
|
tiddlerTagClasses: this.getTagClasses()
|
||||||
|
};
|
||||||
|
// Compute a simple hash to make it easier to detect changes
|
||||||
|
state.hash = state.currentTiddler + state.missingTiddlerClass + state.shadowTiddlerClass + state.systemTiddlerClass + state.tiddlerTagClasses;
|
||||||
|
return state;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Create a string of CSS classes derived from the tags of the current tiddler
|
Create a string of CSS classes derived from the tags of the current tiddler
|
||||||
*/
|
*/
|
||||||
|
@ -69,8 +86,9 @@ TiddlerWidget.prototype.getTagClasses = function() {
|
||||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||||
*/
|
*/
|
||||||
TiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
TiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||||
var changedAttributes = this.computeAttributes();
|
var changedAttributes = this.computeAttributes(),
|
||||||
if(changedAttributes.tiddler) {
|
newTiddlerState = this.computeTiddlerState();
|
||||||
|
if(changedAttributes.tiddler || newTiddlerState.hash !== this.tiddlerState.hash) {
|
||||||
this.refreshSelf();
|
this.refreshSelf();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
Ładowanie…
Reference in New Issue