Skip to content

Instantly share code, notes, and snippets.

@klen

klen/app.js

Last active Dec 17, 2015
Embed
What would you like to do?
/*global window */
'use strict';
require('utils/preload');
require('utils/legacy');
var Backbone = require('backbone');
var app = require('objects/app.js');
var bqueue = require('objects/blanks-queue');
var conf = require('utils/conf');
if (window.localStorage[conf.flag.blanks] === '1') {
bqueue.reset();
}
var colors = require('utils/colors.js');
colors.initialize();
// DEBUG
window.$ = require('utils/jquery');
window.Backbone = Backbone;
window._ = require('utils/underscore');
window.app = app
window.bparser = require('objects/blanks-parser.js');
window.bqueue = require('objects/blanks-queue');
window.colors = colors;
window.counter = require('objects/counter');
window.coverm = require('objects/cover-manager');
window.ical = require('utils/ical');
window.life = require('utils/life');
window.logger = require('utils/logger');
window.moment = require('moment');
window.pcache = require('objects/plans-cache.js');
// END DEBUG
var need_update = 0, update_interval = 60 * 1000; // 60 seconds
Backbone.ajax = function () {
var promise = Backbone.$.ajax.apply(Backbone.$, arguments);
promise.done(function (data, status, request) {
var version = request.getResponseHeader('X-APP-VERSION');
if (!version) return false;
if (!app.version) {
app.version = version;
return version;
}
if (app.version !== version) {
if (new Date().getTime() < (need_update + update_interval)) {
return false;
}
need_update = new Date().getTime();
if (window.confirm('Сервер был обновлен. Для правильной работы рекомендуется перезагрузить страницу.')) {
return window.location.reload();
}
}
});
return promise;
};
var AppView = require('views/app');
new AppView().render();
require('objects/router');
Backbone.history.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.