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 @@ @@ -15,7 +15,6 @@
<!-- endbuild -->
<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" sizes="120x120" href="img/iphone_home120.png">

14
app/js/filters.js

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

9
app/js/i18n.js

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

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

@ -47,6 +47,8 @@ @@ -47,6 +47,8 @@
"settings_modal_follow_us_twitter": "Follow us on Twitter!",
"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_first_name": "First name",
"profile_edit_last_name": "Last name",

16
app/js/services.js

@ -3468,7 +3468,7 @@ angular.module('myApp.services', ['myApp.i18n']) @@ -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;
@ -3478,8 +3478,9 @@ angular.module('myApp.services', ['myApp.i18n']) @@ -3478,8 +3478,9 @@ angular.module('myApp.services', ['myApp.i18n'])
var notificationsCount = 0;
var vibrateSupport = !!navigator.vibrate;
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" />');
var langNotificationsPluralize = _.pluralize('page_title_pluralize_notifications');
var titleBackup = document.title,
titlePromise;
@ -3490,7 +3491,7 @@ angular.module('myApp.services', ['myApp.i18n']) @@ -3490,7 +3491,7 @@ angular.module('myApp.services', ['myApp.i18n'])
if (!newVal) {
document.title = titleBackup;
$('link[rel="icon"]').replaceWith(faviconBackupEl);
$('link[rel="icon"]:first').replaceWith(faviconBackupEl);
notificationsClear();
} else {
titleBackup = document.title;
@ -3499,16 +3500,13 @@ angular.module('myApp.services', ['myApp.i18n']) @@ -3499,16 +3500,13 @@ angular.module('myApp.services', ['myApp.i18n'])
var time = tsNow();
if (!notificationsCount || time % 2000 > 1000) {
document.title = titleBackup;
var curFav = $('link[rel="icon"]');
var curFav = $('link[rel="icon"]:first');
if (curFav.attr('href').indexOf('favicon_unread') != -1) {
curFav.replaceWith(faviconBackupEl);
}
} else {
document.title = notificationsCount > 1
? (notificationsCount + ' notifications')
: '1 notification';
$('link[rel="icon"]').replaceWith(faviconNewEl);
document.title = langNotificationsPluralize(notificationsCount);
$('link[rel="icon"]:first').replaceWith(faviconNewEl);
}
}, 1000);
}

2
app/webogram.appcache

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

Loading…
Cancel
Save