Move to zepto, remove a bunch of inline includes
This commit is contained in:
parent
635ac4a097
commit
70ded10886
10 changed files with 240 additions and 193 deletions
13
index.html
13
index.html
|
@ -347,18 +347,9 @@
|
|||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
<script src="/static/deps/jquery-2.1.4.min.js"></script>
|
||||
<script src="/static/js/shims.js"></script>
|
||||
<script src="/static/js/loadencryption.js"></script>
|
||||
<script src="/static/js/main.js"></script>
|
||||
<script src="/static/js/home.js"></script>
|
||||
<script src="/static/js/updown.js"></script>
|
||||
<script src="/static/js/download.js"></script>
|
||||
<script src="/static/js/textpaste.js"></script>
|
||||
<script src="/config.js"></script>
|
||||
<script src="/static/js/dragresize.js"></script>
|
||||
<script src="/static/js/base/main.js"></script>
|
||||
<script>
|
||||
$(window).unload(function () { $(window).unbind('unload') })
|
||||
window.onunload = function () {}
|
||||
</script>
|
||||
<link rel="stylesheet" href="/static/deps/hybrid.min.css">
|
||||
<script src="/static/deps/highlight.min.js"></script>
|
||||
|
|
4
static/deps/jquery-2.1.4.min.js
vendored
4
static/deps/jquery-2.1.4.min.js
vendored
File diff suppressed because one or more lines are too long
2
static/deps/zepto.min.js
vendored
Normal file
2
static/deps/zepto.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
135
static/js/base/main.js
Normal file
135
static/js/base/main.js
Normal file
|
@ -0,0 +1,135 @@
|
|||
(function(window) {
|
||||
"use strict";
|
||||
window.upload = {}
|
||||
}(window));
|
||||
|
||||
|
||||
(function(upload) {
|
||||
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')
|
||||
script.src = '/static/' + filename
|
||||
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({
|
||||
name: 'contactlink',
|
||||
init: function() {
|
||||
$('#contact').prop('href', upload.config.contact_link)
|
||||
}
|
||||
})
|
||||
|
||||
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 () {
|
||||
upload.load.needsome().need('../config.js').need('js/shims.js').need('deps/zepto.min.js').done(function() {
|
||||
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))
|
|
@ -1,3 +1,5 @@
|
|||
upload.load.need('js/dragresize.js', function() { return window.dragresize })
|
||||
|
||||
upload.modules.addmodule({
|
||||
name: 'download',
|
||||
delkeys: {},
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
$(function () {
|
||||
window.dragresize = true
|
||||
|
||||
var dragging
|
||||
|
||||
var lastx
|
||||
|
@ -97,4 +99,4 @@ $(function () {
|
|||
dragging.removeClass('dragging')
|
||||
dragging = undefined
|
||||
});
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
upload.load.need('js/download.js', function() { return upload.download })
|
||||
upload.load.need('js/textpaste.js', function() { return upload.textpaste })
|
||||
upload.load.need('js/loadencryption.js', function() { return window.crypt })
|
||||
upload.load.need('js/updown.js', function() { return upload.updown })
|
||||
|
||||
upload.modules.addmodule({
|
||||
name: 'home',
|
||||
// Dear santa, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
|
||||
|
@ -103,7 +108,7 @@ upload.modules.addmodule({
|
|||
return
|
||||
}
|
||||
|
||||
if (e.target == document.body && this._ && this._.pastearea.is(':visible')) {
|
||||
if (e.target == document.body && this._ && this._.pastearea.hasClass('hidden')) {
|
||||
e.preventDefault()
|
||||
this.focuspaste()
|
||||
}
|
||||
|
@ -137,7 +142,7 @@ upload.modules.addmodule({
|
|||
},
|
||||
uploaded: function (data, response) {
|
||||
upload.download.delkeys[data.ident] = response.delkey
|
||||
|
||||
|
||||
try {
|
||||
localStorage.setItem('delete-' + data.ident, response.delkey)
|
||||
} catch (e) {
|
||||
|
@ -155,7 +160,7 @@ upload.modules.addmodule({
|
|||
this.dopasteupload('')
|
||||
},
|
||||
pasted: function (e) {
|
||||
if (!this._ || !this._.pastearea.is(':visible')) {
|
||||
if (!this._ || !this._.pastearea.hasClass('visible')) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,115 +1,113 @@
|
|||
var crypt = {}
|
||||
window.crypt = {}
|
||||
|
||||
$(function () {
|
||||
var crypto = window.crypto || window.msCrypto;
|
||||
var crypto = window.crypto || window.msCrypto;
|
||||
|
||||
function getEntropy() {
|
||||
var entropy = new Uint32Array(256)
|
||||
crypto.getRandomValues(entropy)
|
||||
return entropy
|
||||
function getEntropy() {
|
||||
var entropy = new Uint32Array(256)
|
||||
crypto.getRandomValues(entropy)
|
||||
return entropy
|
||||
}
|
||||
|
||||
function getSeed() {
|
||||
var seed = new Uint8Array(16)
|
||||
crypto.getRandomValues(seed)
|
||||
return seed
|
||||
}
|
||||
|
||||
var worker = new Worker("/static/js/encryption.js")
|
||||
|
||||
|
||||
var promises = {}
|
||||
|
||||
function str2ab(str) {
|
||||
var buf = new ArrayBuffer(str.length * 2);
|
||||
var bufView = new DataView(buf);
|
||||
for (var i = 0, strLen = str.length; i < strLen; i++) {
|
||||
bufView.setUint16(i * 2, str.charCodeAt(i), false)
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
function getSeed() {
|
||||
var seed = new Uint8Array(16)
|
||||
crypto.getRandomValues(seed)
|
||||
return seed
|
||||
worker.onmessage = function (e) {
|
||||
if (e.data.type == 'progress') {
|
||||
promises[e.data.id].notify(e.data)
|
||||
} else {
|
||||
promises[e.data.id].resolve(e.data)
|
||||
delete promises[e.data.id]
|
||||
}
|
||||
}
|
||||
|
||||
var worker = new Worker("/static/js/encryption.js")
|
||||
var counter = 0
|
||||
|
||||
function getpromise() {
|
||||
var promise = $.Deferred()
|
||||
var promiseid = counter
|
||||
counter += 1
|
||||
promise.id = promiseid
|
||||
promises[promiseid] = promise;
|
||||
return promise
|
||||
}
|
||||
|
||||
var promises = {}
|
||||
crypt.encrypt = function (file, name) {
|
||||
|
||||
function str2ab(str) {
|
||||
var buf = new ArrayBuffer(str.length * 2);
|
||||
var bufView = new DataView(buf);
|
||||
for (var i = 0, strLen = str.length; i < strLen; i++) {
|
||||
bufView.setUint16(i * 2, str.charCodeAt(i), false)
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
var extension = file.type.split('/')
|
||||
|
||||
worker.onmessage = function (e) {
|
||||
if (e.data.type == 'progress') {
|
||||
promises[e.data.id].notify(e.data)
|
||||
} else {
|
||||
promises[e.data.id].resolve(e.data)
|
||||
delete promises[e.data.id]
|
||||
}
|
||||
}
|
||||
var header = JSON.stringify({
|
||||
'mime': file.type,
|
||||
'name': name ? name : (file.name ? file.name : ('Pasted ' + extension[0] + '.' + (extension[1] == 'plain' ? 'txt' : extension[1])))
|
||||
})
|
||||
|
||||
var counter = 0
|
||||
var zero = new Uint8Array([0, 0]);
|
||||
|
||||
function getpromise() {
|
||||
var promise = $.Deferred()
|
||||
var promiseid = counter
|
||||
counter += 1
|
||||
promise.id = promiseid
|
||||
promises[promiseid] = promise;
|
||||
return promise
|
||||
}
|
||||
var blob = new Blob([str2ab(header), zero, file])
|
||||
|
||||
crypt.encrypt = function (file, name) {
|
||||
var promise = getpromise()
|
||||
|
||||
var extension = file.type.split('/')
|
||||
|
||||
var header = JSON.stringify({
|
||||
'mime': file.type,
|
||||
'name': name ? name : (file.name ? file.name : ('Pasted ' + extension[0] + '.' + (extension[1] == 'plain' ? 'txt' : extension[1])))
|
||||
})
|
||||
|
||||
var zero = new Uint8Array([0, 0]);
|
||||
|
||||
var blob = new Blob([str2ab(header), zero, file])
|
||||
|
||||
var promise = getpromise()
|
||||
|
||||
var fr = new FileReader()
|
||||
|
||||
fr.onload = function () {
|
||||
worker.postMessage({
|
||||
'data': this.result,
|
||||
'entropy': getEntropy(),
|
||||
'seed': getSeed(),
|
||||
'id': promise.id
|
||||
})
|
||||
}
|
||||
|
||||
fr.readAsArrayBuffer(blob)
|
||||
|
||||
return promise
|
||||
}
|
||||
|
||||
|
||||
crypt.ident = function (seed) {
|
||||
var promise = getpromise()
|
||||
var fr = new FileReader()
|
||||
|
||||
fr.onload = function () {
|
||||
worker.postMessage({
|
||||
'seed': seed,
|
||||
'action': 'ident',
|
||||
'data': this.result,
|
||||
'entropy': getEntropy(),
|
||||
'seed': getSeed(),
|
||||
'id': promise.id
|
||||
})
|
||||
|
||||
return promise
|
||||
}
|
||||
|
||||
fr.readAsArrayBuffer(blob)
|
||||
|
||||
crypt.decrypt = function (file, seed) {
|
||||
var promise = getpromise()
|
||||
return promise
|
||||
}
|
||||
|
||||
var fr = new FileReader()
|
||||
|
||||
fr.onload = function () {
|
||||
worker.postMessage({
|
||||
'data': this.result,
|
||||
'action': 'decrypt',
|
||||
'seed': seed,
|
||||
'id': promise.id
|
||||
})
|
||||
}
|
||||
crypt.ident = function (seed) {
|
||||
var promise = getpromise()
|
||||
|
||||
fr.readAsArrayBuffer(file)
|
||||
worker.postMessage({
|
||||
'seed': seed,
|
||||
'action': 'ident',
|
||||
'id': promise.id
|
||||
})
|
||||
|
||||
return promise
|
||||
return promise
|
||||
}
|
||||
|
||||
|
||||
crypt.decrypt = function (file, seed) {
|
||||
var promise = getpromise()
|
||||
|
||||
var fr = new FileReader()
|
||||
|
||||
fr.onload = function () {
|
||||
worker.postMessage({
|
||||
'data': this.result,
|
||||
'action': 'decrypt',
|
||||
'seed': seed,
|
||||
'id': promise.id
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
fr.readAsArrayBuffer(file)
|
||||
|
||||
return promise
|
||||
}
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
upload = {}
|
||||
// Configure in config.js
|
||||
upload.config = {}
|
||||
|
||||
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({
|
||||
name: 'contactlink',
|
||||
init: function() {
|
||||
$('#contact').prop('href', upload.config.contact_link)
|
||||
}
|
||||
})
|
||||
|
||||
upload.modules.addmodule({
|
||||
name: 'route',
|
||||
init: function () {
|
||||
$(window).on('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.prop('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))
|
||||
}
|
||||
})
|
||||
|
||||
$(function () {
|
||||
if (typeof upload.config.api_key != 'undefined') {
|
||||
upload.modules.init()
|
||||
} else {
|
||||
alert("Please configure with config.js (see config.js.example) - No API key")
|
||||
}
|
||||
})
|
|
@ -6,7 +6,7 @@ upload.modules.addmodule({
|
|||
$(document).on('keydown', this.keypress.bind(this))
|
||||
},
|
||||
keypress: function(e) {
|
||||
if (!this.current || !this.current.is(':visible')) {
|
||||
if (!this.current) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue