[geary/bug/728002-webkit2: 61/140] Minor code cleanup.



commit 636e514cda2005d986d876a23589254146b8adb7
Author: Michael James Gratton <mike vee net>
Date:   Wed Jan 4 01:15:08 2017 +1100

    Minor code cleanup.
    
    * src/client/components/client-web-view.vala (ClientWebView): Make some
      unnecessarily internal methods private.
    
    * ui/*.js: Replace "var" with "let" where appropriate - i.e. almost
      everywhere.

 src/client/components/client-web-view.vala |   16 ++++----
 ui/client-web-view.js                      |   16 ++++----
 ui/composer-web-view.js                    |    4 +-
 ui/conversation-web-view.js                |   64 ++++++++++++++--------------
 4 files changed, 50 insertions(+), 50 deletions(-)
---
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index dabbc01..98e8582 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -366,7 +366,13 @@ public class ClientWebView : WebKit.WebView {
         minimum_height = natural_height = 0;
     }
 
-    internal void handle_cid_request(WebKit.URISchemeRequest request) {
+    protected inline void register_message_handler(string name) {
+        if (!get_user_content_manager().register_script_message_handler(name)) {
+            debug("Failed to register script message handler: %s", name);
+        }
+    }
+
+    private void handle_cid_request(WebKit.URISchemeRequest request) {
         string cid = request.get_uri().substring(CID_URL_PREFIX.length);
         Geary.Memory.Buffer? buf = this.cid_resources[cid];
         if (buf != null) {
@@ -379,7 +385,7 @@ public class ClientWebView : WebKit.WebView {
         }
     }
 
-    internal void handle_internal_request(WebKit.URISchemeRequest request) {
+    private void handle_internal_request(WebKit.URISchemeRequest request) {
         if (request.get_uri() == INTERNAL_URL_BODY) {
             Geary.Memory.Buffer buf = new Geary.Memory.StringBuffer(this.body);
             request.finish(buf.get_input_stream(), buf.size, null);
@@ -388,12 +394,6 @@ public class ClientWebView : WebKit.WebView {
         }
     }
 
-    protected inline void register_message_handler(string name) {
-        if (!get_user_content_manager().register_script_message_handler(name)) {
-            debug("Failed to register script message handler: %s", name);
-        }
-    }
-
     // Only allow string-based page loads, and notify but ignore if
     // the user attempts to click on a link. Deny everything else.
     private bool on_decide_policy(WebKit.WebView view,
diff --git a/ui/client-web-view.js b/ui/client-web-view.js
index cc47655..879ac44 100644
--- a/ui/client-web-view.js
+++ b/ui/client-web-view.js
@@ -9,7 +9,7 @@
  * Application logic for ClientWebView and subclasses.
  */
 
-var PageState = function() {
+let PageState = function() {
     this.init.apply(this, arguments);
 };
 PageState.prototype = {
@@ -17,8 +17,8 @@ PageState.prototype = {
         this.allowRemoteImages = false;
         this.is_loaded = false;
 
-        var state = this;
-        var timeoutId = window.setInterval(function() {
+        let state = this;
+        let timeoutId = window.setInterval(function() {
             state.preferredHeightChanged();
             if (state.is_loaded) {
                 window.clearTimeout(timeoutId);
@@ -33,10 +33,10 @@ PageState.prototype = {
     },
     loadRemoteImages: function() {
         this.allowRemoteImages = true;
-        var images = document.getElementsByTagName("IMG");
-        for (var i = 0; i < images.length; i++) {
-            var img = images.item(i);
-            var src = img.src;
+        let images = document.getElementsByTagName("IMG");
+        for (let i = 0; i < images.length; i++) {
+            let img = images.item(i);
+            let src = img.src;
             img.src = "";
             img.src = src;
         }
@@ -53,7 +53,7 @@ PageState.prototype = {
         }
     },
     selectionChanged: function() {
-        var has_selection = !window.getSelection().isCollapsed;
+        let has_selection = !window.getSelection().isCollapsed;
         window.webkit.messageHandlers.selectionChanged.postMessage(has_selection);
     }
 };
diff --git a/ui/composer-web-view.js b/ui/composer-web-view.js
index e48090d..3c7023e 100644
--- a/ui/composer-web-view.js
+++ b/ui/composer-web-view.js
@@ -9,7 +9,7 @@
 /**
  * Application logic for ComposerWebView.
  */
-var ComposerPageState = function() {
+let ComposerPageState = function() {
     this.init.apply(this, arguments);
 };
 ComposerPageState.BODY_ID = "message-body";
@@ -146,7 +146,7 @@ ComposerPageState.htmlToQuotedText = function(root) {
 
     // Reassemble plain text out of parts, and replace non-breaking
     // space with regular space.
-    let text = ComposerPageState.resolveNesting(root.innerText, bqtexts)
+    let text = ComposerPageState.resolveNesting(root.innerText, bqtexts);
 
     // Reassemble DOM now we have the plain text
     root.innerHTML = savedDoc;
diff --git a/ui/conversation-web-view.js b/ui/conversation-web-view.js
index 6f433b4..cf1dcb7 100644
--- a/ui/conversation-web-view.js
+++ b/ui/conversation-web-view.js
@@ -9,7 +9,7 @@
 /**
  * Application logic for ConversationWebView.
  */
-var ConversationPageState = function() {
+let ConversationPageState = function() {
     this.init.apply(this, arguments);
 };
 
@@ -35,7 +35,7 @@ ConversationPageState.prototype = {
      * This should provide a slightly better RTL experience.
      */
     updateDirection: function() {
-        var dir = document.documentElement.dir;
+        let dir = document.documentElement.dir;
         if (dir == null || dir.trim() == "") {
             document.documentElement.dir = "auto";
         }
@@ -58,16 +58,16 @@ ConversationPageState.prototype = {
      * Add top level blockquotes to hide/show container.
      */
     createControllableQuotes: function() {
-        var blockquoteList = document.documentElement.querySelectorAll("blockquote");
-        for (var i = 0; i < blockquoteList.length; ++i) {
-            var blockquote = blockquoteList.item(i);
-            var nextSibling = blockquote.nextSibling;
-            var parent = blockquote.parentNode;
+        let blockquoteList = document.documentElement.querySelectorAll("blockquote");
+        for (let i = 0; i < blockquoteList.length; ++i) {
+            let blockquote = blockquoteList.item(i);
+            let nextSibling = blockquote.nextSibling;
+            let parent = blockquote.parentNode;
 
             // Only insert into a quote container if the element is a
             // top level blockquote
             if (!ConversationPageState.isDescendantOf(blockquote, "BLOCKQUOTE")) {
-                var quoteContainer = document.createElement("DIV");
+                let quoteContainer = document.createElement("DIV");
                 quoteContainer.classList.add(
                     ConversationPageState.QUOTE_CONTAINER_CLASS
                 );
@@ -130,15 +130,15 @@ ConversationPageState.prototype = {
      *
      */
     wrapSignature: function() {
-        var possibleSigs = document.documentElement.querySelectorAll("div,span,p");
-        var i = 0;
-        var sigRegex = new RegExp("^--\\s*$");
-        var alternateSigRegex = new RegExp("^--\\s*(?:<br|\\R)");
+        let possibleSigs = document.documentElement.querySelectorAll("div,span,p");
+        let i = 0;
+        let sigRegex = new RegExp("^--\\s*$");
+        let alternateSigRegex = new RegExp("^--\\s*(?:<br|\\R)");
         for (; i < possibleSigs.length; ++i) {
             // Get the div and check that it starts a signature block
             // and is not inside a quote.
-            var div = possibleSigs.item(i);
-            var innerHTML = div.innerHTML;
+            let div = possibleSigs.item(i);
+            let innerHTML = div.innerHTML;
             if ((sigRegex.test(innerHTML) || alternateSigRegex.test(innerHTML)) &&
                 !ConversationPageState.isDescendantOf(div, "BLOCKQUOTE")) {
                 break;
@@ -147,13 +147,13 @@ ConversationPageState.prototype = {
         // If we have a signature, move it and all of its following
         // siblings that are not quotes inside a signature div.
         if (i < possibleSigs.length) {
-            var elem = possibleSigs.item(i);
-            var parent = elem.parentNode;
-            var signatureContainer = document.createElement("DIV");
+            let elem = possibleSigs.item(i);
+            let parent = elem.parentNode;
+            let signatureContainer = document.createElement("DIV");
             signatureContainer.classList.add("geary-signature");
             do {
                 // Get its sibling _before_ we move it into the signature div.
-                var sibling = elem.nextSibling;
+                let sibling = elem.nextSibling;
                 signatureContainer.appendChild(elem);
                 elem = sibling;
             } while (elem != null);
@@ -161,11 +161,11 @@ ConversationPageState.prototype = {
         }
     },
     getSelectionForQuoting: function() {
-        var quote = null;
-        var selection = window.getSelection();
+        let quote = null;
+        let selection = window.getSelection();
         if (!selection.isCollapsed) {
-            var range = selection.getRangeAt(0);
-            var ancestor = range.commonAncestorContainer;
+            let range = selection.getRangeAt(0);
+            let ancestor = range.commonAncestorContainer;
             if (ancestor.nodeType != Node.ELEMENT_NODE) {
                 ancestor = ancestor.parentNode;
             }
@@ -173,8 +173,8 @@ ConversationPageState.prototype = {
             // If the selection is part of a plain text message,
             // we have to stick it in an appropriately styled div,
             // so that new lines are preserved.
-            var dummy = document.createElement("DIV");
-            var includeDummy = false;
+            let dummy = document.createElement("DIV");
+            let includeDummy = false;
             if (ConversationPageState.isDescendantOf(ancestor, ".plaintext")) {
                 dummy.classList.add("plaintext");
                 dummy.setAttribute("style", "white-space: pre-wrap;");
@@ -184,12 +184,12 @@ ConversationPageState.prototype = {
 
             // Remove the chrome we put around quotes, leaving
             // only the blockquote element.
-            var quotes = dummy.querySelectorAll(
+            let quotes = dummy.querySelectorAll(
                 "." + ConversationPageState.QUOTE_CONTAINER_CLASS
             );
-            for (var i = 0; i < quotes.length; i++) {
-                var div = quotes.item(i);
-                var blockquote = div.querySelector("blockquote");
+            for (let i = 0; i < quotes.length; i++) {
+                let div = quotes.item(i);
+                let blockquote = div.querySelector("blockquote");
                 div.parentNode.replaceChild(blockquote, div);
             }
 
@@ -198,11 +198,11 @@ ConversationPageState.prototype = {
         return quote;
     },
     getSelectionForFind: function() {
-        var value = null;
-        var selection = window.getSelection();
+        let value = null;
+        let selection = window.getSelection();
 
         if (selection.rangeCount > 0) {
-            var range = selection.getRangeAt(0);
+            let range = selection.getRangeAt(0);
             value = range.toString().trim();
             if (value == "") {
                 value = null;
@@ -213,7 +213,7 @@ ConversationPageState.prototype = {
 };
 
 ConversationPageState.isDescendantOf = function(node, ancestorTag) {
-    var ancestor = node.parentNode;
+    let ancestor = node.parentNode;
     while (ancestor != null) {
         if (ancestor.tagName == ancestorTag) {
             return true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]