From 5fb6968e8abff6df7727c53077478270fd16e29c Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 19 Dec 2014 00:29:23 +0000 Subject: [PATCH] _kiwi.utils object for helpers --- client/src/app.js | 5 +++++ client/src/applets/settings.js | 4 ++-- client/src/helpers/desktopnotifications.js | 2 +- client/src/helpers/formatdate.js | 2 +- client/src/models/network.js | 2 +- client/src/views/application.js | 2 +- client/src/views/channelinfo.js | 2 +- client/src/views/topicbar.js | 2 +- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client/src/app.js b/client/src/app.js index 6fe8172..28ddc97 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -8,6 +8,7 @@ _kiwi.misc = {}; _kiwi.model = {}; _kiwi.view = {}; _kiwi.applets = {}; +_kiwi.utils = {}; /** @@ -23,6 +24,7 @@ _kiwi.global = { rpc: undefined, // Instance of WebsocketRpc utils: {}, // References to misc. re-usable helpers / functions + // Make public some internal utils for plugins to make use of initUtils: function() { this.utils.randomString = randomString; this.utils.secondsToTime = secondsToTime; @@ -31,6 +33,9 @@ _kiwi.global = { this.utils.formatIRCMsg = formatIRCMsg; this.utils.styleText = styleText; this.utils.hsl2rgb = hsl2rgb; + + this.utils.notifications = _kiwi.utils.notifications; + this.utils.formatDate = _kiwi.utils.formatDate; }, addMediaMessageType: function(match, buildHtml) { diff --git a/client/src/applets/settings.js b/client/src/applets/settings.js index 504fe60..5d646be 100644 --- a/client/src/applets/settings.js +++ b/client/src/applets/settings.js @@ -37,7 +37,7 @@ } - if (_kiwi.global.utils.notifications.allowed() !== null) { + if (_kiwi.utils.notifications.allowed() !== null) { this.$el.find('.notification_enabler').remove(); } @@ -127,7 +127,7 @@ enableNotifications: function(event){ event.preventDefault(); - var notifications = _kiwi.global.utils.notifications; + var notifications = _kiwi.utils.notifications; notifications.requestPermission().always(_.bind(function () { if (notifications.allowed() !== null) { this.$('.notification_enabler').remove(); diff --git a/client/src/helpers/desktopnotifications.js b/client/src/helpers/desktopnotifications.js index bf1de23..9b6fe4d 100644 --- a/client/src/helpers/desktopnotifications.js +++ b/client/src/helpers/desktopnotifications.js @@ -1,4 +1,4 @@ -_kiwi.global.utils.notifications = (function () { +_kiwi.utils.notifications = (function () { if (!window.Notification) { return { allowed: _.constant(false), diff --git a/client/src/helpers/formatdate.js b/client/src/helpers/formatdate.js index a75af8b..459b42d 100644 --- a/client/src/helpers/formatdate.js +++ b/client/src/helpers/formatdate.js @@ -1,4 +1,4 @@ -var formatDate = (function() { +_kiwi.utils.formatDate = (function() { /* Modified version of date.format.js https://github.com/jacwright/date.format diff --git a/client/src/models/network.js b/client/src/models/network.js index 74b35cf..68792bf 100644 --- a/client/src/models/network.js +++ b/client/src/models/network.js @@ -774,7 +774,7 @@ } else if (event.logon) { logon_date = new Date(); logon_date.setTime(event.logon * 1000); - logon_date = formatDate(logon_date); + logon_date = _kiwi.utils.formatDate(logon_date); panel.addMsg(event.nick, styleText('whois_idle_and_signon', {nick: event.nick, text: translateText('client_models_network_idle_and_signon', [idle_time, logon_date])}), 'whois'); } else if (event.away_reason) { diff --git a/client/src/views/application.js b/client/src/views/application.js index b297b86..9c11d85 100644 --- a/client/src/views/application.js +++ b/client/src/views/application.js @@ -345,7 +345,7 @@ _kiwi.view.Application = Backbone.View.extend({ showNotification: function(title, message) { var icon = this.model.get('base_path') + '/assets/img/ico.png', - notifications = _kiwi.global.utils.notifications; + notifications = _kiwi.utils.notifications; if (!this.has_focus && notifications.allowed()) { notifications diff --git a/client/src/views/channelinfo.js b/client/src/views/channelinfo.js index 0804e3a..cfa29d6 100644 --- a/client/src/views/channelinfo.js +++ b/client/src/views/channelinfo.js @@ -137,7 +137,7 @@ _kiwi.view.ChannelInfo = Backbone.View.extend({ $('').text(ban.banned).appendTo($tr); $('').text(ban.banned_by.split(/[!@]/)[0]).appendTo($tr); - $('').text(formatDate(new Date(parseInt(ban.banned_at, 10) * 1000))).appendTo($tr); + $('').text(_kiwi.utils.formatDate(new Date(parseInt(ban.banned_at, 10) * 1000))).appendTo($tr); $('').appendTo($tr); $table.append($tr); diff --git a/client/src/views/topicbar.js b/client/src/views/topicbar.js index 85c4690..980c901 100644 --- a/client/src/views/topicbar.js +++ b/client/src/views/topicbar.js @@ -48,7 +48,7 @@ _kiwi.view.TopicBar = Backbone.View.extend({ this.setCurrentTopic(channel.get("topic")); if (set_by) { - set_by_text += translateText('client_models_network_topic', [set_by.nick, formatDate(set_by.when)]); + set_by_text += translateText('client_models_network_topic', [set_by.nick, _kiwi.utils.formatDate(set_by.when)]); this.$el.attr('title', set_by_text); } else { this.$el.attr('title', ''); -- 2.25.1