Integrate preferred height JS code into PageState, tidy it up a bit.

* ui/client-web-view.js: Move emitPreferredHeightChanged() into PageState
  as ::preferredHeightChanged(). Add a explicit constructor, move
  instance properties into that. Add an interval timer to periodically
  update the preferred height until loaded.
This commit is contained in:
Michael James Gratton 2016-11-25 22:00:06 +11:00
parent d002722a19
commit 3068d1b0e5

View file

@ -9,9 +9,22 @@
* Application logic for ClientWebView and subclasses.
*/
var PageState = function() { };
var PageState = function() {
this.init.apply(this, arguments);
};
PageState.prototype = {
allowRemoteImages: false,
init: function() {
this.allowRemoteImages = false;
this.loaded = false;
var state = this;
var timeoutId = window.setInterval(function() {
state.preferredHeightChanged();
if (state.loaded) {
window.clearTimeout(timeoutId);
}
}, 50);
},
loadRemoteImages: function() {
this.allowRemoteImages = true;
var images = document.getElementsByTagName("IMG");
@ -24,16 +37,18 @@ PageState.prototype = {
},
remoteImageLoadBlocked: function() {
window.webkit.messageHandlers.remoteImageLoadBlocked.postMessage(null);
},
preferredHeightChanged: function() {
var height = window.document.documentElement.offsetHeight;
if (height > 0) {
window.webkit.messageHandlers.preferredHeightChanged.postMessage(
height
);
}
}
};
function emitPreferredHeightChanged() {
window.webkit.messageHandlers.preferredHeightChanged.postMessage(
window.document.documentElement.offsetHeight
);
}
var geary = new PageState();
window.onload = function() {
emitPreferredHeightChanged();
geary.loaded = true;
};