Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement iphone swiping with a modified jquery.swipe

  • Loading branch information...
commit b0f17d9c294f11a2626ae7ae67606fe29629c131 1 parent a2f35d9
@quirkey quirkey authored
View
1  Jimfile
@@ -15,6 +15,7 @@ jquery.ui.widget 1.8rc3.custom
jquery.ui.mouse 1.8rc3.custom
jquery.ui.sortable 1.8rc3.custom
jquery.tabby
+jquery.swipe
prettify
showdown
sammy 0.5.1
View
2  _attachments/index.html
@@ -42,7 +42,7 @@
<div id="modal-loader" class="modal" style="display:none;"><img src="images/loader-large-black.gif" alt="Loading" /></div>
<div id="modal-notification" class="modal" style="display:none;"><div class="message">&nbsp;</div><br /><button>Close</button></div>
- <script src="javascripts/bundled.js" type="text/javascript" charset="utf-8"></script>
+ <script src="javascripts/compressed.js" type="text/javascript" charset="utf-8"></script>
<script src="javascripts/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
View
16 _attachments/javascripts/app.js
@@ -785,6 +785,22 @@
e.partial('templates/display.html.erb', function(display) {
e.$element().html(display);
e.displaySlide(preso.slide(e.params.slide_id));
+ $('#display .slide').swipe({
+ threshold: {
+ x: 20,
+ y: 30
+ },
+ swipeLeft: function() {
+ e.log('swipeLeft');
+ e.trigger('display-nextslide');
+ },
+ swipeRight: function() {
+ e.log('swipeRight');
+ e.trigger('display-prevslide');
+ }
+ }).dblclick(function() {
+ e.trigger('display-togglenav');
+ });
});
}
});
View
88 _attachments/javascripts/bundled.js
@@ -10173,6 +10173,94 @@ $.extend($.ui.sortable, {
// end of closure
})(jQuery);
+/*
+ * jSwipe - jQuery Plugin
+ * http://plugins.jquery.com/project/swipe
+ * http://www.ryanscherf.com/demos/swipe/
+ *
+ * Copyright (c) 2009 Ryan Scherf (www.ryanscherf.com)
+ * Licensed under the MIT license
+ *
+ * $Date: 2009-07-14 (Tue, 14 Jul 2009) $
+ * $version: 0.1
+ *
+ * This jQuery plugin will only run on devices running Mobile Safari
+ * on iPhone or iPod Touch devices running iPhone OS 2.0 or later.
+ * http://developer.apple.com/iphone/library/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
+ */
+(function($) {
+ $.fn.swipe = function(options) {
+ // Default thresholds & swipe functions
+ var defaults = {
+ threshold: {
+ x: 30,
+ y: 10
+ },
+ swipeLeft: function() { alert('swiped left') },
+ swipeRight: function() { alert('swiped right') },
+ preventDefaultEvents: true
+ };
+
+ var options = $.extend(defaults, options);
+
+ if (!this) return false;
+
+ return this.each(function() {
+
+ var $self = $(this);
+
+ // Private variables for each element
+ var originalCoord = { x: 0, y: 0 };
+ var finalCoord = { x: 0, y: 0 };
+
+ // Screen touched, store the original coordinate
+ function touchStart(event) {
+ console.log('Starting swipe gesture...')
+ originalCoord.x = event.targetTouches[0].pageX;
+ originalCoord.y = event.targetTouches[0].pageY;
+ }
+
+ // Store coordinates as finger is swiping
+ function touchMove(event) {
+ if (defaults.preventDefaultEvents)
+ event.preventDefault();
+ finalCoord.x = event.targetTouches[0].pageX; // Updated X,Y coordinates
+ finalCoord.y = event.targetTouches[0].pageY;
+ }
+
+ // Done Swiping
+ // Swipe should only be on X axis, ignore if swipe on Y axis
+ // Calculate if the swipe was left or right
+ function touchEnd(event) {
+ var changeY = ((originalCoord.y - finalCoord.y) / $self.height()) * 100,
+ changeX = ((originalCoord.x - finalCoord.x) / $self.width()) * 100;
+
+ console.log('Ending swipe gesture ' + changeX + ' ' + changeY);
+ if(changeY < defaults.threshold.y && changeY > (defaults.threshold.y*-1)) {
+ if(changeX > defaults.threshold.x) {
+ options.swipeLeft();
+ }
+ if(changeX < (defaults.threshold.x*-1)) {
+ options.swipeRight();
+ }
+ }
+ }
+
+ // Swipe was canceled
+ function touchCancel(event) {
+ console.log('Canceling swipe gesture...')
+ }
+
+ // Add gestures to all swipable areas
+ this.addEventListener("touchstart", touchStart, false);
+ this.addEventListener("touchmove", touchMove, false);
+ this.addEventListener("touchend", touchEnd, false);
+ this.addEventListener("touchcancel", touchCancel, false);
+
+ });
+ };
+})(jQuery);
+
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
View
265 _attachments/javascripts/compressed.js
136 additions, 129 deletions not shown
View
87 _attachments/javascripts/vendor/jquery.swipe-0.2.js
@@ -0,0 +1,87 @@
+/*
+ * jSwipe - jQuery Plugin
+ * http://plugins.jquery.com/project/swipe
+ * http://www.ryanscherf.com/demos/swipe/
+ *
+ * Copyright (c) 2009 Ryan Scherf (www.ryanscherf.com)
+ * Licensed under the MIT license
+ *
+ * $Date: 2009-07-14 (Tue, 14 Jul 2009) $
+ * $version: 0.1
+ *
+ * This jQuery plugin will only run on devices running Mobile Safari
+ * on iPhone or iPod Touch devices running iPhone OS 2.0 or later.
+ * http://developer.apple.com/iphone/library/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
+ */
+(function($) {
+ $.fn.swipe = function(options) {
+ // Default thresholds & swipe functions
+ var defaults = {
+ threshold: {
+ x: 30,
+ y: 10
+ },
+ swipeLeft: function() { alert('swiped left') },
+ swipeRight: function() { alert('swiped right') },
+ preventDefaultEvents: true
+ };
+
+ var options = $.extend(defaults, options);
+
+ if (!this) return false;
+
+ return this.each(function() {
+
+ var $self = $(this);
+
+ // Private variables for each element
+ var originalCoord = { x: 0, y: 0 };
+ var finalCoord = { x: 0, y: 0 };
+
+ // Screen touched, store the original coordinate
+ function touchStart(event) {
+ console.log('Starting swipe gesture...')
+ originalCoord.x = event.targetTouches[0].pageX;
+ originalCoord.y = event.targetTouches[0].pageY;
+ }
+
+ // Store coordinates as finger is swiping
+ function touchMove(event) {
+ if (defaults.preventDefaultEvents)
+ event.preventDefault();
+ finalCoord.x = event.targetTouches[0].pageX; // Updated X,Y coordinates
+ finalCoord.y = event.targetTouches[0].pageY;
+ }
+
+ // Done Swiping
+ // Swipe should only be on X axis, ignore if swipe on Y axis
+ // Calculate if the swipe was left or right
+ function touchEnd(event) {
+ var changeY = ((originalCoord.y - finalCoord.y) / $self.height()) * 100,
+ changeX = ((originalCoord.x - finalCoord.x) / $self.width()) * 100;
+
+ console.log('Ending swipe gesture ' + changeX + ' ' + changeY);
+ if(changeY < defaults.threshold.y && changeY > (defaults.threshold.y*-1)) {
+ if(changeX > defaults.threshold.x) {
+ options.swipeLeft();
+ }
+ if(changeX < (defaults.threshold.x*-1)) {
+ options.swipeRight();
+ }
+ }
+ }
+
+ // Swipe was canceled
+ function touchCancel(event) {
+ console.log('Canceling swipe gesture...')
+ }
+
+ // Add gestures to all swipable areas
+ this.addEventListener("touchstart", touchStart, false);
+ this.addEventListener("touchmove", touchMove, false);
+ this.addEventListener("touchend", touchEnd, false);
+ this.addEventListener("touchcancel", touchCancel, false);
+
+ });
+ };
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.