veto

Simple Sinatra voting website.
git clone git://git.knutsen.co/veto
Log | Files | Refs | README | LICENSE

commit bf144eb851b7b2eaa73973b32707e78f1b25606e
parent 7df520d8b9600b1ffe2e24512077d0cec95cb339
Author: Fredrik <moi@knutsen.co>
Date:   Tue, 13 Nov 2018 21:49:33 +0000

Merge pull request #12 from Demonstrandum/devel

Messages about to get added, add themselves at save/submit.
Diffstat:
Mpublic/new.js | 6+++++-
Mpublic/styles.css | 3++-
Mserver.rb | 1+
Mviews/index.erb | 55++++++++++++++++++++++++++++++++++++-------------------
Mviews/share.erb | 9+++++++--
5 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/public/new.js b/public/new.js @@ -19,7 +19,11 @@ $('document').ready(() => { return false; }); $('#submit-poll').click(() => { - save(); // Save all changes + // Save all changes. + if (!save()) { + return false; + } + let polls = []; $.ajax({ async: false, diff --git a/public/styles.css b/public/styles.css @@ -1,5 +1,4 @@ @import url('https://fonts.googleapis.com/css?family=Rubik:400,400i,500'); -@import url('https://use.fontawesome.com/releases/v5.4.1/css/all.css'); html, body { margin: 0; @@ -183,6 +182,8 @@ h3 { } .url { + word-break: break-all; + display: block; font-size: 1em; color: #aaa; } diff --git a/server.rb b/server.rb @@ -44,6 +44,7 @@ HEAD_TAGS = <<-HTML <meta name="msapplication-TileColor" content="#ffffff" /> <meta name="theme-color" content="#ffffff" /> + <link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous"> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css" /> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" /> <link rel="stylesheet" type="text/css" href="/styles.css" /> diff --git a/views/index.erb b/views/index.erb @@ -92,9 +92,22 @@ const save = () => { const inputs = $('#options li').children('input'); + let values = Array(...$('#options li span').map((i, e) => e.innerHTML)); + let bad_input = null; inputs.each(function() { const value = this.value; + if (value.length === 0) { + issue(ISSUE.FATAL, `Cannot leave new value empty. Delete it if you don't want it.`); + bad_input = $(this); + return; + } + if (values.includes(value)) { + issue(ISSUE.FATAL, `Cannot have duplicate (primary) options/choices!`); + bad_input = $(this); + return; + } + $(this).parent('li').removeClass('dark-option'); $(this).siblings('span').show().text(value); $(this).siblings('.symbols').find('.option-edit') @@ -102,6 +115,23 @@ .addClass('fa-edit'); this.remove(); }); + + if (bad_input !== null) { + bad_input.attention(); + return false; + } + + let value = $("#addition").val().trim(); + + if (values.includes(value)) { + issue(ISSUE.FATAL, `Cannot have duplicate (primary) options/choices!`); + $('#addition').attention(); + return false; + } + + + if (value.length > 0) add_list(value); + return true; }; $(document).on('click', e => { @@ -149,33 +179,20 @@ $("#addition").on('keypress', key => { let value = $("#addition").val().trim(); - let values = Array(...$('#options li span').map((i, e) => e.innerHTML)); if (key.which === 13 || key.which === 10) { - key.preventDefault(); - save(); if (value.length === 0) { return $('#addition').attention(); } - if (values.includes(value)) { - issue(ISSUE.FATAL, `Cannot have duplicate (primary) options/choices!`); - return $('#addition').attention(); - } - return add_list(value); + key.preventDefault(); + save(); } }); $('.add-option').click(() => { - save(); - let value = $("#addition").val().trim(); - let values = Array(...$('#options li span').map((i, e) => e.innerHTML)); - if (value.length === 0) { - return $('#addition').attention(); - } - if (values.includes(value)) { - issue(ISSUE.FATAL, `Cannot have duplicate (primary) options/choices!`); - return $('#addition').attention(); + if ($('#addition').val().length === 0) { + $('#addition').attention(); + return; } - - return add_list(value); + save(); }); </script> <script> diff --git a/views/share.erb b/views/share.erb @@ -4,8 +4,12 @@ <title>Share Poll</title> <%= head_tags %> <style media="screen"> - body { + body, html { overflow: hidden; + overflow-x: hidden; + overflow-y: hidden; + } + body { width: 100vw; height: 100vh; display: flex; @@ -79,9 +83,10 @@ i:active { cursor: copy; } - input { + input[type=text] { position: absolute; right: -300vw; + visibility: hidden; } </style> </head>