From 6af6d34a4f984fb8be49aeb5b1baf6780b27ed4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 21 Mar 2015 12:27:20 +0100 Subject: [PATCH] Dynamically load twemoji if required --- index.html | 1 - js/glowingbear.js | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index adad7ef..d1dd0ed 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,6 @@ - diff --git a/js/glowingbear.js b/js/glowingbear.js index 526c46f..2ccf3f3 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -377,6 +377,22 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', } }); + // To reduce loading times for users who don't want twemoji, + // load it only if the setting is enabled. + // This also fires when the page is loaded. + settings.addCallback('enableJSEmoji', function(enabled) { + if (enabled && !$rootScope.twemoji_init) { + // Load twemoji only once + $rootScope.twemoji_init = true; + (function() { + var script = document.createElement("script"); + script.type = "text/javascript"; + script.src = "//twemoji.maxcdn.com/twemoji.min.js"; + document.getElementsByTagName("head")[0].appendChild(script); + })(); + } + }); + // Update font family when changed settings.addCallback('fontfamily', function(fontfamily) { utils.changeClassStyle('favorite-font', 'fontFamily', fontfamily);