lib/plugins/iphone.js in shining-2.0.0 vs lib/plugins/iphone.js in shining-2.0.1

- old
+ new

@@ -1,6 +1,6 @@ -// iphone.js: iPhone friendliness. Free of charge. +// iphone.js: iPhone and iPad friendliness. Free of charge. // The iPhone touch code is heavily borrowed from libraries around the web. // If you recognize anything as yours and you'd like credit for it, get in touch. var iPhone = !!navigator.userAgent.match(/iPhone/), iPad = !!navigator.userAgent.match(/iPad/); if (iPhone || iPad) { @@ -8,53 +8,47 @@ Shining.config.transitions = 'none'; if (iPhone) { clearInterval(Shining.pluginProcesses['resize']); $(window).unbind('resize'); } - + var scale = window.innerWidth / document.documentElement.clientWidth; Shining.slides.playSlide = function(name) { var index = Shining.slides._slides.indexOf(name), offset = index * window.innerWidth, slide = Shining.slides._loaded[name]; $('body').transformTransition({translate: {x: -offset }}); Shining.slides.current(name); - var aside = $('#stage .slide:eq(' + index + ') aside'); + var aside = $('body .slide:eq(' + index + ') aside'); if (aside.length) setTimeout( function() { Shining.note(aside.html(), 5000); $('#note').css({right: 10 - offset, maxWidth: '60%'}); }, 500 ); }; - Shining.centerStage = function(animate) { - $('.slide').each(function() { - centerSlide($(this)); - }); - }; - Shining.slides.nextSlide = function() { Shining.slides.playSlide(Shining.slides.next() || Shining.slides.current()); }; Shining.slides.previousSlide = function() { Shining.slides.playSlide(Shining.slides.previous() || Shining.slides.current()); }; function fitToView() { $('div.slide').each(function(i) { - $(this).css({left: i * window.innerWidth, height: window.innerHeight }); + $(this).css({left: i * window.innerWidth }); }); } function centerSlide(slide) { - var top = (window.innerHeight - slide.outerHeight()) / 3; - if (top < 0) top = 0; - slide.css({ top: top }); + // var top = (window.innerHeight - slide.outerHeight()) / 3; + // if (top < 0) top = 0; + // slide.css({ top: top }); } function currentSlide() { return $('#stage .slide:eq(' + Shining.slides._slides.indexOf(Shining.slides.current()) + ')'); } @@ -69,43 +63,47 @@ function flick(direction) { return Shining.slides[direction == 'right' ? 'nextSlide' : 'previousSlide'](); } Shining.when('slidesloaded', function(i) { - $('#stage').empty(); - $(Shining.config.slides).each(function(i) { - var slide = Shining.slides._loaded[this]; - $('<div class="slide">' + slide.markup + '</div>') - .css({left: i * window.innerWidth }) - .appendTo($('#stage')); - }); - if (iPad) Shining.centerStage(); - $('body').bind('touchstart', function() { - $(this).data('pan', { - startX: event.targetTouches[0].screenX, - lastX: event.targetTouches[0].screenX, - startTime: new Date().getTime(), - startOffset: $(this).transform().translate.x, - distance: function() { return Math.round(scale * (this.startX - this.lastX)); }, - delta: function() { - var x = event.targetTouches[0].screenX; - this.dir = this.lastX > x ? 'right' : 'left'; - var delta = Math.round(scale * (this.lastX - x)); - this.lastX = x; - return delta; - }, - duration: function() { return new Date().getTime() - this.startTime; } + setTimeout(function() { + $('body').empty(); + $(Shining.config.slides).each(function(i) { + var slide = Shining.slides._loaded[this]; + $('<div class="slide">' + slide.markup + '</div>') + .css({left: i * $('div.slide').outerWidth() }) + .appendTo($('body')); }); - return false; - }) - .bind('touchmove', function() { - var pan = $(this).data('pan'); - $(this).transform({translateBy: {x: -pan.delta()}}); - return false; - }) - .bind('touchend', function() { - var pan = $(this).data('pan'); - if (pan.dir) flick(pan.dir); - return false; - }); + // alert($('div.slide').outerWidth()); + fitToView(); + $('body').bind('touchstart', function() { + $(this).data('pan', { + startX: event.targetTouches[0].screenX, + lastX: event.targetTouches[0].screenX, + startTime: new Date().getTime(), + startOffset: $(this).transform().translate.x, + distance: function() { return Math.round(scale * (this.startX - this.lastX)); }, + delta: function() { + var x = event.targetTouches[0].screenX; + this.dir = this.lastX > x ? 'right' : 'left'; + var delta = Math.round(scale * (this.lastX - x)); + this.lastX = x; + return delta; + }, + duration: function() { return new Date().getTime() - this.startTime; } + }); + return false; + }) + .bind('touchmove', function() { + var pan = $(this).data('pan'); + $(this).transform({translateBy: {x: -pan.delta()}}); + return false; + }) + .bind('touchend', function() { + var pan = $(this).data('pan'); + if (pan.dir) flick(pan.dir); + return false; + }); + + }, 1000); }); -} \ No newline at end of file +}