Port frontend code to pure Javascript

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-10-06 19:57:53 +02:00
parent 223bfa1605
commit b2843a828a
No known key found for this signature in database
GPG key ID: DC2729FDD34BE99E
13 changed files with 7106 additions and 1561 deletions

1
frontend/app.js Normal file
View file

@ -0,0 +1 @@
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";var r=null;function o(){var e=$("#formCreateSecret").find("textarea").val();return r=Math.random().toString(36).substring(2),e=GibberishAES.enc(e,r),$.ajax("api/create",{method:"post",data:{secret:e},dataType:"json",statusCode:{201:l,400:s,500:s,404:function(){l({secret_id:"foobar"})}}}),!1}function i(){$("#notfound").show()}function c(){0!==window.location.hash.length&&($("#cardNewSecret").hide(),$("#cardSecretURL").hide(),$("#notfound").hide(),$("#somethingwrong").hide(),$("#cardReadSecretPre").show())}function a(){$("#formCreateSecret").bind("submit",o),$("#newSecret, .navbar-brand").bind("click",d),$(window).bind("hashchange",c),$("#revealSecret").bind("click",u),$("textarea").each(function(e,t){var n=function(){t.style.height=t.scrollHeight+"px"},r=function(){window.setTimeout(n,0)};t.setAttribute("style","height: #{this.scrollHeight}px; min-height: #{this.scrollHeight}px; overflow-y:hidden;"),$(t).on("change",n).on("cut",r).on("paste",r).on("drop",r).on("keydown",r)})}function d(){location.href=location.href.split("#")[0]}function u(){var e=window.location.hash,t=(e=decodeURIComponent(e)).split("|");2===t.length&&(e=t[0],r=t[1]);var n=e.substring(1);$.ajax("api/get/"+n,{dataType:"json",statusCode:{404:i,200:f}})}function l(e){var t=e.secret_id;null!==r&&(t=t+"|"+r);var n=location.href.split("#")[0]+"#"+t;$("#cardNewSecret").hide(),$("#cardReadSecretPre").hide(),$("#cardSecretURL").show(),$("#cardSecretURL").find("input").val(n),$("#cardSecretURL").find("input").focus(),$("#cardSecretURL").find("input").select(),r=null}function f(e){var t=e.secret;null!==r&&(t=GibberishAES.dec(t,r)),$("#cardNewSecret").hide(),$("#cardSecretURL").hide(),$("#notfound").hide(),$("#somethingwrong").hide(),$("#cardReadSecretPre").hide(),$("#cardReadSecret").show(),$("#cardReadSecret").find("textarea").val(t),$("#cardReadSecret").find("textarea").trigger("change")}function s(){$("#somethingwrong").show()}$(function(){a(),c()})}]);

View file

@ -1,123 +0,0 @@
securePassword = null
createSecret = () ->
secret = $('#formCreateSecret').find('textarea').val()
securePassword = Math.random().toString(36).substring(2)
secret = GibberishAES.enc(secret, securePassword)
$.ajax 'api/create',
method: "post"
data:
secret: secret
dataType: "json"
statusCode:
201: secretCreated
400: somethingWrong
500: somethingWrong
404: () ->
# Mock for interface testing
secretCreated
secret_id: 'foobar'
false
dataNotFound = () ->
$('#notfound').show()
hashLoad = () ->
hash = window.location.hash
if hash.length == 0
return
$('#cardNewSecret').hide()
$('#cardSecretURL').hide()
$('#notfound').hide()
$('#somethingwrong').hide()
$('#cardReadSecretPre').show()
requestSecret = () ->
hash = window.location.hash
hash = decodeURIComponent(hash)
parts = hash.split '|'
if parts.length == 2
hash = parts[0]
securePassword = parts[1]
id = hash.substring(1)
$.ajax "api/get/#{id}",
dataType: "json"
statusCode:
404: dataNotFound
200: showData
initBinds = () ->
$('#formCreateSecret').bind 'submit', createSecret
$('#newSecret, .navbar-brand').bind 'click', newSecret
$(window).bind 'hashchange', hashLoad
$('#revealSecret').bind 'click', requestSecret
bindResizeTextarea()
newSecret = () ->
location.href = location.href.split('#')[0]
false
bindResizeTextarea = () ->
$('textarea').each(() ->
text = this
doResize = () =>
#text.style.height = 'auto'
text.style.height = (this.scrollHeight) + 'px'
delayedResize = () =>
window.setTimeout doResize, 0
text.setAttribute('style', "height: #{this.scrollHeight}px; min-height: #{this.scrollHeight}px; overflow-y:hidden;")
$(text)
.on('change', doResize)
.on('cut', delayedResize)
.on('paste', delayedResize)
.on('drop', delayedResize)
.on('keydown', delayedResize)
)
secretCreated = (data) ->
secretHash = data.secret_id
if securePassword != null
secretHash = "#{secretHash}|#{securePassword}"
url = "#{location.href.split('#')[0]}##{secretHash}"
$('#cardNewSecret').hide()
$('#cardReadSecretPre').hide()
$('#cardSecretURL').show()
$('#cardSecretURL').find('input').val url
$('#cardSecretURL').find('input').focus()
$('#cardSecretURL').find('input').select()
securePassword = null
showData = (data) ->
secret = data.secret
if securePassword != null
secret = GibberishAES.dec(secret, securePassword)
$('#cardNewSecret').hide()
$('#cardSecretURL').hide()
$('#notfound').hide()
$('#somethingwrong').hide()
$('#cardReadSecretPre').hide()
$('#cardReadSecret').show()
$('#cardReadSecret').find('textarea').val secret
$('#cardReadSecret').find('textarea').trigger 'change'
somethingWrong = () ->
$('#somethingwrong').show()
$ ->
initBinds()
hashLoad()

View file

@ -1 +0,0 @@
'use strict';(function(){var a,b,c,d,e,f,g,h,i,j,k;i=null,b=function(){var a;return a=$('#formCreateSecret').find('textarea').val(),i=Math.random().toString(36).substring(2),a=GibberishAES.enc(a,i),$.ajax('api/create',{method:'post',data:{secret:a},dataType:'json',statusCode:{201:h,400:k,500:k,404:function a(){return h({secret_id:'foobar'})}}}),!1},c=function(){return $('#notfound').show()},d=function(){var a;if(a=window.location.hash,0!==a.length)return $('#cardNewSecret').hide(),$('#cardSecretURL').hide(),$('#notfound').hide(),$('#somethingwrong').hide(),$('#cardReadSecretPre').show()},g=function(){var a,b,d;return a=window.location.hash,a=decodeURIComponent(a),d=a.split('|'),2===d.length&&(a=d[0],i=d[1]),b=a.substring(1),$.ajax('api/get/'+b,{dataType:'json',statusCode:{404:c,200:j}})},e=function(){return $('#formCreateSecret').bind('submit',b),$('#newSecret, .navbar-brand').bind('click',f),$(window).bind('hashchange',d),$('#revealSecret').bind('click',g),a()},f=function(){return location.href=location.href.split('#')[0],!1},a=function(){return $('textarea').each(function(){var a,b,c,d=this;return c=this,b=function(){return c.style.height=d.scrollHeight+'px'},a=function(){return window.setTimeout(b,0)},c.setAttribute('style','height: '+this.scrollHeight+'px; min-height: '+this.scrollHeight+'px; overflow-y:hidden;'),$(c).on('change',b).on('cut',a).on('paste',a).on('drop',a).on('keydown',a)})},h=function(a){var b,c;return b=a.secret_id,null!==i&&(b=b+'|'+i),c=location.href.split('#')[0]+'#'+b,$('#cardNewSecret').hide(),$('#cardReadSecretPre').hide(),$('#cardSecretURL').show(),$('#cardSecretURL').find('input').val(c),$('#cardSecretURL').find('input').focus(),$('#cardSecretURL').find('input').select(),i=null},j=function(a){var b;return b=a.secret,null!==i&&(b=GibberishAES.dec(b,i)),$('#cardNewSecret').hide(),$('#cardSecretURL').hide(),$('#notfound').hide(),$('#somethingwrong').hide(),$('#cardReadSecretPre').hide(),$('#cardReadSecret').show(),$('#cardReadSecret').find('textarea').val(b),$('#cardReadSecret').find('textarea').trigger('change')},k=function(){return $('#somethingwrong').show()},$(function(){return e(),d()})}).call(void 0);

View file

@ -127,7 +127,7 @@
<script src="/js/popper.min.js" integrity="{{SRIHash `/js/popper.min.js`}}"></script>
<script src="/js/bootstrap.min.js" integrity="{{SRIHash `/js/bootstrap.min.js`}}"></script>
<script src="/js/gibberish-aes.min.js" integrity="{{SRIHash `/js/gibberish-aes.min.js`}}"></script>
<script src="application.js" integrity="{{SRIHash `application.js`}}"></script>
<script src="app.js" integrity="{{SRIHash `app.js`}}"></script>
</body>
</html>