-
Notifications
You must be signed in to change notification settings - Fork 1
/
gecko.js
executable file
·1514 lines (1498 loc) · 47 KB
/
gecko.js
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function( window, undefined ) {
"use strict"
var document = window.document;
//navigator = window.navigator,
//location = window.location;
var gecko = (function() {
//cxt could be context or false to clean up the cache
var gecko = function( sel, cxt ) {
//jquery style
return new gecko.fn.init( sel, cxt, rGk );
},
//no conflict vars
_gecko = window.gecko,
_gk = window.gk,
//gecko parent pointer
rGk,
//userAgent = navigator.userAgent,
//ready list
rL,
//DOMContentLoaded
DCL,
//local pointers... faster
toString = Object.prototype.toString,
push = Array.prototype.push,
//fallback function
fallback = function (name, fallback) {
var nativeFn = Array.prototype[name];
return function (obj, iterator, memo) {
var fn = obj ? obj[name]: 0;
return fn && fn === nativeFn ?
fn.call(obj, iterator, memo):
fallback(obj, iterator, memo);
};
},
slice = Array.prototype.slice;
gecko.fn = gecko.prototype = {
constructor: gecko,
init: function( sel, cxt, rGk ) {
//no selector gk(), gk('')
if ( !sel ) {
return this;
}
//dom element
if ( sel.nodeType ) {
this.cxt = this[0] = sel;
this.length = 1;
return this;
}
//gk(function(){}) ready shorthand
if ( gecko.isF( sel ) ) {
return rGk.ready( sel );
}
//local vars
var i=-1, nodes = [],c, ce;
var doc = cxt ? (!cxt.pop ? [cxt] : (typeof cxt === 'object' ? cxt : [document] )): [document];
//if false, clear cache if not we have context
if (typeof cxt !== 'object'){
ce = cxt === false ? cxt : true;
}
//check caches
while(c=doc[++i]){
if (gecko.cache[c] && gecko.cache[c][sel] && ce ){
//we got something, return cached
if (gecko.cache[c][sel].length < 1){
return undefined;
}
if (gecko.cache[c][sel][1]){
nodes = gecko.cache[c][sel];
} else {
nodes = gecko.cache[c][sel];
}
if (nodes[1]){
return gecko.makeArray( nodes, this );
}else{
this.length = nodes.length;
this[0] = nodes[0];
return this;
}
}
}
//selector its a gk object
if ( sel.ctx !== undefined ) {
this.ctx = sel.ctx;
return gecko.makeArray( sel, this );
}
//start selector
i= -1;
while(c=doc[++i]){
// apply querySelector if exists
if (c['querySelectorAll']) {
gecko.sets = c['querySelectorAll'](sel);
} else if (cxt && cxt[0]) {
//context its a gk object, get the element only
return gk(sel, (cxt[0]));
} else {
switch (sel) {
//return some simple and fast cases
case 'a':
gecko.sets = c.links ? c.links : c['getElementsByTagName']('a');
break;
case 'body':
gecko.sets = c.body;
break;
case 'form':
gecko.sets = c.forms ? c.forms : c['getElementsByTagName']('form');
break;
case 'head':
gecko.sets = c['getElementsByTagName']('head')[0];
break;
case 'img':
gecko.sets = c.images ? c.images : c['getElementsByTagName']('img');
break;
case 'title':
gecko.sets = c.title;
break;
// generic case
default:
// split selectors by comma -- to from initial groups of elements
var groups = sel.split(/, */),
groups_length = groups.length - 1,
j = -1;
while (j++ < groups_length) {
// split selectors by space -- to form groups tag-id-class
var singles = groups[j].split(/ +/),
singles_length = singles.length - 1,
i = -1,
level = 0;
// clean nodes with DOM root
gecko.nodes = c;
while (i++ < singles_length) {
/* inspired with John's Resig fast replace implementation,
more details:
http://ejohn.org/blog/search-and-dont-replace/
http://webo.in/articles/habrahabr/40-search-not-replace/
*/
singles[i].replace(/([^\.#]+)?(?:#([^\.#]+))?(?:\.([^\.#]+))?/, function(a, tag, id, klass) {
// fast check for ID
if (tag == '' && klass == '' && !level) {
gecko.nodes = c[0 ? 'all' : 'getElementById'](id);
} else {
// fast check for TAG
if (klass == '' && id == '' && !level) {
gecko.nodes = c['getElementsByTagName'](tag);
// generic sel to get element by TAG, CLASS, ID
} else {
// array to merge results
var newNodes = [],
// length of root nodes
nodes_length = gecko.nodes.length,
J = -1,
// iterator of return array, equals to its length
idx = 0;
// if root is single -- just make it as an array
if (!nodes_length) {
gecko.nodes = [gecko.nodes[0]?gecko.nodes[0]:gecko.nodes];
gecko.nodes.length = 1;
nodes_length = 1;
}
while (J++ < nodes_length) {
var node = gecko.nodes[J];
if (node) {
// find all TAGs
var childs = node['getElementsByTagName'](tag ? tag : '*'),
childs_length = childs.length - 1,
h = -1;
while (h++ < childs_length) {
var child = childs[h];
// check them for ID or CLASS
if ((!id || (id && child.id == id)) && (!klass || (klass && child.className.match(klass)))) {
// add to result array
newNodes.push(child);
}
}
}
}
// put selected nodes in local nodes' set
gecko.nodes = newNodes;
}
}
// dirty iterator to prevent choosing document for deep elements
level++;
});
// remember selected nodes to global set to start new selection
if (groups_length) {
var nodes_length = gecko.nodes.length - 1,
K = -1,
idx = gecko.sets ? gecko.sets.length : 0;
gecko.sets = gecko.sets ? gecko.sets : {};
while (K++ < nodes_length) {
gecko.sets[idx++] = gecko.nodes[K];
}
gecko.sets.length = idx;
// or just copy nodes to this set
}
}
}
gecko.sets = gecko.sets ? gecko.sets : gecko.nodes;
break;
}
}
// save result in cache
if (!gecko.cache[c]){
gecko.cache[c] = [];
}
if (!gecko.cache[c][sel]){
gecko.cache[c][sel] = [];
}
gecko.cache[c][sel] = gecko.sets;
// clear all properties to prevent memory leaks
gecko.sets = gecko.nodes = null;
// return saved result
if (gecko.cache[c][sel].length < 1){
return undefined;
}else{
if (gecko.cache[c][sel][1]){
nodes = gecko.cache[c][sel];
} else {
nodes = gecko.cache[c][sel];
}
}
}
//return nodes with the object
if (nodes[1]){
return gecko.makeArray( nodes, this );
}else{
this.length = nodes.length;
this[0] = nodes[0];
return this;
}
},
//local each
each: function( callback, args ) {
return gecko.each( this, callback, args );
},
//version
gecko: "0.0.1",
//local length
length: 0,
//ready function
ready: function( fn ) {
// Attach the listeners
gecko.bindReady();
// Add the callback
rL.add( fn );
return this;
},
// For internal use only.
// Behaves like an Array's method, not like a gecko method.
push: push,
sort: [].sort,
splice: [].splice
};
//prototyping
gecko.fn.init.prototype = gecko.fn;
//extend function
gecko.extend = gecko.fn.extend = function() {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !gecko.isF(target) ) {
target = {};
}
// extend gecko itself if only one argument is passed
if ( length === i ) {
target = this;
--i;
}
for ( ; i < length; i++ ) {
// Only deal with non-null/undefined values
if ( (options = arguments[ i ]) != null ) {
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];
// Prevent never-ending loop
if ( target === copy ) {
continue;
}
// Recurse if we're merging plain objects or arrays
if ( deep && copy && ( gecko.isPlainObject(copy) || (copyIsArray = gecko.isArray(copy)) ) ) {
if ( copyIsArray ) {
copyIsArray = false;
clone = src && gecko.isArray(src) ? src : [];
} else {
clone = src && gecko.isPlainObject(src) ? src : {};
}
// Never move original objects, clone them
target[ name ] = gecko.extend( deep, clone, copy );
// Don't bring in undefined values
} else if ( copy !== undefined ) {
target[ name ] = copy;
}
}
}
}
// Return the modified object
return target;
};
//extend base object
gecko.extend({
//no conflict stuff
noConflict: function( deep ) {
if ( window.gk === gecko ) {
window.gk = _gk;
}
if ( deep && window.gecko === gecko ) {
window.gecko = _gecko;
}
return gecko;
},
isReady: false,
readyWait: 1,
// current set of nodes, to handle single selectors
nodes : null,
// current sets of nodes, to handle comma-separated selectors
sets : null,
// cache for selected nodes
cache : {},
ready: function( wait ) {
// Either a released hold or an DOMready/load event and not yet ready
if ( (wait === true && !--gecko.readyWait) || (wait !== true && !gecko.isReady) ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( gecko.ready, 1 );
}
// Remember that the DOM is ready
gecko.isReady = true;
// If a normal DOM Ready event fired, decrement, and wait if need be
if ( wait !== true && --gecko.readyWait > 0 ) {
return;
}
// If there are functions bound, to execute
rL.fireWith( document, [ gecko ] );
// Trigger any bound ready events
if ( gecko.fn.trigger ) {
gecko( document ).trigger( "ready" ).off( "ready" );
}
}
},
bindReady: function() {
if ( rL ) {
return;
}
rL = gecko.Callbacks( "once memory" );
// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
if ( document.readyState === "complete" ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
return setTimeout( gecko.ready, 1 );
}
// Mozilla, Opera and webkit nightlies currently support this event
if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", DCL, false );
// A fallback to window.onload, that will always work
window.addEventListener( "load", gecko.ready, false );
// If IE event model is used
} else if ( document.attachEvent ) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent( "onreadystatechange", DCL );
// A fallback to window.onload, that will always work
window.attachEvent( "onload", gecko.ready );
// If IE and not a frame
// continually check to see if the document is ready
var toplevel = false;
try {
toplevel = window.frameElement == null;
} catch(e) {}
if ( document.documentElement.doScroll && toplevel ) {
doScrollCheck();
}
}
},
merge: function( first, second ) {
//merge objects
var i = first.length,
j = 0;
if ( typeof second.length === "number" ) {
for ( var l = second.length; j < l; j++ ) {
first[ i++ ] = second[ j ];
}
} else {
while ( second[j] !== undefined ) {
first[ i++ ] = second[ j++ ];
}
}
first.length = i;
return first;
},
makeArray: function( array, results ) {
//make object an array
var ret = results || [];
if ( array != null ) {
// The window, strings (and functions) also have 'length'
// Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
var type = gecko.type( array );
if ( array.length == null || type === "string" || type === "function" || type === "regexp" || gecko.isWindow( array ) ) {
push.call( ret, array );
} else {
gecko.merge( ret, array );
}
}
return ret;
},
isWindow: function( obj ) {
return obj && typeof obj === "object" && "setInterval" in obj;
},
each: function(o, c, a, z) {
// If not an Array or Object (which would both be object - or function, because Safari's node Collections are!),
// we cannot iterate
// first value===true -> run on a copy of the object
if (o===true) { return gecko.each(gecko.extend(z||c instanceof Array?[]:{},c), a, z); }
// if we haven't got anything to iterate, return
if (!o||!o.length&&!o.hasOwnProperty) { return o; }
// Get length of an Array
var l=o.length||0, a=a||(l===undefined || gecko.isF(o) || (o instanceof Object && !gecko.isArray(o))), i=0;
// We use call to set this to the object we iterate over, thus we can manipulate it within the callback
// Iterate Array over a counter
if (a) {
if (o.gecko){
for (;i<l;) {
if ( c.call(o[i], i, o[i++]) === false ) {
break;
}
}
}else{
for (var k in o) {
if ( c.call(o[k], k, o[k]) === false ){ break }
}
}
}
// Iterate Object over its Instances (hasOwnProperty to avoid the prototype)
else {
for (;i<l;) {
if ( c.call(o, i, o[i++]) === false ) {
break;
}
}
}
return o;
},
//is function
isF: function( obj ) {
return gecko.type(obj) === "function";
},
//is array
isArray: Array.isArray || function( obj ) {
return gecko.type(obj) === "array";
},
//type of object
type: function( obj ) {
if (obj == null) { return String( obj ) };
return toString.call(obj).match(/^\[object (.*)\]$/)[1].toLowerCase();
},
browser: {},
/*
basic yet powerful event system
t.e([node(s):DOM Node|Array], [eventname:String, optional], [callback:Function, this=node, arguments=[event object], optional], [remove:Boolean=true, optional]);
// even if no callback is given, the event array is returned
// if no eventname is given, the whole event object is returned
// Basic event handler
t.eh([event:Event Object, this=node])
// To trigger an event object, use "t.eh.call(node, event)"
TODO: normalized events (mouseenter/leave)
*/
e: function(n, e, c, r) {
// Handle Node Collections
if (!n.nodeName && n.length) { return gecko.each(n, function(i, o) { gecko.extend(o, e, c, r); }, true); }
// Define Events Object, if not present
if (!n.ev) { n.ev={}; }
// return full object if event name is omitted
if (e===undefined) { return n.ev; }
// create Event array / handler if not present (and fill it with the current event)
if (!n.ev[e]) { n.ev[e]=[]; if (typeof(n['on'+e])==='function') { n.ev[e].push(n['on'+e]); }; }
if (n['on'+e]!==gecko.eh) { n['on'+e]=gecko.eh; }
// add callback if present or delete if r is set
if (c!==undefined) {
if (r) { n.ev[e]=gecko.f(n.ev[e], function(gecko, x) { return c===x?u:x; }, true); }
else { n.ev[e].push(c); }
}
return n.ev[e];
},
// Event Handler
eh : function(o) {
// normalize event;
var e=(o||window.event), D=document.documentElement, n=this;
gecko.extend(e, {key: (e.which||e.keyCode||e.charCode), ts: (new Date())*1, mouseX: (e.clientX||0)+(window.pageXOffset||D.scrollLeft||0), mouseY: (e.clientY||0)+(window.pageYOffset||D.scrollTop||0)});
if (!e.target) { e.target=e.srcElement||document; }
// iterate over event array
gecko.each((n.ev||{})[e.type], function(i, c) {
if (typeof c==='function') {
c.call(n, e);
}
});
},
//where is in the array
w:function(x, a) {
var l=a.length;
while (l>-1&&a[--l]!==x);
return l;
},
//filter
f:function(o, c, y) {
if (!o) { return o; }
// find whether we have an array or an object and a callback function or comparative object
var y=y||o instanceof Array;
// if no callback or comparable object is defined, we predefine a unique function
if (c===undefined) { y=true; var c=function(i, v) { var l=i; while (--l>=0) { if (this[l]===v) { return undefined; }}; return v; } }
// Instanciate result Object/Array
var r=(y ? [] : {});
// Iterate over the original Object, if return value is not undefined, add instance to result
gecko.each(o, function(k, v) { if ((c.call(o, k, v))!==undefined) {
if (y) { r.push(v); } else { r[k]=v; }
}}, y);
return r;
},
//cookies
ce: function(o) {
// Get cookie via RegExp
if (typeof(o)==='string') { (new RegExp('(^|[ ;])'+escape(o)+'=([^;]+)')).exec(document.cookie); return unescape(RegExp.$2); }
// otherwise Asseble Cookie
if (o.name && o.value) { document.cookie=escape(o.name)+'='+escape(o.value)+(o.date?('; expires='+(o.date instanceof Date?o.date:new Date(new Date()*1+o.date)).toGMTString()):'')+(o.domain?('; domain='+o.domain):'')+(o.path?'; path='+o.path:'')+(o.extra||'')+';'; }
},
//parrallel functionality
parallel : function (fns, callback) {
var results = new fns.constructor();
gecko.eachParallel(fns, function (fn, k, cb) {
fn(function (err) {
var v = Array.prototype.slice.call(arguments, 1);
results[k] = v.length <= 1 ? v[0]: v;
cb(err);
});
}, function (err) {
(callback || function () {})(err, results);
});
},
//serial functionality
series : function (fns, callback) {
var results = new fns.constructor();
gecko.eachSeries(fns, function (fn, k, cb) {
fn(function (err, result) {
var v = Array.prototype.slice.call(arguments, 1);
results[k] = v.length <= 1 ? v[0]: v;
cb(err);
});
}, function (err) {
(callback || function () {})(err, results);
});
},
//each in parallel
eachParallel : function (obj, iterator, callback) {
var len = obj.length || gecko.keys(obj).length;
if (!len) {
return callback();
}
var completed = 0;
gecko.eachSync(obj, function () {
var cb = function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
if (++completed === len) {
callback();
}
}
};
var args = Array.prototype.slice.call(arguments);
if (iterator.length) {
args = args.slice(0, iterator.length - 1);
args[iterator.length - 1] = cb;
}
else {
args.push(cb);
}
iterator.apply(this, args);
});
},
//each sync
eachSync : fallback('forEach', function (obj, iterator) {
var isObj = obj instanceof Object;
var arr = isObj ? gecko.keys(obj): (obj || []);
for (var i = 0, len = arr.length; i < len; i++) {
var k = isObj ? arr[i]: i;
iterator(obj[k], k, obj);
}
}),
//get all keys
keys : Object.keys || function (obj) {
var results = [];
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
results.push(k);
}
}
return results;
},
//each serial
eachSeries : function (obj, iterator, callback) {
var keys_list = gecko.keys(obj);
if (!keys_list.length) {
return callback();
}
var completed = 0;
var iterate = function () {
var k = keys_list[completed];
var args = [obj[k], k, obj].slice(0, iterator.length - 1);
args[iterator.length - 1] = function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
if (++completed === keys_list.length) {
callback();
}
else {
iterate();
}
}
};
iterator.apply(this, args);
};
iterate();
},
/*
JS/JSONp: load additional JavaScript / loads informations via JSONp
unnamed functions will be temporarily named; name will be deleted for security reasons after 1 s (past timeout)
t.j([url:String], [callback:String(Function name), Function], [timeout,Integer(ms, optional)]);
*/
j: function(u,c,t){
var f=typeof c==='function';
// Name function if unnamed
if (f) { window[(f='fn'+(Math.random()*1E8|0)+(new Date()*1))]=function(c){ return c; }(c); c=f; }
// Create Script-Element with url and add it to body
var s=document.createElement('script');
s.type='text/javascript';
s.src=u+(c||'');
document.body.appendChild(s);
// Timeout
if (t) { window.setTimeout(function() { document.body.removeChild(s); }, t); }
// Remove formerly unnamed function's name
if (f) { window.setTimeout(function() { delete window[c]; }, (t||0)+5000); }
},
/*
ajax:
t.a({
url:[url:String],
method:[method:String,(GET|POST), optional],
data:[postdata:String|Object, optional],
type:[response Object:String(Text, Xml, ...), optional],
async:[callback:Function, optional]
});
*/
a: function(o) {
// create XMLHttpRequest or leave
var x=(window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"));
if (!x) { return false; }
// Open Request
x.open(o.method||'GET', o.url, !!o.async, o.user, o.pass);
// Send data
x.send(o.data?(typeof o.data==='object'?gecko.p(o.data):o.data):null);
// if not async, return result
if (!o.async) { return o.type===true?x:x['response'+o.type||'Text']; }
// if async, set result handler function
x.onreadystatechange=function(e) { if (x.readyState===4) { o.async.call(x,x['response'+o.type||'Text']); } }
// return Request object
return x;
},
/*
parametrize
t.p([object:Object], [middle:String, optional], [connector:String, optional], [prefix:String, optional], [suffix:String, optional], [filter1:Function, optional], [filter2:Function, optional]);
// Defaults (without anything but "o" results in URL parameterisation
*/
p: function(o, m, c, p, s, f1, f2) {
// instance => prefix+filtered key+middle+filtered value+suffix; instance + connector + instance => result
var r=[];
t.i(o, function(k, v) { r.push((p===u?'':p)+(f1||escape)(k)+(m===u?'=':m)+(f2||escape)(v)+(s===u?'':s)); });
return r.join(c===u?'&':c);
},
//date format
df: (function () {
function strMonth(value) {
switch (parseInt(value)) {
case 1:
return "Jan";
case 2:
return "Feb";
case 3:
return "Mar";
case 4:
return "Apr";
case 5:
return "May";
case 6:
return "Jun";
case 7:
return "Jul";
case 8:
return "Aug";
case 9:
return "Sep";
case 10:
return "Oct";
case 11:
return "Nov";
case 12:
return "Dec";
default:
return value;
}
}
var parseMonth = function (value) {
switch (value) {
case "Jan":
return "01";
case "Feb":
return "02";
case "Mar":
return "03";
case "Apr":
return "04";
case "May":
return "05";
case "Jun":
return "06";
case "Jul":
return "07";
case "Aug":
return "08";
case "Sep":
return "09";
case "Oct":
return "10";
case "Nov":
return "11";
case "Dec":
return "12";
default:
return value;
}
};
var parseTime = function (value) {
var retValue = value, hour,
minute, second;
if (retValue.indexOf(".") !== -1) {
retValue = retValue.substring(0, retValue.indexOf("."));
}
var values3 = retValue.split(":");
if (values3.length === 3) {
hour = values3[0];
minute = values3[1];
second = values3[2];
return {
time: retValue,
hour: hour,
minute: minute,
second: second
};
} else {
return {
time: "",
hour: "",
minute: "",
second: ""
};
}
};
return {
date: function (value, format) {
//value = new java.util.Date()
//2009-12-18 10:54:50.546
try {
var year = null,month = null,
dayOfMonth = null, time = null;
var time = null; //json, time, hour, minute, second
if (typeof value.getFullYear === "function") {
year = value.getFullYear();
month = value.getMonth() + 1;
dayOfMonth = value.getDate();
time = parseTime(value.toTimeString());
} else if (value.search(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.?\d{0,3}\+\d{2}:\d{2}/) != -1) { // 2009-04-19T16:11:05+02:00
var values = value.split(/[T\+-]/);
year = values[0];
month = values[1];
dayOfMonth = values[2];
time = parseTime(values[3].split(".")[0]);
} else {
var values = value.split(" ");
switch (values.length) {
case 6: //Wed Jan 13 10:43:41 CET 2010
year = values[5];
month = parseMonth(values[1]);
dayOfMonth = values[2];
time = parseTime(values[3]);
break;
case 2: //2009-12-18 10:54:50.546
var values2 = values[0].split("-");
year = values2[0];
month = values2[1];
dayOfMonth = values2[2];
time = parseTime(values[1]);
break;
case 7: // Tue Mar 01 2011 12:01:42 GMT-0800 (PST)
case 9: //added by Larry, for Fri Apr 08 2011 00:00:00 GMT+0800 (China Standard Time)
case 10: //added by Larry, for Fri Apr 08 2011 00:00:00 GMT+0200 (W. Europe Daylight Time)
year = values[3];
month = parseMonth(values[1]);
dayOfMonth = values[2];
time = parseTime(values[4]);
break;
default:
return value;
}
}
var pattern = "";
var retValue = "";
//Issue 1 - variable scope issue in format.date
//Thanks jakemonO
for (var i = 0; i < format.length; i++) {
var currentPattern = format.charAt(i);
pattern += currentPattern;
switch (pattern) {
case "dd":
if(dayOfMonth.length === 1){
dayOfMonth = '0' + dayOfMonth;
}
retValue += dayOfMonth;
pattern = "";
break;
case "MMM":
retValue += strMonth(month);
pattern = "";
break;
case "MM":
if (format.charAt(i+1) == "M") {
break;
}
retValue += month;
pattern = "";
break;
case "yyyy":
retValue += year;
pattern = "";
break;
case "HH":
retValue += time.hour;
pattern = "";
break;
case "hh":
//time.hour is "00" as string == is used instead of ===
retValue += (time.hour == 0 ? 12 : time.hour < 13 ? time.hour : time.hour - 12);
pattern = "";
break;
case "mm":
retValue += time.minute;
pattern = "";
break;
case "ss":
//ensure only seconds are added to the return string
retValue += time.second.substring(0, 2);
pattern = "";
break;
//case "tz":
// //parse out the timezone information
// retValue += time.second.substring(3, time.second.length);
// pattern = "";
// break;
case "a":
retValue += time.hour >= 12 ? "PM" : "AM";
pattern = "";
break;
case " ":
retValue += currentPattern;
pattern = "";
break;
case "/":
retValue += currentPattern;
pattern = "";
break;
case ":":
retValue += currentPattern;
pattern = "";
break;
default:
if (pattern.length === 2 && pattern.indexOf("y") !== 0) {
retValue += pattern.substring(0, 1);
pattern = pattern.substring(1, 2);
} else if ((pattern.length === 3 && pattern.indexOf("yyy") === -1)) {
pattern = "";
}
}
}
return retValue;
} catch (e) {
console.log(e);
return value;
}
}
};
} ())
});
rGk = gecko(document);
// Cleanup functions for the document ready method
if ( document.addEventListener ) {
DCL = function() {
document.removeEventListener( "DOMContentLoaded", DCL, false );
gecko.ready();
};
} else if ( document.attachEvent ) {
DCL = function() {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( document.readyState === "complete" ) {
document.detachEvent( "onreadystatechange", DCL );
gecko.ready();
}
};
}
// The DOM ready check for Internet Explorer
function doScrollCheck() {
if ( gecko.isReady ) {
return;
}
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
// and execute any waiting functions
gecko.ready();
};
return gecko;
})();
var flagsCache = {};
function createFlags( flags ) {
var object = flagsCache[ flags ] = {},
i, length;
flags = flags.split( /\s+/ );
for ( i = 0, length = flags.length; i < length; i++ ) {
object[ flags[i] ] = true;
}
return object;
}
/*
* Create a callback list using the following parameters:
*
* flags: an optional list of space-separated flags that will change how
* the callback list behaves
*
* By default a callback list will act like an event callback list and can be
* "fired" multiple times.
*
* Possible flags:
*
* once: will ensure the callback list can only be fired once (like a Deferred)
*
* memory: will keep track of previous values and will call any callback added
* after the list has been fired right away with the latest "memorized"
* values (like a Deferred)
*
* unique: will ensure a callback can only be added once (no duplicate in the list)
*
* stopOnFalse: interrupt callings when a callback returns false
*
*/
gecko.Callbacks = function( flags ) {
// Convert flags from String-formatted to Object-formatted
// (we check in cache first)
flags = flags ? ( flagsCache[ flags ] || createFlags( flags ) ) : {};
var // Actual callback list
list = [],
// Stack of fire calls for repeatable lists
stack = [],
// Last fire value (for non-forgettable lists)
memory,