Browse Source

Fixed favicon replacement

Closes #500
master
Igor Zhukov 10 years ago
parent
commit
5f1118039d
  1. 1
      app/index.html
  2. 14
      app/js/filters.js
  3. 9
      app/js/i18n.js
  4. 2
      app/js/locales/en-us.json
  5. 16
      app/js/services.js
  6. 2
      app/webogram.appcache

1
app/index.html

@ -15,7 +15,6 @@
<!-- endbuild --> <!-- endbuild -->
<link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="icon" href="favicon.ico" type="image/x-icon" />
<!-- <link rel="icon" href="img/icon/icon128.png" sizes="128x128" type="image/png"> -->
<link rel="apple-touch-icon" href="img/iphone_home120.png"> <link rel="apple-touch-icon" href="img/iphone_home120.png">
<link rel="apple-touch-icon" sizes="120x120" href="img/iphone_home120.png"> <link rel="apple-touch-icon" sizes="120x120" href="img/iphone_home120.png">

14
app/js/filters.js

@ -172,13 +172,9 @@ angular.module('myApp.filters', ['myApp.i18n'])
} }
}]) }])
.filter('relativeTime', ['$rootScope', '$filter', '$locale', '_', function($rootScope, $filter, $locale, _) { .filter('relativeTime', ['$filter', '_', function($filter, _) {
var langMinutes = $rootScope.$eval( var langMinutesPluralize = _.pluralize('relative_time_pluralize_minutes_ago'),
_('relative_time_pluralize_minutes_ago') langHoursPluralize = _.pluralize('relative_time_pluralize_hours_ago');
),
langHours = $rootScope.$eval(
_('relative_time_pluralize_hours_ago')
);
return function (timestamp) { return function (timestamp) {
var ticks = timestamp * 1000, var ticks = timestamp * 1000,
@ -189,11 +185,11 @@ angular.module('myApp.filters', ['myApp.i18n'])
} }
if (diff < 3000000) { if (diff < 3000000) {
var minutes = Math.ceil(diff / 60000); var minutes = Math.ceil(diff / 60000);
return (langMinutes[$locale.pluralCat(minutes)] || '').replace('{}', minutes); return langMinutesPluralize(minutes);
} }
if (diff < 10000000) { if (diff < 10000000) {
var hours = Math.ceil(diff / 3600000); var hours = Math.ceil(diff / 3600000);
return (langHours[$locale.pluralCat(hours)] || '').replace('{}', hours); return langHoursPluralize(hours);
} }
return $filter('dateOrTime')(timestamp); return $filter('dateOrTime')(timestamp);
} }

9
app/js/i18n.js

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('myApp.i18n', ['izhukov.utils']) angular.module('myApp.i18n', ['izhukov.utils'])
.factory('_', [function() { .factory('_', ['$rootScope', '$locale', function($rootScope, $locale) {
var locale = Config.I18n.locale; var locale = Config.I18n.locale;
var messages = Config.I18n.messages; var messages = Config.I18n.messages;
var fallbackMessages = Config.I18n.fallback_messages; var fallbackMessages = Config.I18n.fallback_messages;
@ -79,6 +79,13 @@ angular.module('myApp.i18n', ['izhukov.utils'])
return locale; return locale;
}; };
_.pluralize = function (msgid) {
var categories = $rootScope.$eval(_(msgid + '_raw'));
return function (count) {
return (categories[$locale.pluralCat(count)] || '').replace('{}', count);
}
};
return _; return _;
}]) }])

2
app/js/locales/en-us.json

@ -47,6 +47,8 @@
"settings_modal_follow_us_twitter": "Follow us on Twitter!", "settings_modal_follow_us_twitter": "Follow us on Twitter!",
"settings_modal_recent_updates": "Recent updates (ver. {version})", "settings_modal_recent_updates": "Recent updates (ver. {version})",
"page_title_pluralize_notifications": "{'0': 'No notifications', 'one': '1 notification', 'other': '{} notifications'}",
"profile_edit_modal_title": "Edit profile", "profile_edit_modal_title": "Edit profile",
"profile_edit_first_name": "First name", "profile_edit_first_name": "First name",
"profile_edit_last_name": "Last name", "profile_edit_last_name": "Last name",

16
app/js/services.js

@ -3468,7 +3468,7 @@ angular.module('myApp.services', ['myApp.i18n'])
}) })
.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, MtpApiManager, AppPeersManager, IdleManager, Storage, AppRuntimeManager) { .service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, _, MtpApiManager, AppPeersManager, IdleManager, Storage, AppRuntimeManager) {
navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate; navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate;
@ -3478,8 +3478,9 @@ angular.module('myApp.services', ['myApp.i18n'])
var notificationsCount = 0; var notificationsCount = 0;
var vibrateSupport = !!navigator.vibrate; var vibrateSupport = !!navigator.vibrate;
var peerSettings = {}; var peerSettings = {};
var faviconBackupEl = $('link[rel="icon"]'), var faviconBackupEl = $('link[rel="icon"]:first'),
faviconNewEl = $('<link rel="icon" href="favicon_unread.ico" type="image/x-icon" />'); faviconNewEl = $('<link rel="icon" href="favicon_unread.ico" type="image/x-icon" />');
var langNotificationsPluralize = _.pluralize('page_title_pluralize_notifications');
var titleBackup = document.title, var titleBackup = document.title,
titlePromise; titlePromise;
@ -3490,7 +3491,7 @@ angular.module('myApp.services', ['myApp.i18n'])
if (!newVal) { if (!newVal) {
document.title = titleBackup; document.title = titleBackup;
$('link[rel="icon"]').replaceWith(faviconBackupEl); $('link[rel="icon"]:first').replaceWith(faviconBackupEl);
notificationsClear(); notificationsClear();
} else { } else {
titleBackup = document.title; titleBackup = document.title;
@ -3499,16 +3500,13 @@ angular.module('myApp.services', ['myApp.i18n'])
var time = tsNow(); var time = tsNow();
if (!notificationsCount || time % 2000 > 1000) { if (!notificationsCount || time % 2000 > 1000) {
document.title = titleBackup; document.title = titleBackup;
var curFav = $('link[rel="icon"]'); var curFav = $('link[rel="icon"]:first');
if (curFav.attr('href').indexOf('favicon_unread') != -1) { if (curFav.attr('href').indexOf('favicon_unread') != -1) {
curFav.replaceWith(faviconBackupEl); curFav.replaceWith(faviconBackupEl);
} }
} else { } else {
document.title = notificationsCount > 1 document.title = langNotificationsPluralize(notificationsCount);
? (notificationsCount + ' notifications') $('link[rel="icon"]:first').replaceWith(faviconNewEl);
: '1 notification';
$('link[rel="icon"]').replaceWith(faviconNewEl);
} }
}, 1000); }, 1000);
} }

2
app/webogram.appcache

@ -1,6 +1,6 @@
CACHE MANIFEST CACHE MANIFEST
# 38 # 39
NETWORK: NETWORK:
* *

Loading…
Cancel
Save