Skip to content

Commit

Permalink
Fix #3 - Make the full shelving always fit the screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarsev committed Oct 24, 2016
1 parent 712fcc3 commit b8bacac
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<link rel="stylesheet" href="out/style.css" />
</head>
<body class="page-background">
<header>
<nav>
<button class="page-background" id="reset" />
<button class="page-background" id="score" />
<button class="page-background" id="aboutButton" />
<button id="switchLang"><span>&nbsp;</span></button>
</header>
</nav>
<main>
<table class="shelves-texture" id="Chronoshelves"></table>
<div id="Drawerlayer"></div>
Expand Down
5 changes: 3 additions & 2 deletions src/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ export default class Drawer {

resetPosition (dom) {
let r = dom.getBoundingClientRect();
let w = this.div.clientWidth;
removeClass(this.div, 'dropped');
removeClass(this.div, 'wrong');
this.correct = 0;
this.droppedshelf = undefined;
Shelf.deadjustDrawer(this);
this.div.style.left = (r.left+(r.right-r.left)*(0.05+Math.random()*0.7))+"px";
this.div.style.top = (r.top+(r.bottom-r.top)*(0.05+Math.random()*0.8))+"px";
this.div.style.left = (r.left+(r.right-r.left-w)*(0.05+Math.random()*0.95))+"px";
this.div.style.top = (r.top+(r.bottom-r.top)*(0.05+Math.random()*0.85))+"px";
}

dragHandler (istouch, e) {
Expand Down
16 changes: 16 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ if (agedata.style) {
document.head.appendChild(custom);
}

// Fit shelves


function resize () {
if (window.innerWidth>0.75*window.innerHeight) {
let top = document.querySelector('nav').getBoundingClientRect().bottom;
let n_shelves = myShelves.root.querySelectorAll('tr').length;
document.body.style.fontSize = 3*(window.innerHeight-top)/n_shelves+'px';
} else {
document.body.style.fontSize = '';
}
myShelves.resize();
}
resize();
window.onresize = resize;

// DIALOGS

let overlay = document.getElementById('overlay');
Expand Down
7 changes: 6 additions & 1 deletion src/shelves.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ export default class Shelves {
this.drawers.forEach(x => x.resetPosition(this.layer));

document.addEventListener('touchmove', this.checkTouchShelf.bind(this), false);
window.onresize = () => this.drawers.forEach(d => {
}

resize () {
this.drawers.forEach(d => {
if (d.droppedshelf) {
d.droppedshelf.adjustDrawer(d);
d.droppedshelf.drop(d);
} else {
d.resetPosition(this.layer);
}
});
}
Expand Down
19 changes: 11 additions & 8 deletions src/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
@shadowcolor: rgba(0,0,0,0.5);
@fossils: #eddebb url('../res/fossils.png') repeat;

@shelfh: 4.2vh;
@bodyspacing: 1vh;
@shelfh: @shelfw/4;
@shelfspace: @shelfh/6;
@shelfw: 4*@shelfh;
@shelfw: 1em;

@import 'https://fonts.googleapis.com/css?family=Catamaran';

Expand All @@ -27,14 +28,16 @@
}

body {
padding: 2vh;
font-size: 20vmin;
padding: @bodyspacing;
font-family: 'Catamaran', sans-serif;
}

header {
nav {
padding-bottom: @bodyspacing;
display: block;
width: 100%;
text-align: center;
line-height: 0;
}

main {
Expand Down Expand Up @@ -136,10 +139,10 @@ aside {
button {
font-family: inherit;
font-size: @shelfh/2;
padding: @shelfh/16 @shelfh/4;
margin: @shelfh/8;
padding: 0.2em 0.8em;
margin: 0 0.3em;
border: 1px solid black;
border-radius: @shelfh/2;
border-radius: 0.8em;
cursor: pointer;
overflow: hidden;
min-width: 3em;
Expand Down

0 comments on commit b8bacac

Please sign in to comment.