sports_db 0.0.3 → 0.0.4
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/app/assets/javascripts/clients/android/client.js +53 -0
- data/app/assets/javascripts/clients/ios/client.js +58 -0
- data/app/assets/javascripts/core/Application.js +173 -0
- data/app/assets/javascripts/core/BaseView.js +117 -0
- data/app/assets/javascripts/core/History.js +45 -0
- data/app/assets/javascripts/core/Mock.js +90 -0
- data/app/assets/javascripts/core/Timer.js +18 -0
- data/app/assets/javascripts/core/View.js +56 -0
- data/app/assets/javascripts/core/utilities.js +81 -0
- data/app/assets/javascripts/libs/SimpleInheritance.js +53 -0
- data/app/assets/javascripts/libs/microjungle.zepto.js +45 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/ajax.js +279 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/assets.js +21 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/data.js +66 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/detect.js +40 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/event.js +224 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/form.js +40 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/fx.js +91 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/fx_methods.js +72 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/gesture.js +35 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/polyfill.js +36 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/selector.js +70 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/stack.js +22 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/touch.js +85 -0
- data/app/assets/javascripts/libs/zepto-v1.0rc1/zepto.js +591 -0
- data/app/assets/javascripts/libs/zepto_0.8.js +1213 -0
- data/app/assets/javascripts/plugins/assert.js +11 -0
- data/app/assets/javascripts/plugins/calnav.js +18 -0
- data/app/assets/javascripts/plugins/detect.js +16 -0
- data/app/assets/javascripts/plugins/filterable.js +12 -0
- data/app/assets/javascripts/plugins/flash.js +15 -0
- data/app/assets/javascripts/plugins/jquery.zumobi-0.2.js +57 -0
- data/app/assets/javascripts/plugins/loading.js +47 -0
- data/app/assets/javascripts/plugins/params.js +27 -0
- data/app/assets/javascripts/plugins/resizeable.js +40 -0
- data/app/assets/stylesheets/_base.css.scss +42 -0
- data/app/assets/stylesheets/_filterable.css.scss +19 -0
- data/app/assets/stylesheets/_flash.css.scss +9 -0
- data/app/assets/stylesheets/_loading.css.scss +28 -0
- data/app/assets/stylesheets/_play.css.scss +38 -0
- data/app/assets/stylesheets/_reset.css.scss +33 -0
- data/app/assets/stylesheets/_table_base.scss +121 -0
- data/app/assets/stylesheets/mock.css.scss +52 -0
- data/app/controllers/application_controller.rb +39 -0
- data/app/views/application/load.html.erb +1 -0
- data/app/views/layouts/application.html.erb +27 -0
- data/lib/sports_db/version.rb +1 -1
- metadata +90 -5
@@ -0,0 +1,1213 @@
|
|
1
|
+
// v.8
|
2
|
+
// ZEPTO_COMPONENTS = [
|
3
|
+
// # 'polyfill',
|
4
|
+
// 'zepto',
|
5
|
+
// 'event',
|
6
|
+
// # 'detect',
|
7
|
+
// 'fx',
|
8
|
+
// 'fx_methods',
|
9
|
+
// 'ajax',
|
10
|
+
// # 'form',
|
11
|
+
// # 'assets',
|
12
|
+
// 'data',
|
13
|
+
// # 'touch',
|
14
|
+
// # 'gesture'
|
15
|
+
// ]
|
16
|
+
|
17
|
+
// Zepto.js
|
18
|
+
// (c) 2010, 2011 Thomas Fuchs
|
19
|
+
// Zepto.js may be freely distributed under the MIT license.
|
20
|
+
|
21
|
+
var Zepto = (function() {
|
22
|
+
var undefined, key, $$, classList, emptyArray = [], slice = emptyArray.slice,
|
23
|
+
document = window.document,
|
24
|
+
elementDisplay = {}, classCache = {},
|
25
|
+
getComputedStyle = document.defaultView.getComputedStyle,
|
26
|
+
cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
|
27
|
+
fragmentRE = /^\s*<(\w+)[^>]*>/,
|
28
|
+
elementTypes = [1, 9, 11],
|
29
|
+
adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ],
|
30
|
+
table = document.createElement('table'),
|
31
|
+
tableRow = document.createElement('tr'),
|
32
|
+
containers = {
|
33
|
+
'tr': document.createElement('tbody'),
|
34
|
+
'tbody': table, 'thead': table, 'tfoot': table,
|
35
|
+
'td': tableRow, 'th': tableRow,
|
36
|
+
'*': document.createElement('div')
|
37
|
+
},
|
38
|
+
readyRE = /complete|loaded|interactive/,
|
39
|
+
classSelectorRE = /^\.([\w-]+)$/,
|
40
|
+
idSelectorRE = /^#([\w-]+)$/,
|
41
|
+
tagSelectorRE = /^[\w-]+$/;
|
42
|
+
|
43
|
+
function isF(value) { return ({}).toString.call(value) == "[object Function]" }
|
44
|
+
function isO(value) { return value instanceof Object }
|
45
|
+
function isA(value) { return value instanceof Array }
|
46
|
+
function likeArray(obj) { return typeof obj.length == 'number' }
|
47
|
+
|
48
|
+
function compact(array) { return array.filter(function(item){ return item !== undefined && item !== null }) }
|
49
|
+
function flatten(array) { return array.length > 0 ? [].concat.apply([], array) : array }
|
50
|
+
function camelize(str) { return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
|
51
|
+
function dasherize(str){
|
52
|
+
return str.replace(/::/g, '/')
|
53
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
54
|
+
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
55
|
+
.replace(/_/g, '-')
|
56
|
+
.toLowerCase();
|
57
|
+
}
|
58
|
+
function uniq(array) { return array.filter(function(item,index,array){ return array.indexOf(item) == index }) }
|
59
|
+
|
60
|
+
function classRE(name){
|
61
|
+
return name in classCache ?
|
62
|
+
classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'));
|
63
|
+
}
|
64
|
+
|
65
|
+
function maybeAddPx(name, value) { return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value; }
|
66
|
+
|
67
|
+
function defaultDisplay(nodeName) {
|
68
|
+
var element, display;
|
69
|
+
if (!elementDisplay[nodeName]) {
|
70
|
+
element = document.createElement(nodeName);
|
71
|
+
document.body.appendChild(element);
|
72
|
+
display = getComputedStyle(element, '').getPropertyValue("display");
|
73
|
+
element.parentNode.removeChild(element);
|
74
|
+
display == "none" && (display = "block");
|
75
|
+
elementDisplay[nodeName] = display;
|
76
|
+
}
|
77
|
+
return elementDisplay[nodeName];
|
78
|
+
}
|
79
|
+
|
80
|
+
function fragment(html, name) {
|
81
|
+
if (name === undefined) fragmentRE.test(html) && RegExp.$1;
|
82
|
+
if (!(name in containers)) name = '*';
|
83
|
+
var container = containers[name];
|
84
|
+
container.innerHTML = '' + html;
|
85
|
+
return slice.call(container.childNodes);
|
86
|
+
}
|
87
|
+
|
88
|
+
function Z(dom, selector){
|
89
|
+
dom = dom || emptyArray;
|
90
|
+
dom.__proto__ = Z.prototype;
|
91
|
+
dom.selector = selector || '';
|
92
|
+
return dom;
|
93
|
+
}
|
94
|
+
|
95
|
+
function $(selector, context){
|
96
|
+
if (!selector) return Z();
|
97
|
+
if (context !== undefined) return $(context).find(selector);
|
98
|
+
else if (isF(selector)) return $(document).ready(selector);
|
99
|
+
else if (selector instanceof Z) return selector;
|
100
|
+
else {
|
101
|
+
var dom;
|
102
|
+
if (isA(selector)) dom = compact(selector);
|
103
|
+
else if (elementTypes.indexOf(selector.nodeType) >= 0 || selector === window)
|
104
|
+
dom = [selector], selector = null;
|
105
|
+
else if (fragmentRE.test(selector))
|
106
|
+
dom = fragment(selector.trim(), RegExp.$1), selector = null;
|
107
|
+
else if (selector.nodeType && selector.nodeType == 3) dom = [selector];
|
108
|
+
else dom = $$(document, selector);
|
109
|
+
return Z(dom, selector);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
$.extend = function(target){
|
114
|
+
slice.call(arguments, 1).forEach(function(source) {
|
115
|
+
for (key in source) target[key] = source[key];
|
116
|
+
})
|
117
|
+
return target;
|
118
|
+
}
|
119
|
+
|
120
|
+
$.qsa = $$ = function(element, selector){
|
121
|
+
var found;
|
122
|
+
return (element === document && idSelectorRE.test(selector)) ?
|
123
|
+
( (found = element.getElementById(RegExp.$1)) ? [found] : emptyArray ) :
|
124
|
+
slice.call(
|
125
|
+
classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) :
|
126
|
+
tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) :
|
127
|
+
element.querySelectorAll(selector)
|
128
|
+
);
|
129
|
+
}
|
130
|
+
|
131
|
+
function filtered(nodes, selector){
|
132
|
+
return selector === undefined ? $(nodes) : $(nodes).filter(selector);
|
133
|
+
}
|
134
|
+
|
135
|
+
function funcArg(context, arg, idx, payload){
|
136
|
+
return isF(arg) ? arg.call(context, idx, payload) : arg;
|
137
|
+
}
|
138
|
+
|
139
|
+
$.isFunction = isF;
|
140
|
+
$.isObject = isO;
|
141
|
+
$.isArray = isA;
|
142
|
+
|
143
|
+
$.map = function(elements, callback) {
|
144
|
+
var value, values = [], i, key;
|
145
|
+
if (likeArray(elements))
|
146
|
+
for (i = 0; i < elements.length; i++) {
|
147
|
+
value = callback(elements[i], i);
|
148
|
+
if (value != null) values.push(value);
|
149
|
+
}
|
150
|
+
else
|
151
|
+
for (key in elements) {
|
152
|
+
value = callback(elements[key], key);
|
153
|
+
if (value != null) values.push(value);
|
154
|
+
}
|
155
|
+
return flatten(values);
|
156
|
+
}
|
157
|
+
|
158
|
+
$.each = function(elements, callback) {
|
159
|
+
var i, key;
|
160
|
+
if (likeArray(elements))
|
161
|
+
for(i = 0; i < elements.length; i++) {
|
162
|
+
if(callback(i, elements[i]) === false) return elements;
|
163
|
+
}
|
164
|
+
else
|
165
|
+
for(key in elements) {
|
166
|
+
if(callback(key, elements[key]) === false) return elements;
|
167
|
+
}
|
168
|
+
return elements;
|
169
|
+
}
|
170
|
+
|
171
|
+
$.fn = {
|
172
|
+
forEach: emptyArray.forEach,
|
173
|
+
reduce: emptyArray.reduce,
|
174
|
+
push: emptyArray.push,
|
175
|
+
indexOf: emptyArray.indexOf,
|
176
|
+
concat: emptyArray.concat,
|
177
|
+
map: function(fn){
|
178
|
+
return $.map(this, function(el, i){ return fn.call(el, i, el) });
|
179
|
+
},
|
180
|
+
slice: function(){
|
181
|
+
return $(slice.apply(this, arguments));
|
182
|
+
},
|
183
|
+
ready: function(callback){
|
184
|
+
if (readyRE.test(document.readyState)) callback($);
|
185
|
+
else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false);
|
186
|
+
return this;
|
187
|
+
},
|
188
|
+
get: function(idx){ return idx === undefined ? this : this[idx] },
|
189
|
+
size: function(){ return this.length },
|
190
|
+
remove: function () {
|
191
|
+
return this.each(function () {
|
192
|
+
if (this.parentNode != null) {
|
193
|
+
this.parentNode.removeChild(this);
|
194
|
+
}
|
195
|
+
});
|
196
|
+
},
|
197
|
+
each: function(callback){
|
198
|
+
this.forEach(function(el, idx){ callback.call(el, idx, el) });
|
199
|
+
return this;
|
200
|
+
},
|
201
|
+
filter: function(selector){
|
202
|
+
return $([].filter.call(this, function(element){
|
203
|
+
return element.parentNode && $$(element.parentNode, selector).indexOf(element) >= 0;
|
204
|
+
}));
|
205
|
+
},
|
206
|
+
end: function(){
|
207
|
+
return this.prevObject || $();
|
208
|
+
},
|
209
|
+
andSelf:function(){
|
210
|
+
return this.add(this.prevObject || $())
|
211
|
+
},
|
212
|
+
add:function(selector,context){
|
213
|
+
return $(uniq(this.concat($(selector,context))));
|
214
|
+
},
|
215
|
+
is: function(selector){
|
216
|
+
return this.length > 0 && $(this[0]).filter(selector).length > 0;
|
217
|
+
},
|
218
|
+
not: function(selector){
|
219
|
+
var nodes=[];
|
220
|
+
if (isF(selector) && selector.call !== undefined)
|
221
|
+
this.each(function(idx){
|
222
|
+
if (!selector.call(this,idx)) nodes.push(this);
|
223
|
+
});
|
224
|
+
else {
|
225
|
+
var excludes = typeof selector == 'string' ? this.filter(selector) :
|
226
|
+
(likeArray(selector) && isF(selector.item)) ? slice.call(selector) : $(selector);
|
227
|
+
this.forEach(function(el){
|
228
|
+
if (excludes.indexOf(el) < 0) nodes.push(el);
|
229
|
+
});
|
230
|
+
}
|
231
|
+
return $(nodes);
|
232
|
+
},
|
233
|
+
eq: function(idx){
|
234
|
+
return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1);
|
235
|
+
},
|
236
|
+
first: function(){ var el = this[0]; return el && !isO(el) ? el : $(el) },
|
237
|
+
last: function(){ var el = this[this.length - 1]; return el && !isO(el) ? el : $(el) },
|
238
|
+
find: function(selector){
|
239
|
+
var result;
|
240
|
+
if (this.length == 1) result = $$(this[0], selector);
|
241
|
+
else result = this.map(function(){ return $$(this, selector) });
|
242
|
+
return $(result);
|
243
|
+
},
|
244
|
+
closest: function(selector, context){
|
245
|
+
var node = this[0], candidates = $$(context || document, selector);
|
246
|
+
if (!candidates.length) node = null;
|
247
|
+
while (node && candidates.indexOf(node) < 0)
|
248
|
+
node = node !== context && node !== document && node.parentNode;
|
249
|
+
return $(node);
|
250
|
+
},
|
251
|
+
parents: function(selector){
|
252
|
+
var ancestors = [], nodes = this;
|
253
|
+
while (nodes.length > 0)
|
254
|
+
nodes = $.map(nodes, function(node){
|
255
|
+
if ((node = node.parentNode) && node !== document && ancestors.indexOf(node) < 0) {
|
256
|
+
ancestors.push(node);
|
257
|
+
return node;
|
258
|
+
}
|
259
|
+
});
|
260
|
+
return filtered(ancestors, selector);
|
261
|
+
},
|
262
|
+
parent: function(selector){
|
263
|
+
return filtered(uniq(this.pluck('parentNode')), selector);
|
264
|
+
},
|
265
|
+
children: function(selector){
|
266
|
+
return filtered(this.map(function(){ return slice.call(this.children) }), selector);
|
267
|
+
},
|
268
|
+
siblings: function(selector){
|
269
|
+
return filtered(this.map(function(i, el){
|
270
|
+
return slice.call(el.parentNode.children).filter(function(child){ return child!==el });
|
271
|
+
}), selector);
|
272
|
+
},
|
273
|
+
empty: function(){ return this.each(function(){ this.innerHTML = '' }) },
|
274
|
+
pluck: function(property){ return this.map(function(){ return this[property] }) },
|
275
|
+
show: function(){
|
276
|
+
return this.each(function() {
|
277
|
+
this.style.display == "none" && (this.style.display = null);
|
278
|
+
if (getComputedStyle(this, '').getPropertyValue("display") == "none") {
|
279
|
+
this.style.display = defaultDisplay(this.nodeName)
|
280
|
+
}
|
281
|
+
})
|
282
|
+
},
|
283
|
+
replaceWith: function(newContent) {
|
284
|
+
return this.each(function() {
|
285
|
+
$(this).before(newContent).remove();
|
286
|
+
});
|
287
|
+
},
|
288
|
+
wrap: function(newContent) {
|
289
|
+
return this.each(function() {
|
290
|
+
$(this).wrapAll($(newContent)[0].cloneNode(false));
|
291
|
+
});
|
292
|
+
},
|
293
|
+
wrapAll: function(newContent) {
|
294
|
+
if (this[0]) {
|
295
|
+
$(this[0]).before(newContent = $(newContent));
|
296
|
+
newContent.append(this);
|
297
|
+
}
|
298
|
+
return this;
|
299
|
+
},
|
300
|
+
unwrap: function(){
|
301
|
+
this.parent().each(function(){
|
302
|
+
$(this).replaceWith($(this).children());
|
303
|
+
});
|
304
|
+
return this;
|
305
|
+
},
|
306
|
+
hide: function(){
|
307
|
+
return this.css("display", "none")
|
308
|
+
},
|
309
|
+
toggle: function(setting){
|
310
|
+
return (setting === undefined ? this.css("display") == "none" : setting) ? this.show() : this.hide();
|
311
|
+
},
|
312
|
+
prev: function(){ return $(this.pluck('previousElementSibling')) },
|
313
|
+
next: function(){ return $(this.pluck('nextElementSibling')) },
|
314
|
+
html: function(html){
|
315
|
+
return html === undefined ?
|
316
|
+
(this.length > 0 ? this[0].innerHTML : null) :
|
317
|
+
this.each(function (idx) {
|
318
|
+
var originHtml = this.innerHTML;
|
319
|
+
$(this).empty().append( funcArg(this, html, idx, originHtml) );
|
320
|
+
});
|
321
|
+
},
|
322
|
+
text: function(text){
|
323
|
+
return text === undefined ?
|
324
|
+
(this.length > 0 ? this[0].textContent : null) :
|
325
|
+
this.each(function(){ this.textContent = text });
|
326
|
+
},
|
327
|
+
attr: function(name, value){
|
328
|
+
var res;
|
329
|
+
return (typeof name == 'string' && value === undefined) ?
|
330
|
+
(this.length == 0 ? undefined :
|
331
|
+
(name == 'value' && this[0].nodeName == 'INPUT') ? this.val() :
|
332
|
+
(!(res = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : res
|
333
|
+
) :
|
334
|
+
this.each(function(idx){
|
335
|
+
if (isO(name)) for (key in name) this.setAttribute(key, name[key])
|
336
|
+
else this.setAttribute(name, funcArg(this, value, idx, this.getAttribute(name)));
|
337
|
+
});
|
338
|
+
},
|
339
|
+
removeAttr: function(name) {
|
340
|
+
return this.each(function() { this.removeAttribute(name); });
|
341
|
+
},
|
342
|
+
data: function(name, value){
|
343
|
+
return this.attr('data-' + name, value);
|
344
|
+
},
|
345
|
+
val: function(value){
|
346
|
+
return (value === undefined) ?
|
347
|
+
(this.length > 0 ? this[0].value : null) :
|
348
|
+
this.each(function(idx){
|
349
|
+
this.value = funcArg(this, value, idx, this.value);
|
350
|
+
});
|
351
|
+
},
|
352
|
+
offset: function(){
|
353
|
+
if(this.length==0) return null;
|
354
|
+
var obj = this[0].getBoundingClientRect();
|
355
|
+
return {
|
356
|
+
left: obj.left + window.pageXOffset,
|
357
|
+
top: obj.top + window.pageYOffset,
|
358
|
+
width: obj.width,
|
359
|
+
height: obj.height
|
360
|
+
};
|
361
|
+
},
|
362
|
+
css: function(property, value){
|
363
|
+
if (value === undefined && typeof property == 'string') {
|
364
|
+
return(
|
365
|
+
this.length == 0
|
366
|
+
? undefined
|
367
|
+
: this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property)
|
368
|
+
);
|
369
|
+
}
|
370
|
+
var css = '';
|
371
|
+
for (key in property) css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';';
|
372
|
+
if (typeof property == 'string') css = dasherize(property) + ":" + maybeAddPx(property, value);
|
373
|
+
return this.each(function() { this.style.cssText += ';' + css });
|
374
|
+
},
|
375
|
+
index: function(element){
|
376
|
+
return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]);
|
377
|
+
},
|
378
|
+
hasClass: function(name){
|
379
|
+
if (this.length < 1) return false;
|
380
|
+
else return classRE(name).test(this[0].className);
|
381
|
+
},
|
382
|
+
addClass: function(name){
|
383
|
+
return this.each(function(idx) {
|
384
|
+
classList = [];
|
385
|
+
var cls = this.className, newName = funcArg(this, name, idx, cls);
|
386
|
+
newName.split(/\s+/g).forEach(function(klass) {
|
387
|
+
if (!$(this).hasClass(klass)) {
|
388
|
+
classList.push(klass)
|
389
|
+
}
|
390
|
+
}, this);
|
391
|
+
classList.length && (this.className += (cls ? " " : "") + classList.join(" "))
|
392
|
+
});
|
393
|
+
},
|
394
|
+
removeClass: function(name){
|
395
|
+
return this.each(function(idx) {
|
396
|
+
if(name === undefined)
|
397
|
+
return this.className = '';
|
398
|
+
classList = this.className;
|
399
|
+
funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass) {
|
400
|
+
classList = classList.replace(classRE(klass), " ")
|
401
|
+
});
|
402
|
+
this.className = classList.trim()
|
403
|
+
});
|
404
|
+
},
|
405
|
+
toggleClass: function(name, when){
|
406
|
+
return this.each(function(idx){
|
407
|
+
var newName = funcArg(this, name, idx, this.className);
|
408
|
+
(when === undefined ? !$(this).hasClass(newName) : when) ?
|
409
|
+
$(this).addClass(newName) : $(this).removeClass(newName);
|
410
|
+
});
|
411
|
+
}
|
412
|
+
};
|
413
|
+
|
414
|
+
'filter,add,not,eq,first,last,find,closest,parents,parent,children,siblings'.split(',').forEach(function(property){
|
415
|
+
var fn = $.fn[property];
|
416
|
+
$.fn[property] = function() {
|
417
|
+
var ret = fn.apply(this, arguments);
|
418
|
+
ret.prevObject = this;
|
419
|
+
return ret;
|
420
|
+
}
|
421
|
+
});
|
422
|
+
|
423
|
+
['width', 'height'].forEach(function(dimension){
|
424
|
+
$.fn[dimension] = function(value) {
|
425
|
+
var offset, Dimension = dimension.replace(/./, function(m) { return m[0].toUpperCase() });
|
426
|
+
if (value === undefined) return this[0] == window ? window['inner' + Dimension] :
|
427
|
+
this[0] == document ? document.documentElement['offset' + Dimension] :
|
428
|
+
(offset = this.offset()) && offset[dimension];
|
429
|
+
else return this.each(function(idx){
|
430
|
+
var el = $(this);
|
431
|
+
el.css(dimension, funcArg(this, value, idx, el[dimension]()));
|
432
|
+
});
|
433
|
+
}
|
434
|
+
});
|
435
|
+
|
436
|
+
function insert(operator, target, node) {
|
437
|
+
var parent = (operator % 2) ? target : target.parentNode;
|
438
|
+
parent && parent.insertBefore(node,
|
439
|
+
!operator ? target.nextSibling : // after
|
440
|
+
operator == 1 ? parent.firstChild : // prepend
|
441
|
+
operator == 2 ? target : // before
|
442
|
+
null); // append
|
443
|
+
}
|
444
|
+
|
445
|
+
function traverseNode (node, fun) {
|
446
|
+
fun(node);
|
447
|
+
for (var key in node.childNodes) {
|
448
|
+
traverseNode(node.childNodes[key], fun);
|
449
|
+
}
|
450
|
+
}
|
451
|
+
|
452
|
+
adjacencyOperators.forEach(function(key, operator) {
|
453
|
+
$.fn[key] = function(html){
|
454
|
+
var nodes = isO(html) ? html : fragment(html);
|
455
|
+
if (!('length' in nodes) || nodes.nodeType) nodes = [nodes];
|
456
|
+
if (nodes.length < 1) return this;
|
457
|
+
var size = this.length, copyByClone = size > 1, inReverse = operator < 2;
|
458
|
+
|
459
|
+
return this.each(function(index, target){
|
460
|
+
for (var i = 0; i < nodes.length; i++) {
|
461
|
+
var node = nodes[inReverse ? nodes.length-i-1 : i];
|
462
|
+
traverseNode(node, function (node) {
|
463
|
+
if (node.nodeName != null && node.nodeName.toUpperCase() === 'SCRIPT' && (!node.type || node.type === 'text/javascript')) {
|
464
|
+
window['eval'].call(window, node.innerHTML);
|
465
|
+
}
|
466
|
+
});
|
467
|
+
if (copyByClone && index < size - 1) node = node.cloneNode(true);
|
468
|
+
insert(operator, target, node);
|
469
|
+
}
|
470
|
+
});
|
471
|
+
};
|
472
|
+
|
473
|
+
var reverseKey = (operator % 2) ? key+'To' : 'insert'+(operator ? 'Before' : 'After');
|
474
|
+
$.fn[reverseKey] = function(html) {
|
475
|
+
$(html)[key](this);
|
476
|
+
return this;
|
477
|
+
};
|
478
|
+
});
|
479
|
+
|
480
|
+
Z.prototype = $.fn;
|
481
|
+
|
482
|
+
return $;
|
483
|
+
})();
|
484
|
+
|
485
|
+
window.Zepto = Zepto;
|
486
|
+
'$' in window || (window.$ = Zepto);
|
487
|
+
// Zepto.js
|
488
|
+
// (c) 2010, 2011 Thomas Fuchs
|
489
|
+
// Zepto.js may be freely distributed under the MIT license.
|
490
|
+
|
491
|
+
(function($){
|
492
|
+
var $$ = $.qsa, handlers = {}, _zid = 1, specialEvents={};
|
493
|
+
|
494
|
+
specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents';
|
495
|
+
|
496
|
+
function zid(element) {
|
497
|
+
return element._zid || (element._zid = _zid++);
|
498
|
+
}
|
499
|
+
function findHandlers(element, event, fn, selector) {
|
500
|
+
event = parse(event);
|
501
|
+
if (event.ns) var matcher = matcherFor(event.ns);
|
502
|
+
return (handlers[zid(element)] || []).filter(function(handler) {
|
503
|
+
return handler
|
504
|
+
&& (!event.e || handler.e == event.e)
|
505
|
+
&& (!event.ns || matcher.test(handler.ns))
|
506
|
+
&& (!fn || handler.fn == fn)
|
507
|
+
&& (!selector || handler.sel == selector);
|
508
|
+
});
|
509
|
+
}
|
510
|
+
function parse(event) {
|
511
|
+
var parts = ('' + event).split('.');
|
512
|
+
return {e: parts[0], ns: parts.slice(1).sort().join(' ')};
|
513
|
+
}
|
514
|
+
function matcherFor(ns) {
|
515
|
+
return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)');
|
516
|
+
}
|
517
|
+
|
518
|
+
function eachEvent(events, fn, iterator){
|
519
|
+
if ($.isObject(events)) $.each(events, iterator);
|
520
|
+
else events.split(/\s/).forEach(function(type){ iterator(type, fn) });
|
521
|
+
}
|
522
|
+
|
523
|
+
function add(element, events, fn, selector, getDelegate){
|
524
|
+
var id = zid(element), set = (handlers[id] || (handlers[id] = []));
|
525
|
+
eachEvent(events, fn, function(event, fn){
|
526
|
+
var delegate = getDelegate && getDelegate(fn, event),
|
527
|
+
callback = delegate || fn;
|
528
|
+
var proxyfn = function (event) {
|
529
|
+
var result = callback.apply(element, [event].concat(event.data));
|
530
|
+
if (result === false) event.preventDefault();
|
531
|
+
return result;
|
532
|
+
};
|
533
|
+
var handler = $.extend(parse(event), {fn: fn, proxy: proxyfn, sel: selector, del: delegate, i: set.length});
|
534
|
+
set.push(handler);
|
535
|
+
element.addEventListener(handler.e, proxyfn, false);
|
536
|
+
});
|
537
|
+
}
|
538
|
+
function remove(element, events, fn, selector){
|
539
|
+
var id = zid(element);
|
540
|
+
eachEvent(events || '', fn, function(event, fn){
|
541
|
+
findHandlers(element, event, fn, selector).forEach(function(handler){
|
542
|
+
delete handlers[id][handler.i];
|
543
|
+
element.removeEventListener(handler.e, handler.proxy, false);
|
544
|
+
});
|
545
|
+
});
|
546
|
+
}
|
547
|
+
|
548
|
+
$.event = { add: add, remove: remove }
|
549
|
+
|
550
|
+
$.fn.bind = function(event, callback){
|
551
|
+
return this.each(function(){
|
552
|
+
add(this, event, callback);
|
553
|
+
});
|
554
|
+
};
|
555
|
+
$.fn.unbind = function(event, callback){
|
556
|
+
return this.each(function(){
|
557
|
+
remove(this, event, callback);
|
558
|
+
});
|
559
|
+
};
|
560
|
+
$.fn.one = function(event, callback){
|
561
|
+
return this.each(function(i, element){
|
562
|
+
add(this, event, callback, null, function(fn, type){
|
563
|
+
return function(){
|
564
|
+
var result = fn.apply(element, arguments);
|
565
|
+
remove(element, type, fn);
|
566
|
+
return result;
|
567
|
+
}
|
568
|
+
});
|
569
|
+
});
|
570
|
+
};
|
571
|
+
|
572
|
+
var returnTrue = function(){return true},
|
573
|
+
returnFalse = function(){return false},
|
574
|
+
eventMethods = {
|
575
|
+
preventDefault: 'isDefaultPrevented',
|
576
|
+
stopImmediatePropagation: 'isImmediatePropagationStopped',
|
577
|
+
stopPropagation: 'isPropagationStopped'
|
578
|
+
};
|
579
|
+
function createProxy(event) {
|
580
|
+
var proxy = $.extend({originalEvent: event}, event);
|
581
|
+
$.each(eventMethods, function(name, predicate) {
|
582
|
+
proxy[name] = function(){
|
583
|
+
this[predicate] = returnTrue;
|
584
|
+
return event[name].apply(event, arguments);
|
585
|
+
};
|
586
|
+
proxy[predicate] = returnFalse;
|
587
|
+
})
|
588
|
+
return proxy;
|
589
|
+
}
|
590
|
+
|
591
|
+
// emulates the 'defaultPrevented' property for browsers that have none
|
592
|
+
function fix(event) {
|
593
|
+
if (!('defaultPrevented' in event)) {
|
594
|
+
event.defaultPrevented = false;
|
595
|
+
var prevent = event.preventDefault;
|
596
|
+
event.preventDefault = function() {
|
597
|
+
this.defaultPrevented = true;
|
598
|
+
prevent.call(this);
|
599
|
+
}
|
600
|
+
}
|
601
|
+
}
|
602
|
+
|
603
|
+
$.fn.delegate = function(selector, event, callback){
|
604
|
+
return this.each(function(i, element){
|
605
|
+
add(element, event, callback, selector, function(fn){
|
606
|
+
return function(e){
|
607
|
+
var evt, match = $(e.target).closest(selector, element).get(0);
|
608
|
+
if (match) {
|
609
|
+
evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element});
|
610
|
+
return fn.apply(match, [evt].concat([].slice.call(arguments, 1)));
|
611
|
+
}
|
612
|
+
}
|
613
|
+
});
|
614
|
+
});
|
615
|
+
};
|
616
|
+
$.fn.undelegate = function(selector, event, callback){
|
617
|
+
return this.each(function(){
|
618
|
+
remove(this, event, callback, selector);
|
619
|
+
});
|
620
|
+
}
|
621
|
+
|
622
|
+
$.fn.live = function(event, callback){
|
623
|
+
$(document.body).delegate(this.selector, event, callback);
|
624
|
+
return this;
|
625
|
+
};
|
626
|
+
$.fn.die = function(event, callback){
|
627
|
+
$(document.body).undelegate(this.selector, event, callback);
|
628
|
+
return this;
|
629
|
+
};
|
630
|
+
|
631
|
+
$.fn.on = function(event, selector, callback){
|
632
|
+
return selector === undefined || $.isFunction(selector) ?
|
633
|
+
this.bind(event, selector) : this.delegate(selector, event, callback);
|
634
|
+
};
|
635
|
+
$.fn.off = function(event, selector, callback){
|
636
|
+
return selector === undefined || $.isFunction(selector) ?
|
637
|
+
this.unbind(event, selector) : this.undelegate(selector, event, callback);
|
638
|
+
};
|
639
|
+
|
640
|
+
$.fn.trigger = function(event, data){
|
641
|
+
if (typeof event == 'string') event = $.Event(event);
|
642
|
+
fix(event);
|
643
|
+
event.data = data;
|
644
|
+
return this.each(function(){ this.dispatchEvent(event) });
|
645
|
+
};
|
646
|
+
|
647
|
+
// triggers event handlers on current element just as if an event occurred,
|
648
|
+
// doesn't trigger an actual event, doesn't bubble
|
649
|
+
$.fn.triggerHandler = function(event, data){
|
650
|
+
var e, result;
|
651
|
+
this.each(function(i, element){
|
652
|
+
e = createProxy(typeof event == 'string' ? $.Event(event) : event);
|
653
|
+
e.data = data; e.target = element;
|
654
|
+
$.each(findHandlers(element, event.type || event), function(i, handler){
|
655
|
+
result = handler.proxy(e);
|
656
|
+
if (e.isImmediatePropagationStopped()) return false;
|
657
|
+
});
|
658
|
+
});
|
659
|
+
return result;
|
660
|
+
};
|
661
|
+
|
662
|
+
// shortcut methods for `.bind(event, fn)` for each event type
|
663
|
+
('focusin focusout load resize scroll unload click dblclick '+
|
664
|
+
'mousedown mouseup mousemove mouseover mouseout '+
|
665
|
+
'change select keydown keypress keyup error').split(' ').forEach(function(event) {
|
666
|
+
$.fn[event] = function(callback){ return this.bind(event, callback) };
|
667
|
+
});
|
668
|
+
|
669
|
+
['focus', 'blur'].forEach(function(name) {
|
670
|
+
$.fn[name] = function(callback) {
|
671
|
+
if (callback) this.bind(name, callback);
|
672
|
+
else if (this.length) try { this.get(0)[name]() } catch(e){};
|
673
|
+
return this;
|
674
|
+
};
|
675
|
+
});
|
676
|
+
|
677
|
+
$.Event = function(type, props) {
|
678
|
+
var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true;
|
679
|
+
if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]);
|
680
|
+
event.initEvent(type, bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null);
|
681
|
+
return event;
|
682
|
+
};
|
683
|
+
|
684
|
+
})(Zepto);
|
685
|
+
// Zepto.js
|
686
|
+
// (c) 2010, 2011 Thomas Fuchs
|
687
|
+
// Zepto.js may be freely distributed under the MIT license.
|
688
|
+
|
689
|
+
(function($, undefined){
|
690
|
+
var prefix = '', eventPrefix, endEventName, endAnimationName,
|
691
|
+
vendors = {Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS'},
|
692
|
+
document = window.document, testEl = document.createElement('div'),
|
693
|
+
supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i;
|
694
|
+
|
695
|
+
function downcase(str) { return str.toLowerCase() }
|
696
|
+
function normalizeEvent(name) { return eventPrefix ? eventPrefix + name : downcase(name) };
|
697
|
+
|
698
|
+
$.each(vendors, function(vendor, event){
|
699
|
+
if (testEl.style[vendor + 'TransitionProperty'] !== undefined) {
|
700
|
+
prefix = '-' + downcase(vendor) + '-';
|
701
|
+
eventPrefix = event;
|
702
|
+
return false;
|
703
|
+
}
|
704
|
+
});
|
705
|
+
|
706
|
+
$.fx = {
|
707
|
+
off: (eventPrefix === undefined && testEl.style.transitionProperty === undefined),
|
708
|
+
cssPrefix: prefix,
|
709
|
+
transitionEnd: normalizeEvent('TransitionEnd'),
|
710
|
+
animationEnd: normalizeEvent('AnimationEnd')
|
711
|
+
};
|
712
|
+
|
713
|
+
$.fn.animate = function(properties, duration, ease, callback){
|
714
|
+
if ($.isObject(duration))
|
715
|
+
ease = duration.easing, callback = duration.complete, duration = duration.duration;
|
716
|
+
if (duration) duration = duration / 1000;
|
717
|
+
return this.anim(properties, duration, ease, callback);
|
718
|
+
};
|
719
|
+
|
720
|
+
$.fn.anim = function(properties, duration, ease, callback){
|
721
|
+
var transforms, cssProperties = {}, key, that = this, wrappedCallback, endEvent = $.fx.transitionEnd;
|
722
|
+
if (duration === undefined) duration = 0.4;
|
723
|
+
if ($.fx.off) duration = 0;
|
724
|
+
|
725
|
+
if (typeof properties == 'string') {
|
726
|
+
// keyframe animation
|
727
|
+
cssProperties[prefix + 'animation-name'] = properties;
|
728
|
+
cssProperties[prefix + 'animation-duration'] = duration + 's';
|
729
|
+
endEvent = $.fx.animationEnd;
|
730
|
+
} else {
|
731
|
+
// CSS transitions
|
732
|
+
for (key in properties)
|
733
|
+
if (supportedTransforms.test(key)) {
|
734
|
+
transforms || (transforms = []);
|
735
|
+
transforms.push(key + '(' + properties[key] + ')');
|
736
|
+
}
|
737
|
+
else cssProperties[key] = properties[key];
|
738
|
+
|
739
|
+
if (transforms) cssProperties[prefix + 'transform'] = transforms.join(' ');
|
740
|
+
if (!$.fx.off) cssProperties[prefix + 'transition'] = 'all ' + duration + 's ' + (ease || '');
|
741
|
+
}
|
742
|
+
|
743
|
+
wrappedCallback = function(){
|
744
|
+
var props = {};
|
745
|
+
props[prefix + 'transition'] = props[prefix + 'animation-name'] = 'none';
|
746
|
+
$(this).css(props);
|
747
|
+
callback && callback.call(this);
|
748
|
+
}
|
749
|
+
if (duration > 0) this.one(endEvent, wrappedCallback);
|
750
|
+
|
751
|
+
setTimeout(function() {
|
752
|
+
that.css(cssProperties);
|
753
|
+
if (duration <= 0) setTimeout(function() {
|
754
|
+
that.each(function(){ wrappedCallback.call(this) });
|
755
|
+
}, 0);
|
756
|
+
}, 0);
|
757
|
+
|
758
|
+
return this;
|
759
|
+
};
|
760
|
+
|
761
|
+
testEl = null;
|
762
|
+
})(Zepto);
|
763
|
+
// Zepto.js
|
764
|
+
// (c) 2010, 2011 Thomas Fuchs
|
765
|
+
// Zepto.js may be freely distributed under the MIT license.
|
766
|
+
|
767
|
+
(function($){
|
768
|
+
var jsonpID = 0,
|
769
|
+
isObject = $.isObject,
|
770
|
+
document = window.document,
|
771
|
+
key,
|
772
|
+
name;
|
773
|
+
|
774
|
+
// trigger a custom event and return false if it was cancelled
|
775
|
+
function triggerAndReturn(context, eventName, data) {
|
776
|
+
var event = $.Event(eventName);
|
777
|
+
$(context).trigger(event, data);
|
778
|
+
return !event.defaultPrevented;
|
779
|
+
}
|
780
|
+
|
781
|
+
// trigger an Ajax "global" event
|
782
|
+
function triggerGlobal(settings, context, eventName, data) {
|
783
|
+
if (settings.global) return triggerAndReturn(context || document, eventName, data);
|
784
|
+
}
|
785
|
+
|
786
|
+
// Number of active Ajax requests
|
787
|
+
$.active = 0;
|
788
|
+
|
789
|
+
function ajaxStart(settings) {
|
790
|
+
if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart');
|
791
|
+
}
|
792
|
+
function ajaxStop(settings) {
|
793
|
+
if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop');
|
794
|
+
}
|
795
|
+
|
796
|
+
// triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
|
797
|
+
function ajaxBeforeSend(xhr, settings) {
|
798
|
+
var context = settings.context;
|
799
|
+
if (settings.beforeSend.call(context, xhr, settings) === false ||
|
800
|
+
triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
|
801
|
+
return false;
|
802
|
+
|
803
|
+
triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]);
|
804
|
+
}
|
805
|
+
function ajaxSuccess(data, xhr, settings) {
|
806
|
+
var context = settings.context, status = 'success';
|
807
|
+
settings.success.call(context, data, status, xhr);
|
808
|
+
triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]);
|
809
|
+
ajaxComplete(status, xhr, settings);
|
810
|
+
}
|
811
|
+
// type: "timeout", "error", "abort", "parsererror"
|
812
|
+
function ajaxError(error, type, xhr, settings) {
|
813
|
+
var context = settings.context;
|
814
|
+
settings.error.call(context, xhr, type, error);
|
815
|
+
triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error]);
|
816
|
+
ajaxComplete(type, xhr, settings);
|
817
|
+
}
|
818
|
+
// status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
|
819
|
+
function ajaxComplete(status, xhr, settings) {
|
820
|
+
var context = settings.context;
|
821
|
+
settings.complete.call(context, xhr, status);
|
822
|
+
triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]);
|
823
|
+
ajaxStop(settings);
|
824
|
+
}
|
825
|
+
|
826
|
+
// Empty function, used as default callback
|
827
|
+
function empty() {}
|
828
|
+
|
829
|
+
// ### $.ajaxJSONP
|
830
|
+
//
|
831
|
+
// Load JSON from a server in a different domain (JSONP)
|
832
|
+
//
|
833
|
+
// *Arguments:*
|
834
|
+
//
|
835
|
+
// options — object that configure the request,
|
836
|
+
// see avaliable options below
|
837
|
+
//
|
838
|
+
// *Avaliable options:*
|
839
|
+
//
|
840
|
+
// url — url to which the request is sent
|
841
|
+
// success — callback that is executed if the request succeeds
|
842
|
+
// error — callback that is executed if the server drops error
|
843
|
+
// context — in which context to execute the callbacks in
|
844
|
+
//
|
845
|
+
// *Example:*
|
846
|
+
//
|
847
|
+
// $.ajaxJSONP({
|
848
|
+
// url: 'http://example.com/projects?callback=?',
|
849
|
+
// success: function (data) {
|
850
|
+
// projects.push(json);
|
851
|
+
// }
|
852
|
+
// });
|
853
|
+
//
|
854
|
+
$.ajaxJSONP = function(options){
|
855
|
+
var callbackName = 'jsonp' + (++jsonpID),
|
856
|
+
script = document.createElement('script'),
|
857
|
+
abort = function(){
|
858
|
+
$(script).remove();
|
859
|
+
if (callbackName in window) window[callbackName] = empty;
|
860
|
+
ajaxComplete(xhr, options, 'abort');
|
861
|
+
},
|
862
|
+
xhr = { abort: abort }, abortTimeout;
|
863
|
+
|
864
|
+
window[callbackName] = function(data){
|
865
|
+
clearTimeout(abortTimeout);
|
866
|
+
$(script).remove();
|
867
|
+
delete window[callbackName];
|
868
|
+
ajaxSuccess(data, xhr, options);
|
869
|
+
};
|
870
|
+
|
871
|
+
script.src = options.url.replace(/=\?/, '=' + callbackName);
|
872
|
+
$('head').append(script);
|
873
|
+
|
874
|
+
if (options.timeout > 0) abortTimeout = setTimeout(function(){
|
875
|
+
xhr.abort();
|
876
|
+
ajaxComplete(xhr, options, 'timeout');
|
877
|
+
}, options.timeout);
|
878
|
+
|
879
|
+
return xhr;
|
880
|
+
};
|
881
|
+
|
882
|
+
// ### $.ajaxSettings
|
883
|
+
//
|
884
|
+
// AJAX settings
|
885
|
+
//
|
886
|
+
$.ajaxSettings = {
|
887
|
+
// Default type of request
|
888
|
+
type: 'GET',
|
889
|
+
// Callback that is executed before request
|
890
|
+
beforeSend: empty,
|
891
|
+
// Callback that is executed if the request succeeds
|
892
|
+
success: empty,
|
893
|
+
// Callback that is executed the the server drops error
|
894
|
+
error: empty,
|
895
|
+
// Callback that is executed on request complete (both: error and success)
|
896
|
+
complete: empty,
|
897
|
+
// The context for the callbacks
|
898
|
+
context: null,
|
899
|
+
// Whether to trigger "global" Ajax events
|
900
|
+
global: true,
|
901
|
+
// Transport
|
902
|
+
xhr: function () {
|
903
|
+
return new window.XMLHttpRequest();
|
904
|
+
},
|
905
|
+
// MIME types mapping
|
906
|
+
accepts: {
|
907
|
+
script: 'text/javascript, application/javascript',
|
908
|
+
json: 'application/json',
|
909
|
+
xml: 'application/xml, text/xml',
|
910
|
+
html: 'text/html',
|
911
|
+
text: 'text/plain'
|
912
|
+
},
|
913
|
+
// Whether the request is to another domain
|
914
|
+
crossDomain: false,
|
915
|
+
// Default timeout
|
916
|
+
timeout: 0
|
917
|
+
};
|
918
|
+
|
919
|
+
// ### $.ajax
|
920
|
+
//
|
921
|
+
// Perform AJAX request
|
922
|
+
//
|
923
|
+
// *Arguments:*
|
924
|
+
//
|
925
|
+
// options — object that configure the request,
|
926
|
+
// see avaliable options below
|
927
|
+
//
|
928
|
+
// *Avaliable options:*
|
929
|
+
//
|
930
|
+
// type ('GET') — type of request GET / POST
|
931
|
+
// url (window.location) — url to which the request is sent
|
932
|
+
// data — data to send to server,
|
933
|
+
// can be string or object
|
934
|
+
// dataType ('json') — what response type you accept from
|
935
|
+
// the server:
|
936
|
+
// 'json', 'xml', 'html', or 'text'
|
937
|
+
// timeout (0) — request timeout
|
938
|
+
// beforeSend — callback that is executed before
|
939
|
+
// request send
|
940
|
+
// complete — callback that is executed on request
|
941
|
+
// complete (both: error and success)
|
942
|
+
// success — callback that is executed if
|
943
|
+
// the request succeeds
|
944
|
+
// error — callback that is executed if
|
945
|
+
// the server drops error
|
946
|
+
// context — in which context to execute the
|
947
|
+
// callbacks in
|
948
|
+
//
|
949
|
+
// *Example:*
|
950
|
+
//
|
951
|
+
// $.ajax({
|
952
|
+
// type: 'POST',
|
953
|
+
// url: '/projects',
|
954
|
+
// data: { name: 'Zepto.js' },
|
955
|
+
// dataType: 'html',
|
956
|
+
// timeout: 100,
|
957
|
+
// context: $('body'),
|
958
|
+
// success: function (data) {
|
959
|
+
// this.append(data);
|
960
|
+
// },
|
961
|
+
// error: function (xhr, type) {
|
962
|
+
// alert('Error!');
|
963
|
+
// }
|
964
|
+
// });
|
965
|
+
//
|
966
|
+
$.ajax = function(options){
|
967
|
+
var settings = $.extend({}, options || {});
|
968
|
+
for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key];
|
969
|
+
|
970
|
+
ajaxStart(settings);
|
971
|
+
|
972
|
+
if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) &&
|
973
|
+
RegExp.$2 != window.location.host;
|
974
|
+
|
975
|
+
if (/=\?/.test(settings.url)) return $.ajaxJSONP(settings);
|
976
|
+
|
977
|
+
if (!settings.url) settings.url = window.location.toString();
|
978
|
+
if (settings.data && !settings.contentType) settings.contentType = 'application/x-www-form-urlencoded';
|
979
|
+
if (isObject(settings.data)) settings.data = $.param(settings.data);
|
980
|
+
|
981
|
+
if (settings.type.match(/get/i) && settings.data) {
|
982
|
+
var queryString = settings.data;
|
983
|
+
if (settings.url.match(/\?.*=/)) {
|
984
|
+
queryString = '&' + queryString;
|
985
|
+
} else if (queryString[0] != '?') {
|
986
|
+
queryString = '?' + queryString;
|
987
|
+
}
|
988
|
+
settings.url += queryString;
|
989
|
+
}
|
990
|
+
|
991
|
+
var mime = settings.accepts[settings.dataType],
|
992
|
+
baseHeaders = { },
|
993
|
+
protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
|
994
|
+
xhr = $.ajaxSettings.xhr(), abortTimeout;
|
995
|
+
|
996
|
+
if (!settings.crossDomain) baseHeaders['X-Requested-With'] = 'XMLHttpRequest';
|
997
|
+
if (mime) baseHeaders['Accept'] = mime;
|
998
|
+
settings.headers = $.extend(baseHeaders, settings.headers || {});
|
999
|
+
|
1000
|
+
xhr.onreadystatechange = function(){
|
1001
|
+
if (xhr.readyState == 4) {
|
1002
|
+
clearTimeout(abortTimeout);
|
1003
|
+
var result, error = false;
|
1004
|
+
if ((xhr.status >= 200 && xhr.status < 300) || (xhr.status == 0 && protocol == 'file:')) {
|
1005
|
+
if (mime == 'application/json' && !(/^\s*$/.test(xhr.responseText))) {
|
1006
|
+
try { result = JSON.parse(xhr.responseText); }
|
1007
|
+
catch (e) { error = e; }
|
1008
|
+
}
|
1009
|
+
else result = xhr.responseText;
|
1010
|
+
if (error) ajaxError(error, 'parsererror', xhr, settings);
|
1011
|
+
else ajaxSuccess(result, xhr, settings);
|
1012
|
+
} else {
|
1013
|
+
ajaxError(null, 'error', xhr, settings);
|
1014
|
+
}
|
1015
|
+
}
|
1016
|
+
};
|
1017
|
+
|
1018
|
+
xhr.open(settings.type, settings.url, true);
|
1019
|
+
|
1020
|
+
if (settings.contentType) settings.headers['Content-Type'] = settings.contentType;
|
1021
|
+
for (name in settings.headers) xhr.setRequestHeader(name, settings.headers[name]);
|
1022
|
+
|
1023
|
+
if (ajaxBeforeSend(xhr, settings) === false) {
|
1024
|
+
xhr.abort();
|
1025
|
+
return false;
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
if (settings.timeout > 0) abortTimeout = setTimeout(function(){
|
1029
|
+
xhr.onreadystatechange = empty;
|
1030
|
+
xhr.abort();
|
1031
|
+
ajaxError(null, 'timeout', xhr, settings);
|
1032
|
+
}, settings.timeout);
|
1033
|
+
|
1034
|
+
xhr.send(settings.data);
|
1035
|
+
return xhr;
|
1036
|
+
};
|
1037
|
+
|
1038
|
+
// ### $.get
|
1039
|
+
//
|
1040
|
+
// Load data from the server using a GET request
|
1041
|
+
//
|
1042
|
+
// *Arguments:*
|
1043
|
+
//
|
1044
|
+
// url — url to which the request is sent
|
1045
|
+
// success — callback that is executed if the request succeeds
|
1046
|
+
//
|
1047
|
+
// *Example:*
|
1048
|
+
//
|
1049
|
+
// $.get(
|
1050
|
+
// '/projects/42',
|
1051
|
+
// function (data) {
|
1052
|
+
// $('body').append(data);
|
1053
|
+
// }
|
1054
|
+
// );
|
1055
|
+
//
|
1056
|
+
$.get = function(url, success){ return $.ajax({ url: url, success: success }) };
|
1057
|
+
|
1058
|
+
// ### $.post
|
1059
|
+
//
|
1060
|
+
// Load data from the server using POST request
|
1061
|
+
//
|
1062
|
+
// *Arguments:*
|
1063
|
+
//
|
1064
|
+
// url — url to which the request is sent
|
1065
|
+
// [data] — data to send to server, can be string or object
|
1066
|
+
// [success] — callback that is executed if the request succeeds
|
1067
|
+
// [dataType] — type of expected response
|
1068
|
+
// 'json', 'xml', 'html', or 'text'
|
1069
|
+
//
|
1070
|
+
// *Example:*
|
1071
|
+
//
|
1072
|
+
// $.post(
|
1073
|
+
// '/projects',
|
1074
|
+
// { name: 'Zepto.js' },
|
1075
|
+
// function (data) {
|
1076
|
+
// $('body').append(data);
|
1077
|
+
// },
|
1078
|
+
// 'html'
|
1079
|
+
// );
|
1080
|
+
//
|
1081
|
+
$.post = function(url, data, success, dataType){
|
1082
|
+
if ($.isFunction(data)) dataType = dataType || success, success = data, data = null;
|
1083
|
+
return $.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType });
|
1084
|
+
};
|
1085
|
+
|
1086
|
+
// ### $.getJSON
|
1087
|
+
//
|
1088
|
+
// Load JSON from the server using GET request
|
1089
|
+
//
|
1090
|
+
// *Arguments:*
|
1091
|
+
//
|
1092
|
+
// url — url to which the request is sent
|
1093
|
+
// success — callback that is executed if the request succeeds
|
1094
|
+
//
|
1095
|
+
// *Example:*
|
1096
|
+
//
|
1097
|
+
// $.getJSON(
|
1098
|
+
// '/projects/42',
|
1099
|
+
// function (json) {
|
1100
|
+
// projects.push(json);
|
1101
|
+
// }
|
1102
|
+
// );
|
1103
|
+
//
|
1104
|
+
$.getJSON = function(url, success){
|
1105
|
+
return $.ajax({ url: url, success: success, dataType: 'json' });
|
1106
|
+
};
|
1107
|
+
|
1108
|
+
// ### $.fn.load
|
1109
|
+
//
|
1110
|
+
// Load data from the server into an element
|
1111
|
+
//
|
1112
|
+
// *Arguments:*
|
1113
|
+
//
|
1114
|
+
// url — url to which the request is sent
|
1115
|
+
// [success] — callback that is executed if the request succeeds
|
1116
|
+
//
|
1117
|
+
// *Examples:*
|
1118
|
+
//
|
1119
|
+
// $('#project_container').get(
|
1120
|
+
// '/projects/42',
|
1121
|
+
// function () {
|
1122
|
+
// alert('Project was successfully loaded');
|
1123
|
+
// }
|
1124
|
+
// );
|
1125
|
+
//
|
1126
|
+
// $('#project_comments').get(
|
1127
|
+
// '/projects/42 #comments',
|
1128
|
+
// function () {
|
1129
|
+
// alert('Comments was successfully loaded');
|
1130
|
+
// }
|
1131
|
+
// );
|
1132
|
+
//
|
1133
|
+
$.fn.load = function(url, success){
|
1134
|
+
if (!this.length) return this;
|
1135
|
+
var self = this, parts = url.split(/\s/), selector;
|
1136
|
+
if (parts.length > 1) url = parts[0], selector = parts[1];
|
1137
|
+
$.get(url, function(response){
|
1138
|
+
self.html(selector ?
|
1139
|
+
$(document.createElement('div')).html(response).find(selector).html()
|
1140
|
+
: response);
|
1141
|
+
success && success.call(self);
|
1142
|
+
});
|
1143
|
+
return this;
|
1144
|
+
};
|
1145
|
+
|
1146
|
+
var escape = encodeURIComponent;
|
1147
|
+
|
1148
|
+
function serialize(params, obj, traditional, scope){
|
1149
|
+
var array = $.isArray(obj);
|
1150
|
+
$.each(obj, function(key, value) {
|
1151
|
+
if (scope) key = traditional ? scope : scope + '[' + (array ? '' : key) + ']';
|
1152
|
+
// handle data in serializeArray() format
|
1153
|
+
if (!scope && array) params.add(value.name, value.value);
|
1154
|
+
// recurse into nested objects
|
1155
|
+
else if (traditional ? $.isArray(value) : isObject(value))
|
1156
|
+
serialize(params, value, traditional, key);
|
1157
|
+
else params.add(key, value);
|
1158
|
+
});
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
// ### $.param
|
1162
|
+
//
|
1163
|
+
// Encode object as a string of URL-encoded key-value pairs
|
1164
|
+
//
|
1165
|
+
// *Arguments:*
|
1166
|
+
//
|
1167
|
+
// obj — object to serialize
|
1168
|
+
// [traditional] — perform shallow serialization
|
1169
|
+
//
|
1170
|
+
// *Example:*
|
1171
|
+
//
|
1172
|
+
// $.param( { name: 'Zepto.js', version: '0.6' } );
|
1173
|
+
//
|
1174
|
+
$.param = function(obj, traditional){
|
1175
|
+
var params = [];
|
1176
|
+
params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) };
|
1177
|
+
serialize(params, obj, traditional);
|
1178
|
+
return params.join('&').replace('%20', '+');
|
1179
|
+
};
|
1180
|
+
})(Zepto);
|
1181
|
+
// Zepto.js
|
1182
|
+
// (c) 2010, 2011 Thomas Fuchs
|
1183
|
+
// Zepto.js may be freely distributed under the MIT license.
|
1184
|
+
|
1185
|
+
// The following code is heavily inspired by jQuery's $.fn.data()
|
1186
|
+
|
1187
|
+
(function($) {
|
1188
|
+
var data = {}, dataAttr = $.fn.data,
|
1189
|
+
uuid = $.uuid = +new Date(),
|
1190
|
+
exp = $.expando = 'Zepto' + uuid;
|
1191
|
+
|
1192
|
+
function getData(node, name) {
|
1193
|
+
var id = node[exp], store = id && data[id];
|
1194
|
+
return name === undefined ? store || setData(node) :
|
1195
|
+
(store && store[name]) || dataAttr.call($(node), name);
|
1196
|
+
}
|
1197
|
+
|
1198
|
+
function setData(node, name, value) {
|
1199
|
+
var id = node[exp] || (node[exp] = ++uuid),
|
1200
|
+
store = data[id] || (data[id] = {});
|
1201
|
+
if (name !== undefined) store[name] = value;
|
1202
|
+
return store;
|
1203
|
+
};
|
1204
|
+
|
1205
|
+
$.fn.data = function(name, value) {
|
1206
|
+
return value === undefined ?
|
1207
|
+
this.length == 0 ? undefined : getData(this[0], name) :
|
1208
|
+
this.each(function(idx){
|
1209
|
+
setData(this, name, $.isFunction(value) ?
|
1210
|
+
value.call(this, idx, getData(this, name)) : value);
|
1211
|
+
});
|
1212
|
+
};
|
1213
|
+
})(Zepto);
|