Mattias Bodlund 1 year ago
parent
commit
c859283aa4
5 changed files with 63 additions and 10 deletions
  1. +3
    -3
      Gemfile.lock
  2. +6
    -3
      app/assets/stylesheets/application.css
  3. +6
    -0
      app/helpers/site_helper.rb
  4. +42
    -2
      app/javascript/application.js
  5. +6
    -2
      app/views/site/tmpl_list.html.erb

+ 3
- 3
Gemfile.lock View File

@ -133,7 +133,7 @@ GEM
irb (1.12.0) irb (1.12.0)
rdoc rdoc
reline (>= 0.4.2) reline (>= 0.4.2)
jbuilder (2.11.5)
jbuilder (2.12.0)
actionview (>= 5.0.0) actionview (>= 5.0.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
kaminari (1.2.2) kaminari (1.2.2)
@ -256,7 +256,7 @@ GEM
redis-client (0.22.1) redis-client (0.22.1)
connection_pool connection_pool
regexp_parser (2.9.0) regexp_parser (2.9.0)
reline (0.5.3)
reline (0.5.4)
io-console (~> 0.5) io-console (~> 0.5)
request_store (1.6.0) request_store (1.6.0)
rack (>= 1.4) rack (>= 1.4)
@ -269,7 +269,7 @@ GEM
rexml (~> 3.2, >= 3.2.5) rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0) rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0) websocket (~> 1.0)
sidekiq (7.2.3)
sidekiq (7.2.4)
concurrent-ruby (< 2) concurrent-ruby (< 2)
connection_pool (>= 2.3.0) connection_pool (>= 2.3.0)
rack (>= 2.2.4) rack (>= 2.2.4)


+ 6
- 3
app/assets/stylesheets/application.css View File

@ -365,7 +365,8 @@ input[type=range] {
ul.card__stack { ul.card__stack {
max-width: 270px; max-width: 270px;
margin-bottom: 24px; margin-bottom: 24px;
aspect-ratio: 0.72972972972973;
position: relative;
& a { & a {
text-decoration: none; text-decoration: none;
@ -381,8 +382,8 @@ ul.card__stack {
} }
.card { .card {
max-width: 270px;
aspect-ratio: 0.72972972972973;
position: absolute;
inset: 0 0 0 0;
font-size: var(--fs-xl); font-size: var(--fs-xl);
font-weight: 700; font-weight: 700;
display: grid; display: grid;
@ -390,6 +391,8 @@ ul.card__stack {
grid-template-rows: 1fr 4fr 1fr; grid-template-rows: 1fr 4fr 1fr;
justify-items: center; justify-items: center;
transition: transform 0.3s ease-in-out 0s;
& div { & div {
text-align: center; text-align: center;
} }


+ 6
- 0
app/helpers/site_helper.rb View File

@ -19,4 +19,10 @@ module SiteHelper
t(:client_name) t(:client_name)
end end
def random_value(from, to)
range = rand(2) == 0 ? (-to..-from) : (from..to)
rand(range)
end
end end

+ 42
- 2
app/javascript/application.js View File

@ -1,3 +1,41 @@
function rand_in_range(from, to) {
const rand = Math.floor(Math.random() * (to - from + 1)) + from
const is_neg = Math.random() < 0.5
return is_neg ? -rand : rand
}
function shuffle_cards() {
const cards = document.querySelectorAll('.card')
const random_index = Math.floor(Math.random() * cards.length);
cards.forEach((card, index) => {
if (index == random_index) {
card.classList.add('active')
card.style.zIndex = '1'
card.style.transform = `none`
} else {
card.classList.remove('active')
card.style.zIndex = 'auto'
card.style.transform = `rotate(${rand_in_range(2,5)}deg) translate(${rand_in_range(2,5)}px, ${rand_in_range(2,5)}px)`
}
})
}
document.querySelectorAll('.button_shuffle_cards').forEach((item, index) => {
item.addEventListener('click', (e) => {
shuffle_cards()
})
if (index == 0)
shuffle_cards()
})
// Choose language confirmation button // Choose language confirmation button
document.querySelectorAll('#confirm_btn').forEach((confirm_btn) => { document.querySelectorAll('#confirm_btn').forEach((confirm_btn) => {
confirm_btn.addEventListener('click', (e) => { confirm_btn.addEventListener('click', (e) => {
@ -40,8 +78,10 @@ function unlockStartHandler() {
function unlockEndHandler() { function unlockEndHandler() {
curr_value = +this.value; curr_value = +this.value;
if (curr_value >= this.max) {
alert('Unlocked');
if (curr_value >= this.max) {
const card = document.querySelector('.card.active')
window.location.href = card.parentNode.getAttribute('href')
// reset // reset
this.value = 0; this.value = 0;


+ 6
- 2
app/views/site/tmpl_list.html.erb View File

@ -1,9 +1,13 @@
<%- content_for :title, node_title(@node) %>
<%-
content_for :title, node_title(@node)
cards = @node.children.viewable.ordered
%>
<div class="cards__container"> <div class="cards__container">
<ul class="card__stack"> <ul class="card__stack">
<% @node.children.viewable.ordered.each do |node| %> <% @node.children.viewable.ordered.each do |node| %>
<li> <li>
<%= link_to node.url do %> <%= link_to node.url do %>
<div class="card"> <div class="card">
@ -23,7 +27,7 @@
</div> </div>
</li> </li>
<li> <li>
<button type="button" class="button__base button__base-light">
<button type="button" class="button__base button__base-light button_shuffle_cards">
<%= t 'shuffle_cards' %> <%= t 'shuffle_cards' %>
</button> </button>
</li> </li>


Loading…
Cancel
Save