main.js
5.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.trimLeft = function() {
return this.replace(/^\s+/,"");
}
String.prototype.trimRight = function() {
return this.replace(/\s+$/,"");
}
//Demos file list (in order of presentation)
//THe page name is formed from the file name.
var fileList = [
'Basic_swipe.html',
'Single_swipe.html',
'Any_finger_swipe.html',
'Finger_swipe.html',
'Swipe_status.html',
'Pinch.html',
'Pinch_status.html',
'Pinch_and_Swipe.html',
'Trigger_handlers.html',
'Stop_propegation.html',
'Handlers_and_events.html',
'Tap_vs_swipe.html',
'Hold.html',
'Excluded_children.html',
'Page_zoom.html',
'Thresholds.html',
'Enable_and_destroy.html',
'Page_scrolling.html',
'Options.html',
'Image_gallery_example.html'
];
/**
* Builds the demo page
*/
function init() {
buildTitle();
buildCodeExample();
buildNavigation();
}
/**
* Creates the navigation components
*/
function buildNavigation() {
$('.navigation').each(function( index ) {
$(this).html( getNavigation() );
});
$('.navigation_menu').each(function( index ) {
$(this).html( getNavigationMenu() );
})
$('.navigation_list').each(function( index ) {
$(this).html( getNavigationList() );
})
$('#menu').change( function() {
location.href=$(this).val();
});
$('#menu li').click( function() {
location.href=$(this).val();
});
$('.example_btn').click( function() {
$(document).scrollTop( $("#test").offset().top );
});
$('.events code').click( function() {
location.href = '../docs/symbols/%24.fn.swipe.html#event:' + $(this).text();
});
$('.properties code').click( function() {
location.href = '../docs/symbols/%24.fn.swipe.defaults.html#' + $(this).text();
});
$('.methods code').click( function() {
location.href = '../docs/symbols/%24.fn.swipe.html#' + $(this).text();
});
}
/**
* Builds the title element
*/
function buildTitle() {
$('.title').each(function( index ) {
$(this).html( getTitle() );
})
}
/**
* Copies the <script> tag contents, and populates the demo pretty print div to display the
* code example.
*/
function buildCodeExample() {
$('.prettyprint').each(function( index ) {
//$(this).text( $("#"+$(this).attr('data-src')).html() );
var src = $("#"+$(this).attr('data-src')).html();
if(src) {
var lines = src.split("\n");
var trimedLines=[];
var trimIndex=null;
for (var i=0; i<lines.length; i++) {
var line = lines[i];
if(trimIndex===null) {
var trimmed = line.trimLeft();
if(line.length>0) {
trimIndex = line.length - trimmed.length;
}
}
if(line.length>0) {
//Tabs to spaces
line = line.replace(/\t/g, ' '); //not using $nbsp; as we want to display HTML tags, so we set the text value, not html
trimedLines.push( line.substr(trimIndex) );
}
};
var html = trimedLines.join("\n");
$(this).text( html );
}
});
//prettyPrint();
}
/**
* Returns the current file being viewed.
*/
function getCurrentFile() {
var url = window.location.pathname;
var file = url.substring(url.lastIndexOf('/')+1);
return file;
}
/**
* Returns the current page name
*/
function getPageName( file ) {
if(!file)
file=getCurrentFile();
var fileTokens = file.split("_");
var fileName = fileTokens.join(" ");
var nameTokens = fileName.split(".");
nameTokens.pop();
var name = nameTokens.join(" ");
return name;
}
/**
* Writes out the page title template
*/
function getTitle() {
var html = "<h2><a href=\"http://labs.rampinteractive.co.uk/touchSwipe/\">TouchSwipe</a> Demo</h2>";
html += "<h3>to be viewed on touch based devices</h3>";
html += "<h1>"+getPageName()+"<span class='navigation_menu pull-right'></span></h1>";
return html;
}
/**
* Returns HTML mark up for the pagination buttons
*/
function getNavigation() {
var index = fileList.indexOf( getCurrentFile() );
var html ="<div class='pagination'>";
if(index>0) {
html += "<a class='pull-left btn' href='"+fileList[index-1]+"'><< "+getPageName(fileList[index-1])+"</a>";
}
if(index<fileList.length-1) {
html += "<a class='pull-right btn' href='"+fileList[index+1]+"'>"+getPageName(fileList[index+1])+" >></a>";
}
html += "</div><div class='clear'></div>"
return html;
}
/**
* Returns HTML mark up for the drop down menu
*/
function getNavigationMenu() {
var html = "<select id='menu' class='pull_right'>";
for(var i=0; i<fileList.length; i++) {
var selected="";
if(fileList[i] == getCurrentFile()) {
selected=' selected ';
}
html+="<option value='"+fileList[i]+"'"+selected+">"+getPageName(fileList[i])+"</option>";
}
html += "</select>";
return html;
}
/**
* Returns HTML mark up for the list menu
*/
function getNavigationList() {
var html = "<ul>";
for(var i=0; i<fileList.length; i++) {
html+="<li><a href='"+fileList[i]+"'>"+getPageName(fileList[i])+"</a></li>";
}
html += "</ul>";
return html;
}
$(function() {
init();
});