2015-08-05 02:48:46 +02:00
|
|
|
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 })
|
|
|
|
|
2015-06-11 06:02:46 +02:00
|
|
|
upload.modules.addmodule({
|
|
|
|
name: 'home',
|
|
|
|
// Dear santa, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
|
|
|
|
template: '\
|
2015-06-11 23:08:54 +02:00
|
|
|
<div class="topbar">\
|
2015-06-11 11:55:38 +02:00
|
|
|
<div class="viewswitcher">\
|
|
|
|
<a id="newpaste" class="btn">New Paste</a>\
|
2015-06-11 06:02:46 +02:00
|
|
|
</div>\
|
2015-06-11 23:08:54 +02:00
|
|
|
</div>\
|
2015-06-11 06:02:46 +02:00
|
|
|
<div class="contentarea" id="uploadview">\
|
2015-06-24 03:53:47 +02:00
|
|
|
<div class="centerview">\
|
2015-06-24 02:55:58 +02:00
|
|
|
<div id="pastearea" class="boxarea">\
|
2015-06-11 06:02:46 +02:00
|
|
|
<h1>Upload</h1>\
|
|
|
|
</div>\
|
2015-06-24 02:55:58 +02:00
|
|
|
<div class="hidden boxarea" id="uploadprogress">\
|
|
|
|
<h1 id="progresstype"></h1>\
|
2015-06-11 06:02:46 +02:00
|
|
|
<h1 id="progressamount"></h1>\
|
|
|
|
<div id="progressamountbg"></div>\
|
|
|
|
</div>\
|
|
|
|
<div class="hidden" id="uploadfinish">\
|
|
|
|
<h1><a href="" id="finallink">Link</a></h1>\
|
|
|
|
</div>\
|
|
|
|
<form>\
|
|
|
|
<input type="file" id="filepicker" class="hidden" />\
|
|
|
|
</form>\
|
2015-06-24 03:53:47 +02:00
|
|
|
</div>\
|
2015-06-11 06:02:46 +02:00
|
|
|
</div>',
|
|
|
|
init: function () {
|
|
|
|
upload.modules.setdefault(this)
|
|
|
|
$(document).on('change', '#filepicker', this.pickerchange.bind(this))
|
|
|
|
$(document).on('click', '#pastearea', this.pickfile.bind(this))
|
|
|
|
$(document).on('dragover', '#pastearea', this.dragover.bind(this))
|
|
|
|
$(document).on('dragleave', '#pastearea', this.dragleave.bind(this))
|
|
|
|
$(document).on('drop', '#pastearea', this.drop.bind(this))
|
2015-06-11 11:55:38 +02:00
|
|
|
$(document).on('click', '#newpaste', this.newpaste.bind(this))
|
2015-06-11 06:02:46 +02:00
|
|
|
$(document).on('click', this.triggerfocuspaste.bind(this))
|
|
|
|
this.initpastecatcher()
|
|
|
|
$(document).on('paste', this.pasted.bind(this))
|
|
|
|
},
|
|
|
|
dragleave: function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
this._.pastearea.removeClass('dragover')
|
|
|
|
},
|
|
|
|
drop: function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
this._.pastearea.removeClass('dragover')
|
2016-01-22 01:59:55 +01:00
|
|
|
if (e.dataTransfer.files.length > 0) {
|
|
|
|
this.doupload(e.dataTransfer.files[0])
|
2015-06-12 00:35:15 +02:00
|
|
|
}
|
2015-06-11 06:02:46 +02:00
|
|
|
},
|
|
|
|
dragover: function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
this._.pastearea.addClass('dragover')
|
|
|
|
},
|
|
|
|
pickfile: function(e) {
|
|
|
|
this._.filepicker.click()
|
|
|
|
},
|
|
|
|
pickerchange: function(e) {
|
|
|
|
if (e.target.files.length > 0) {
|
|
|
|
this.doupload(e.target.files[0])
|
|
|
|
$(e.target).parents('form')[0].reset()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
route: function (route, content) {
|
2015-06-25 20:27:35 +02:00
|
|
|
if (content && content != 'noref') {
|
2015-06-11 06:02:46 +02:00
|
|
|
return upload.download
|
|
|
|
}
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
render: function (view) {
|
|
|
|
view.html(this.template)
|
|
|
|
this._ = {}
|
2015-06-11 11:55:38 +02:00
|
|
|
this._.view = view
|
2015-06-11 06:02:46 +02:00
|
|
|
this._.filepicker = view.find('#filepicker')
|
|
|
|
this._.pastearea = view.find('#pastearea')
|
2015-06-24 02:55:58 +02:00
|
|
|
this._.newpaste = view.find('#newpaste')
|
2015-06-11 06:02:46 +02:00
|
|
|
this._.progress = {}
|
|
|
|
this._.progress.main = view.find('#uploadprogress')
|
2015-06-24 02:55:58 +02:00
|
|
|
this._.progress.type = view.find('#progresstype')
|
2015-06-11 06:02:46 +02:00
|
|
|
this._.progress.amount = view.find('#progressamount')
|
|
|
|
this._.progress.bg = view.find('#progressamountbg')
|
|
|
|
$('#footer').show()
|
|
|
|
},
|
|
|
|
initroute: function () {
|
|
|
|
this.focuspaste()
|
|
|
|
},
|
|
|
|
unrender: function() {
|
|
|
|
delete this['_']
|
|
|
|
},
|
|
|
|
initpastecatcher: function () {
|
|
|
|
this.pastecatcher = $('<pre>').prop('id', 'pastecatcher')
|
|
|
|
this.pastecatcher.prop('contenteditable', true)
|
|
|
|
$('body').append(this.pastecatcher)
|
|
|
|
},
|
|
|
|
focuspaste: function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
this.pastecatcher.focus()
|
|
|
|
}, 100)
|
|
|
|
},
|
|
|
|
triggerfocuspaste: function(e) {
|
|
|
|
if (e.which != 1) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-08-13 01:00:29 +02:00
|
|
|
if (e.target == document.body && this._ && !this._.pastearea.hasClass('hidden')) {
|
2015-06-11 06:02:46 +02:00
|
|
|
e.preventDefault()
|
|
|
|
this.focuspaste()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
progress: function(e) {
|
2015-06-24 02:55:58 +02:00
|
|
|
if (e.eventsource != 'encrypt') {
|
|
|
|
this._.progress.type.text('Uploading')
|
|
|
|
} else {
|
|
|
|
this._.progress.type.text('Encrypting')
|
|
|
|
}
|
2015-06-11 06:02:46 +02:00
|
|
|
var percent = (e.loaded / e.total) * 100
|
2015-06-24 02:55:58 +02:00
|
|
|
this._.progress.bg.css('width', percent + '%')
|
2015-06-11 06:02:46 +02:00
|
|
|
this._.progress.amount.text(Math.floor(percent) + '%')
|
|
|
|
},
|
|
|
|
doupload: function (blob) {
|
|
|
|
this._.pastearea.addClass('hidden')
|
|
|
|
this._.progress.main.removeClass('hidden')
|
2015-06-24 02:55:58 +02:00
|
|
|
this._.progress.type.text('Encrypting')
|
2015-06-11 06:02:46 +02:00
|
|
|
this._.progress.bg.css('width', 0)
|
2015-06-24 02:55:58 +02:00
|
|
|
this._.newpaste.addClass('hidden')
|
2015-06-11 06:02:46 +02:00
|
|
|
upload.updown.upload(blob, this.progress.bind(this), this.uploaded.bind(this))
|
|
|
|
},
|
2015-06-11 11:55:38 +02:00
|
|
|
closepaste: function() {
|
2016-01-22 01:59:55 +01:00
|
|
|
this._.pastearea.removeClass('hidden')
|
2015-06-11 11:55:38 +02:00
|
|
|
this._.view.find('#uploadview').show()
|
|
|
|
this._.view.find('.viewswitcher').show()
|
|
|
|
},
|
|
|
|
dopasteupload: function (data) {
|
2016-01-22 01:59:55 +01:00
|
|
|
this._.pastearea.addClass('hidden')
|
2015-06-11 11:55:38 +02:00
|
|
|
this._.view.find('#uploadview').hide()
|
|
|
|
this._.view.find('.viewswitcher').hide()
|
|
|
|
upload.textpaste.render(this._.view, 'Pasted text.txt', data, 'text/plain', this.closepaste.bind(this))
|
|
|
|
},
|
2015-06-11 06:02:46 +02:00
|
|
|
uploaded: function (data, response) {
|
2015-07-10 21:20:36 +02:00
|
|
|
upload.download.delkeys[data.ident] = response.delkey
|
2015-08-05 02:48:46 +02:00
|
|
|
|
2015-07-10 21:20:36 +02:00
|
|
|
try {
|
|
|
|
localStorage.setItem('delete-' + data.ident, response.delkey)
|
2015-07-10 21:28:01 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
2015-07-10 21:20:36 +02:00
|
|
|
|
2015-06-25 20:27:35 +02:00
|
|
|
if (window.location.hash == '#noref') {
|
|
|
|
history.replaceState(undefined, undefined, '#' + data.seed)
|
|
|
|
upload.route.setroute(upload.download, undefined, data.seed)
|
|
|
|
} else {
|
|
|
|
window.location = '#' + data.seed
|
|
|
|
}
|
2015-06-11 06:02:46 +02:00
|
|
|
},
|
2015-06-11 11:55:38 +02:00
|
|
|
newpaste: function() {
|
|
|
|
this.dopasteupload('')
|
|
|
|
},
|
2015-06-11 06:02:46 +02:00
|
|
|
pasted: function (e) {
|
2016-01-22 01:59:55 +01:00
|
|
|
if (!this._ || this._.pastearea.hasClass('hidden')) {
|
2015-06-11 06:02:46 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-01-22 01:59:55 +01:00
|
|
|
var items = e.clipboardData.items
|
2015-06-11 06:02:46 +02:00
|
|
|
|
2016-01-22 01:59:55 +01:00
|
|
|
var text = e.clipboardData.getData('text/plain')
|
2015-06-11 06:02:46 +02:00
|
|
|
|
|
|
|
if (text) {
|
2015-06-11 11:55:38 +02:00
|
|
|
e.preventDefault()
|
2015-06-11 12:04:00 +02:00
|
|
|
this.dopasteupload(text)
|
2015-06-11 06:02:46 +02:00
|
|
|
} else if (typeof items == 'undefined') {
|
2015-06-12 00:32:19 +02:00
|
|
|
self = this
|
2015-06-11 06:02:46 +02:00
|
|
|
setTimeout(function () {
|
2015-06-12 00:32:19 +02:00
|
|
|
if (self.pastecatcher.find('img').length) {
|
|
|
|
var src = self.pastecatcher.find('img').prop('src')
|
2015-06-11 06:02:46 +02:00
|
|
|
if (src.startsWith('data:')) {
|
2015-06-12 00:32:19 +02:00
|
|
|
self.doupload(dataURItoBlob(src))
|
2015-06-11 06:02:46 +02:00
|
|
|
} else {
|
2015-06-12 00:32:19 +02:00
|
|
|
// TODO: Firefox
|
2015-06-11 06:02:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 0)
|
|
|
|
} else if (items.length >= 1) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
var blob = items[i].getAsFile()
|
|
|
|
if (blob) {
|
|
|
|
this.doupload(blob)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|