Skip to content

Commit

Permalink
Merge pull request paulrouget#86 from paulrouget/view-mode
Browse files Browse the repository at this point in the history
Add view mode (by @Hywan)
  • Loading branch information
hsablonniere committed May 3, 2012
2 parents e3fc67c + 054cf07 commit fc61be9
Showing 1 changed file with 91 additions and 10 deletions.
101 changes: 91 additions & 10 deletions template.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,28 @@ <h2>End!</h2>
<link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet'>

<style>
html { background-color: black; }
body { background-color: white; border-radius: 12px}
html, .view body { background-color: black; counter-reset: slideidx; }
body, .view section { background-color: white; border-radius: 12px }
/* A section is a slide. It's size is 800x600, and this will never change */
section {
section, .view head > title {
/* The font from Google */
font-family: 'Oswald', arial, serif;
font-size: 30px;
}

.view section:after {
counter-increment: slideidx;
content: counter(slideidx, decimal-leading-zero);
position: absolute; bottom: -80px; right: 100px;
color: white;
}

.view head > title {
color: white;
text-align: center;
margin: 1em 0 1em 0;
}

h1, h2 {
margin-top: 200px;
text-align: center;
Expand Down Expand Up @@ -129,10 +143,20 @@ <h2>End!</h2>
https://developer.mozilla.org/en/CSS/CSS_transitions
How to use CSS3 Transitions: */
section {
-moz-transition: left 400ms linear 0s;
-webkit-transition: left 400ms linear 0s;
-ms-transition: left 400ms linear 0s;
transition: left 400ms linear 0s;
-moz-transition: left 400ms linear 0s;
-webkit-transition: left 400ms linear 0s;
-ms-transition: left 400ms linear 0s;
transition: left 400ms linear 0s;
}
.view section {
-moz-transition: none;
-webkit-transition: none;
-ms-transition: none;
transition: none;
}

.view section[aria-selected] {
border: 5px red solid;
}

/* Before */
Expand Down Expand Up @@ -186,15 +210,44 @@ <h2>End!</h2>
margin-left: -400px; margin-top: -300px;
position: absolute; top: 50%; left: 50%;
overflow: hidden;
display: none;
}
.view body {
position: static;
margin: 0; padding: 0;
width: 100%; height: 100%;
display: inline-block;
overflow: visible; overflow-x: hidden;
/* undo Dz.onresize */
transform: none !important;
-moz-transform: none !important;
-webkit-transform: none !important;
-o-transform: none !important;
-ms-transform: none !important;
}
.view head, .view head > title { display: block }
section {
position: absolute;
pointer-events: none;
width: 100%; height: 100%;
}
.view section {
pointer-events: auto;
position: static;
width: 800px; height: 600px;
margin: -150px -200px;
float: left;

transform: scale(.4);
-moz-transform: scale(.4);
-webkit-transform: scale(.4);
-o-transform: scale(.4);
-ms-transform: scale(.4);
}
.view section > * { pointer-events: none; }
section[aria-selected] { pointer-events: auto; }
html { overflow: hidden; }
body { display: none; }
html.view { overflow: visible; }
body.loaded { display: block; }
.incremental {visibility: hidden; }
.incremental[active] {visibility: visible; }
Expand All @@ -206,6 +259,9 @@ <h2>End!</h2>
-ms-transition: width 400ms linear 0s;
transition: width 400ms linear 0s;
}
.view #progress-bar {
display: none;
}
figure {
width: 100%;
height: 100%;
Expand All @@ -223,6 +279,7 @@ <h2>End!</h2>
remoteWindows: [],
idx: -1,
step: 0,
html: null,
slides: null,
progressBar : null,
params: {
Expand All @@ -232,14 +289,16 @@ <h2>End!</h2>

Dz.init = function() {
document.body.className = "loaded";
this.slides = $$("body > section");
this.slides = Array.prototype.slice.call($$("body > section"));
this.progressBar = $("#progress-bar");
this.html = document.body.parentNode;
this.setupParams();
this.onhashchange();
this.setupTouchEvents();
this.onresize();
this.setupView();
}

Dz.setupParams = function() {
var p = window.location.search.substr(1).split('&');
p.forEach(function(e, i, a) {
Expand Down Expand Up @@ -289,6 +348,10 @@ <h2>End!</h2>
aEvent.preventDefault();
this.goFullscreen();
}
if (aEvent.keyCode == 79) { // o
aEvent.preventDefault();
this.toggleView();
}
}

/* Touch Events */
Expand Down Expand Up @@ -322,6 +385,16 @@ <h2>End!</h2>
}
}

Dz.setupView = function() {
document.body.addEventListener("click", function ( e ) {
if (!Dz.html.classList.contains("view")) return;
if (!e.target || e.target.nodeName != "SECTION") return;

Dz.html.classList.remove("view");
Dz.setCursor(Dz.slides.indexOf(e.target) + 1);
}, false);
}

/* Adapt the size of the slides to the window */

Dz.onresize = function() {
Expand Down Expand Up @@ -453,6 +526,14 @@ <h2>End!</h2>
this.setCursor(lastIdx, lastStep);
}

Dz.toggleView = function() {
this.html.classList.toggle("view");

if (this.html.classList.contains("view")) {
$("section[aria-selected]").scrollIntoView(true);
}
}

Dz.setSlide = function(aIdx) {
this.idx = aIdx;
var old = $("section[aria-selected]");
Expand Down

0 comments on commit fc61be9

Please sign in to comment.