annotate static/jqtouch.js @ 3:942d4cfc2538

Add static alias. Correct typos in demo paths.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 15 Aug 2011 19:05:23 +0930
parents 2d9ee2b3ae82
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 /*
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 _/ _/_/ _/_/_/_/_/ _/
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 _/ _/ _/ _/_/ _/ _/ _/_/_/ _/_/_/
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 _/ _/_/ _/ _/ _/_/ _/_/_/ _/_/_/ _/ _/
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 _/
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 _/
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 Created by David Kaneda <http://www.davidkaneda.com>
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 Documentation and issue tracking on GitHub <http://wiki.github.com/senchalabs/jQTouch/>
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 Special thanks to Jonathan Stark <http://jonathanstark.com/>
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 and pinch/zoom <http://www.pinchzoom.com/>
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 (c) 2010 by jQTouch project members.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 See LICENSE.txt for license.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 $Revision: 166 $
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 $Date: Tue Mar 29 01:24:46 EDT 2011 $
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 $LastChangedBy: jonathanstark $
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 */
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 (function($) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 $.jQTouch = function(options) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 // Initialize internal jQT variables
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 var $body,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 $head=$('head'),
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 initialPageId='',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 hist=[],
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 newPageCount=0,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 jQTSettings={},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 currentPage='',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 orientation='portrait',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 tapReady=true,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 lastTime=0,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 lastAnimationTime=0,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 touchSelectors=[],
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 publicObj={},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 tapBuffer=351,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 extensions=$.jQTouch.prototype.extensions,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 animations=[],
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 hairExtensions='',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 defaults = {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 addGlossToIcon: true,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 backSelector: '.back, .cancel, .goback',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 cacheGetRequests: true,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 debug: false,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 fallback2dAnimation: 'fade',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 fixedViewport: true,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 formSelector: 'form',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 fullScreen: true,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 fullScreenClass: 'fullscreen',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 hoverDelay: 50,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 icon: null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 iconPad: null, // available in iOS 4.2 and later.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 icon4: null, // available in iOS 4.2 and later.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 moveThreshold: 10,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 preloadImages: false,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 pressDelay: 1000,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 startupScreen: null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 statusBar: 'default', // other options: black-translucent, black
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 submitSelector: '.submit',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 touchSelector: 'a, .touch',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 useAnimations: true,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 useFastTouch: true, // experimental
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 animations: [ // highest to lowest priority
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 {selector:'.cube', name:'cubeleft', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 {selector:'.cubeleft', name:'cubeleft', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 {selector:'.cuberight', name:'cuberight', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 {selector:'.dissolve', name:'dissolve', is3d:false},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 {selector:'.fade', name:'fade', is3d:false},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 {selector:'.flip', name:'flipleft', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 {selector:'.flipleft', name:'flipleft', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 {selector:'.flipright', name:'flipright', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 {selector:'.pop', name:'pop', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 {selector:'.slide', name:'slideleft', is3d:false},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 {selector:'.slidedown', name:'slidedown', is3d:false},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 {selector:'.slideleft', name:'slideleft', is3d:false},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 {selector:'.slideright', name:'slideright', is3d:false},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 {selector:'.slideup', name:'slideup', is3d:false},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 {selector:'.swap', name:'swapleft', is3d:true},
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 {selector:'#jqt > * > ul li a', name:'slideleft', is3d:false}
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 ]
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 };
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 function _debug(message) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 var now = (new Date).getTime();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 var delta = now - lastTime;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 lastTime = now;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 if (jQTSettings.debug) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 if (message) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 _log(delta + ': ' + message);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 _log(delta + ': ' + 'Called ' + arguments.callee.caller.name);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 function _log(message) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 if (window.console !== undefined) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 console.log(message);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 function addAnimation(animation) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 // _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 if (typeof(animation.selector) === 'string' && typeof(animation.name) === 'string') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 animations.push(animation);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 function addPageToHistory(page, animation) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 hist.unshift({
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 page: page,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 animation: animation,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 hash: '#' + page.attr('id'),
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 id: page.attr('id')
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 function clickHandler(e) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 if (!tapReady) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 _debug('ClickHandler handler aborted because tap is not ready');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 e.preventDefault();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 // Figure out whether to prevent default
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 var $el = $(e.target);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 // Find the nearest tappable ancestor
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 if (!$el.is(touchSelectors.join(', '))) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137 $el = $(e.target).closest(touchSelectors.join(', '));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 // Prevent default if we found an internal link (relative or absolute)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 if ($el && $el.attr('href') && !$el.isExternalLink()) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142 _debug('Need to prevent default click behavior');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143 e.preventDefault();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 _debug('No need to prevent default click behavior');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148 // Trigger a tap event if touchstart is not on the job
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 if ($.support.touch) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150 _debug('Not converting click to a tap event because touch handler is on the job');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 _debug('Converting click event to a tap event because touch handlers are not present or off');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 $(e.target).trigger('tap', e);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
156 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 function doNavigation(fromPage, toPage, animation, goingBack) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 // Error check for target page
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 if (toPage.length === 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 $.fn.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 _debug('Target element is missing.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167 // Error check for fromPage===toPage
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 if (toPage.hasClass('current')) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 $.fn.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 _debug('You are already on the page you are trying to navigate to.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
171 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
174 // Collapse the keyboard
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175 $(':focus').blur();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177 // Position the incoming page so toolbar is at top of viewport regardless of scroll position on from page
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178 // toPage.css('top', window.pageYOffset);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
179
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
180 fromPage.trigger('pageAnimationStart', { direction: 'out' });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181 toPage.trigger('pageAnimationStart', { direction: 'in' });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
183 if ($.support.animationEvents && animation && jQTSettings.useAnimations) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
184
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
185 tapReady = false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187 // Fail over to 2d animation if need be
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
188 if (!$.support.transform3d && animation.is3d) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 animation.name = jQTSettings.fallback2dAnimation;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
190 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
191
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 // Reverse animation if need be
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
193 var finalAnimationName;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
194 if (goingBack) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
195 if (animation.name.indexOf('left') > 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
196 finalAnimationName = animation.name.replace(/left/, 'right');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
197 } else if (animation.name.indexOf('right') > 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
198 finalAnimationName = animation.name.replace(/right/, 'left');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
199 } else if (animation.name.indexOf('up') > 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
200 finalAnimationName = animation.name.replace(/up/, 'down');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
201 } else if (animation.name.indexOf('down') > 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
202 finalAnimationName = animation.name.replace(/down/, 'up');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
203 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
204 finalAnimationName = animation.name;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
205 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
206 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
207 finalAnimationName = animation.name;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
208 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
209
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
210 // _debug('finalAnimationName is ' + finalAnimationName);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
211
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
212 // Bind internal "cleanup" callback
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
213 fromPage.bind('webkitAnimationEnd', navigationEndHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
214 fromPage.bind('webkitTransitionEnd', navigationEndHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
215
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
216 // Trigger animations
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
217 scrollTo(0, 0);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
218 toPage.addClass(finalAnimationName + ' in current');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
219 fromPage.addClass(finalAnimationName + ' out');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
220
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
221 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
222 toPage.addClass('current');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
223 navigationEndHandler();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
224 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
225
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
226 // Define private navigationEnd callback
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
227 function navigationEndHandler(event) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
228 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
229
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
230 if ($.support.animationEvents && animation && jQTSettings.useAnimations) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
231 fromPage.unbind('webkitAnimationEnd', navigationEndHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
232 fromPage.unbind('webkitTransitionEnd', navigationEndHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
233 fromPage.removeClass(finalAnimationName + ' out current');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
234 toPage.removeClass(finalAnimationName + ' in');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
235 // scrollTo(0, 0);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
236 // toPage.css('top', 0);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
237 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
238 fromPage.removeClass(finalAnimationName + ' out current');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
239 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
240
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
241 // Housekeeping
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
242 currentPage = toPage;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
243 if (goingBack) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
244 hist.shift();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
245 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
246 addPageToHistory(currentPage, animation);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
247 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
248
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
249 fromPage.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
250 lastAnimationTime = (new Date()).getTime();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
251 setHash(currentPage.attr('id'));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
252 tapReady = true;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
253
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
254 // Trigger custom events
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
255 toPage.trigger('pageAnimationEnd', {direction:'in', animation:animation});
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
256 fromPage.trigger('pageAnimationEnd', {direction:'out', animation:animation});
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
257
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
258 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
259
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
260 // We's out
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
261 return true;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
262 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
263 function getOrientation() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
264 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
265 return orientation;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
266 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
267 function goBack() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
268 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
269
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
270 // Error checking
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
271 if (hist.length < 1 ) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
272 _debug('History is empty.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
273 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
274
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
275 if (hist.length === 1 ) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
276 _debug('You are on the first panel.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
277 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
278
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
279 var from = hist[0], to = hist[1];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
280
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
281 if (doNavigation(from.page, to.page, from.animation, true)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
282 return publicObj;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
283 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
284 _debug('Could not go back.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
285 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
286 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
287
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
288 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
289 function goTo(toPage, animation, reverse) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
290 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
291
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
292 if (reverse) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
293 _log('The reverse parameter of the goTo() function has been deprecated.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
294 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
295
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
296 var fromPage = hist[0].page;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
297
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
298 if (typeof animation === 'string') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
299 for (var i=0, max=animations.length; i < max; i++) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
300 if (animations[i].name === animation) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
301 animation = animations[i];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
302 break;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
303 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
304 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
305 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
306
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
307 if (typeof(toPage) === 'string') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
308 var nextPage = $(toPage);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
309 if (nextPage.length < 1) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
310 showPageByHref(toPage, {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
311 'animation': animation
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
312 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
313 return;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
314 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
315 toPage = nextPage;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
316 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
317
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
318 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
319 if (doNavigation(fromPage, toPage, animation)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
320 return publicObj;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
321 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
322 _debug('Could not animate pages.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
323 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
324 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
325 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
326 function hashChangeHandler(e) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
327 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
328 if (location.hash === hist[0].hash) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
329 _debug('We are on the right panel');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
330 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
331 _debug('We are not on the right panel');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
332 if(location.hash === hist[1].hash) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
333 goBack();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
334 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
335 _debug(location.hash + ' !== ' + hist[1].hash);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
336 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
337 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
338 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
339 function init(options) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
340 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
341 jQTSettings = $.extend({}, defaults, options);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
342
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
343 // Preload images
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
344 if (jQTSettings.preloadImages) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
345 for (var i = jQTSettings.preloadImages.length - 1; i >= 0; i--) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
346 (new Image()).src = jQTSettings.preloadImages[i];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
347 };
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
348 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
349
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
350 // Set appropriate icon (retina display available in iOS 4.2 and later.)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
351 var precomposed = (jQTSettings.addGlossToIcon) ? '' : '-precomposed';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
352 if (jQTSettings.icon) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
353 hairExtensions += '<link rel="apple-touch-icon' + precomposed + '" href="' + jQTSettings.icon + '" />';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
354 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
355 if (jQTSettings.iconPad) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
356 hairExtensions += '<link rel="apple-touch-icon' + precomposed + '" sizes="72x72" href="' + jQTSettings.iconPad + '" />';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
357 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
358 if (jQTSettings.icon4) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
359 hairExtensions += '<link rel="apple-touch-icon' + precomposed + '" sizes="114x114" href="' + jQTSettings.icon4 + '" />';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
360 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
361
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
362 // Set startup screen
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
363 if (jQTSettings.startupScreen) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
364 hairExtensions += '<link rel="apple-touch-startup-image" href="' + jQTSettings.startupScreen + '" />';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
365 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
366
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
367 // Set viewport
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
368 if (jQTSettings.fixedViewport) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
369 hairExtensions += '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;"/>';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
370 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
371
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
372 // Set full-screen
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
373 if (jQTSettings.fullScreen) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
374 hairExtensions += '<meta name="apple-mobile-web-app-capable" content="yes" />';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
375 if (jQTSettings.statusBar) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
376 hairExtensions += '<meta name="apple-mobile-web-app-status-bar-style" content="' + jQTSettings.statusBar + '" />';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
377 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
378 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
379
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
380 // Attach hair extensions
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
381 if (hairExtensions) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
382 $head.prepend(hairExtensions);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
383 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
384
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
385 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
386 function insertPages(nodes, animation) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
387 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
388
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
389 var targetPage = null;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
390 $(nodes).each(function(index, node) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
391 var $node = $(this);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
392 if (!$node.attr('id')) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
393 $node.attr('id', 'page-' + (++newPageCount));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
394 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
395
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
396 // Remove any existing instance
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
397 $('#' + $node.attr('id')).remove();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
398
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
399 $body.trigger('pageInserted', {page: $node.appendTo($body)});
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
400
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
401 if ($node.hasClass('current') || !targetPage) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
402 targetPage = $node;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
403 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
404 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
405 if (targetPage !== null) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
406 goTo(targetPage, animation);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
407 return targetPage;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
408 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
409 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
410 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
411 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
412 function mousedownHandler(e) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
413 var timeDiff = (new Date()).getTime() - lastAnimationTime;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
414 if (timeDiff < tapBuffer) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
415 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
416 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
417 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
418 function orientationChangeHandler() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
419 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
420
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
421 orientation = Math.abs(window.orientation) == 90 ? 'landscape' : 'portrait';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
422 $body.removeClass('portrait landscape').addClass(orientation).trigger('turn', {orientation: orientation});
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
423 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
424 function setHash(hash) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
425 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
426
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
427 // Trim leading # if need be
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
428 hash = hash.replace(/^#/, ''),
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
429
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
430 // Change hash
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
431 location.hash = '#' + hash;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
432
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
433 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
434 function showPageByHref(href, options) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
435 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
436
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
437 var defaults = {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
438 data: null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
439 method: 'GET',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
440 animation: null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
441 callback: null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
442 $referrer: null
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
443 };
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
444
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
445 var settings = $.extend({}, defaults, options);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
446
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
447 if (href != '#') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
448 $.ajax({
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
449 url: href,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
450 data: settings.data,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
451 type: settings.method,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
452 success: function (data, textStatus) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
453 var firstPage = insertPages(data, settings.animation);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
454 if (firstPage) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
455 if (settings.method == 'GET' && jQTSettings.cacheGetRequests === true && settings.$referrer) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
456 settings.$referrer.attr('href', '#' + firstPage.attr('id'));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
457 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
458 if (settings.callback) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
459 settings.callback(true);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
460 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
461 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
462 },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
463 error: function (data) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
464 if (settings.$referrer) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
465 settings.$referrer.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
466 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
467 if (settings.callback) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
468 settings.callback(false);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
469 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
470 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
471 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
472 } else if (settings.$referrer) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
473 settings.$referrer.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
474 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
475 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
476 function submitHandler(e, callback) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
477 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
478
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
479 $(':focus').blur();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
480
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
481 e.preventDefault();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
482
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
483 var $form = (typeof(e)==='string') ? $(e).eq(0) : (e.target ? $(e.target) : $(e));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
484
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
485 _debug($form.attr('action'));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
486
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
487 if ($form.length && $form.is(jQTSettings.formSelector) && $form.attr('action')) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
488 showPageByHref($form.attr('action'), {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
489 data: $form.serialize(),
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
490 method: $form.attr('method') || "POST",
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
491 animation: animations[0] || null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
492 callback: callback
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
493 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
494 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
495 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
496 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
497 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
498 function submitParentForm($el) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
499 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
500
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
501 var $form = $el.closest('form');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
502 if ($form.length === 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
503 _debug('No parent form found');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
504 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
505 _debug('About to submit parent form');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
506 var evt = $.Event('submit');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
507 evt.preventDefault();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
508 $form.trigger(evt);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
509 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
510 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
511 return true;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
512 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
513 function supportForAnimationEvents() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
514 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
515
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
516 return (typeof WebKitAnimationEvent != 'undefined');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
517 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
518 function supportForCssMatrix() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
519 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
520
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
521 return (typeof WebKitCSSMatrix != 'undefined');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
522 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
523 function supportForTouchEvents() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
524 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
525
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
526 /*
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
527 // If dev wants fast touch off, shut off touch whether device supports it or not
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
528 if (!jQTSettings.useFastTouch) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
529 return false
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
530 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
531
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
532 */
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
533 // Dev must want touch, so check for support
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
534 if (typeof TouchEvent != 'undefined') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
535 if (window.navigator.userAgent.indexOf('Mobile') > -1) { // Grrrr...
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
536 return true;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
537 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
538 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
539 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
540 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
541 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
542 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
543 };
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
544 function supportForTransform3d() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
545 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
546
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
547 var head, body, style, div, result;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
548
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
549 head = document.getElementsByTagName('head')[0];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
550 body = document.body;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
551
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
552 style = document.createElement('style');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
553 style.textContent = '@media (transform-3d),(-o-transform-3d),(-moz-transform-3d),(-ms-transform-3d),(-webkit-transform-3d),(modernizr){#jqtTestFor3dSupport{height:3px}}';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
554
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
555 div = document.createElement('div');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
556 div.id = 'jqtTestFor3dSupport';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
557
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
558 // Add to the page
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
559 head.appendChild(style);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
560 body.appendChild(div);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
561
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
562 // Check the result
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
563 result = div.offsetHeight === 3;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
564
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
565 // Clean up
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
566 style.parentNode.removeChild(style);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
567 div.parentNode.removeChild(div);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
568
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
569 // Pass back result
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
570 // _debug('Support for 3d transforms: ' + result);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
571 return result;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
572 };
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
573 function tapHandler(e){
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
574 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
575
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
576 if (!tapReady) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
577 _debug('Tap is not ready');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
578 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
579 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
580
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
581 // Grab the target element
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
582 var $el = $(e.target);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
583
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
584 // Find the nearest tappable ancestor
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
585 if (!$el.is(touchSelectors.join(', '))) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
586 var $el = $(e.target).closest(touchSelectors.join(', '));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
587 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
588
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
589 // Make sure we have a tappable element
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
590 if (!$el.length || !$el.attr('href')) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
591 _debug('Could not find a link related to tapped element');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
592 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
593 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
594
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
595 // Init some vars
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
596 var target = $el.attr('target'),
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
597 hash = $el.attr('hash') || ($el.prop && $el.prop('hash')), //jQuery attr vs. prop
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
598 animation = null;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
599
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
600 if ($el.isExternalLink()) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
601 $el.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
602 return true;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
603
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
604 } else if ($el.is(jQTSettings.backSelector)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
605 // User clicked or tapped a back button
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
606 goBack(hash);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
607
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
608 } else if ($el.is(jQTSettings.submitSelector)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
609 // User clicked or tapped a submit element
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
610 submitParentForm($el);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
611
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
612 } else if (target === '_webapp') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
613 // User clicked or tapped an internal link, fullscreen mode
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
614 window.location = $el.attr('href');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
615 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
616
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
617 } else if ($el.attr('href') === '#') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
618 // Allow tap on item with no href
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
619 $el.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
620 return true;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
621
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
622 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
623
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
624 // Figure out the animation to use
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
625 for (var i=0, max=animations.length; i < max; i++) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
626 if ($el.is(animations[i].selector)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
627 animation = animations[i];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
628 break;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
629 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
630 };
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
631
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
632 if (!animation) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
633 _log('Animation could not be found. Using slideleft.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
634 animation = 'slideleft';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
635 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
636
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
637 if (hash && hash !== '#') {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
638 // Internal href
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
639 $el.addClass('active');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
640 goTo($(hash).data('referrer', $el), animation, $el.hasClass('reverse'));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
641 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
642
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
643 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
644 // External href
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
645 $el.addClass('loading active');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
646 showPageByHref($el.attr('href'), {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
647 animation: animation,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
648 callback: function() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
649 $el.removeClass('loading');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
650 setTimeout($.fn.unselect, 250, $el);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
651 },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
652 $referrer: $el
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
653 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
654 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
655 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
656 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
657 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
658 function touchStartHandler(e) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
659 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
660
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
661 if (!tapReady) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
662 _debug('TouchStart handler aborted because tap is not ready');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
663 e.preventDefault();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
664 return false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
665 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
666
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
667 var $el = $(e.target);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
668
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
669 // Error check
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
670 if (!$el.length) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
671 _debug('Could not find target of touchstart event.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
672 return;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
673 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
674
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
675 var startTime = (new Date).getTime(),
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
676 hoverTimeout = null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
677 pressTimeout = null,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
678 touch,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
679 startX,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
680 startY,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
681 deltaX = 0,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
682 deltaY = 0,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
683 deltaT = 0;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
684
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
685 if (event.changedTouches && event.changedTouches.length) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
686 touch = event.changedTouches[0];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
687 startX = touch.pageX;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
688 startY = touch.pageY;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
689 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
690
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
691 // Prep the element
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
692 $el.bind('touchmove',touchMoveHandler).bind('touchend',touchEndHandler).bind('touchcancel',touchCancelHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
693
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
694 hoverTimeout = setTimeout(function() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
695 $el.makeActive();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
696 }, jQTSettings.hoverDelay);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
697
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
698 pressTimeout = setTimeout(function() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
699 $el.unbind('touchmove',touchMoveHandler).unbind('touchend',touchEndHandler).unbind('touchcancel',touchCancelHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
700 $el.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
701 clearTimeout(hoverTimeout);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
702 $el.trigger('press');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
703 }, jQTSettings.pressDelay);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
704
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
705 // Private touch functions
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
706 function touchCancelHandler(e) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
707 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
708 clearTimeout(hoverTimeout);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
709 $el.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
710 $el.unbind('touchmove',touchMoveHandler).unbind('touchend',touchEndHandler).unbind('touchcancel',touchCancelHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
711 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
712
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
713 function touchEndHandler(e) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
714 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
715 // updateChanges();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
716 $el.unbind('touchend',touchEndHandler).unbind('touchcancel',touchCancelHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
717 clearTimeout(hoverTimeout);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
718 clearTimeout(pressTimeout);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
719 if (Math.abs(deltaX) < jQTSettings.moveThreshold && Math.abs(deltaY) < jQTSettings.moveThreshold && deltaT < jQTSettings.pressDelay) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
720 // e.preventDefault();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
721 // e.stopImmediatePropagation();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
722 $el.trigger('tap', e);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
723 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
724 $el.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
725 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
726 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
727
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
728 function touchMoveHandler(e) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
729 // _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
730 updateChanges();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
731 var absX = Math.abs(deltaX);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
732 var absY = Math.abs(deltaY);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
733 var direction;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
734 if (absX > absY && (absX > 35) && deltaT < 1000) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
735 if (deltaX < 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
736 direction = 'left';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
737 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
738 direction = 'right';
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
739 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
740 $el.unbind('touchmove',touchMoveHandler).unbind('touchend',touchEndHandler).unbind('touchcancel',touchCancelHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
741 $el.trigger('swipe', {direction:direction, deltaX:deltaX, deltaY: deltaY});
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
742 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
743 $el.unselect();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
744 clearTimeout(hoverTimeout);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
745 if (absX > jQTSettings.moveThreshold || absY > jQTSettings.moveThreshold) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
746 clearTimeout(pressTimeout);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
747 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
748 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
749
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
750 function updateChanges() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
751 // _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
752 var firstFinger = event.changedTouches[0] || null;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
753 deltaX = firstFinger.pageX - startX;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
754 deltaY = firstFinger.pageY - startY;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
755 deltaT = (new Date).getTime() - startTime;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
756 // _debug('deltaX:'+deltaX+';deltaY:'+deltaY+';');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
757 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
758
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
759 } // End touch handler
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
760 function useFastTouch(setting) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
761 _debug();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
762
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
763 if (setting !== undefined) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
764 if (setting === true) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
765 if (supportForTouchEvents()) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
766 $.support.touch = true;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
767 } else{
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
768 _log('This device does not support touch events');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
769 };
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
770 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
771 $.support.touch = false;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
772 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
773 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
774
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
775 return $.support.touch;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
776
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
777 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
778
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
779 // Get the party started
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
780 init(options);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
781
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
782 // Document ready stuff
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
783 $(document).ready(function() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
784
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
785 // Store some properties in the jQuery support object
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
786 $.support.animationEvents = supportForAnimationEvents();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
787 $.support.cssMatrix = supportForCssMatrix();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
788 $.support.touch = supportForTouchEvents() && jQTSettings.useFastTouch;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
789 $.support.transform3d = supportForTransform3d();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
790
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
791 if (!$.support.touch) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
792 _log('This device does not support touch interaction, or it has been deactivated by the developer. Some features might be unavailable.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
793 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
794 if (!$.support.transform3d) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
795 _log('This device does not support 3d animation. 2d animations will be used instead.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
796 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
797
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
798 // Define public jQuery functions
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
799 $.fn.isExternalLink = function() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
800 var $el = $(this);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
801 return ($el.attr('target') == '_blank' || $el.attr('rel') == 'external' || $el.is('a[href^="http://maps.google.com"], a[href^="mailto:"], a[href^="tel:"], a[href^="javascript:"], a[href*="youtube.com/v"], a[href*="youtube.com/watch"]'));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
802 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
803 $.fn.makeActive = function() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
804 return $(this).addClass('active');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
805 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
806 $.fn.press = function(fn) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
807 if ($.isFunction(fn)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
808 return $(this).live('press', fn);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
809 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
810 return $(this).trigger('press');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
811 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
812 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
813 $.fn.swipe = function(fn) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
814 if ($.isFunction(fn)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
815 return $(this).live('swipe', fn);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
816 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
817 return $(this).trigger('swipe');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
818 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
819 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
820 $.fn.tap = function(fn) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
821 if ($.isFunction(fn)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
822 return $(this).live('tap', fn);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
823 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
824 return $(this).trigger('tap');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
825 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
826 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
827 $.fn.unselect = function(obj) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
828 if (obj) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
829 obj.removeClass('active');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
830 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
831 $('.active').removeClass('active');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
832 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
833 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
834
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
835 // Add extensions
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
836 for (var i=0, max=extensions.length; i < max; i++) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
837 var fn = extensions[i];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
838 if ($.isFunction(fn)) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
839 $.extend(publicObj, fn(publicObj));
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
840 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
841 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
842
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
843 // Set up animations array
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
844 if (jQTSettings['cubeSelector']) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
845 _log('NOTE: cubeSelector has been deprecated. Please use cubeleftSelector instead.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
846 jQTSettings['cubeleftSelector'] = jQTSettings['cubeSelector'];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
847 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
848 if (jQTSettings['flipSelector']) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
849 _log('NOTE: flipSelector has been deprecated. Please use flipleftSelector instead.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
850 jQTSettings['flipleftSelector'] = jQTSettings['flipSelector'];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
851 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
852 if (jQTSettings['slideSelector']) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
853 _log('NOTE: slideSelector has been deprecated. Please use slideleftSelector instead.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
854 jQTSettings['slideleftSelector'] = jQTSettings['slideSelector'];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
855 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
856 for (var i=0, max=defaults.animations.length; i < max; i++) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
857 var animation = defaults.animations[i];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
858 if(jQTSettings[animation.name + 'Selector'] !== undefined){
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
859 animation.selector = jQTSettings[animation.name + 'Selector'];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
860 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
861 addAnimation(animation);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
862 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
863
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
864 // Create an array of stuff that needs touch event handling
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
865 touchSelectors.push('input'); // TODO: Ask DK why inputs are considered touch selectors
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
866 touchSelectors.push(jQTSettings.touchSelector);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
867 touchSelectors.push(jQTSettings.backSelector);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
868 touchSelectors.push(jQTSettings.submitSelector);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
869 $(touchSelectors.join(', ')).css('-webkit-touch-callout', 'none');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
870
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
871 // Make sure we have a jqt element
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
872 $body = $('#jqt');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
873 if ($body.length === 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
874 _log('Could not find an element with the id "jqt", so the body id has been set to "jqt". If you are having any problems, wrapping your panels in a div with the id "jqt" might help.');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
875 $body = $('body').attr('id', 'jqt');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
876 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
877
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
878 // Add some specific css if need be
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
879 if ($.support.transform3d) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
880 $body.addClass('supports3d');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
881 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
882 if (jQTSettings.fullScreenClass && window.navigator.standalone == true) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
883 $body.addClass(jQTSettings.fullScreenClass + ' ' + jQTSettings.statusBar);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
884 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
885 if (window.navigator.userAgent.match(/Android/ig)) { // Grr... added to postion checkbox labels. Lame. I know. - js
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
886 $body.addClass('android');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
887 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
888
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
889 // Bind events
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
890 $(window).bind('hashchange', hashChangeHandler);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
891 $body.bind('touchstart', touchStartHandler)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
892 .bind('click', clickHandler)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
893 .bind('mousedown', mousedownHandler)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
894 .bind('orientationchange', orientationChangeHandler)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
895 .bind('submit', submitHandler)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
896 .bind('tap', tapHandler)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
897 .trigger('orientationchange');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
898
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
899
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
900 // Determine what the "current" (initial) panel should be
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
901 if ($('#jqt > .current').length == 0) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
902 currentPage = $('#jqt > *:first');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
903 } else {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
904 currentPage = $('#jqt > .current:first');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
905 $('#jqt > .current').removeClass('current');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
906 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
907
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
908 // Go to the top of the "current" page
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
909 $(currentPage).addClass('current');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
910 initialPageId = $(currentPage).attr('id');
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
911 setHash(initialPageId);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
912 addPageToHistory(currentPage);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
913 scrollTo(0, 0);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
914
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
915 // Make sure none of the panels yank the location bar into view
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
916 $('#jqt > *').css('minHeight', window.innerHeight);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
917
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
918 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
919
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
920 // Expose public methods and properties
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
921 publicObj = {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
922 addAnimation: addAnimation,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
923 animations: animations,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
924 getOrientation: getOrientation,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
925 goBack: goBack,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
926 goTo: goTo,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
927 hist: hist,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
928 settings: jQTSettings,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
929 submitForm: submitHandler,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
930 support: $.support,
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
931 useFastTouch: useFastTouch
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
932 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
933 return publicObj;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
934 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
935
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
936 // Extensions directly manipulate the jQTouch object, before it's initialized.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
937 $.jQTouch.prototype.extensions = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
938 $.jQTouch.addExtension = function(extension) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
939 $.jQTouch.prototype.extensions.push(extension);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
940 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
941
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
942 })(jQuery);