|
|
|
@ -1,23 +1,5 @@
|
|
|
|
|
console.log('SW!');
|
|
|
|
|
/* jshint ignore:start */
|
|
|
|
|
importScripts('/bower_components/requirejs/require.js');
|
|
|
|
|
require.config({
|
|
|
|
|
// fix up locations so that relative urls work.
|
|
|
|
|
baseUrl: '/',
|
|
|
|
|
paths: {
|
|
|
|
|
// jquery declares itself as literally "jquery" so it cannot be pulled by path :(
|
|
|
|
|
"jquery": "/bower_components/jquery/dist/jquery.min",
|
|
|
|
|
// json.sortify same
|
|
|
|
|
"json.sortify": "/bower_components/json.sortify/dist/JSON.sortify",
|
|
|
|
|
cm: '/bower_components/codemirror'
|
|
|
|
|
},
|
|
|
|
|
map: {
|
|
|
|
|
'*': {
|
|
|
|
|
'css': '/bower_components/require-css/css.js',
|
|
|
|
|
'less': '/common/RequireLess.js',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window = self;
|
|
|
|
|
localStorage = {
|
|
|
|
@ -26,16 +8,6 @@ localStorage = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.tabs = {};
|
|
|
|
|
var findTab = function (port) {
|
|
|
|
|
var tab;
|
|
|
|
|
Object.keys(self.tabs).some(function (id) {
|
|
|
|
|
if (self.tabs[id].port === port) {
|
|
|
|
|
tab = port;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return tab;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var postMsg = function (client, data) {
|
|
|
|
|
client.port.postMessage(data);
|
|
|
|
@ -47,6 +19,10 @@ var debug = function (msg) { console.log(msg); };
|
|
|
|
|
var init = function (client, cb) {
|
|
|
|
|
debug('SharedW INIT');
|
|
|
|
|
|
|
|
|
|
require([
|
|
|
|
|
'/common/requireconfig.js'
|
|
|
|
|
], function (RequireConfig) {
|
|
|
|
|
require.config(RequireConfig());
|
|
|
|
|
require([
|
|
|
|
|
'/common/common-util.js',
|
|
|
|
|
'/common/outer/worker-channel.js',
|
|
|
|
@ -152,10 +128,11 @@ var init = function (client, cb) {
|
|
|
|
|
|
|
|
|
|
client.msgEv = msgEv;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onconnect = function(e) {
|
|
|
|
|
debug('New ShardWorker client');
|
|
|
|
|
debug('New SharedWorker client');
|
|
|
|
|
var port = e.ports[0];
|
|
|
|
|
var cId = Number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER))
|
|
|
|
|
var client = self.tabs[cId] = {
|
|
|
|
@ -176,29 +153,3 @@ onconnect = function(e) {
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.tabs = {};
|
|
|
|
|
self.addEventListener('message', function (e) {
|
|
|
|
|
var cId = e.source.id;
|
|
|
|
|
if (e.data === "INIT") {
|
|
|
|
|
if (tabs[cId]) { return; }
|
|
|
|
|
tabs[cId] = {
|
|
|
|
|
client: e.source
|
|
|
|
|
};
|
|
|
|
|
init(e.source, function () {
|
|
|
|
|
postMsg(e.source, 'SW_READY');
|
|
|
|
|
});
|
|
|
|
|
} else if (self.tabs[cId] && self.tabs[cId].msgEv) {
|
|
|
|
|
self.tabs[cId].msgEv.fire(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
self.addEventListener('install', function (e) {
|
|
|
|
|
debug('V1 installing…');
|
|
|
|
|
self.skipWaiting();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('activate', function (e) {
|
|
|
|
|
debug('V1 now ready to handle fetches!');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|