[geary/wip/728002-webkit2: 38/96] Integrate preferred height JS code into PageState, tidy it up a bit.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/728002-webkit2: 38/96] Integrate preferred height JS code into PageState, tidy it up a bit.
- Date: Sat, 14 Jan 2017 12:15:01 +0000 (UTC)
commit 045f295079f633d564460f11123d8c3b905ac294
Author: Michael James Gratton <mike vee net>
Date: Fri Nov 25 22:00:06 2016 +1100
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.
ui/client-web-view.js | 33 ++++++++++++++++++++++++---------
1 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/ui/client-web-view.js b/ui/client-web-view.js
index 0b52438..89c47f0 100644
--- a/ui/client-web-view.js
+++ b/ui/client-web-view.js
@@ -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;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]