| 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536 |
1
1
1
1
1
1
1
20
20
1
12
1
5
1
4
4
4
8
7
4
1
9
1
8
8
8
8
8
8
8
1
1
1
4
4
4
1
4
4
4
4
4
1
4
4
1
4
1
1
1
4
2
4
4
1
1
1
2
2
1
1
1
1
1
4
2
1
1
6
1
1
1
2
1
1
1
1
1
4
4
4
4
12
4
4
4
1
1
4
4
1
3
3
3
2
2
1
1
5
5
1
4
4
1
1
1
6
6
6
6
6
6
6
3
3
12
11
11
4
7
3
2
1
4
2
2
2
1
1
1
4
1
2
2
2
2
1
1
1
2
1
2
2
2
1
2
1
1
1
2
1
640
1
1
1
1
1
1
3
3
641
641
641
1
641
641
641
641
1
1
1
1
220
220
220
1
1
420
420
420
1
1
1
2
8
1
1
8
8
2
2
16
16
16
8
8
3
3
3
1
3
3
3
3
7
7
7
7
1
1
1
1
1
1
1
| /*global define */
(function(global, factory) {
"use strict";
Iif (typeof module === "object" && typeof module.exports === "object") {
module.exports = global.document ?
factory(global, true) :
function(w) {
if (!w.document) {
throw new Error("jQuery requires a window with a document");
}
return factory(w);
};
} else {
factory(global);
}
}(typeof window !== "undefined" ? window : this, function(window, noGlobal) {
'use strict';
var Lettuce = function() {};
Lettuce.VERSION = '0.2.3';
window.lettuce = Lettuce;
/* (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Underscore may be freely distributed under the MIT license.
*/
Lettuce.isObject = function (obj) {
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
};
Lettuce.isFunction = function(obj) {
return typeof obj == 'function' || false;
};
Lettuce.defaults = function(obj) {
if (!Lettuce.isObject(obj)) {
return obj;
}
for (var i = 1, length = arguments.length; i < length; i++) {
var source = arguments[i];
for (var prop in source) {
if (obj[prop] === void 0) {
obj[prop] = source[prop];
}
}
}
return obj;
};
Lettuce.extend = function (obj) {
if (!Lettuce.isObject(obj)) {
return obj;
}
var source, prop;
for (var i = 1, length = arguments.length; i < length; i++) {
source = arguments[i];
for (prop in source) {
Eif (hasOwnProperty.call(source, prop)) {
obj[prop] = source[prop];
}
}
}
return obj;
};
/**
* Lettuce Class 0.0.1
* JavaScript Class built-in inheritance system
*(c) 2015, Fengda Huang - http://www.phodal.com
*
* Copyright (c) 2011, 2012 Jeanine Adkisson.
* MIT Licensed.
* Inspired by https://github.com/munro/self, https://github.com/jneen/pjs
*/
Lettuce.prototype.Class = (function (prototype, ownProperty) {
var lettuceClass = function Klass(_superclass, definition) {
function Class() {
var self = this instanceof Class ? this : new Basic();
self.init.apply(self, arguments);
return self;
}
function Basic() {
}
Class.Basic = Basic;
var _super = Basic[prototype] = _superclass[prototype];
var proto = Basic[prototype] = Class[prototype] = new Basic();
proto.constructor = Class;
Class.extend = function (def) {
return new Klass(Class, def);
};
var open = (Class.open = function (def) {
if (Lettuce.isFunction(def)) {
def = def.call(Class, proto, _super, Class, _superclass);
}
if (Lettuce.isObject(def)) {
for (var key in def) {
Eif (ownProperty.call(def, key)) {
proto[key] = def[key];
}
}
}
if (!('init' in proto)) {
proto.init = _superclass;
}
return Class;
});
return (open)(definition);
};
return lettuceClass;
})('prototype', ({}).hasOwnProperty);
var Parser = new Lettuce.prototype.Class({});
Parser.prototype.init = function (options) {
this.options = options || {};
Lettuce.defaults(this.options, {
first: 'first',
regex: /.*Page/,
last: 'last'
});
};
Parser.prototype.run = function (methods) {
var self = this;
self.methods = methods;
self.execute(self.options.first);
for (var key in self.methods) {
if (key !== self.options.last && key.match(self.options.regex)) {
this.execute(key);
}
}
self.execute(self.options.last);
};
Parser.prototype.execute = function (methodName) {
this.methods[methodName]();
};
var parser = {
Parser: Parser
};
Lettuce.prototype = Lettuce.extend(Lettuce.prototype, parser);
Lettuce.get = function (url, callback) {
Lettuce.send(url, 'GET', callback);
};
Lettuce.load = function (url, callback) {
Lettuce.send(url, 'GET', callback);
};
Lettuce.post = function (url, data, callback) {
Lettuce.send(url, 'POST', callback, data);
};
Lettuce.send = function (url, method, callback, data) {
data = data || null;
var request = new XMLHttpRequest();
Eif (callback instanceof Function) {
request.onreadystatechange = function () {
if (request.readyState === 4 && (request.status === 200 || request.status === 0)) {
callback(request.responseText);
}
};
}
request.open(method, url, true);
if (data instanceof Object) {
data = JSON.stringify(data);
request.setRequestHeader('Content-Type', 'application/json');
}
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
request.send(data);
};
var Event = {
on: function(event, callback){
this._events = this._events || {};
this._events[event] = this._events[event] || [];
this._events[event].push(callback);
},
off: function(event, callback){
this._events = this._events || {};
if (event in this._events === false) {
return;
}
this._events[event].splice(this._events[event].indexOf(callback), 1);
},
trigger: function(event){
this._events = this._events || {};
if (event in this._events === false) {
return;
}
for (var i = 0; i < this._events[event].length; i++) {
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
}
}
};
var event = {
Event: Event
};
Lettuce.prototype = Lettuce.extend(Lettuce.prototype, event);
/*
* JavaScript Templates 2.4.1
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*
* Inspired by John Resig's JavaScript Micro-Templating:
* http://ejohn.org/blog/javascript-micro-templating/
*/
/*jslint evil: true, regexp: true, unparam: true */
var Template = {
regexp: /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,
encReg: /[<>&"'\x00]/g,
encMap: {
"<": "<",
">": ">",
"&": "&",
"\"": """,
"'": "'"
},
arg: "o",
helper: ",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
",include=function(s,d){_s+=tmpl(s,d);}",
tmpl: function (str, data){
var f = !/[^\w\-\.:]/.test(str) ? "" : this.compile(str);
return f(data, this);
},
compile: function (str) {
var fn, variable;
variable = this.arg + ',tmpl';
fn = "var _e=tmpl.encode" + this.helper + ",_s='" + str.replace(this.regexp, this.func) + "';";
fn = fn + "return _s;";
return new Function(variable, fn);
},
encode: function (s) {
/*jshint eqnull:true */
var encodeRegex = /[<>&"'\x00]/g,
encodeMap = {
"<": "<",
">": ">",
"&": "&",
"\"": """,
"'": "'"
};
return (s == null ? "" : "" + s).replace(
encodeRegex,
function (c) {
return encodeMap[c] || "";
}
);
},
func: function (s, p1, p2, p3, p4, p5) {
var specialCharMAP = {
"\n": "\\n",
"\r": "\\r",
"\t": "\\t",
" ": " "
};
if (p1) { // whitespace, quote and backspace in HTML context
return specialCharMAP[p1] || "\\" + p1;
}
if (p2) { // interpolation: {%=prop%}, or unescaped: {%#prop%}
if (p2 === "=") {
return "'+_e(" + p3 + ")+'";
}
return "'+(" + p3 + "==null?'':" + p3 + ")+'";
}
if (p4) { // evaluation start tag: {%
return "';";
}
Eif (p5) { // evaluation end tag: %}
return "_s+='";
}
}
};
var template = {
Template: Template
};
Lettuce.prototype = Lettuce.extend(Lettuce.prototype, template);
/*
* Copyright 2012-2013 (c) Pierre Duquesne <stackp@online.fr>
* Licensed under the New BSD License.
* https://github.com/stackp/promisejs
*/
function Promise() {
this._callbacks = [];
}
Promise.prototype.then = function(func, context) {
var p;
Iif (this._isdone) {
p = func.apply(context, this.result);
} else {
p = new Promise();
this._callbacks.push(function () {
var res = func.apply(context, arguments);
Eif (res && typeof res.then === 'function') {
res.then(p.done, p);
}
});
}
return p;
};
Promise.prototype.done = function() {
this.result = arguments;
this._isdone = true;
for (var i = 0; i < this._callbacks.length; i++) {
this._callbacks[i].apply(null, arguments);
}
this._callbacks = [];
};
var promise = {
Promise: Promise
};
Lettuce.prototype = Lettuce.extend(Lettuce.prototype, promise);
var FX = {
easing: {
linear: function(progress) {
return progress;
},
quadratic: function(progress) {
return Math.pow(progress, 2);
},
swing: function(progress) {
return 0.5 - Math.cos(progress * Math.PI) / 2;
},
circ: function(progress) {
return 1 - Math.sin(Math.acos(progress));
},
back: function(progress, x) {
return Math.pow(progress, 2) * ((x + 1) * progress - x);
},
bounce: function(progress) {
for (var a = 0, b = 1; 1; a += b, b /= 2) {
Eif (progress >= (7 - 4 * a) / 11) {
return -Math.pow((11 - 6 * a - 11 * progress) / 4, 2) + Math.pow(b, 2);
}
}
},
elastic: function(progress, x) {
return Math.pow(2, 10 * (progress - 1)) * Math.cos(20 * Math.PI * x / 3 * progress);
}
},
animate: function(options) {
var start = new Date();
var id = setInterval(function() {
var timePassed = new Date() - start;
var progress = timePassed / options.duration;
if (progress > 1) {
progress = 1;
}
options.progress = progress;
var delta = options.delta(progress);
options.step(delta);
if (progress == 1) {
clearInterval(id);
options.complete();
}
}, options.delay || 10);
},
fadeOut: function(element, options) {
var to = 1;
this.animate({
duration: options.duration,
delta: function(progress) {
progress = this.progress;
return FX.easing.swing(progress);
},
complete: options.complete,
step: function(delta) {
element.style.opacity = to - delta;
}
});
},
fadeIn: function(element, options) {
var to = 0;
this.animate({
duration: options.duration,
delta: function(progress) {
progress = this.progress;
return FX.easing.swing(progress);
},
complete: options.complete,
step: function(delta) {
element.style.opacity = to + delta;
}
});
}
};
var fx = {
FX: FX
};
Lettuce.prototype = Lettuce.extend(Lettuce.prototype, fx);
/*
*Inspired by http://krasimirtsonev.com/blog/article/A-modern-JavaScript-router-in-100-lines-history-api-pushState-hash-url
* Backbone
*/
var Router = {
routes: [],
hashStrip: /^#*/,
location: window.location,
getFragment: function () {
return (this.location).hash.replace(this.hashStrip, '');
},
add: function (regex, handler) {
if (Lettuce.isFunction(regex)) {
handler = regex;
regex = '';
}
this.routes.push({regex: regex, handler: handler});
return this;
},
check: function (self) {
var fragment = self.getFragment();
for (var i = 0; i < self.routes.length; i++) {
var newFragment = "#" + fragment;
var match = newFragment.match(self.routes[i].regex);
if (match) {
match.shift();
self.routes[i].handler.apply({}, match);
}
}
},
load: function () {
var self, checkUrl;
self = this;
checkUrl = function () {
self.check(self);
};
function addEventListener() {
Eif (window.addEventListener) {
window.addEventListener("hashchange", checkUrl, false);
}
else if (window.attachEvent) {
window.attachEvent("onhashchange", checkUrl);
}
}
addEventListener();
return this;
},
navigate: function (path) {
path = path ? path : '';
this.location.href.match(/#(.*)$/);
this.location.href = this.location.href.replace(/#(.*)$/, '') + '#' + path;
return this;
}
};
var router = {
Router: Router
};
Lettuce.prototype = Lettuce.extend(Lettuce.prototype, router);
Iif (typeof define === "function" && define.amd) {
define("lettuce", [], function () {
return Lettuce;
});
}
var strundefined = typeof undefined;
Eif (typeof noGlobal === strundefined) {
window.Lettuce = Lettuce;
}
return Lettuce;
}));
|