forked from ccoenraets/PageSlider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
68 lines (58 loc) · 3.2 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
window.addEventListener('load', function () {
new FastClick(document.body);
}, false);
// The dynamically built HTML pages. In a real-life app, In a real-life app, use Handlerbar.js, Mustache.js or another template engine
var homePage =
'<div>' +
'<div class="header"><h1>Page Slider</h1></div>' +
'<div class="scroller">' +
'<ul class="list">' +
'<li><a href="#page1"><strong>Build Bot</strong></a></li>' +
'<li><a href="#page2"><strong>Medi Bot</strong></a></li>' +
'<li><a href="#page3"><strong>Ripple Bot</strong></a></li>' +
'</ul>' +
'</div>' +
'</div>';
var detailsPage =
'<div>' +
'<div class="header"><a href="#" class="btn">Back</a><h1>Robot</h1></div>' +
'<div class="scroller">' +
'<div class="robot">' +
'<img src="images/{{img}}"/>' +
'<h2>{{name}}</h2>' +
'<p>{{description}}</p>' +
'</div>' +
'</div>' +
'</div>';
var slider = new PageSlider($("#container"));
$(window).on('hashchange', route);
// Basic page routing
function route(event) {
var page,
hash = window.location.hash;
if (hash === "#page1") {
page = merge(detailsPage, {img: "buildbot.jpg", name: "Build Bot", description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."});
// slider.slide($(page), "right");
} else if (hash === "#page2") {
page = merge(detailsPage, {img: "medibot.jpg", name: "Medi Bot", description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."});
// slider.slide($(page), "right");
} else if (hash === "#page3") {
page = merge(detailsPage, {img: "ripplebot.jpg", name: "Ripple Bot", description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."});
// slider.slide($(page), "right");
}
else {
page = homePage;
// slider.slide($(homePage), "left");
}
console.log("Calling slide");
slider.slidePage($(page), function(direction) {
console.log("animation complete");
});
}
// Primitive template processing. In a real-life app, use Handlerbar.js, Mustache.js or another template engine
function merge(tpl, data) {
return tpl.replace("{{img}}", data.img)
.replace("{{name}}", data.name)
.replace("{{description}}", data.description);
}
route();