Browse Source
Adding linter for JS code For now it doesn’t pass well, but that’s a startTitanNano-voice_recorder
25 changed files with 16841 additions and 17321 deletions
@ -1,98 +1,103 @@ |
|||||||
(function initApplication () { |
;(function initApplication () { |
||||||
var classes = [ |
var classes = [ |
||||||
Config.Navigator.osX ? 'osx' : 'non_osx', |
Config.Navigator.osX ? 'osx' : 'non_osx', |
||||||
Config.Navigator.msie ? 'msie' : 'non_msie', |
Config.Navigator.msie ? 'msie' : 'non_msie', |
||||||
Config.Navigator.retina ? 'is_2x' : 'is_1x' |
Config.Navigator.retina ? 'is_2x' : 'is_1x' |
||||||
]; |
] |
||||||
if (Config.Modes.ios_standalone) { |
if (Config.Modes.ios_standalone) { |
||||||
classes.push('ios_standalone'); |
classes.push('ios_standalone') |
||||||
} |
} |
||||||
$(document.body).addClass(classes.join(' ')); |
$(document.body).addClass(classes.join(' ')) |
||||||
|
|
||||||
ConfigStorage.get('layout_selected', 'i18n_locale', function (params) { |
ConfigStorage.get('layout_selected', 'i18n_locale', function (params) { |
||||||
var layout = params[0], |
var layout = params[0] |
||||||
locale = params[1], |
var locale = params[1] |
||||||
defaultLocale = 'en-us', |
var defaultLocale = 'en-us' |
||||||
bootReady = { |
var bootReady = { |
||||||
dom: false, |
dom: false, |
||||||
i18n_ng: false, |
i18n_ng: false, |
||||||
i18n_messages: false, |
i18n_messages: false, |
||||||
i18n_fallback: false |
i18n_fallback: false |
||||||
}, |
} |
||||||
checkReady = function checkReady () { |
var checkReady = function checkReady () { |
||||||
var i, ready = true; |
var i |
||||||
for (i in bootReady) { |
var ready = true |
||||||
if (bootReady.hasOwnProperty(i) && bootReady[i] === false) { |
for (i in bootReady) { |
||||||
ready = false; |
if (bootReady.hasOwnProperty(i) && bootReady[i] === false) { |
||||||
break; |
ready = false |
||||||
} |
break |
||||||
} |
} |
||||||
if (ready) { |
} |
||||||
bootReady.boot = false; |
if (ready) { |
||||||
angular.bootstrap(document, ['myApp']); |
bootReady.boot = false |
||||||
} |
angular.bootstrap(document, ['myApp']) |
||||||
}; |
} |
||||||
|
} |
||||||
|
|
||||||
if (Config.Modes.force_mobile) { |
if (Config.Modes.force_mobile) { |
||||||
layout = 'mobile'; |
layout = 'mobile' |
||||||
} |
} |
||||||
else if (Config.Modes.force_desktop) { |
else if (Config.Modes.force_desktop) { |
||||||
layout = 'desktop'; |
layout = 'desktop' |
||||||
} |
} |
||||||
|
|
||||||
switch (layout) { |
switch (layout) { |
||||||
case 'mobile': Config.Mobile = true; break; |
case 'mobile': |
||||||
case 'desktop': Config.Mobile = false; break; |
Config.Mobile = true |
||||||
|
break |
||||||
|
case 'desktop': |
||||||
|
Config.Mobile = false |
||||||
|
break |
||||||
default: |
default: |
||||||
var width = $(window).width(); |
var width = $(window).width() |
||||||
Config.Mobile = Config.Navigator.mobile || width > 10 && width < 480; |
Config.Mobile = Config.Navigator.mobile || width > 10 && width < 480 |
||||||
break; |
break |
||||||
} |
} |
||||||
$('head').append( |
$('head').append( |
||||||
'<link rel="stylesheet" href="css/' + (Config.Mobile ? 'mobile.css' : 'desktop.css') + '" />' |
'<link rel="stylesheet" href="css/' + (Config.Mobile ? 'mobile.css' : 'desktop.css') + '" />' |
||||||
); |
) |
||||||
|
|
||||||
if (!locale) { |
if (!locale) { |
||||||
locale = (navigator.language || '').toLowerCase(); |
locale = (navigator.language || '').toLowerCase() |
||||||
locale = Config.I18n.aliases[locale] || locale; |
locale = Config.I18n.aliases[locale] || locale |
||||||
} |
} |
||||||
for (var i = 0; i < Config.I18n.supported.length; i++) { |
for (var i = 0; i < Config.I18n.supported.length; i++) { |
||||||
if (Config.I18n.supported[i] == locale) { |
if (Config.I18n.supported[i] == locale) { |
||||||
Config.I18n.locale = locale; |
Config.I18n.locale = locale |
||||||
break; |
break |
||||||
} |
} |
||||||
} |
} |
||||||
bootReady.i18n_ng = Config.I18n.locale == defaultLocale; // Already included
|
bootReady.i18n_ng = Config.I18n.locale == defaultLocale // Already included
|
||||||
|
|
||||||
$.getJSON('js/locales/' + Config.I18n.locale + '.json').success(function (json) { |
$.getJSON('js/locales/' + Config.I18n.locale + '.json').success(function (json) { |
||||||
Config.I18n.messages = json; |
Config.I18n.messages = json |
||||||
bootReady.i18n_messages = true; |
bootReady.i18n_messages = true |
||||||
if (Config.I18n.locale == defaultLocale) { // No fallback, leave empty object
|
if (Config.I18n.locale == defaultLocale) { // No fallback, leave empty object
|
||||||
bootReady.i18n_fallback = true; |
bootReady.i18n_fallback = true |
||||||
} |
} |
||||||
checkReady(); |
checkReady() |
||||||
}); |
}) |
||||||
|
|
||||||
if (Config.I18n.locale != defaultLocale) { |
if (Config.I18n.locale != defaultLocale) { |
||||||
$.getJSON('js/locales/' + defaultLocale + '.json').success(function (json) { |
$.getJSON('js/locales/' + defaultLocale + '.json').success(function (json) { |
||||||
Config.I18n.fallback_messages = json; |
Config.I18n.fallback_messages = json |
||||||
bootReady.i18n_fallback = true; |
bootReady.i18n_fallback = true |
||||||
checkReady(); |
checkReady() |
||||||
}); |
}) |
||||||
} |
} |
||||||
|
|
||||||
$(document).ready(function() { |
$(document).ready(function () { |
||||||
bootReady.dom = true; |
bootReady.dom = true |
||||||
if (!bootReady.i18n_ng) { // onDOMready because needs to be after angular
|
if (!bootReady.i18n_ng) { // onDOMready because needs to be after angular
|
||||||
$('<script>').appendTo('body') |
$('<script>').appendTo('body') |
||||||
.on('load', function() { |
.on('load', function () { |
||||||
bootReady.i18n_ng = true; |
bootReady.i18n_ng = true |
||||||
checkReady(); |
checkReady() |
||||||
}) |
}) |
||||||
.attr('src', 'vendor/angular/i18n/angular-locale_' + Config.I18n.locale + '.js'); |
.attr('src', 'vendor/angular/i18n/angular-locale_' + Config.I18n.locale + '.js') |
||||||
} else { |
} else { |
||||||
checkReady(); |
checkReady() |
||||||
} |
} |
||||||
}); |
}) |
||||||
}); |
}) |
||||||
})(); |
})() |
||||||
|
File diff suppressed because one or more lines are too long
@ -1,127 +1,127 @@ |
|||||||
'use strict'; |
'use strict' |
||||||
|
|
||||||
angular.module('myApp.i18n', ['izhukov.utils']) |
angular.module('myApp.i18n', ['izhukov.utils']) |
||||||
.factory('_', ['$rootScope', '$locale', function($rootScope, $locale) { |
.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 |
||||||
var paramRegEx = /\{\s*([a-zA-Z\d\-_]+)(?:\s*:\s*(.*?))?\s*\}/g; |
var paramRegEx = /\{\s*([a-zA-Z\d\-_]+)(?:\s*:\s*(.*?))?\s*\}/g |
||||||
|
|
||||||
function insertParams(msgstr, params) { |
function insertParams (msgstr, params) { |
||||||
return msgstr.replace(paramRegEx, function ($0, paramKey, nestedMsgStr) { |
return msgstr.replace(paramRegEx, function ($0, paramKey, nestedMsgStr) { |
||||||
var param = params[paramKey]; |
var param = params[paramKey] |
||||||
if (param === undefined) { |
if (param === undefined) { |
||||||
console.warn('[i18n] missing param ' + paramKey + ' for message "' + msgstr + '"'); |
console.warn('[i18n] missing param ' + paramKey + ' for message "' + msgstr + '"') |
||||||
return ''; |
return '' |
||||||
} |
} |
||||||
if (nestedMsgStr !== undefined) { |
if (nestedMsgStr !== undefined) { |
||||||
param = insertParams(param, nestedMsgStr.split('|')); |
param = insertParams(param, nestedMsgStr.split('|')) |
||||||
} |
} |
||||||
return param.toString().trim(); |
return param.toString().trim() |
||||||
}); |
}) |
||||||
} |
} |
||||||
|
|
||||||
function parseMarkdownString(msgstr, msgid) { |
function parseMarkdownString (msgstr, msgid) { |
||||||
msgstr = msgstr |
msgstr = msgstr |
||||||
.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>") |
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>') |
||||||
.replace(/\n| /g, "<br/>"); |
.replace(/\n| /g, '<br/>') |
||||||
|
|
||||||
return msgstr; |
return msgstr |
||||||
} |
} |
||||||
|
|
||||||
function _(msgid, params) { |
function _ (msgid, params) { |
||||||
var raw = false; |
var raw = false |
||||||
var msgstr = msgid; |
var msgstr = msgid |
||||||
|
|
||||||
if (msgid.substr(-4) === '_raw') { |
if (msgid.substr(-4) === '_raw') { |
||||||
raw = true; |
raw = true |
||||||
msgid = msgid.substr(0, msgid.length - 4); |
msgid = msgid.substr(0, msgid.length - 4) |
||||||
} |
} |
||||||
|
|
||||||
if (messages.hasOwnProperty(msgid)) { |
if (messages.hasOwnProperty(msgid)) { |
||||||
msgstr = messages[msgid]; |
msgstr = messages[msgid] |
||||||
} else if (fallbackMessages.hasOwnProperty(msgid)) { |
} else if (fallbackMessages.hasOwnProperty(msgid)) { |
||||||
msgstr = fallbackMessages[msgid]; |
msgstr = fallbackMessages[msgid] |
||||||
console.warn('[i18n] missing locale key ' + locale + ' / ' + msgid); |
console.warn('[i18n] missing locale key ' + locale + ' / ' + msgid) |
||||||
} else { |
} else { |
||||||
console.warn('[i18n] missing key ' + msgid); |
console.warn('[i18n] missing key ' + msgid) |
||||||
return msgid; |
return msgid |
||||||
} |
} |
||||||
|
|
||||||
if (!raw) { |
if (!raw) { |
||||||
msgstr = encodeEntities(msgstr); |
msgstr = encodeEntities(msgstr) |
||||||
} |
} |
||||||
if (msgid.substr(-3) == '_md') { |
if (msgid.substr(-3) == '_md') { |
||||||
msgstr = parseMarkdownString(msgstr); |
msgstr = parseMarkdownString(msgstr) |
||||||
} |
} |
||||||
|
|
||||||
if (arguments.length > 1) { |
if (arguments.length > 1) { |
||||||
if (typeof params == 'string') { |
if (typeof params == 'string') { |
||||||
Array.prototype.shift.apply(arguments); |
Array.prototype.shift.apply(arguments) |
||||||
msgstr = insertParams(msgstr, arguments); |
msgstr = insertParams(msgstr, arguments) |
||||||
} else { |
} else { |
||||||
msgstr = insertParams(msgstr, params); |
msgstr = insertParams(msgstr, params) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return msgstr; |
return msgstr |
||||||
} |
} |
||||||
|
|
||||||
_.locale = function () { |
_.locale = function () { |
||||||
return locale; |
return locale |
||||||
}; |
} |
||||||
|
|
||||||
_.pluralize = function (msgid) { |
_.pluralize = function (msgid) { |
||||||
var categories = $rootScope.$eval(_(msgid + '_raw')); |
var categories = $rootScope.$eval(_(msgid + '_raw')) |
||||||
return function (count) { |
return function (count) { |
||||||
return (categories[$locale.pluralCat(count)] || '').replace('{}', count); |
return (categories[$locale.pluralCat(count)] || '').replace('{}', count) |
||||||
} |
} |
||||||
}; |
} |
||||||
|
|
||||||
return _; |
return _ |
||||||
}]) |
}]) |
||||||
|
|
||||||
.filter('i18n', ['_', function(_) { |
.filter('i18n', ['_', function (_) { |
||||||
return function (msgid, params) { |
return function (msgid, params) { |
||||||
return _(msgid + '_raw', params); |
return _(msgid + '_raw', params) |
||||||
} |
} |
||||||
}]) |
}]) |
||||||
|
|
||||||
.directive('ngPluralize', ['_', function(_) { |
.directive('ngPluralize', ['_', function (_) { |
||||||
return { |
return { |
||||||
restrict: 'EA', |
restrict: 'EA', |
||||||
priority: 1, // execute before built-in ngPluralize
|
priority: 1, // execute before built-in ngPluralize
|
||||||
compile: function(element) { |
compile: function (element) { |
||||||
var msgid = element.attr('when'); |
var msgid = element.attr('when') |
||||||
var msgstr = _(msgid + '_raw'); |
var msgstr = _(msgid + '_raw') |
||||||
element.attr('when', msgstr); |
element.attr('when', msgstr) |
||||||
} |
} |
||||||
} |
} |
||||||
}]) |
}]) |
||||||
|
|
||||||
.directive('myI18n', ['_', function(_) { |
.directive('myI18n', ['_', function (_) { |
||||||
return { |
return { |
||||||
restrict: 'EA', |
restrict: 'EA', |
||||||
compile: function(element) { |
compile: function (element) { |
||||||
var params = element.children('my-i18n-param:not([name]), [my-i18n-param=""]:not([name])').map(function(index, param) { |
var params = element.children('my-i18n-param:not([name]), [my-i18n-param=""]:not([name])').map(function (index, param) { |
||||||
return param.outerHTML; |
return param.outerHTML |
||||||
}).toArray(); |
}).toArray() |
||||||
element.children('my-i18n-param[name], [my-i18n-param]:not([my-i18n-param=""]), [my-i18n-param][name]').each(function(i, param) { |
element.children('my-i18n-param[name], [my-i18n-param]:not([my-i18n-param=""]), [my-i18n-param][name]').each(function (i, param) { |
||||||
params[angular.element(param).attr('my-i18n-param') || angular.element(param).attr('name')] = param.outerHTML; |
params[angular.element(param).attr('my-i18n-param') || angular.element(param).attr('name')] = param.outerHTML |
||||||
}); |
}) |
||||||
element.children('my-i18n-param').remove(); |
element.children('my-i18n-param').remove() |
||||||
var formats = element.attr("my-i18n") || element.attr("msgid") ? element : element.children('my-i18n-format, [my-i18n-format]'); |
var formats = element.attr('my-i18n') || element.attr('msgid') ? element : element.children('my-i18n-format, [my-i18n-format]') |
||||||
formats.each(function(index, element) { |
formats.each(function (index, element) { |
||||||
var format = angular.element(element); |
var format = angular.element(element) |
||||||
var msgid = format.attr("my-i18n") || format.attr("msgid") || format.attr("my-i18n-format") || format.html().replace(/\s+/g, ' ').trim(); |
var msgid = format.attr('my-i18n') || format.attr('msgid') || format.attr('my-i18n-format') || format.html().replace(/\s+/g, ' ').trim() |
||||||
if (format.hasClass('nocopy')) { |
if (format.hasClass('nocopy')) { |
||||||
var msgstr = _(msgid + '_raw', params); |
var msgstr = _(msgid + '_raw', params) |
||||||
format.attr('data-content', msgstr); |
format.attr('data-content', msgstr) |
||||||
} else { |
} else { |
||||||
var msgstr = _(msgid, params); |
var msgstr = _(msgid, params) |
||||||
format.html(msgstr); |
format.html(msgstr) |
||||||
} |
} |
||||||
}); |
}) |
||||||
} |
} |
||||||
} |
} |
||||||
}]); |
}]) |
||||||
|
@ -1,135 +1,136 @@ |
|||||||
// Console-polyfill. MIT license.
|
// Console-polyfill. MIT license.
|
||||||
// https://github.com/paulmillr/console-polyfill
|
// https://github.com/paulmillr/console-polyfill
|
||||||
// Make it safe to do console.log() always.
|
// Make it safe to do console.log() always.
|
||||||
(function(global) { |
;(function (global) { |
||||||
'use strict'; |
'use strict' |
||||||
global.console = global.console || {}; |
global.console = global.console || {} |
||||||
var con = global.console; |
var con = global.console |
||||||
var prop, method; |
var prop |
||||||
var empty = {}; |
var method |
||||||
var dummy = function() {}; |
var empty = {} |
||||||
var properties = 'memory'.split(','); |
var dummy = function () {} |
||||||
|
var properties = 'memory'.split(',') |
||||||
var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + |
var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + |
||||||
'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + |
'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + |
||||||
'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); |
'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',') |
||||||
while (prop = properties.pop()) if (!con[prop]) con[prop] = empty; |
while (prop = properties.pop()) if (!con[prop]) con[prop] = empty |
||||||
while (method = methods.pop()) if (!con[method]) con[method] = dummy; |
while (method = methods.pop()) if (!con[method]) con[method] = dummy |
||||||
})(typeof window === 'undefined' ? this : window); |
})(typeof window === 'undefined' ? this : window) |
||||||
// Using `this` for web workers while maintaining compatibility with browser
|
// Using `this` for web workers while maintaining compatibility with browser
|
||||||
// targeted script loaders such as Browserify or Webpack where the only way to
|
// targeted script loaders such as Browserify or Webpack where the only way to
|
||||||
// get to the global object is via `window`.
|
// get to the global object is via `window`.
|
||||||
|
|
||||||
/* Array.indexOf polyfill */ |
/* Array.indexOf polyfill */ |
||||||
if (!Array.prototype.indexOf) { |
if (!Array.prototype.indexOf) { |
||||||
Array.prototype.indexOf = function(searchElement, fromIndex) { |
Array.prototype.indexOf = function (searchElement, fromIndex) { |
||||||
var k; |
var k |
||||||
if (this == null) { |
if (this == null) { |
||||||
throw new TypeError('"this" is null or not defined'); |
throw new TypeError('"this" is null or not defined') |
||||||
} |
} |
||||||
|
|
||||||
var O = Object(this); |
var O = Object(this) |
||||||
var len = O.length >>> 0; |
var len = O.length >>> 0 |
||||||
if (len === 0) { |
if (len === 0) { |
||||||
return -1; |
return -1 |
||||||
} |
} |
||||||
var n = +fromIndex || 0; |
var n = +fromIndex || 0 |
||||||
|
|
||||||
if (Math.abs(n) === Infinity) { |
if (Math.abs(n) === Infinity) { |
||||||
n = 0; |
n = 0 |
||||||
} |
} |
||||||
if (n >= len) { |
if (n >= len) { |
||||||
return -1; |
return -1 |
||||||
} |
} |
||||||
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); |
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0) |
||||||
while (k < len) { |
while (k < len) { |
||||||
if (k in O && O[k] === searchElement) { |
if (k in O && O[k] === searchElement) { |
||||||
return k; |
return k |
||||||
} |
} |
||||||
k++; |
k++ |
||||||
} |
} |
||||||
return -1; |
return -1 |
||||||
}; |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Array.isArray polyfill */ |
/* Array.isArray polyfill */ |
||||||
if (!Array.isArray) { |
if (!Array.isArray) { |
||||||
Array.isArray = function(arg) { |
Array.isArray = function (arg) { |
||||||
return Object.prototype.toString.call(arg) === '[object Array]'; |
return Object.prototype.toString.call(arg) === '[object Array]' |
||||||
}; |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Object.create polyfill */ |
/* Object.create polyfill */ |
||||||
if (typeof Object.create != 'function') { |
if (typeof Object.create != 'function') { |
||||||
Object.create = (function() { |
Object.create = (function () { |
||||||
var Object = function() {}; |
var Object = function () {} |
||||||
return function (prototype) { |
return function (prototype) { |
||||||
if (arguments.length > 1) { |
if (arguments.length > 1) { |
||||||
throw Error('Second argument not supported'); |
throw Error('Second argument not supported') |
||||||
} |
} |
||||||
if (typeof prototype != 'object') { |
if (typeof prototype != 'object') { |
||||||
throw TypeError('Argument must be an object'); |
throw TypeError('Argument must be an object') |
||||||
} |
} |
||||||
Object.prototype = prototype; |
Object.prototype = prototype |
||||||
var result = new Object(); |
var result = { } |
||||||
Object.prototype = null; |
Object.prototype = null |
||||||
return result; |
return result |
||||||
}; |
} |
||||||
})(); |
})() |
||||||
} |
} |
||||||
|
|
||||||
/* Function.bind polyfill */ |
/* Function.bind polyfill */ |
||||||
if (!Function.prototype.bind) { |
if (!Function.prototype.bind) { |
||||||
Function.prototype.bind = function (oThis) { |
Function.prototype.bind = function (oThis) { |
||||||
if (typeof this !== "function") { |
if (typeof this !== 'function') { |
||||||
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); |
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable') |
||||||
} |
} |
||||||
|
|
||||||
var aArgs = Array.prototype.slice.call(arguments, 1), |
var aArgs = Array.prototype.slice.call(arguments, 1) |
||||||
fToBind = this, |
var fToBind = this |
||||||
fNOP = function () {}, |
var fNOP = function () {} |
||||||
fBound = function () { |
var fBound = function () { |
||||||
return fToBind.apply(this instanceof fNOP && oThis |
return fToBind.apply(this instanceof fNOP && oThis |
||||||
? this |
? this |
||||||
: oThis, |
: oThis, |
||||||
aArgs.concat(Array.prototype.slice.call(arguments))); |
aArgs.concat(Array.prototype.slice.call(arguments))) |
||||||
}; |
} |
||||||
|
|
||||||
fNOP.prototype = this.prototype; |
fNOP.prototype = this.prototype |
||||||
fBound.prototype = new fNOP(); |
fBound.prototype = new fNOP() |
||||||
|
|
||||||
return fBound; |
return fBound |
||||||
}; |
} |
||||||
} |
} |
||||||
|
|
||||||
/* setZeroTimeout polyfill, from http://dbaron.org/log/20100309-faster-timeouts */ |
/* setZeroTimeout polyfill, from http://dbaron.org/log/20100309-faster-timeouts */ |
||||||
(function(global) { |
(function (global) { |
||||||
var timeouts = []; |
var timeouts = [] |
||||||
var messageName = 'zero-timeout-message'; |
var messageName = 'zero-timeout-message' |
||||||
|
|
||||||
function setZeroTimeout(fn) { |
function setZeroTimeout (fn) { |
||||||
timeouts.push(fn); |
timeouts.push(fn) |
||||||
global.postMessage(messageName, '*'); |
global.postMessage(messageName, '*') |
||||||
} |
} |
||||||
|
|
||||||
function handleMessage(event) { |
function handleMessage (event) { |
||||||
if (event.source == global && event.data == messageName) { |
if (event.source == global && event.data == messageName) { |
||||||
event.stopPropagation(); |
event.stopPropagation() |
||||||
if (timeouts.length > 0) { |
if (timeouts.length > 0) { |
||||||
var fn = timeouts.shift(); |
var fn = timeouts.shift() |
||||||
fn(); |
fn() |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
global.addEventListener('message', handleMessage, true); |
global.addEventListener('message', handleMessage, true) |
||||||
|
|
||||||
var originalSetTimeout = global.setTimeout; |
var originalSetTimeout = global.setTimeout |
||||||
global.setTimeout = function (callback, delay) { |
global.setTimeout = function (callback, delay) { |
||||||
if (!delay || delay <= 5) { |
if (!delay || delay <= 5) { |
||||||
return setZeroTimeout(callback); |
return setZeroTimeout(callback) |
||||||
} |
} |
||||||
return originalSetTimeout(callback, delay); |
return originalSetTimeout(callback, delay) |
||||||
}; |
} |
||||||
|
|
||||||
global.setZeroTimeout = setZeroTimeout; |
global.setZeroTimeout = setZeroTimeout |
||||||
})(this); |
})(this) |
||||||
|
@ -1,92 +1,92 @@ |
|||||||
(function initAutoUpgrade () { |
;(function initAutoUpgrade () { |
||||||
// Prevent click-jacking
|
// Prevent click-jacking
|
||||||
try { |
try { |
||||||
if (window == window.top || window.chrome && chrome.app && chrome.app.window) { |
if (window == window.top || window.chrome && chrome.app && chrome.app.window) { |
||||||
document.documentElement.style.display = 'block'; |
document.documentElement.style.display = 'block' |
||||||
} else { |
} else { |
||||||
top.location = self.location; |
top.location = self.location |
||||||
} |
} |
||||||
} catch (e) {console.error('CJ protection', e)}; |
} catch (e) {console.error('CJ protection', e) } |
||||||
|
|
||||||
window.safeConfirm = function (params, callback) { |
window.safeConfirm = function (params, callback) { |
||||||
if (typeof params === 'string') { |
if (typeof params === 'string') { |
||||||
params = {message: params}; |
params = {message: params} |
||||||
} |
} |
||||||
var result = false |
var result = false |
||||||
try { |
try { |
||||||
result = confirm(params.message); |
result = confirm(params.message) |
||||||
} catch (e) { |
} catch (e) { |
||||||
result = true; |
result = true |
||||||
} |
} |
||||||
setTimeout(function () {callback(result)}, 10); |
setTimeout(function () {callback(result)}, 10) |
||||||
}; |
} |
||||||
|
|
||||||
if ((!navigator.serviceWorker && !window.applicationCache) || Config.Modes.packed || !window.addEventListener) { |
if ((!navigator.serviceWorker && !window.applicationCache) || Config.Modes.packed || !window.addEventListener) { |
||||||
return; |
return |
||||||
} |
} |
||||||
|
|
||||||
var declined = false; |
var declined = false |
||||||
function updateFound() { |
function updateFound () { |
||||||
if (!declined) { |
if (!declined) { |
||||||
safeConfirm({type: 'WEBOGRAM_UPDATED_RELOAD', message: 'A new version of Webogram is downloaded. Launch it?'}, function (result) { |
safeConfirm({type: 'WEBOGRAM_UPDATED_RELOAD', message: 'A new version of Webogram is downloaded. Launch it?'}, function (result) { |
||||||
if (result) { |
if (result) { |
||||||
window.location.reload(); |
window.location.reload() |
||||||
} else { |
} else { |
||||||
declined = true; |
declined = true |
||||||
} |
} |
||||||
}); |
}) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
if (navigator.serviceWorker) { |
if (navigator.serviceWorker) { |
||||||
// If available, use a Service Worker to handle offlining.
|
// If available, use a Service Worker to handle offlining.
|
||||||
navigator.serviceWorker.register('offline-worker.js').then(function(registration) { |
navigator.serviceWorker.register('offline-worker.js').then(function (registration) { |
||||||
console.log('offline worker registered'); |
console.log('offline worker registered') |
||||||
registration.addEventListener('updatefound', function() { |
registration.addEventListener('updatefound', function () { |
||||||
var installingWorker = this.installing; |
var installingWorker = this.installing |
||||||
|
|
||||||
// Wait for the new service worker to be installed before prompting to update.
|
// Wait for the new service worker to be installed before prompting to update.
|
||||||
installingWorker.addEventListener('statechange', function() { |
installingWorker.addEventListener('statechange', function () { |
||||||
switch (installingWorker.state) { |
switch (installingWorker.state) { |
||||||
case 'installed': |
case 'installed': |
||||||
// Only show the prompt if there is currently a controller so it is not
|
// Only show the prompt if there is currently a controller so it is not
|
||||||
// shown on first load.
|
// shown on first load.
|
||||||
if (navigator.serviceWorker.controller) { |
if (navigator.serviceWorker.controller) { |
||||||
updateFound(); |
updateFound() |
||||||
} |
} |
||||||
break; |
break |
||||||
|
|
||||||
case 'redundant': |
case 'redundant': |
||||||
console.error('The installing service worker became redundant.'); |
console.error('The installing service worker became redundant.') |
||||||
break; |
break |
||||||
} |
} |
||||||
}); |
}) |
||||||
}); |
}) |
||||||
}); |
}) |
||||||
} else { |
} else { |
||||||
// Otherwise, use AppCache.
|
// Otherwise, use AppCache.
|
||||||
var appCache = window.applicationCache, |
var appCache = window.applicationCache |
||||||
updateTimeout = false, |
var updateTimeout = false |
||||||
scheduleUpdate = function (delay) { |
var scheduleUpdate = function (delay) { |
||||||
clearTimeout(updateTimeout); |
clearTimeout(updateTimeout) |
||||||
updateTimeout = setTimeout(function () { |
updateTimeout = setTimeout(function () { |
||||||
try { |
try { |
||||||
appCache.update(); |
appCache.update() |
||||||
} catch (ex) { |
} catch (ex) { |
||||||
console.log('appCache.update: ' + ex); |
console.log('appCache.update: ' + ex) |
||||||
} |
} |
||||||
}, delay || 300000); |
}, delay || 300000) |
||||||
}; |
} |
||||||
|
|
||||||
scheduleUpdate(3000); |
scheduleUpdate(3000) |
||||||
window.addEventListener('load', function () { |
window.addEventListener('load', function () { |
||||||
appCache.addEventListener('updateready', function () { |
appCache.addEventListener('updateready', function () { |
||||||
if (appCache.status == appCache.UPDATEREADY) { |
if (appCache.status == appCache.UPDATEREADY) { |
||||||
updateFound(); |
updateFound() |
||||||
} |
} |
||||||
}, false); |
}, false) |
||||||
appCache.addEventListener('noupdate', function () {scheduleUpdate()}, false); |
appCache.addEventListener('noupdate', function () {scheduleUpdate()}, false) |
||||||
appCache.addEventListener('error', function () {scheduleUpdate()}, false); |
appCache.addEventListener('error', function () {scheduleUpdate()}, false) |
||||||
}); |
}) |
||||||
} |
} |
||||||
})(); |
})() |
||||||
|
Loading…
Reference in new issue