5 var supportsOrientationChange
= "onorientationchange" in window
,
6 orientationEvent
= supportsOrientationChange
? "orientationchange" : "resize";
8 window
.addEventListener(orientationEvent
, function() {
9 //alert('rotated' + window.orientation + " " + screen.width);
10 var or
= window
.orientation
;
11 if(or
== 90 || or
== -90){
12 // We have a landscape screen
15 // We have a portrait screen
19 if(agent
== "ipad" || agent
== "iphone" || agent
== "ipod"){
20 if(or
== "landscape"){
21 width
= window
.height
;
22 height
= window
.width
;
25 height
= window
.height
;
29 height
= window
.height
;
32 //alert('adding class: '+or);
34 $('#kiwi').removeClass("portrait");
36 $('#kiwi').removeClass("landscape");
38 $('#kiwi').addClass(or
);
53 function registerTouches(obj
){
55 //$(document).ready(function(){
56 obj
.ontouchstart = function(e
) {
58 document
.touchx_start
= e
.touches
[0].pageX
;
59 document
.touchy_start
= e
.touches
[0].pageY
;
61 obj
.ontouchmove = function(e
) {
63 document
.touchx_cur
= e
.touches
[0].pageX
;
64 document
.touchy_cur
= e
.touches
[0].pageY
;
66 var xdiff
= document
.touchx_start
- document
.touchx_cur
67 var ydiff
= document
.touchy_start
- document
.touchy_cur
71 var n
= obj
.attr("scrollTop")+ydiff
;
72 //alert("down (xdiff="+xdiff+" ydiff="+ydiff+" scrollTop="+obj.attr("scrollTop")+") "+n );
73 obj
.attr("scrollTop", n
);
74 } else if(ydiff
> 20){
75 var n
= obj
.attr("scrollTop")+ydiff
;
76 //alert("up (xdiff="+xdiff+" ydiff="+ydiff+" scrollTop="+obj.attr("scrollTop")+") "+n);
77 obj
.attr("scrollTop", n
);
80 obj
.ontouchend = function(e
) {
83 var xdiff
= document
.touchx_start
- document
.touchx_cur
84 var ydiff
= document
.touchy_start
- document
.touchy_cur
85 //alert('x='+xdiff+' y='+ydiff);
86 //alert('Start: x='+document.touchx+' y='+document.touchy+"\n"+'End: x='+e.pageX+' y='+e.pageY);
88 if(xdiff
< -150 && (ydiff
> -250 && ydiff
< 250)){
89 //alert("next window (xdiff="+xdiff+" ydiff="+ydiff+")");
91 } else if(xdiff
> 150 && (ydiff
> -250 && ydiff
< 250)){
92 //alert("previous window (xdiff="+xdiff+" ydiff="+ydiff+")");
93 front
.tabviewsPrevious();
117 * jSwipe - jQuery Plugin
118 * http://plugins.jquery.com/project/swipe
119 * http://www.ryanscherf.com/demos/swipe/
121 * Copyright (c) 2009 Ryan Scherf (www.ryanscherf.com)
122 * Licensed under the MIT license
124 * $Date: 2009-07-14 (Tue, 14 Jul 2009) $
127 * This jQuery plugin will only run on devices running Mobile Safari
128 * on iPhone or iPod Touch devices running iPhone OS 2.0 or later.
129 * http://developer.apple.com/iphone/library/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
132 $.fn
.swipe = function(options
) {
134 // Default thresholds & swipe functions
140 swipeLeft: function() { },
141 swipeRight: function() { }
144 var options
= $.extend(defaults
, options
);
146 if (!this) return false;
148 return this.each(function() {
152 // Private variables for each element
153 var originalCoord
= { x
: 0, y
: 0 }
154 var finalCoord
= { x
: 0, y
: 0 }
156 // Screen touched, store the original coordinate
157 function touchStart(event
) {
158 //console.log('Starting swipe gesture...')
159 originalCoord
.x
= event
.targetTouches
[0].pageX
160 originalCoord
.y
= event
.targetTouches
[0].pageY
163 // Store coordinates as finger is swiping
164 function touchMove(event
) {
165 //event.preventDefault();
166 finalCoord
.x
= event
.targetTouches
[0].pageX
// Updated X,Y coordinates
167 finalCoord
.y
= event
.targetTouches
[0].pageY
171 // Swipe should only be on X axis, ignore if swipe on Y axis
172 // Calculate if the swipe was left or right
173 function touchEnd(event
) {
174 //console.log('Ending swipe gesture...')
175 var changeY
= originalCoord
.y
- finalCoord
.y
176 if(changeY
< defaults
.threshold
.y
&& changeY
> (defaults
.threshold
.y
*-1)) {
177 changeX
= originalCoord
.x
- finalCoord
.x
179 if(changeX
> defaults
.threshold
.x
) {
182 if(changeX
< (defaults
.threshold
.x
*-1)) {
183 defaults
.swipeRight()
189 function touchStart(event
) {
190 //console.log('Starting swipe gesture...')
191 originalCoord
.x
= event
.targetTouches
[0].pageX
192 originalCoord
.y
= event
.targetTouches
[0].pageY
194 finalCoord
.x
= originalCoord
.x
195 finalCoord
.y
= originalCoord
.y
198 // Swipe was canceled
199 function touchCancel(event
) {
200 //console.log('Canceling swipe gesture...')
203 // Add gestures to all swipable areas
204 this.addEventListener("touchstart", touchStart
, false);
205 this.addEventListener("touchmove", touchMove
, false);
206 this.addEventListener("touchend", touchEnd
, false);
207 this.addEventListener("touchcancel", touchCancel
, false);
214 swipeLeft: function(){ front
.windowsNext(); },
215 swipeRight: function(){ front
.windowsPrevious(); },
216 threshold
: {x
: 30, y
: 20}