From 11a1423f7655228d4d0eb2d628d55d5ecab0b434 Mon Sep 17 00:00:00 2001
From: chylex <info@chylex.com>
Date: Wed, 8 Mar 2017 13:06:50 +0100
Subject: [PATCH] Make sure the app is loaded before hooking account selectors

---
 Resources/Scripts/code.js | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index 22065993..837e2a9f 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -497,18 +497,20 @@
   //
   // Block: Swap shift key functionality for selecting accounts.
   //
-  $(".js-drawer[data-drawer='compose']").delegate(".js-account-list > .js-account-item", "click", function(e){
-    e.shiftKey = !e.shiftKey;
-  });
-  
-  TD.components.AccountSelector.prototype.refreshPostingAccounts = appendToFunction(TD.components.AccountSelector.prototype.refreshPostingAccounts, function(){
-    if (!this.$node.attr("td-account-selector-hook")){
-      this.$node.attr("td-account-selector-hook", "1");
-      
-      this.$node.delegate(".js-account-item", "click", function(e){
-        e.shiftKey = !e.shiftKey;
-      });
-    }
+  onAppReady.push(function(){
+    $(".js-drawer[data-drawer='compose']").delegate(".js-account-list > .js-account-item", "click", function(e){
+      e.shiftKey = !e.shiftKey;
+    });
+
+    TD.components.AccountSelector.prototype.refreshPostingAccounts = appendToFunction(TD.components.AccountSelector.prototype.refreshPostingAccounts, function(){
+      if (!this.$node.attr("td-account-selector-hook")){
+        this.$node.attr("td-account-selector-hook", "1");
+
+        this.$node.delegate(".js-account-item", "click", function(e){
+          e.shiftKey = !e.shiftKey;
+        });
+      }
+    });
   });
   
   //