jqmobi-rails 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +68 -0
- data/jqmobi-rails.gemspec +17 -0
- data/lib/jqmobi/rails/engine.rb +6 -0
- data/lib/jqmobi/rails/version.rb +7 -0
- data/lib/jqmobi/rails.rb +7 -0
- data/lib/jqmobi-rails.rb +1 -0
- data/vendor/assets/javascripts/jq.mobi.js +1894 -0
- data/vendor/assets/javascripts/jq.mobi_ujs.js +393 -0
- data/vendor/assets/javascripts/jq.ui.js +3396 -0
- data/vendor/assets/javascripts/plugins/jq.actionsheet.js +99 -0
- data/vendor/assets/javascripts/plugins/jq.alphatable.js +136 -0
- data/vendor/assets/javascripts/plugins/jq.carousel.js +415 -0
- data/vendor/assets/javascripts/plugins/jq.css3animate.js +155 -0
- data/vendor/assets/javascripts/plugins/jq.drawer.js +224 -0
- data/vendor/assets/javascripts/plugins/jq.fx.js +110 -0
- data/vendor/assets/javascripts/plugins/jq.passwordBox.js +45 -0
- data/vendor/assets/javascripts/plugins/jq.popup.js +201 -0
- data/vendor/assets/javascripts/plugins/jq.scroller.js +540 -0
- data/vendor/assets/javascripts/plugins/jq.selectBox.js +315 -0
- data/vendor/assets/javascripts/plugins/jq.shake.js +39 -0
- data/vendor/assets/javascripts/plugins/jq.social.js +113 -0
- data/vendor/assets/javascripts/plugins/jq.swipe.js +121 -0
- data/vendor/assets/javascripts/plugins/jq.template.js +26 -0
- data/vendor/assets/javascripts/plugins/jq.web.min.js +66 -0
- data/vendor/assets/stylesheets/plugins/jq.actionsheet.css +57 -0
- data/vendor/assets/stylesheets/plugins/jq.popup.css +73 -0
- data/vendor/assets/stylesheets/plugins/jq.scroller.css +10 -0
- data/vendor/assets/stylesheets/plugins/jq.selectBox.css +35 -0
- metadata +77 -0
@@ -0,0 +1,315 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright: AppMobi
|
3
|
+
* Description: This script will replace all drop downs with friendly select controls. Users can still interact
|
4
|
+
* with the old drop down box as normal with javascript, and this will be reflected
|
5
|
+
|
6
|
+
*/
|
7
|
+
(function($) {
|
8
|
+
$['selectBox'] = {
|
9
|
+
oldSelects: {},
|
10
|
+
scroller: null,
|
11
|
+
getOldSelects: function(elID) {
|
12
|
+
if ($.os.android == false)
|
13
|
+
return;
|
14
|
+
if (!$.fn['scroller']) {
|
15
|
+
alert("This library requires jq.web.Scroller");
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
var container = elID && document.getElementById(elID) ? document.getElementById(elID) : document;
|
19
|
+
if (!container) {
|
20
|
+
alert("Could not find container element for jq.web.selectBox " + elID);
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
var sels = container.getElementsByTagName("select");
|
24
|
+
var that = this;
|
25
|
+
for (var i = 0; i < sels.length; i++) {
|
26
|
+
if (this.oldSelects[sels[i].id])
|
27
|
+
continue;
|
28
|
+
(function(theSel) {
|
29
|
+
var fakeInput = document.createElement("div");
|
30
|
+
var selWidth = parseInt(theSel.style.width) > 0 ? parseInt(theSel.style.width) : 100;
|
31
|
+
var selHeight = parseInt(theSel.style.height) > 0 ? parseInt(theSel.style.height) : 20;
|
32
|
+
fakeInput.style.width = selWidth + "px";
|
33
|
+
fakeInput.style.height = selHeight + "px";
|
34
|
+
fakeInput.style.position = "absolute";
|
35
|
+
fakeInput.style.left = "0px";
|
36
|
+
fakeInput.style.top = "0px";
|
37
|
+
fakeInput.style.zIndex = "1";
|
38
|
+
if (theSel.value)
|
39
|
+
fakeInput.innerHTML = theSel.options[theSel.selectedIndex].text;
|
40
|
+
fakeInput.style.background = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAeCAIAAABFWWJ4AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkM1NjQxRUQxNUFEODExRTA5OUE3QjE3NjI3MzczNDAzIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkM1NjQxRUQyNUFEODExRTA5OUE3QjE3NjI3MzczNDAzIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QzU2NDFFQ0Y1QUQ4MTFFMDk5QTdCMTc2MjczNzM0MDMiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QzU2NDFFRDA1QUQ4MTFFMDk5QTdCMTc2MjczNzM0MDMiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz6YWbdCAAAAlklEQVR42mIsKChgIBGwAHFPTw/xGkpKSlggrG/fvhGjgYuLC0gyMZAOoPb8//9/0Or59+8f8XrICQN66SEnDOgcp3AgKiqKqej169dY9Hz69AnCuHv3rrKyMrIKoAhcVlBQELt/gIqwstHD4B8quH37NlAQSKKJEwg3iLbBED8kpeshoGcwh5uuri5peoBFMEluAwgwAK+5aXfuRb4gAAAAAElFTkSuQmCC') right top no-repeat";
|
41
|
+
fakeInput.style.backgroundColor = "white";
|
42
|
+
fakeInput.className = "jqmobiSelect_fakeInput " + theSel.className;
|
43
|
+
fakeInput.id = theSel.id + "_jqmobiSelect";
|
44
|
+
|
45
|
+
fakeInput.style.border = "1px solid gray";
|
46
|
+
fakeInput.style.color = "black";
|
47
|
+
fakeInput.linkId = theSel.id;
|
48
|
+
fakeInput.onclick = function(e) {
|
49
|
+
that.initDropDown(this.linkId);
|
50
|
+
};
|
51
|
+
theSel.parentNode.appendChild(fakeInput);
|
52
|
+
theSel.parentNode.style.position = "relative";
|
53
|
+
theSel.style.display = "none";
|
54
|
+
theSel.style.webkitAppearance = "none";
|
55
|
+
// Create listeners to watch when the select value has changed.
|
56
|
+
// This is needed so the users can continue to interact as normal,
|
57
|
+
// via jquery or other frameworks
|
58
|
+
for (var j = 0; j < theSel.options.length; j++) {
|
59
|
+
if (theSel.options[j].selected) {
|
60
|
+
fakeInput.value = theSel.options[j].text;
|
61
|
+
}
|
62
|
+
theSel.options[j].watch( "selected", function(prop, oldValue, newValue) {
|
63
|
+
if (newValue == true) {
|
64
|
+
that.updateMaskValue(this.parentNode.id, this.text, this.value);
|
65
|
+
this.parentNode.value = this.value;
|
66
|
+
}
|
67
|
+
return newValue;
|
68
|
+
});
|
69
|
+
}
|
70
|
+
theSel.watch("selectedIndex", function(prop, oldValue, newValue) {
|
71
|
+
if (this.options[newValue]) {
|
72
|
+
that.updateMaskValue(this.id, this.options[newValue].text, this.options[newValue].value);
|
73
|
+
this.value = this.options[newValue].value;
|
74
|
+
}
|
75
|
+
return newValue;
|
76
|
+
});
|
77
|
+
|
78
|
+
fakeInput = null;
|
79
|
+
imageMask = null;
|
80
|
+
that.oldSelects[theSel.id] = 1;
|
81
|
+
|
82
|
+
|
83
|
+
})(sels[i]);
|
84
|
+
}
|
85
|
+
that.createHtml();
|
86
|
+
},
|
87
|
+
updateDropdown: function(id) {
|
88
|
+
var el = document.getElementById(id);
|
89
|
+
if (!el)
|
90
|
+
return;
|
91
|
+
for (var j = 0; j < el.options.length; j++) {
|
92
|
+
if (el.options[j].selected)
|
93
|
+
fakeInput.value = el.options[j].text;
|
94
|
+
el.options[j].watch("selected", function(prop, oldValue, newValue) {
|
95
|
+
if (newValue == true) {
|
96
|
+
that.updateMaskValue(this.parentNode.id, this.text, this.value);
|
97
|
+
this.parentNode.value = this.value;
|
98
|
+
}
|
99
|
+
return newValue;
|
100
|
+
});
|
101
|
+
}
|
102
|
+
el = null;
|
103
|
+
},
|
104
|
+
initDropDown: function(elID) {
|
105
|
+
|
106
|
+
var that = this;
|
107
|
+
var el = document.getElementById(elID);
|
108
|
+
if (el.disabled)
|
109
|
+
return;
|
110
|
+
if (!el || !el.options || el.options.length == 0)
|
111
|
+
return;
|
112
|
+
var htmlTemplate = "";
|
113
|
+
var foundInd = 0;
|
114
|
+
document.getElementById("jqmobiSelectBoxScroll").innerHTML = "";
|
115
|
+
|
116
|
+
document.getElementById("jqmobiSelectBoxHeaderTitle").innerHTML = (el.name != undefined && el.name != "undefined" && el.name != "" ? el.name : elID);
|
117
|
+
|
118
|
+
for (var j = 0; j < el.options.length; j++) {
|
119
|
+
var currInd = j;
|
120
|
+
el.options[j].watch( "selected", function(prop, oldValue, newValue) {
|
121
|
+
if (newValue == true) {
|
122
|
+
that.updateMaskValue(this.parentNode.id, this.text, this.value);
|
123
|
+
this.parentNode.value = this.value;
|
124
|
+
}
|
125
|
+
return newValue;
|
126
|
+
});
|
127
|
+
var checked = (el.value == el.options[j].value) ? true : false;
|
128
|
+
var button = "";
|
129
|
+
var bg = "background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0.17, rgb(102,102,102)),color-stop(0.59, rgb(94,94,94)))";
|
130
|
+
var foundID;
|
131
|
+
var div = document.createElement("div");
|
132
|
+
div.className = "jqmobiSelectRow";
|
133
|
+
if (checked) {
|
134
|
+
bg = "background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0.17, rgb(8,8,8)),color-stop(0.59, rgb(38,38,38)))";
|
135
|
+
button = "checked";
|
136
|
+
foundInd = j;
|
137
|
+
foundID = "id='jqmobiSelectBox_found'";
|
138
|
+
div.className = "jqmobiSelectRowFound";
|
139
|
+
} else {
|
140
|
+
foundID = "";
|
141
|
+
}
|
142
|
+
|
143
|
+
div.id = foundID;
|
144
|
+
div.style.cssText = ";line-height:40px;font-size:14px;padding-left:10px;height:40px;width:100%;position:relative;width:100%;border-bottom:1px solid black;background:white;";
|
145
|
+
var anchor = document.createElement("a");
|
146
|
+
anchor.href = "javascript:;";
|
147
|
+
div.tmpValue = j;
|
148
|
+
div.onclick = function(e) {
|
149
|
+
that.setDropDownValue(elID, this.tmpValue);
|
150
|
+
};
|
151
|
+
anchor.style.cssText = "text-decoration:none;color:black;";
|
152
|
+
anchor.innerHTML = el.options[j].text;
|
153
|
+
var span = document.createElement("span");
|
154
|
+
span.style.cssText = "float:right;margin-right:20px;margin-top:-2px";
|
155
|
+
var rad = document.createElement("button");
|
156
|
+
if (foundID) {
|
157
|
+
rad.style.cssText = "background: #000;padding: 0px 0px;border-radius:15px;border:3px solid black;";
|
158
|
+
rad.className = "jqmobiSelectRowButtonFound";
|
159
|
+
} else {
|
160
|
+
rad.style.cssText = "background: #ffffff;padding: 0px 0px;border-radius:15px;border:3px solid black;";
|
161
|
+
rad.className = "jqmobiSelectRowButton";
|
162
|
+
}
|
163
|
+
rad.style.width = "20px";
|
164
|
+
rad.style.height = "20px";
|
165
|
+
|
166
|
+
rad.checked = button;
|
167
|
+
|
168
|
+
anchor.className = "jqmobiSelectRowText";
|
169
|
+
span.appendChild(rad);
|
170
|
+
div.appendChild(anchor);
|
171
|
+
div.appendChild(span);
|
172
|
+
|
173
|
+
document.getElementById("jqmobiSelectBoxScroll").appendChild(div);
|
174
|
+
|
175
|
+
span = null;
|
176
|
+
rad = null;
|
177
|
+
anchor = null;
|
178
|
+
}
|
179
|
+
try {
|
180
|
+
document.getElementById("jqmobiSelectModal").style.display = 'block';
|
181
|
+
} catch (e) {
|
182
|
+
console.log("Error showing div " + e);
|
183
|
+
}
|
184
|
+
try {
|
185
|
+
if (div) {
|
186
|
+
var scrollThreshold = numOnly(div.style.height);
|
187
|
+
var offset = numOnly(document.getElementById("jqmobiSelectBoxHeader").style.height);
|
188
|
+
|
189
|
+
if (foundInd * scrollThreshold + offset >= numOnly(document.getElementById("jqmobiSelectBoxFix").clientHeight) - offset)
|
190
|
+
var scrollToPos = (foundInd) * -scrollThreshold + offset;
|
191
|
+
else
|
192
|
+
scrollToPos = 0;
|
193
|
+
this.scroller.scrollTo({
|
194
|
+
x: 0,
|
195
|
+
y: scrollToPos
|
196
|
+
});
|
197
|
+
}
|
198
|
+
} catch (e) {
|
199
|
+
console.log("error init dropdown" + e);
|
200
|
+
}
|
201
|
+
div = null;
|
202
|
+
el = null;
|
203
|
+
},
|
204
|
+
updateMaskValue: function(elID, value, val2) {
|
205
|
+
|
206
|
+
var el = document.getElementById(elID + "_jqmobiSelect");
|
207
|
+
var el2 = document.getElementById(elID);
|
208
|
+
if (el)
|
209
|
+
el.innerHTML = value;
|
210
|
+
if (typeof (el2.onchange) == "function")
|
211
|
+
el2.onchange(val2);
|
212
|
+
el = null;
|
213
|
+
el2 = null;
|
214
|
+
},
|
215
|
+
setDropDownValue: function(elID, value) {
|
216
|
+
|
217
|
+
var el = document.getElementById(elID);
|
218
|
+
if (el) {
|
219
|
+
el.selectedIndex = value;
|
220
|
+
$(el).trigger("change");
|
221
|
+
}
|
222
|
+
this.scroller.scrollTo({
|
223
|
+
x: 0,
|
224
|
+
y: 0
|
225
|
+
});
|
226
|
+
this.hideDropDown();
|
227
|
+
el = null;
|
228
|
+
},
|
229
|
+
hideDropDown: function() {
|
230
|
+
document.getElementById("jqmobiSelectModal").style.display = 'none';
|
231
|
+
document.getElementById("jqmobiSelectBoxScroll").innerHTML = "";
|
232
|
+
},
|
233
|
+
createHtml: function() {
|
234
|
+
var that = this;
|
235
|
+
if (document.getElementById("jqmobiSelectBoxContainer")) {
|
236
|
+
return;
|
237
|
+
}
|
238
|
+
var modalDiv = document.createElement("div");
|
239
|
+
|
240
|
+
modalDiv.style.cssText = "position:absolute;top:0px;bottom:0px;left:0px;right:0px;background:rgba(0,0,0,.7);z-index:200000;display:none;";
|
241
|
+
modalDiv.id = "jqmobiSelectModal";
|
242
|
+
|
243
|
+
var myDiv = document.createElement("div");
|
244
|
+
myDiv.id = "jqmobiSelectBoxContainer";
|
245
|
+
myDiv.style.cssText = "position:absolute;top:8%;bottom:10%;display:block;width:90%;margin:auto;margin-left:5%;height:90%px;background:white;color:black;border:1px solid black;border-radius:6px;";
|
246
|
+
myDiv.innerHTML = "<div id='jqmobiSelectBoxHeader' style=\"display:block;font-family:'Eurostile-Bold', Eurostile, Helvetica, Arial, sans-serif;color:#fff;font-weight:bold;font-size:18px;line-height:34px;height:34px; text-transform:uppercase;text-align:left;text-shadow:rgba(0,0,0,.9) 0px -1px 1px; padding: 0px 8px 0px 8px; border-top-left-radius:5px; border-top-right-radius:5px; -webkit-border-top-left-radius:5px; -webkit-border-top-right-radius:5px; background:#39424b; margin:1px;\"><div style='float:left;' id='jqmobiSelectBoxHeaderTitle'></div><div style='float:right;width:60px;margin-top:-5px'><div id='jqmobiSelectClose' class='button' style='width:60px;height:32px;line-height:32px;'>Close</div></div></div>";
|
247
|
+
myDiv.innerHTML += '<div id="jqmobiSelectBoxFix" style="position:relative;height:90%;background:white;overflow:hidden;width:100%;"><div id="jqmobiSelectBoxScroll"></div></div>';
|
248
|
+
var that = this;
|
249
|
+
modalDiv.appendChild(myDiv);
|
250
|
+
|
251
|
+
$(document).ready(function() {
|
252
|
+
|
253
|
+
if(jq("#jQUi"))
|
254
|
+
jq("#jQUi").append(modalDiv);
|
255
|
+
else
|
256
|
+
document.body.appendChild(modalDiv);
|
257
|
+
var close = $("#jqmobiSelectClose").get();
|
258
|
+
close.onclick = function() {
|
259
|
+
that.hideDropDown();
|
260
|
+
};
|
261
|
+
|
262
|
+
var styleSheet = $("<style>.jqselectscrollBarV{opacity:1 !important;}</style>").get();
|
263
|
+
document.body.appendChild(styleSheet);
|
264
|
+
try {
|
265
|
+
that.scroller = $("#jqmobiSelectBoxScroll").scroller({
|
266
|
+
scroller: false,
|
267
|
+
verticalScroll: true,
|
268
|
+
vScrollCSS: "jqselectscrollBarV"
|
269
|
+
});
|
270
|
+
|
271
|
+
} catch (e) {
|
272
|
+
console.log("Error creating select html " + e);
|
273
|
+
}
|
274
|
+
modalDiv = null;
|
275
|
+
myDiv = null;
|
276
|
+
styleSheet = null;
|
277
|
+
});
|
278
|
+
}
|
279
|
+
};
|
280
|
+
//The following is based off Eli Grey's shim
|
281
|
+
//https://gist.github.com/384583
|
282
|
+
//We use HTMLElement to not cause problems with other objects
|
283
|
+
if (!HTMLElement.prototype.watch) {
|
284
|
+
HTMLElement.prototype.watch = function (prop, handler) {
|
285
|
+
var oldval = this[prop], newval = oldval,
|
286
|
+
getter = function () {
|
287
|
+
return newval;
|
288
|
+
},
|
289
|
+
setter = function (val) {
|
290
|
+
oldval = newval;
|
291
|
+
return newval = handler.call(this, prop, oldval, val);
|
292
|
+
};
|
293
|
+
if (delete this[prop]) { // can't watch constants
|
294
|
+
if (HTMLElement.defineProperty) { // ECMAScript 5
|
295
|
+
HTMLElement.defineProperty(this, prop, {
|
296
|
+
get: getter,
|
297
|
+
set: setter,
|
298
|
+
enumerable: false,
|
299
|
+
configurable: true
|
300
|
+
});
|
301
|
+
} else if (HTMLElement.prototype.__defineGetter__ && HTMLElement.prototype.__defineSetter__) { // legacy
|
302
|
+
HTMLElement.prototype.__defineGetter__.call(this, prop, getter);
|
303
|
+
HTMLElement.prototype.__defineSetter__.call(this, prop, setter);
|
304
|
+
}
|
305
|
+
}
|
306
|
+
};
|
307
|
+
}
|
308
|
+
if (!HTMLElement.prototype.unwatch) {
|
309
|
+
HTMLElement.prototype.unwatch = function (prop) {
|
310
|
+
var val = this[prop];
|
311
|
+
delete this[prop]; // remove accessors
|
312
|
+
this[prop] = val;
|
313
|
+
};
|
314
|
+
}
|
315
|
+
})(jq);
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/**
|
2
|
+
* jq.web.shake - a library to detect shake events for AppMobi Apps
|
3
|
+
& Copyright 2011 - AppMobi
|
4
|
+
*/
|
5
|
+
(function ($) {
|
6
|
+
$['shake'] = function (callback, threshold) {
|
7
|
+
var accelCounter = 0;
|
8
|
+
var timer;
|
9
|
+
var prevX = 0;
|
10
|
+
var prevY = 0;
|
11
|
+
var prevZ = 0;
|
12
|
+
if (!threshold) threshold = 5;
|
13
|
+
var suc = function (a) {
|
14
|
+
|
15
|
+
if ((Math.abs(a.x - prevX)) > 0.8) {
|
16
|
+
accelCounter++;
|
17
|
+
} else if ((Math.abs(a.y - prevY)) > 0.8) {
|
18
|
+
accelCounter++;
|
19
|
+
} else if ((Math.abs(a.z - prevZ)) > 0.8) {
|
20
|
+
accelCounter++;
|
21
|
+
}
|
22
|
+
prevX = a.x;
|
23
|
+
prevY = a.y;
|
24
|
+
prevZ = a.z;
|
25
|
+
if (accelCounter >= (threshold)) {
|
26
|
+
callback();
|
27
|
+
accelCounter = 0;
|
28
|
+
}
|
29
|
+
};
|
30
|
+
|
31
|
+
if (callback && typeof (callback) == "function") {
|
32
|
+
// create the options object and set the frequency to receive samples
|
33
|
+
var opt = new AppMobi.AccelerationOptions();
|
34
|
+
opt.frequency = 100;
|
35
|
+
// use the special timer variable which will send the samples back
|
36
|
+
timer = AppMobi.accelerometer.watchAcceleration(suc, opt);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
})(jq)
|
@@ -0,0 +1,113 @@
|
|
1
|
+
/**
|
2
|
+
* jq.web.social - A wrapper library for oAuth requests
|
3
|
+
* Copyright 2011 - AppMobi
|
4
|
+
*/
|
5
|
+
|
6
|
+
(function($){
|
7
|
+
$['social'] = function(serviceName) {
|
8
|
+
if (!this instanceof social) {
|
9
|
+
return new social(serviceName);
|
10
|
+
}
|
11
|
+
this.serviceName = serviceName;
|
12
|
+
var that = this;
|
13
|
+
|
14
|
+
document.addEventListener("appMobi.oauth.busy", function(e) {
|
15
|
+
if (e.id == that.serviceID)
|
16
|
+
that.error(e, "oAuth is busy");
|
17
|
+
}, false);
|
18
|
+
document.addEventListener("appMobi.oauth.unavailable", function(e) {
|
19
|
+
if (e.id == that.serviceID)
|
20
|
+
that.error(e, "oAuth is unavailable");
|
21
|
+
}, false);
|
22
|
+
document.addEventListener("appMobi.oauth.protected.data", function(e) {
|
23
|
+
if (e.id == that.serviceID)
|
24
|
+
that.processRequest(e);
|
25
|
+
}, false);
|
26
|
+
};
|
27
|
+
|
28
|
+
social.prototype = {
|
29
|
+
callBacks : {},
|
30
|
+
serviceName : null,
|
31
|
+
serviceID : null,
|
32
|
+
makeRequest : function(serviceUrl, serviceID, method, callback, body,headers) {
|
33
|
+
if (!serviceUrl) {
|
34
|
+
alert("Please provide a request url");
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
if (!serviceID)
|
38
|
+
serviceID = "";
|
39
|
+
this.serviceID = this.serviceName + "_" + serviceID;
|
40
|
+
|
41
|
+
if (!method)
|
42
|
+
method = "GET";
|
43
|
+
if (!body)
|
44
|
+
body = "";
|
45
|
+
if (!headers)
|
46
|
+
headers = "";
|
47
|
+
if (callback) {
|
48
|
+
this.callBacks[this.serviceID] = callback;
|
49
|
+
}
|
50
|
+
try {
|
51
|
+
var params = new AppMobi.OAuth.ProtectedDataParameters();
|
52
|
+
params.service = this.serviceName;
|
53
|
+
params.url = serviceUrl;
|
54
|
+
params.id = this.serviceID;
|
55
|
+
params.method = method;
|
56
|
+
params.body = body;
|
57
|
+
params.headers = headers;
|
58
|
+
|
59
|
+
var rqStr = "";
|
60
|
+
for ( var j in params) {
|
61
|
+
rqStr += j + " = " + params[j] + "\n";
|
62
|
+
}
|
63
|
+
AppMobi.oauth.getProtectedData(params);
|
64
|
+
} catch (e) {
|
65
|
+
alert("Error " + e.message);
|
66
|
+
}
|
67
|
+
},
|
68
|
+
error : function(msg, errorMsg) {
|
69
|
+
var rqStr = "";
|
70
|
+
for ( var j in errorMsg) {
|
71
|
+
rqStr += j + " " + errorMsg[j] + "\n";
|
72
|
+
}
|
73
|
+
alert("Error with oAuth request " + this.serviceID + " " + rqStr
|
74
|
+
+ " " + errorMsg);
|
75
|
+
},
|
76
|
+
processRequest : function(evt) {
|
77
|
+
try {
|
78
|
+
if (this.callBacks[evt.id]) {
|
79
|
+
this.callBacks[evt.id](evt);
|
80
|
+
}
|
81
|
+
} catch (e) {
|
82
|
+
alert("error with cb " + e);
|
83
|
+
}
|
84
|
+
},
|
85
|
+
deAuthorizeService : function(cb) {
|
86
|
+
|
87
|
+
try {
|
88
|
+
var that = this;
|
89
|
+
if (cb) {
|
90
|
+
that.tmpCB = cb;
|
91
|
+
document.addEventListener("appMobi.oauth.unauthorize.service",
|
92
|
+
this.deAuthorizeCB, false);
|
93
|
+
}
|
94
|
+
AppMobi.oauth.unauthorizeService(this.serviceName);
|
95
|
+
|
96
|
+
} catch (ex) {
|
97
|
+
alert("Error removing " + ex);
|
98
|
+
}
|
99
|
+
},
|
100
|
+
deAuthorizeCB : function(evt) {
|
101
|
+
if (evt.service == this.serviceName) {
|
102
|
+
if (evt.success == false)
|
103
|
+
alert(evt.error);
|
104
|
+
else if (this.tmpCB) {
|
105
|
+
this.tmpCB();
|
106
|
+
delete this["tmpCB"];
|
107
|
+
}
|
108
|
+
}
|
109
|
+
document.removeEventListener("appMobi.oauth.unauthorize.service",this.deAuthorizeCB);
|
110
|
+
}
|
111
|
+
};
|
112
|
+
return social;
|
113
|
+
})(jq);
|
@@ -0,0 +1,121 @@
|
|
1
|
+
/**
|
2
|
+
* $().swipe - a library to detect swipe events for jqMobi apps
|
3
|
+
* Copyright 2011 - AppMobi
|
4
|
+
* Executes a callback function and passes in the direction return
|
5
|
+
* @string (left,right,up,down)
|
6
|
+
*/
|
7
|
+
(function($) {
|
8
|
+
var cache = [];
|
9
|
+
$.fn["swipeListener"] = function(opts) {
|
10
|
+
|
11
|
+
if (opts === undefined && this.length > 0)
|
12
|
+
{
|
13
|
+
return cache[this[0].id] ? cache[this[0].id] : null;
|
14
|
+
}
|
15
|
+
for (var i = 0; i < this.length; i++) {
|
16
|
+
tmp = new swipeListener(this[i], opts);
|
17
|
+
if (this[i].id)
|
18
|
+
cache[this[i].id] = tmp;
|
19
|
+
}
|
20
|
+
return this.length == 1 ? tmp : this;
|
21
|
+
};
|
22
|
+
var swipeListener = (function() {
|
23
|
+
var swipeListener = function(elID, opts) {
|
24
|
+
var that = this;
|
25
|
+
if (typeof (elID) == "string")
|
26
|
+
this.el = document.getElementById(elID);
|
27
|
+
else
|
28
|
+
this.el = elID
|
29
|
+
if (!this.el) {
|
30
|
+
alert("Error adding swipe listener for " + elID);
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
this.el.addEventListener('touchmove', function(e) {
|
34
|
+
that.touchMove(e);
|
35
|
+
}, false);
|
36
|
+
this.el.addEventListener('touchend', function(e) {
|
37
|
+
that.touchEnd(e);
|
38
|
+
}, false);
|
39
|
+
for (j in opts) {
|
40
|
+
this[j] = opts[j];
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
swipeListener.prototype = {
|
45
|
+
startX: 0,
|
46
|
+
startY: 0,
|
47
|
+
movingX: 0,
|
48
|
+
movingY: 0,
|
49
|
+
vthreshold: 50,
|
50
|
+
hthreshold: 50,
|
51
|
+
movingElement: false,
|
52
|
+
swipeDirection: {
|
53
|
+
up: false,
|
54
|
+
down: false,
|
55
|
+
left: false,
|
56
|
+
right: false
|
57
|
+
},
|
58
|
+
callBack: null,
|
59
|
+
|
60
|
+
cancel: function() {
|
61
|
+
this.startX = 0;
|
62
|
+
this.startY = 0;
|
63
|
+
this.movingX = 0;
|
64
|
+
this.movingY = 0;
|
65
|
+
this.movingElement = false;
|
66
|
+
this.swipeDirection = {
|
67
|
+
up: false,
|
68
|
+
down: false,
|
69
|
+
left: false,
|
70
|
+
right: false
|
71
|
+
};
|
72
|
+
},
|
73
|
+
touchStart: function(event) {
|
74
|
+
if (event.touches[0].target && event.touches[0].target.type != undefined) {
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
if (event.touches.length == 1) {
|
78
|
+
this.movingElement = true;
|
79
|
+
this.startX = event.touches[0].pageX;
|
80
|
+
this.startY = event.touches[0].pageY;
|
81
|
+
event.preventDefault();
|
82
|
+
}
|
83
|
+
},
|
84
|
+
touchMove: function(event) {
|
85
|
+
if (this.movingElement == false)
|
86
|
+
this.touchStart(event);
|
87
|
+
event.preventDefault();
|
88
|
+
if (event.touches.length > 1 || !this.movingElement) {
|
89
|
+
this.cancel();
|
90
|
+
return;
|
91
|
+
}
|
92
|
+
this.movingX = event.touches[0].pageX - this.startX;
|
93
|
+
this.movingY = event.touches[0].pageY - this.startY;
|
94
|
+
},
|
95
|
+
touchEnd: function(event) {
|
96
|
+
if (!this.movingElement)
|
97
|
+
return;
|
98
|
+
event.preventDefault();
|
99
|
+
var swiped = false;
|
100
|
+
if (Math.abs(this.movingX) > this.hthreshold) {
|
101
|
+
this.swipeDirection.right = this.movingX > 0;
|
102
|
+
this.swipeDirection.left = this.movingX < 0;
|
103
|
+
swiped = true;
|
104
|
+
}
|
105
|
+
if (Math.abs(this.movingY) > this.vthreshold) {
|
106
|
+
this.swipeDirection.up = this.movingY < 0;
|
107
|
+
this.swipeDirection.down = this.movingY > 0;
|
108
|
+
swiped = true;
|
109
|
+
}
|
110
|
+
if (swiped && typeof (this.callBack == "function"))
|
111
|
+
this.callBack(this.swipeDirection);
|
112
|
+
|
113
|
+
this.cancel();
|
114
|
+
}
|
115
|
+
};
|
116
|
+
return swipeListener;
|
117
|
+
})();
|
118
|
+
|
119
|
+
// Helper function to get only
|
120
|
+
|
121
|
+
})(jq);
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* jq.web.template - a javascript template library
|
3
|
+
* Templating from John Resig - http://ejohn.org/ - MIT Licensed
|
4
|
+
*/
|
5
|
+
(function($) {
|
6
|
+
$["template"] = function(tmpl, data) {
|
7
|
+
return (template(tmpl, data));
|
8
|
+
};
|
9
|
+
$["tmpl"] = function(tmpl, data) {
|
10
|
+
return $(template(tmpl, data));
|
11
|
+
};
|
12
|
+
var template = function(str, data) {
|
13
|
+
//If there's no data, let's pass an empty object so the user isn't forced to.
|
14
|
+
if (!data)
|
15
|
+
data = {};
|
16
|
+
return tmpl(str, data);
|
17
|
+
};
|
18
|
+
|
19
|
+
(function() {
|
20
|
+
var cache = {};
|
21
|
+
this.tmpl = function tmpl(str, data) {
|
22
|
+
var fn = !/\W/.test(str) ? cache[str] = cache[str] || tmpl(document.getElementById(str).innerHTML) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%>)/g, "\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g, "',$1,'").split("<%").join("');").split("%>").join("p.push('") + "');}return p.join('');");
|
23
|
+
return data ? fn(data) : fn;
|
24
|
+
};
|
25
|
+
})();
|
26
|
+
})(jq);
|