From 330942b111f536d20f6126852dad5699034d37f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 24 Feb 2014 15:34:42 +0000 Subject: [PATCH 1/6] Remove unused variable --- js/glowingbear.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 9ef90b0..ca7aa6f 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -565,7 +565,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', }; $rootScope.updateTitle = function() { - var unreadFragment = ''; var notifications = $rootScope.unreadCount('notification'); if (notifications > 0) { // New notifications deserve an exclamation mark From e301849a73a125f24c2050a30e026c9fe424b53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 24 Feb 2014 22:16:49 +0000 Subject: [PATCH 2/6] Remove unused functions and parameters --- js/glowingbear.js | 25 +------------------------ js/irc-utils.js | 1 - 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index ca7aa6f..d218487 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -226,13 +226,11 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc weechat.factory('connection', ['$rootScope', '$log', - '$store', 'handlers', 'models', 'ngWebsockets', function($rootScope, $log, - storage, handlers, models, ngWebsockets) { @@ -241,27 +239,6 @@ function($rootScope, // Takes care of the connection and websocket hooks - var _formatForWs = function(message) { - /* - * Formats a weechat message to be sent over - * the websocket. - */ - message.replace(/[\r\n]+$/g, "").split("\n"); - return message; - }; - - var _send = function(message) { - return ngWebsockets.send(_formatForWs(message)); - }; - - var _sendAll = function(messages) { - for (var i in messages) { - messages[i] = _formatForWs(messages[i]); - } - return ngWebsockets.sendAll(messages); - }; - - var connect = function (host, port, passwd, ssl, noCompression) { var proto = ssl ? 'wss' : 'ws'; var url = proto + "://" + host + ":" + port + "/weechat"; @@ -363,7 +340,7 @@ function($rootScope, }; - var onmessage = function(event) { + var onmessage = function() { // If we recieve a message from WeeChat it means that // password was OK. Store that result and check for it // in the failure handler. diff --git a/js/irc-utils.js b/js/irc-utils.js index 3413559..ff4c488 100644 --- a/js/irc-utils.js +++ b/js/irc-utils.js @@ -53,7 +53,6 @@ var IrcUtils = { * @return Next nick (may be the same) */ _nextNick: function(iterCandidate, currentNick, nickList) { - var firstInGroup = null; var matchingNicks = []; var at = null; var lcIterCandidate = iterCandidate.toLowerCase(); From 3f68a156a49a5aab5dc1b027958caa6d13dfd70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 25 Feb 2014 20:41:41 +0000 Subject: [PATCH 3/6] Move initialisation code to functions --- js/glowingbear.js | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index d218487..8e02916 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -462,15 +462,6 @@ function($rootScope, }]); weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) { - if (window.Notification) { - // Request notification permission - Notification.requestPermission(function (status) { - $log.info('Notification permission status:',status); - if (Notification.permission !== status) { - Notification.permission = status; - } - }); - } $scope.mobile_cutoff = 968; @@ -501,29 +492,46 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', console.log(watchers.length); }; - $scope.requestWebkitNotificationPermission = function() { + + // Ask for permission to display desktop notifications + $scope.requestNotificationPermission = function() { + // Firefox + if (window.Notification) { + Notification.requestPermission(function(status) { + $log.info('Notification permission status: ', status); + if (Notification.permission !== status) { + Notification.permission = status; + } + }); + } + + // Webkit if (window.webkitNotifications !== undefined) { var havePermission = window.webkitNotifications.checkPermission(); if (havePermission !== 0) { // 0 is PERMISSION_ALLOWED - $log.info('Notification permission status:', havePermission === 0); + $log.info('Notification permission status: ', havePermission === 0); window.webkitNotifications.requestPermission(); } } }; - // Check for firefox & app installed - if (navigator.mozApps !== undefined) { - navigator.mozApps.getSelf().onsuccess = function _onAppReady(evt) { - var app = evt.target.result; - if (app) { - $scope.isinstalled = true; - } else { - $scope.isinstalled = false; - } - }; - } else { - $scope.isinstalled = false; - } + + $scope.isinstalled = (function() { + // Check for firefox & app installed + if (navigator.mozApps !== undefined) { + navigator.mozApps.getSelf().onsuccess = function _onAppReady(evt) { + var app = evt.target.result; + if (app) { + return true; + } else { + return false; + } + }; + } else { + return false; + } + }()); + // Reduce buffers with "+" operation over a key. Mostly useful for unread/notification counts. $rootScope.unreadCount = function(type) { @@ -774,7 +782,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.connect = function() { - $scope.requestWebkitNotificationPermission(); + $scope.requestNotificationPermission(); connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl); }; $scope.disconnect = function() { From 997fe91d3ecd025613f4c53f756e1b1fdbba70b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 25 Feb 2014 20:42:06 +0000 Subject: [PATCH 4/6] Remove redundant line localStorage triggers this on page load anyway --- js/glowingbear.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 8e02916..81cf25e 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -713,7 +713,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', } }); - $rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number'; $scope.setActiveBuffer = function(bufferId, key) { // If we are on mobile we need to collapse the menu on sidebar clicks From 1664b34cc9dfe5a0281ae07368e227225307a80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 25 Feb 2014 20:42:59 +0000 Subject: [PATCH 5/6] Reorder statements for easier reading --- js/glowingbear.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 81cf25e..3bf6a3a 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -617,14 +617,14 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', } }); - $scope.showSidebar = true; - - $scope.buffers = models.model.buffers; - $rootScope.$on('relayDisconnect', function() { models.reinitialize(); }); + $scope.showSidebar = true; + + $scope.buffers = models.model.buffers; + $scope.activeBuffer = models.getActiveBuffer; $rootScope.waseverconnected = false; From 0cc693fe7d14e17318153edda244ca945e7b7d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 25 Feb 2014 21:17:29 +0000 Subject: [PATCH 6/6] Move mobile device detection to a function avoids code duplication --- js/glowingbear.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 3bf6a3a..8bebb4f 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -463,15 +463,6 @@ function($rootScope, weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) { - $scope.mobile_cutoff = 968; - - // Focuses itself when active buffer is changed - $rootScope.$on('activeBufferChanged', function() { - if (document.body.clientWidth >= $scope.mobile_cutoff) { - $('#sendMessage').focus(); - } - }); - $rootScope.countWatchers = function () { var root = $(document.getElementsByTagName('body')); var watchers = []; @@ -493,6 +484,13 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', }; + $rootScope.isMobileDevice = function() { + // TODO don't base detection solely on screen width + var mobile_cutoff = 968; + return (document.body.clientWidth < mobile_cutoff); + }; + + // Ask for permission to display desktop notifications $scope.requestNotificationPermission = function() { // Firefox @@ -605,6 +603,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Check if we should show nicklist or not $scope.showNicklist = $scope.updateShowNicklist(); + + if (!$rootScope.isMobileDevice()) { + $('#sendMessage').focus(); + } }); $scope.favico = new Favico({animation: 'none'}); @@ -663,7 +665,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // If we are on mobile chhange some defaults // We use 968 px as the cutoff, which should match the value in glowingbear.css - if (document.body.clientWidth < $scope.mobile_cutoff) { + if ($rootScope.isMobileDevice()) { $scope.nonicklist = true; $scope.noembed = true; $scope.notimestamp = true; @@ -671,22 +673,22 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Open and close panels while on mobile devices through swiping $scope.swipeSidebar = function() { - if (document.body.clientWidth < $scope.mobile_cutoff) { + if ($rootScope.isMobileDevice()) { $scope.showSidebar = !$scope.showSidebar; } }; $scope.openNick = function() { - if (document.body.clientWidth < $scope.mobile_cutoff) { - if($scope.nonicklist) { + if ($rootScope.isMobileDevice()) { + if ($scope.nonicklist) { $scope.nonicklist = false; } } }; $scope.closeNick = function() { - if (document.body.clientWidth < $scope.mobile_cutoff) { - if(!$scope.nonicklist) { + if ($rootScope.isMobileDevice()) { + if (!$scope.nonicklist) { $scope.nonicklist = true; } } @@ -717,7 +719,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.setActiveBuffer = function(bufferId, key) { // If we are on mobile we need to collapse the menu on sidebar clicks // We use 968 px as the cutoff, which should match the value in glowingbear.css - if (document.body.clientWidth < $scope.mobile_cutoff) { + if ($rootScope.isMobileDevice()) { $scope.showSidebar = false; } return models.setActiveBuffer(bufferId, key);