-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslide.js
112 lines (94 loc) · 3.04 KB
/
slide.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(function () {
$.slide = {
init: function (slides) {
if (slides) {
$.slide.slides = $(slides);
}
if (!$.slide.slides || !$.slide.slides.length) {
$.slide.slides = $(".slide");
}
$.slide.current = 0;
if (!$.slide.init.done) {
// bind events for changing slides
$(window)
.keydown(function (e) {
if ($("body").hasClass("slideshow")) {
if ((e.keyCode === 39) || (e.keyCode === 40) || (e.keyCode === 32)) { // [left], [down], [space]
$.slide.next();
e.preventDefault();
} else if ((e.keyCode === 37) || (e.keyCode === 38)) { // [right], [up]
$.slide.prev();
e.preventDefault();
}
}
});
// bind events to slideshow action links
$.each(["start", "stop", "toggle", "next", "prev"], function () {
var name = this + "";
$("a[rel='slide." + name + "']").click(function () {
$.slide[name]();
return false;
});
});
// turn all links with rel='iframe' into iframes
// each iframe will be covered by overlay to prevent stealing focus
$(".slide a[rel='iframe']").each(function () {
var iframe = '<iframe src="{src}" class="slideshow-only" scrolling="no"></iframe>',
overlay = '<div class="slideshow-only overlay"><a href="{href}" title="{title}" target="_blank">{text}</a></div>';
iframe = iframe.replace(/\{src\}/, this.href);
overlay = overlay.replace(/\{title\}/g, this.title).replace(/\{href\}|\{text\}/g, this.href);
$(this).after(overlay).after(iframe);
});
$.slide.init.done = true;
}
},
start: function (slide) {
$("body").addClass("slideshow");
$.slide.show(slide);
},
stop: function () {
$("body").removeClass("slideshow");
window.location.hash = "";
},
toggle: function () {
if ($("body").hasClass("slideshow")) {
$.slide.stop();
} else {
$.slide.start();
}
},
show: function (slide) {
if (typeof slide !== 'number') {
slide = $.slide.slides.index($(slide));
}
if (slide < 0) {
slide = 0;
} else if (slide >= $.slide.slides.length) {
slide = $.slide.slides.length - 1;
}
if (slide !== $.slide.current) {
$.slide.current = slide;
slide = $.slide.slides.eq(slide);
$('html,body').animate({scrollTop: slide.offset().top, scrollLeft: slide.offset().left}, 500, function () {
if (slide.attr("id")) {
window.location.hash = "#" + slide.attr("id");
}
});
}
},
next: function () {
$.slide.show($.slide.current + 1);
},
prev: function () {
$.slide.show($.slide.current - 1);
}
};
$.fn.slideshow = function (slide) {
$.slide.init(this);
$.slide.start(slide);
return this;
};
$(document).ready(function () {
$.slide.init();
});
}());