Grafting the new server to the new backbone client
[KiwiIRC.git] / client / js / touchscreen_tweaks.js
CommitLineData
54f4a22e
D
1/*
2 Orientation stuff
3*/
ccb38943 4
54f4a22e
D
5var supportsOrientationChange = "onorientationchange" in window,
6 orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
7
8window.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
13 or = "landscape";
14 } else {
15 // We have a portrait screen
16 or = "portrait";
17 }
18
19 if(agent == "ipad" || agent == "iphone" || agent == "ipod"){
20 if(or == "landscape"){
21 width = window.height;
22 height = window.width;
23 } else {
24 width = window.width;
25 height = window.height;
26 }
27 } else {
28 width = window.width;
29 height = window.height;
30 }
31
32 //alert('adding class: '+or);
33 if(or=="landscape"){
34 $('#kiwi').removeClass("portrait");
35 } else {
36 $('#kiwi').removeClass("landscape");
37 }
38 $('#kiwi').addClass(or);
39}, false);
ccb38943 40
54f4a22e
D
41
42
43
44
45
46
47
48
49/*
50 Scroll stuff
51*/
52
53function registerTouches(obj){
54 return;
55//$(document).ready(function(){
56 obj.ontouchstart = function(e) {
57 e.preventDefault();
58 document.touchx_start = e.touches[0].pageX;
59 document.touchy_start = e.touches[0].pageY;
60 }
61 obj.ontouchmove = function(e) {
62 e.preventDefault();
63 document.touchx_cur = e.touches[0].pageX;
64 document.touchy_cur = e.touches[0].pageY;
65
66 var xdiff = document.touchx_start - document.touchx_cur
67 var ydiff = document.touchy_start - document.touchy_cur
68
69 var obj = $(this);
70 if(ydiff < -20){
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);
78 }
79 }
80 obj.ontouchend = function(e) {
81 e.preventDefault();
82
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);
87
88 if(xdiff < -150 && (ydiff > -250 && ydiff < 250)){
89 //alert("next window (xdiff="+xdiff+" ydiff="+ydiff+")");
90 front.tabviewsNext();
91 } else if(xdiff > 150 && (ydiff > -250 && ydiff < 250)){
92 //alert("previous window (xdiff="+xdiff+" ydiff="+ydiff+")");
93 front.tabviewsPrevious();
94 }
95 }
96//});
ccb38943
D
97}
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116/*
117 * jSwipe - jQuery Plugin
118 * http://plugins.jquery.com/project/swipe
119 * http://www.ryanscherf.com/demos/swipe/
120 *
121 * Copyright (c) 2009 Ryan Scherf (www.ryanscherf.com)
122 * Licensed under the MIT license
123 *
124 * $Date: 2009-07-14 (Tue, 14 Jul 2009) $
125 * $version: 0.1.2
126 *
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
130 */
131(function($) {
132 $.fn.swipe = function(options) {
133
134 // Default thresholds & swipe functions
135 var defaults = {
136 threshold: {
137 x: 30,
138 y: 10
139 },
140 swipeLeft: function() { },
141 swipeRight: function() { }
142 };
143
144 var options = $.extend(defaults, options);
145
146 if (!this) return false;
147
148 return this.each(function() {
149
150 var me = $(this)
151
152 // Private variables for each element
153 var originalCoord = { x: 0, y: 0 }
154 var finalCoord = { x: 0, y: 0 }
155
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
161 }
162
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
168 }
169
170 // Done Swiping
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
178
179 if(changeX > defaults.threshold.x) {
180 defaults.swipeLeft()
181 }
182 if(changeX < (defaults.threshold.x*-1)) {
183 defaults.swipeRight()
184 }
185 }
186 }
187
188 // Swipe was started
189 function touchStart(event) {
190 //console.log('Starting swipe gesture...')
191 originalCoord.x = event.targetTouches[0].pageX
192 originalCoord.y = event.targetTouches[0].pageY
193
194 finalCoord.x = originalCoord.x
195 finalCoord.y = originalCoord.y
196 }
197
198 // Swipe was canceled
199 function touchCancel(event) {
200 //console.log('Canceling swipe gesture...')
201 }
202
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);
208
209 });
210 };
211})(jQuery);
212
213$(document).swipe({
214 swipeLeft: function(){ front.windowsNext(); },
215 swipeRight: function(){ front.windowsPrevious(); },
216 threshold: {x: 30, y: 20}
217});