diff options
author | Eric Bidelman | 2012-04-14 14:39:08 -0700 |
---|---|---|
committer | Eric Bidelman | 2012-04-14 14:39:08 -0700 |
commit | ba1842bd2162d4fa3c7189621825afd765bea5fa (patch) | |
tree | a001e4f56275a0c19ce889b5aa44c2d7dc34e6c7 /js/slides.js | |
parent | 92d59f701df13fe8e99d2c908dcf18450c53b762 (diff) | |
download | io-slides-remote-ba1842bd2162d4fa3c7189621825afd765bea5fa.tar.gz |
Hammer.js instead. Touch working on mobile
style sheets now in main .html file. Better for mobile rather than dynamically loading in js
matcMedia polyfill
Diffstat (limited to 'js/slides.js')
-rw-r--r-- | js/slides.js | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/js/slides.js b/js/slides.js index cf31aba..784d122 100644 --- a/js/slides.js +++ b/js/slides.js | |||
@@ -52,6 +52,18 @@ SlideDeck.prototype.getCurrentSlideFromHash_ = function() { | |||
52 | SlideDeck.prototype.onDomLoaded_ = function(e) { | 52 | SlideDeck.prototype.onDomLoaded_ = function(e) { |
53 | this.slides_ = document.querySelectorAll('slide:not([hidden]):not(.backdrop)'); | 53 | this.slides_ = document.querySelectorAll('slide:not([hidden]):not(.backdrop)'); |
54 | 54 | ||
55 | // If we're on a smartphone device, load phone.css. | ||
56 | if (window.matchMedia('only screen and (max-device-width: 480px)').matches) { | ||
57 | // var style = document.createElement('link'); | ||
58 | // style.rel = 'stylesheet'; | ||
59 | // style.type = 'text/css'; | ||
60 | // style.href = this.CSS_DIR_ + 'phone.css'; | ||
61 | // document.querySelector('head').appendChild(style); | ||
62 | |||
63 | // Remove widescreen if it's applied. | ||
64 | document.querySelector('slides').classList.remove('layout-widescreen'); | ||
65 | } | ||
66 | |||
55 | // Load config. | 67 | // Load config. |
56 | this.loadConfig_(); | 68 | this.loadConfig_(); |
57 | this.addEventListeners_(); | 69 | this.addEventListeners_(); |
@@ -172,7 +184,7 @@ SlideDeck.prototype.loadConfig_ = function() { | |||
172 | 184 | ||
173 | var settings = this.config_.settings; | 185 | var settings = this.config_.settings; |
174 | 186 | ||
175 | this.loadTheme_(settings.theme || 'default'); | 187 | this.loadTheme_(settings.theme || []); |
176 | 188 | ||
177 | if (settings.favIcon) { | 189 | if (settings.favIcon) { |
178 | this.addFavIcon_(settings.favIcon); | 190 | this.addFavIcon_(settings.favIcon); |
@@ -235,21 +247,32 @@ SlideDeck.prototype.loadConfig_ = function() { | |||
235 | document.querySelector('[data-config-presenter]').innerHTML = html; | 247 | document.querySelector('[data-config-presenter]').innerHTML = html; |
236 | } | 248 | } |
237 | 249 | ||
250 | var slides = document.querySelector('slides'); | ||
251 | |||
238 | /* Clicking and tapping */ | 252 | /* Clicking and tapping */ |
239 | var el = document.createElement('div'); | 253 | var el = document.createElement('div'); |
240 | el.classList.add('slide-area'); | 254 | el.classList.add('slide-area'); |
241 | el.id = 'prev-slide-area'; | 255 | el.id = 'prev-slide-area'; |
242 | el.addEventListener('click', this.prevSlide.bind(this), false); | 256 | el.addEventListener('click', this.prevSlide.bind(this), false); |
243 | document.querySelector('slides').appendChild(el); | 257 | slides.appendChild(el); |
244 | 258 | ||
245 | var el = document.createElement('div'); | 259 | var el = document.createElement('div'); |
246 | el.classList.add('slide-area'); | 260 | el.classList.add('slide-area'); |
247 | el.id = 'next-slide-area'; | 261 | el.id = 'next-slide-area'; |
248 | el.addEventListener('click', this.nextSlide.bind(this), false); | 262 | el.addEventListener('click', this.nextSlide.bind(this), false); |
249 | document.querySelector('slides').appendChild(el); | 263 | slides.appendChild(el); |
250 | 264 | ||
251 | if (!!!('enableTouch' in settings) || settings.enableTouch) { | 265 | if (!!!('enableTouch' in settings) || settings.enableTouch) { |
252 | var toucher = new TouchManager(this); | 266 | var self = this; |
267 | |||
268 | var hammer = new Hammer(slides); | ||
269 | hammer.ondragend = function(e) { | ||
270 | if (e.direction == 'right' || e.direction == 'down') { | ||
271 | self.prevSlide(); | ||
272 | } else if (e.direction == 'left' || e.direction == 'up') { | ||
273 | self.nextSlide(); | ||
274 | } | ||
275 | }; | ||
253 | } | 276 | } |
254 | }; | 277 | }; |
255 | 278 | ||
@@ -553,7 +576,13 @@ SlideDeck.prototype.addFavIcon_ = function(favIcon) { | |||
553 | * @param {string} theme | 576 | * @param {string} theme |
554 | */ | 577 | */ |
555 | SlideDeck.prototype.loadTheme_ = function(theme) { | 578 | SlideDeck.prototype.loadTheme_ = function(theme) { |
556 | var styles = [/*'../../js/prettify/prettify',*/ theme]; | 579 | var styles = []; |
580 | if (theme.constructor.name === 'String') { | ||
581 | styles.push(theme); | ||
582 | } else { | ||
583 | styles = theme; | ||
584 | } | ||
585 | |||
557 | for (var i = 0, style; themeUrl = styles[i]; i++) { | 586 | for (var i = 0, style; themeUrl = styles[i]; i++) { |
558 | var style = document.createElement('link'); | 587 | var style = document.createElement('link'); |
559 | style.rel = 'stylesheet'; | 588 | style.rel = 'stylesheet'; |
@@ -565,11 +594,11 @@ SlideDeck.prototype.loadTheme_ = function(theme) { | |||
565 | } | 594 | } |
566 | document.querySelector('head').appendChild(style); | 595 | document.querySelector('head').appendChild(style); |
567 | } | 596 | } |
568 | 597 | // TODO(ericbidelman): Removed this. | |
569 | var viewportMeta = document.createElement('meta'); | 598 | // var viewportMeta = document.createElement('meta'); |
570 | viewportMeta.name = 'viewport'; | 599 | // viewportMeta.name = 'viewport'; |
571 | viewportMeta.content = 'width=1100,height=750'; | 600 | // viewportMeta.content = 'width=1100,height=750'; |
572 | document.querySelector('head').appendChild(viewportMeta); | 601 | // document.querySelector('head').appendChild(viewportMeta); |
573 | 602 | ||
574 | var appleMeta = document.createElement('meta'); | 603 | var appleMeta = document.createElement('meta'); |
575 | appleMeta.name = 'apple-mobile-web-app-capable'; | 604 | appleMeta.name = 'apple-mobile-web-app-capable'; |
@@ -601,7 +630,8 @@ SlideDeck.prototype.loadAnalytics_ = function() { | |||
601 | 630 | ||
602 | yepnope({ | 631 | yepnope({ |
603 | test: !!body.classList && !!body.dataset, | 632 | test: !!body.classList && !!body.dataset, |
604 | nope: ['js/polyfills/classList.min.js', 'js/polyfills/dataset.min.js'], | 633 | nope: ['js/polyfills/classList.min.js', 'js/polyfills/dataset.min.js', |
634 | 'js/polyfills/matchMedia.js'], | ||
605 | complete: function() { | 635 | complete: function() { |
606 | window.slidedeck = new SlideDeck(); | 636 | window.slidedeck = new SlideDeck(); |
607 | } | 637 | } |