From bac46e47ac65e8ff896472234b50bd97001c8945 Mon Sep 17 00:00:00 2001 From: mmk2410 Date: Tue, 7 Apr 2015 22:34:24 +0200 Subject: [PATCH] JS in own file; Ported Decode writtenMorse engine; design fixes --- index.html | 68 ++++------ js/engine/DecodeWrittenMorse.js | 217 ++++++++++++++++++++++++++++++++ js/web/web.js | 57 +++++++++ res/css/main.css | 13 +- res/css/main.sass | 10 ++ 5 files changed, 318 insertions(+), 47 deletions(-) create mode 100644 js/engine/DecodeWrittenMorse.js create mode 100644 js/web/web.js diff --git a/index.html b/index.html index 304f5b7..b53b873 100644 --- a/index.html +++ b/index.html @@ -9,58 +9,36 @@ + + + Morse Converter -
- -
writtenMorse
-
Normal Morse
-
-
About
-
-
-
- -
-
- ENCODE - DECODE -
-
-
-
- -
+
+ +
writtenMorse
+
Normal Morse
+
+
About
+
+
+
+ +
+
+ ENCODE + DECODE
+
+
+ +
+
+
- diff --git a/js/engine/DecodeWrittenMorse.js b/js/engine/DecodeWrittenMorse.js new file mode 100644 index 0000000..1cd6df2 --- /dev/null +++ b/js/engine/DecodeWrittenMorse.js @@ -0,0 +1,217 @@ +function decodeWrittenMorseManager(message) { + if(message == ""){ + return "Please enter at least one character" + } else { + if (message.endsWith(" ")) { + message = message.substring(0, message.length - 1) + } + // Variables + var input = message.toUpperCase() + var output = "" + if (input == "LETTERSPACE") { + output = "#" + } else if (input == "END OF WORK") { + output = "000101" + } else if (input == "ERROR") { + output = "00000000" + } else if (input == "STARTING SIGNAL") { + output = "10101" + } else if (input == "ENDING SIGNAL") { + output = "01010" + } else if (input == "UNDERSTOOD") { + output = "00010" + } else if (input == "WAIT") { + output = "01000" + } else if (input == "SOS") { + output = "000111000" + } else if (input == "LETTER SPACE") { + output = "##" + } else if (input == "WORD SPACE") { + output = "+" + } else { + for (var c = input.length; c > 0; c--) { + if (input.startsWith(" ")) { + if (output.endsWith("#")) { + output = output.substring(0, output.length - 1) + } + output = output +"+" + input = input.substring(1, input.length) + } else if (input.startsWith("A")) { + output = output + "01#" + input = input.substring(1, input.length) + } else if (input.startsWith("B")) { + output = output +"1000#" + input = input.substring(1, input.length) + } else if (input.startsWith("C")) { + output = output +"1010#" + input = input.substring(1, input.length) + } else if (input.startsWith("D")) { + output = output +"100#" + input = input.substring(1, input.length) + } else if (input.startsWith("E")) { + output = output +"0#" + input = input.substring(1, input.length) + } else if (input.startsWith("F")) { + output = output +"0010#" + input = input.substring(1, input.length) + } else if (input.startsWith("G")) { + output = output +"110#" + input = input.substring(1, input.length) + } else if (input.startsWith("H")) { + output = output +"0000#" + input = input.substring(1, input.length) + } else if (input.startsWith("I")) { + output = output +"00#" + input = input.substring(1, input.length) + } else if (input.startsWith("J")) { + output = output +"0111#" + input = input.substring(1, input.length) + } else if (input.startsWith("K")) { + output = output +"101#" + input = input.substring(1, input.length) + } else if (input.startsWith("L")) { + output = output +"0100#" + input = input.substring(1, input.length) + } else if (input.startsWith("M")) { + output = output +"11#" + input = input.substring(1, input.length) + } else if (input.startsWith("N")) { + output = output +"10#" + input = input.substring(1, input.length) + } else if (input.startsWith("O")) { + output = output +"111#" + input = input.substring(1, input.length) + } else if (input.startsWith("P")) { + output = output +"0110#" + input = input.substring(1, input.length) + } else if (input.startsWith("Q")) { + output = output +"1101#" + input = input.substring(1, input.length) + } else if (input.startsWith("R")) { + output = output +"010#" + input = input.substring(1, input.length) + } else if (input.startsWith("S")) { + output = output +"000#" + input = input.substring(1, input.length) + } else if (input.startsWith("T")) { + output = output +"1#" + input = input.substring(1, input.length) + } else if (input.startsWith("U")) { + output = output +"001#" + input = input.substring(1, input.length) + } else if (input.startsWith("V")) { + output = output +"0001#" + input = input.substring(1, input.length) + } else if (input.startsWith("W")) { + output = output +"011#" + input = input.substring(1, input.length) + } else if (input.startsWith("X")) { + output = output +"1001#" + input = input.substring(1, input.length) + } else if (input.startsWith("Y")) { + output = output +"1011#" + input = input.substring(1, input.length) + } else if (input.startsWith("Z")) { + output = output +"1100#" + input = input.substring(1, input.length) + } else if (input.startsWith("0")) { + output = output +"11111#" + input = input.substring(1, input.length) + } else if (input.startsWith("1")) { + output = output +"01111#" + input = input.substring(1, input.length) + } else if (input.startsWith("2")) { + output = output +"00111#" + input = input.substring(1, input.length) + } else if (input.startsWith("3")) { + output = output +"00011#" + input = input.substring(1, input.length) + } else if (input.startsWith("4")) { + output = output +"00001#" + input = input.substring(1, input.length) + } else if (input.startsWith("5")) { + output = output +"00000#" + input = input.substring(1, input.length) + } else if (input.startsWith("6")) { + output = output +"10000#" + input = input.substring(1, input.length) + } else if (input.startsWith("7")) { + output = output +"11000#" + input = input.substring(1, input.length) + } else if (input.startsWith("8")) { + output = output +"11100#" + input = input.substring(1, input.length) + } else if (input.startsWith("9")) { + output = output +"11110#" + input = input.substring(1, input.length) + } else if (input.startsWith("Ä")) { + output = output +"0101#" + input = input.substring(1, input.length) + } else if (input.startsWith("Ö")) { + output = output +"1110#" + input = input.substring(1, input.length) + } else if (input.startsWith("Ü")) { + output = output +"0011#" + input = input.substring(1, input.length) + } else if (input.startsWith("ß")) { + output = output +"00011000#" + input = input.substring(1, input.length) + } else if (input.startsWith(".")) { + output = output +"010101#" + input = input.substring(1, input.length) + } else if (input.startsWith(",")) { + output = output +"110011#" + input = input.substring(1, input.length) + } else if (input.startsWith(":")) { + output = output +"111000#" + input = input.substring(1, input.length) + } else if (input.startsWith(";")) { + output = output +"101010#" + input = input.substring(1, input.length) + } else if (input.startsWith("?")) { + output = output +"001100#" + input = input.substring(1, input.length) + } else if (input.startsWith("!")) { + output = output +"101011#" + input = input.substring(1, input.length) + } else if (input.startsWith("-")) { + output = output +"100001#" + input = input.substring(1, input.length) + } else if (input.startsWith("_")) { + output = output +"001101#" + input = input.substring(1, input.length) + } else if (input.startsWith("(")) { + output = output +"10110#" + input = input.substring(1, input.length) + } else if (input.startsWith(")")) { + output = output +"101101#" + input = input.substring(1, input.length) + } else if (input.startsWith("=")) { + output = output +"10001#" + input = input.substring(1, input.length) + } else if (input.startsWith("+")) { + output = output +"01010#" + input = input.substring(1, input.length) + } else if (input.startsWith("/")) { + output = output +"10010#" + input = input.substring(1, input.length) + } else if (input.startsWith("@")) { + output = output +"011010#" + input = input.substring(1, input.length) + } else if (input.startsWith("'")) { + output = output +"011110#" + input = input.substring(1, input.length) + } else if (input.startsWith("$")) { + output = output +"0001001#" + input = input.substring(1, input.length) + } else { + output = "Code not listed or wrong." + } + } + if (output.endsWith("#")) { + output = output.substring(0, output.length - 1) + } + } + return output + } +} diff --git a/js/web/web.js b/js/web/web.js new file mode 100644 index 0000000..577a0b2 --- /dev/null +++ b/js/web/web.js @@ -0,0 +1,57 @@ +var dur = 150 +var drawerStatus = true +var writtenMorse = true +function drawer(){ + if(window.innerWidth <= 1400){ + if(drawerStatus){ + $('.drawer').show('slide', {direction: 'left'}, dur) + $('.actionbar').before("
") + $('.overlay').animate({"opacity":"0.4"}, dur) + drawerStatus = false + } else { + $('.drawer').hide('slide', {direction: 'left'}, dur) + $('.overlay').animate({"opacity":"0"}, dur, function callback (){ + $('.overlay').remove() + }) + drawerStatus = true + } + } +} + +function encode(){ + var input = $('#textarea').val() + if(writtenMorse){ + $("#output").text("The normal morse engine is not ported jet.") + } else { + //TODO port the normal morse decode engine + $("#output").text("The normal morse engine is not ported jet.") + } + $('#outputcard').fadeIn(dur) +} + +function decode(){ + var input = $('#textarea').val() + if(writtenMorse){ + $('#output').text(decodeWrittenMorseManager(input)) + } else { + //TODO port the normal morse decode engine + $("#output").text("The normal morse engine is not ported jet.") + } + $('#outputcard').fadeIn(dur) +} + +function writtenMorse(){ + writtenMorse = true + drawer() +} + +function normalMorse(){ + writtenMorse = false + drawer() +} + +function about(){ + $("body").fadeOut(dur, function callback(){ + window.location = "http://marcel-kapfer.de/writtenmorse" + }) +} diff --git a/res/css/main.css b/res/css/main.css index ddb07b9..e884fb3 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -46,7 +46,8 @@ body { height: 72px; line-height: 72px; font-size: 18px; - padding-left: 16px; } + padding-left: 16px; + cursor: pointer; } .draweritem:hover { background: #e0e0e0; } @@ -100,7 +101,8 @@ body { min-width: 64px; margin-left: 8px; padding: 5px; - color: #03a9f4; } + color: #03a9f4; + cursor: pointer; } .cardbutton:hover { background: #e0e0e0; } @@ -115,6 +117,13 @@ body { height: 100%; z-index: 30; } +#output { + -moz-hyphens: auto; + -ms-hyphens: auto; + -webkit-hyphens: auto; + hyphens: auto; + word-wrap: break-word; } + #outputcard { display: none; } diff --git a/res/css/main.sass b/res/css/main.sass index 033de9f..de3a096 100644 --- a/res/css/main.sass +++ b/res/css/main.sass @@ -68,6 +68,7 @@ body line-height: $drawer-item-height font-size: $drawer-item-font-size padding-left: 16px + cursor: pointer .draweritem:hover background: $hovered-element-color @@ -117,6 +118,7 @@ body margin-left: 8px padding: 5px color: $primary-color + cursor: pointer .cardbutton:hover background: $hovered-element-color @@ -131,6 +133,14 @@ body height: 100% z-index: 30 +#output + -moz-hyphens: auto + -ms-hyphens: auto + -webkit-hyphens: auto + hyphens: auto + word-wrap: break-word + + #outputcard display: none