The code you posted is NOT the code I published! Most notably, you’ve added
if($tw.node) return
at the beginning of the function. This explicitly prevents the code from reporting any errors or updating the info tiddlers when running in a NodeJS environment.
The purpose of my code is to get the current window width and height values (in pixels) and store them in $:/info/browser/window/width
and $:/info/browser/window/height
shadow tiddlers. This code is intially invoked at startup by the TWCore’s “info” mechanism which creates the respective $:/info/...
tiddlers based on the array of objects returned.
The code also sets up a window event listener, so that whenever the browser window is resized, the respective $:/info/...
tiddlers are updated (via the updateInfoTiddlersCallback
function) to reflect the new window width and height.
Here’s the actual current code from TiddlyTools/Modules/Info/WindowSize.js:
/*\
title:TiddlyTools/Modules/Info/WindowSize.js
type: application/javascript
module-type: info
save window size (pixels) to $:/info/browser/window/width and $:/info/browser/window/height
with resize listener
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.getInfoTiddlerFields = function(updateInfoTiddlersCallback) {
try {
var getWindowSize=function() {
var w=( window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth );
var h=( window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight );
return ([{title:"$:/info/browser/window/width",text:w.toString()},{title:"$:/info/browser/window/height",text:h.toString()}]);
};
window.addEventListener("resize",function(){updateInfoTiddlersCallback(getWindowSize());});
return getWindowSize();
}
catch(e) { return([]); }
};
})();
Note that, for normal browser-based usage, there will always be a window
object, and the function works as intended… it gets the current browser window width and height, and also sets up a resize
listener.
Using the above code, the tiddlywiki-app does successfully set the initial $:/info/...
tiddler values. However, when the tiddlywiki-app window is resized, it does not seem that the “resize” event listener is triggered and the $:/info/...
tiddlers are not being updated.
Can you make your tiddlywiki-app code trigger the “resize” event listener? If not, can you suggest some alternative code that I can add to my implementation to achieve the same outcome?
-e