2015-08-05 02:48:46 +02:00
|
|
|
(function(window) {
|
|
|
|
"use strict";
|
|
|
|
window.upload = {}
|
|
|
|
}(window));
|
|
|
|
|
|
|
|
|
|
|
|
(function(upload) {
|
2016-01-08 16:01:50 +01:00
|
|
|
upload.config = {}
|
|
|
|
|
2015-08-05 02:48:46 +02:00
|
|
|
upload.load = {
|
|
|
|
loaded: 0,
|
|
|
|
doneloaded: function() {
|
|
|
|
this.loaded -= 1
|
|
|
|
if (this.loaded <= 0) {
|
|
|
|
this.cb()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
load: function(filename, test, onload) {
|
|
|
|
if (test && test()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
var head = document.getElementsByTagName('head')[0]
|
|
|
|
var script = document.createElement('script')
|
2016-01-08 16:01:50 +01:00
|
|
|
script.src = './' + filename
|
2015-08-05 02:48:46 +02:00
|
|
|
script.async = true
|
|
|
|
script.onload = onload
|
|
|
|
head.appendChild(script)
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
needsome: function() {
|
|
|
|
this.loaded += 1
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
done: function(callback) {
|
|
|
|
this.loaded -= 1
|
|
|
|
this.cb = callback
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
then: function(callback) {
|
|
|
|
this.deferred.then(callback)
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
need: function(filename, test) {
|
|
|
|
this.loaded += 1
|
|
|
|
if(!this.load(filename, test, this.doneloaded.bind(this))) {
|
|
|
|
this.loaded -= 1
|
|
|
|
}
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
upload.modules = {
|
|
|
|
modules: [],
|
|
|
|
addmodule: function (module) {
|
|
|
|
this.modules.unshift(module)
|
|
|
|
upload[module.name] = module
|
|
|
|
},
|
|
|
|
initmodule: function (module) {
|
|
|
|
module.init()
|
|
|
|
},
|
|
|
|
setdefault: function (module) {
|
|
|
|
this.default = module
|
|
|
|
},
|
|
|
|
init: function () {
|
|
|
|
this.modules.forEach(this.initmodule.bind(this))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
upload.modules.addmodule({
|
2016-01-28 00:43:38 +01:00
|
|
|
name: 'footer',
|
2015-08-05 02:48:46 +02:00
|
|
|
init: function() {
|
2016-01-28 00:43:38 +01:00
|
|
|
$('#footer').html(upload.config.footer)
|
2015-08-05 02:48:46 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
upload.modules.addmodule({
|
|
|
|
name: 'route',
|
|
|
|
init: function () {
|
|
|
|
window.addEventListener('hashchange', this.hashchange.bind(this))
|
|
|
|
this.hashchange()
|
|
|
|
},
|
|
|
|
setroute: function (module, routeroot, route) {
|
|
|
|
view = $('.modulecontent.modulearea')
|
|
|
|
if (!this.currentmodule || this.currentmodule != module) {
|
|
|
|
// TODO: better
|
|
|
|
if (this.currentmodule) {
|
|
|
|
this.currentmodule.unrender()
|
|
|
|
}
|
|
|
|
this.currentmodule = module
|
|
|
|
view.id = 'module_' + module.name
|
|
|
|
module.render(view)
|
|
|
|
}
|
|
|
|
module.initroute(route, routeroot)
|
|
|
|
},
|
|
|
|
tryroute: function (route) {
|
|
|
|
var isroot = route.startsWith('/')
|
|
|
|
var normalroute = isroot ? route.substring(1) : route
|
|
|
|
var route = normalroute.substr(normalroute.indexOf('/') + 1)
|
|
|
|
var routeroot = normalroute.substr(0, normalroute.indexOf('/'))
|
|
|
|
var chosenmodule
|
|
|
|
if (!normalroute) {
|
|
|
|
chosenmodule = upload.modules.default
|
|
|
|
} else {
|
|
|
|
upload.modules.modules.every(function (module) {
|
|
|
|
if (!module.route) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (module.route(routeroot, route)) {
|
|
|
|
chosenmodule = module
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (!chosenmodule) {
|
|
|
|
chosenmodule = upload.modules.default
|
|
|
|
}
|
|
|
|
setTimeout(this.setroute.bind(this, chosenmodule, routeroot, route), 0)
|
|
|
|
},
|
|
|
|
hashchange: function () {
|
|
|
|
this.tryroute(window.location.hash.substring(1))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}(window.upload));
|
|
|
|
|
|
|
|
|
|
|
|
(function () {
|
2016-01-08 16:01:50 +01:00
|
|
|
upload.load.needsome().need('config.js').need('js/shims.js').need('deps/zepto.min.js').done(function() {
|
2015-08-05 02:48:46 +02:00
|
|
|
upload.load.needsome().need('js/home.js', function() {return upload.home}).done(function() {
|
|
|
|
if (typeof upload.config != 'undefined') {
|
|
|
|
upload.modules.init()
|
|
|
|
} else {
|
|
|
|
alert("Please configure with config.js (see config.js.example)")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}(upload))
|