diff options
Diffstat (limited to 'slides.js')
-rw-r--r-- | slides.js | 455 |
1 files changed, 0 insertions, 455 deletions
diff --git a/slides.js b/slides.js deleted file mode 100644 index db2c636..0000000 --- a/slides.js +++ /dev/null | |||
@@ -1,455 +0,0 @@ | |||
1 | /** | ||
2 | * @constructor | ||
3 | */ | ||
4 | function SlideDeck() { | ||
5 | this.curSlide_ = 0; | ||
6 | this.slides = []; | ||
7 | this.config_ = null; | ||
8 | |||
9 | this.getCurrentSlideFromHash_(); | ||
10 | |||
11 | document.addEventListener('DOMContentLoaded', | ||
12 | this.handleDomLoaded_.bind(this), false); | ||
13 | } | ||
14 | |||
15 | /** | ||
16 | * @const | ||
17 | * @private | ||
18 | */ | ||
19 | SlideDeck.prototype.SLIDE_CLASSES_ = ['far-past', 'past', 'current', 'next', | ||
20 | 'far-next']; | ||
21 | |||
22 | /** | ||
23 | * @private | ||
24 | */ | ||
25 | SlideDeck.prototype.getCurrentSlideFromHash_ = function() { | ||
26 | var slideNo = parseInt(document.location.hash.substr(1)); | ||
27 | |||
28 | if (slideNo) { | ||
29 | this.curSlide_ = slideNo; | ||
30 | } | ||
31 | }; | ||
32 | |||
33 | /** | ||
34 | * @private | ||
35 | */ | ||
36 | SlideDeck.prototype.handleDomLoaded_ = function() { | ||
37 | this.slides_ = document.querySelectorAll('slide:not(.hidden)'); | ||
38 | |||
39 | // Load config | ||
40 | this.loadConfig_(); | ||
41 | this.addEventListeners_(); | ||
42 | this.updateSlides_(); | ||
43 | }; | ||
44 | |||
45 | /** | ||
46 | * @private | ||
47 | */ | ||
48 | SlideDeck.prototype.addEventListeners_ = function() { | ||
49 | document.addEventListener('keydown', this.handleBodyKeyDown_.bind(this), | ||
50 | false); | ||
51 | window.addEventListener('popstate', this.handlePopState_.bind(this), | ||
52 | false); | ||
53 | }; | ||
54 | |||
55 | /** | ||
56 | * @private | ||
57 | * @param {Event} e | ||
58 | */ | ||
59 | SlideDeck.prototype.handlePopState_ = function(e) { | ||
60 | if (e.state != null) { | ||
61 | this.curSlide_ = e.state; | ||
62 | this.updateSlides_(true); | ||
63 | } | ||
64 | }; | ||
65 | |||
66 | /** | ||
67 | * @param {Event} e | ||
68 | */ | ||
69 | SlideDeck.prototype.handleBodyKeyDown_ = function(e) { | ||
70 | if (/^(input|textarea)$/i.test(e.target.nodeName) || | ||
71 | e.target.isContentEditable) { | ||
72 | return; | ||
73 | } | ||
74 | |||
75 | switch (e.keyCode) { | ||
76 | case 39: // right arrow | ||
77 | case 32: // space | ||
78 | case 34: // PgDn | ||
79 | this.nextSlide(); | ||
80 | e.preventDefault(); | ||
81 | break; | ||
82 | |||
83 | case 37: // left arrow | ||
84 | case 8: // Backspace | ||
85 | case 33: // PgUp | ||
86 | this.prevSlide(); | ||
87 | e.preventDefault(); | ||
88 | break; | ||
89 | |||
90 | case 40: // down arrow | ||
91 | //if (this.isChromeVoxActive()) { | ||
92 | // speakNextItem(); | ||
93 | //} else { | ||
94 | this.nextSlide(); | ||
95 | //} | ||
96 | e.preventDefault(); | ||
97 | break; | ||
98 | |||
99 | case 38: // up arrow | ||
100 | //if (this.isChromeVoxActive()) { | ||
101 | // speakPrevItem(); | ||
102 | //} else { | ||
103 | this.prevSlide(); | ||
104 | //} | ||
105 | e.preventDefault(); | ||
106 | break; | ||
107 | |||
108 | case 78: // N | ||
109 | document.body.classList.toggle('with-notes'); | ||
110 | break; | ||
111 | |||
112 | case 27: // ESC | ||
113 | document.body.classList.remove('with-notes'); | ||
114 | break; | ||
115 | |||
116 | //case 13: // Enter | ||
117 | case 70: // F | ||
118 | // Only respect 'f'/enter on body. Don't want to capture keys from <input> | ||
119 | if (e.target == document.body) { | ||
120 | if (e.keyCode != 13 && !document.webkitIsFullScreen) { | ||
121 | document.body.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); | ||
122 | } else { | ||
123 | document.webkitCancelFullScreen(); | ||
124 | } | ||
125 | } | ||
126 | break; | ||
127 | } | ||
128 | }; | ||
129 | |||
130 | /** | ||
131 | * @private | ||
132 | */ | ||
133 | SlideDeck.prototype.loadConfig_ = function() { | ||
134 | var configScripts = | ||
135 | document.querySelector('script[type="text/slide-config"]'); | ||
136 | if (configScripts) { | ||
137 | eval(configScripts.innerHTML); | ||
138 | this.config_ = slideConfig; | ||
139 | } | ||
140 | |||
141 | var settings = this.config_.settings; | ||
142 | |||
143 | this.loadTheme_(settings.theme || 'default'); | ||
144 | |||
145 | if (settings.favIcon) { | ||
146 | this.addFavIcon_(settings.favIcon); | ||
147 | } | ||
148 | |||
149 | if (settings.title) { | ||
150 | document.title = settings.title; | ||
151 | } | ||
152 | |||
153 | if (settings.usePrettify || true) { | ||
154 | console.log('Use prettify'); | ||
155 | } | ||
156 | |||
157 | if (settings.analyticsId) { | ||
158 | this.loadAnalytics_(); | ||
159 | } | ||
160 | |||
161 | if (settings.fonts) { | ||
162 | this.addFonts_(settings.fonts); | ||
163 | } | ||
164 | |||
165 | if (settings.useBuilds || true) { | ||
166 | this.makeBuildLists_(); | ||
167 | } | ||
168 | }; | ||
169 | |||
170 | /** | ||
171 | * @private | ||
172 | * @param {Array.<string>} fonts | ||
173 | */ | ||
174 | SlideDeck.prototype.addFonts_ = function(fonts) { | ||
175 | var el = document.createElement('link'); | ||
176 | el.rel = 'stylesheet'; | ||
177 | el.href = 'http://fonts.googleapis.com/css?family=' + fonts.join('|') + '&v2'; | ||
178 | document.querySelector('head').appendChild(el); | ||
179 | |||
180 | }; | ||
181 | |||
182 | /** | ||
183 | * @private | ||
184 | */ | ||
185 | SlideDeck.prototype.buildNextItem_ = function() { | ||
186 | var slide = this.slides_[this.curSlide_]; | ||
187 | var toBuild = slide.querySelector('.to-build'); | ||
188 | var built = slide.querySelector('.build-current'); | ||
189 | |||
190 | if (built) { | ||
191 | built.classList.remove('build-current'); | ||
192 | if (built.classList.contains('fade')) { | ||
193 | built.classList.add('build-fade'); | ||
194 | } | ||
195 | } | ||
196 | |||
197 | if (!toBuild) { | ||
198 | var items = slide.querySelectorAll('.build-fade'); | ||
199 | for (var j = 0, item; item = items[j]; j++) { | ||
200 | item.classList.remove('build-fade'); | ||
201 | } | ||
202 | return false; | ||
203 | } | ||
204 | |||
205 | toBuild.classList.remove('to-build'); | ||
206 | toBuild.classList.add('build-current'); | ||
207 | |||
208 | /*if (isChromeVoxActive()) { | ||
209 | speakAndSyncToNode(toBuild); | ||
210 | }*/ | ||
211 | |||
212 | return true; | ||
213 | }; | ||
214 | |||
215 | /** | ||
216 | * @param {boolean=} opt_dontPush | ||
217 | */ | ||
218 | SlideDeck.prototype.prevSlide = function(opt_dontPush) { | ||
219 | if (this.curSlide_ > 1) { | ||
220 | this.curSlide_--; | ||
221 | |||
222 | this.updateSlides_(opt_dontPush); | ||
223 | } | ||
224 | }; | ||
225 | |||
226 | /** | ||
227 | * @param {boolean=} opt_dontPush | ||
228 | */ | ||
229 | SlideDeck.prototype.nextSlide = function(opt_dontPush) { | ||
230 | |||
231 | if (this.buildNextItem_()) { | ||
232 | return; | ||
233 | } | ||
234 | |||
235 | if (this.curSlide_ < this.slides_.length - 1) { | ||
236 | this.curSlide_++; | ||
237 | |||
238 | this.updateSlides_(opt_dontPush); | ||
239 | } | ||
240 | }; | ||
241 | |||
242 | /** | ||
243 | * @private | ||
244 | */ | ||
245 | SlideDeck.prototype.updateSlides_ = function(opt_dontPush) { | ||
246 | var dontPush = opt_dontPush || false; | ||
247 | |||
248 | var curSlide = this.curSlide_; | ||
249 | for (var i = 0; i < this.slides_.length; i++) { | ||
250 | switch (i) { | ||
251 | case curSlide - 2: | ||
252 | this.updateSlideClass_(i, 'far-past'); | ||
253 | break; | ||
254 | case curSlide - 1: | ||
255 | this.updateSlideClass_(i, 'past'); | ||
256 | break; | ||
257 | case curSlide: | ||
258 | this.updateSlideClass_(i, 'current'); | ||
259 | break; | ||
260 | case curSlide + 1: | ||
261 | this.updateSlideClass_(i, 'next'); | ||
262 | break; | ||
263 | case curSlide + 2: | ||
264 | this.updateSlideClass_(i, 'far-next'); | ||
265 | break; | ||
266 | default: | ||
267 | this.updateSlideClass_(i); | ||
268 | break; | ||
269 |