[geary/wip/728002-webkit2: 43/43] Integrate preferred height JS code into PageState, tidy it up a bit.



commit ae5d23489cfe02052da64c223b303b21229547c1
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]