about summary refs log tree commit diff stats
path: root/app/views
diff options
context:
space:
mode:
Diffstat (limited to 'app/views')
-rw-r--r--app/views/wittle/puzzles/_handle_puzzle.html.erb75
-rw-r--r--app/views/wittle/puzzles/show.html.haml13
2 files changed, 50 insertions, 38 deletions
diff --git a/app/views/wittle/puzzles/_handle_puzzle.html.erb b/app/views/wittle/puzzles/_handle_puzzle.html.erb index 3d593a4..be9166a 100644 --- a/app/views/wittle/puzzles/_handle_puzzle.html.erb +++ b/app/views/wittle/puzzles/_handle_puzzle.html.erb
@@ -4,41 +4,52 @@ var timerInterval
4 4
5window.onload = function() { 5window.onload = function() {
6 <% if @playable %> 6 <% if @playable %>
7 function pad(val) { 7 function pad(val) {
8 var valString = val + "" 8 var valString = val + ""
9 if (valString.length < 2) 9 if (valString.length < 2)
10 { 10 {
11 return "0" + valString 11 return "0" + valString
12 } else { 12 } else {
13 return valString 13 return valString
14 }
14 } 15 }
15 } 16 function setTime() {
16 function setTime() { 17 ++totalSeconds
17 ++totalSeconds 18 $("#seconds").text(pad(totalSeconds%60))
18 $("#seconds").text(pad(totalSeconds%60)) 19 $("#minutes").text(pad(parseInt(totalSeconds/60)))
19 $("#minutes").text(pad(parseInt(totalSeconds/60))) 20 }
20 } 21 $("#sens").val(window.settings.sensitivity)
21 $("#sens").val(window.settings.sensitivity) 22 $("#sens").on("change", function() {
22 $("#sens").on("change", function() { 23 window.settings.sensitivity = this.value
23 window.settings.sensitivity = this.value 24 })
24 }) 25 $("#volume").val(parseFloat(window.settings.volume))
25 $("#volume").val(parseFloat(window.settings.volume)) 26 $("#volume").on("change", function() {
26 $("#volume").on("change", function() { 27 window.settings.volume = this.value
27 window.settings.volume = this.value 28 })
28 })
29 $("#activation-button button").on("click", function() {
30 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
31 draw(puzzle)
32 29
33 $("#activation-button").hide() 30 <% if @already_started %>
31 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
32 draw(puzzle)
33 <% else %>
34 $("#activation-button button").on("click", function() {
35 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
36 draw(puzzle)
34 37
35 timerInterval = setInterval(setTime, 1000); 38 $("#activation-button").hide()
36 }) 39
40 timerInterval = setInterval(setTime, 1000);
41
42 $.ajax({
43 type: "POST",
44 url: "<%= start_puzzle_path(@puzzle, format: :js) %>"
45 })
46 })
47 <% end %>
37 <% else %> 48 <% else %>
38 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>") 49 var puzzle = window.deserializePuzzle("<%= @puzzle.data %>")
39 draw(puzzle) 50 draw(puzzle)
40 drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @puzzle.solved_data) %>")) 51 drawPath(puzzle, JSON.parse("<%= escape_javascript(sanitize @puzzle.solved_data) %>"))
41 window.trace = function() {} 52 window.trace = function() {}
42 <% end %> 53 <% end %>
43} 54}
44 55
@@ -49,7 +60,7 @@ window.TRACE_COMPLETION_FUNC = function(puzzle, rawPath) {
49 $.ajax({ 60 $.ajax({
50 type: "POST", 61 type: "POST",
51 url: "<%= solve_puzzle_path(@puzzle, format: :js) %>", 62 url: "<%= solve_puzzle_path(@puzzle, format: :js) %>",
52 data: { solved: JSON.stringify(rawPath), time: totalSeconds } 63 data: { solved: JSON.stringify(rawPath) <% unless @already_started %> , time: totalSeconds <% end %> }
53 }) 64 })
54} 65}
55 66
diff --git a/app/views/wittle/puzzles/show.html.haml b/app/views/wittle/puzzles/show.html.haml index deda344..c46e5ce 100644 --- a/app/views/wittle/puzzles/show.html.haml +++ b/app/views/wittle/puzzles/show.html.haml
@@ -3,12 +3,13 @@
3 %svg#puzzle{ style: "pointer-events: auto"} 3 %svg#puzzle{ style: "pointer-events: auto"}
4#submission-form 4#submission-form
5- if @playable 5- if @playable
6 #activation-button 6 - unless @already_started
7 %button{ type: "button" } Reveal Puzzle 7 #activation-button
8 #timer 8 %button{ type: "button" } Reveal Puzzle
9 %label#minutes 00 9 #timer
10 %label#colon : 10 %label#minutes 00
11 %label#seconds 00 11 %label#colon :
12 %label#seconds 00
12 %details#trace-settings 13 %details#trace-settings
13 %summary Settings 14 %summary Settings
14 .things 15 .things