-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjqlite.1.1.2.js
1508 lines (1316 loc) · 44.5 KB
/
jqlite.1.1.2.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
/*!
* jQLite JavaScript Library v1.1.2 (http://code.google.com/p/jqlite/)
*
* Copyright (c) 2010 Brett Fattori (bfattori@gmail.com)
* Licensed under the MIT license
* http://www.opensource.org/licenses/mit-license.php
*
* Many thanks to the jQuery team's efforts. Some code is
* Copyright (c) 2010, John Resig. See
* http://jquery.org/license
*
* @author Brett Fattori (bfattori@gmail.com)
* @author $Author$
* @version $Revision$
*
* Created: 03/29/2010
* Modified: $Date$
*/
(function() {
function now(){
return +new Date;
}
/*
Simplified DOM selection engine
START ---------------------------------------------------------
*/
var parseChunks = function(stringSelector, contextNodes) {
if (stringSelector === "" && contextNodes) {
return contextNodes;
}
var chunks = stringSelector.split(" ");
// Revise the context nodes
var chunk = chunks.shift();
var ctxNode;
// Is the chunk an Id selector?
if (chunk.charAt(0) == "#") {
var idNode = document.getElementById(chunk.substring(1));
ctxNode = idNode ? [idNode] : [];
} else {
var elName = chunk.charAt(0) !== "." ? chunk.split(".")[0] : "*";
var classes = chunk.split(".");
var attrs = null;
// Remove any attributes from the element
if (elName.indexOf("[") != -1) {
attrs = elName;
elName = elName.substr(0, elName.indexOf("["));
}
var cFn = function(node) {
var aC = arguments.callee;
if ((!aC.needClass || hasClasses(node, aC.classes)) &&
(!aC.needAttribute || hasAttributes(node, aC.attributes))) {
return node;
}
};
// Find tags in the context of the element
var cnodes = [];
for (var cxn = 0; cxn < contextNodes.length; cxn++) {
var x = contextNodes[cxn].getElementsByTagName(elName);
for (var a = 0;a < x.length; a++) {
cnodes.push(x[a]);
}
}
if (classes) {
classes.shift();
}
ctxNode = [];
cFn.classes = classes;
if (attrs != null) {
var b1 = attrs.indexOf("[");
var b2 = attrs.lastIndexOf("]");
var as = attrs.substring(b1 + 1,b2);
var attrib = as.split("][");
}
cFn.attributes = attrs != null ? attrib : null;
cFn.needClass = (chunk.indexOf(".") != -1 && classes.length > 0);
cFn.needAttribute = (attrs != null);
for (var j = 0; j < cnodes.length; j++) {
if (cFn(cnodes[j])) {
ctxNode.push(cnodes[j]);
}
}
}
return parseChunks(chunks.join(" "), ctxNode);
};
var parseSelector = function(selector, context) {
context = context || document;
if (selector.nodeType && selector.nodeType === DOM_DOCUMENT_NODE) {
selector = document.body;
if (selector === null) {
// Body not ready yet, return the document instead
return [document];
}
}
if (selector.nodeType && selector.nodeType === DOM_ELEMENT_NODE) {
// Is the selector already a single DOM node?
return [selector];
}
if (selector.jquery && typeof selector.jquery === "string") {
// Is the selector a jQL object?
return selector.toArray();
}
if (context) {
context = cleanUp(context);
}
if (jQL.isArray(selector)) {
// This is already an array of nodes
return selector;
} else if (typeof selector === "string") {
// This is the meat and potatoes
var nodes = [];
for (var cN = 0; cN < context.length; cN++) {
// For each context node, look for the
// specified node within it
var ctxNode = [context[cN]];
if (!jQL.forceSimpleSelectorEngine && ctxNode[0].querySelectorAll) {
var nl = ctxNode[0].querySelectorAll(selector);
for (var tni = 0; tni < nl.length; tni++) {
nodes.push(nl.item(tni));
}
} else {
nodes = nodes.concat(parseChunks(selector, ctxNode));
}
}
return nodes;
} else {
// What do you want me to do with this?
return null;
}
};
var hasClasses = function(node, cArr) {
if (node.className.length == 0) {
return false;
}
var cn = node.className.split(" ");
var cC = cArr.length;
for (var c = 0; c < cArr.length; c++) {
if (jQL.inArray(cArr[c], cn) != -1) {
cC--;
}
}
return (cC == 0);
};
var hasAttributes = function(node, attrs) {
var satisfied = true;
for (var i = 0; i < attrs.length; i++) {
var tst = attrs[i].split("=");
var op = (tst[0].indexOf("!") != -1 || tst[0].indexOf("*") != -1) ? tst[0].charAt(tst[0].length - 1) + "=" : "=";
if (op != "=") {
tst[0] = tst[0].substring(0, tst[0].length - 1);
}
switch (op) {
case "=": satisfied &= (node.getAttribute(tst[0]) === tst[1]); break;
case "!=": satisfied &= (node.getAttribute(tst[0]) !== tst[1]); break;
case "*=": satisfied &= (node.getAttribute(tst[0]).indexOf(tst[1]) != -1); break;
default: satisfied = false;
}
}
return satisfied;
};
/*
END -----------------------------------------------------------
Simplified DOM selection engine
*/
var gSupportScriptEval = false;
setTimeout(function() {
var root = document.body;
if (!root) {
setTimeout(arguments.callee, 33);
return;
}
var script = document.createElement("script"),
id = "i" + new Date().getTime();
script.type = "text/javascript";
try {
script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
} catch(e) {}
root.insertBefore( script, root.firstChild );
// Make sure that the execution of code works by injecting a script
// tag with appendChild/createTextNode
// (IE doesn't support this, fails, and uses .text instead)
var does = true;
if ( window[ id ] ) {
delete window[ id ];
} else {
does = false;
}
root.removeChild( script );
gSupportScriptEval = does;
}, 33);
var stripScripts = function(data) {
// Wrap the data in a dom element
var div = document.createElement("div");
div.innerHTML = data;
// Strip out all scripts
var scripts = div.getElementsByTagName("script");
return { scripts: scripts, data: data};
};
var properCase = function(str, skipFirst) {
skipFirst = skipFirst || false;
str = (!str ? "" : str.toString().replace(/^\s*|\s*$/g,""));
var returnString = "";
if(str.length <= 0){
return "";
}
var ucaseNextFlag = false;
if(!skipFirst) {
returnString += str.charAt(0).toUpperCase();
} else {
returnString += str.charAt(0);
}
for(var counter=1;counter < str.length;counter++) {
if(ucaseNextFlag) {
returnString += str.charAt(counter).toUpperCase();
} else {
returnString += str.charAt(counter).toLowerCase();
}
var character = str.charCodeAt(counter);
ucaseNextFlag = character == 32 || character == 45 || character == 46;
if(character == 99 || character == 67) {
if(str.charCodeAt(counter-1)==77 || str.charCodeAt(counter-1)==109) {
ucaseNextFlag = true;
}
}
}
return returnString;
};
var fixStyleProp = function(name) {
var tempName = name.replace(/-/g, " ");
tempName = properCase(tempName, true);
return tempName.replace(/ /g, "");
};
//------------------ EVENTS
/**
* Associative array of events and their types
* @private
*/
var EVENT_TYPES = {click:"MouseEvents",dblclick:"MouseEvents",mousedown:"MouseEvents",mouseup:"MouseEvents",
mouseover:"MouseEvents",mousemove:"MouseEvents",mouseout:"MouseEvents",contextmenu:"MouseEvents",
keypress:"KeyEvents",keydown:"KeyEvents",keyup:"KeyEvents",load:"HTMLEvents",unload:"HTMLEvents",
abort:"HTMLEvents",error:"HTMLEvents",resize:"HTMLEvents",scroll:"HTMLEvents",select:"HTMLEvents",
change:"HTMLEvents",submit:"HTMLEvents",reset:"HTMLEvents",focus:"HTMLEvents",blur:"HTMLEvents",
touchstart:"MouseEvents",touchend:"MouseEvents",touchmove:"MouseEvents"};
var createEvent = function(eventType) {
if (typeof eventType === "string") {
eventType = eventType.toLowerCase();
}
var evt = null;
var eventClass = EVENT_TYPES[eventType] || "Event";
if(document.createEvent) {
evt = document.createEvent(eventClass);
evt._eventClass = eventClass;
if(eventType) {
evt.initEvent(eventType, true, true);
}
}
if(document.createEventObject) {
evt = document.createEventObject();
if(eventType) {
evt.type = eventType;
evt._eventClass = eventClass;
}
}
return evt;
};
var fireEvent = function(node, eventType, data) {
var evt = createEvent(eventType);
if (evt._eventClass !== "Event") {
evt.data = data;
return node.dispatchEvent(evt);
} else {
var eHandlers = node._handlers || {};
var handlers = eHandlers[eventType];
if (handlers) {
for (var h = 0; h < handlers.length; h++) {
var args = jQL.isArray(data) ? data : [];
args.unshift(evt);
var op = handlers[h].apply(node, args);
op = (typeof op == "undefined" ? true : op);
if (!op) {
break;
}
}
}
}
};
var setHandler = function(node, eventType, fn) {
if (!jQL.isFunction(fn)) {
return;
}
if (typeof eventType === "string") {
eventType = eventType.toLowerCase();
}
var eventClass = EVENT_TYPES[eventType];
if (eventType.indexOf("on") == 0) {
eventType = eventType.substring(2);
}
if (eventClass) {
// Let the browser handle it
var handler = function(evt) {
var aC = arguments.callee;
var args = evt.data || [];
args.unshift(evt);
var op = aC.fn.apply(node, args);
if (typeof op != "undefined" && op === false) {
if (evt.preventDefault && evt.stopPropagation) {
evt.preventDefault();
evt.stopPropagation();
} else {
evt.returnValue = false;
evt.cancelBubble = true;
}
return false;
}
return true;
};
handler.fn = fn;
if (node.addEventListener) {
node.addEventListener(eventType, handler, false);
} else {
node.attachEvent("on" + eventType, handler);
}
} else {
if (!node._handlers) {
node._handlers = {};
}
var handlers = node._handlers[eventType] || [];
handlers.push(fn);
node._handlers[eventType] = handlers;
}
};
/**
* jQuery "lite"
*
* This is a small subset of support for jQuery-like functionality. It
* is not intended to be a full replacement, but it will provide some
* of the functionality which jQuery provides to allow development
* using jQuery-like syntax.
*/
var jQL = function(s, e) {
return new jQLp().init(s, e);
},
document = window.document,
hasOwnProperty = Object.prototype.hasOwnProperty,
toString = Object.prototype.toString,
push = Array.prototype.push,
slice = Array.prototype.slice,
DOM_ELEMENT_NODE = 1,
DOM_DOCUMENT_NODE = 9,
readyStack = [],
isReady = false,
setReady = false,
DOMContentLoaded;
/**
* Force the usage of the simplified selector engine. Setting this to true will
* cause the simplified selector engine to be used, limiting the number of available
* selectors based on the original (jQLite v1.0.0 - v1.1.0) selector engine. Keeping
* the value at "false" will allow jQLite to switch to using [element].querySelectorAll()
* if it is available. This provides a speed increase, but it may function differently
* based on each platform.
*/
jQL.forceSimpleSelectorEngine = false;
/**
* Loop over each object, performing the function for each one
* @param obj
* @param fn
*/
jQL.each = function(obj, fn) {
var name, i = 0,
length = obj.length,
isObj = length === undefined || jQL.isFunction(obj);
if ( isObj ) {
for ( name in obj ) {
if ( fn.call( obj[ name ], name, obj[ name ] ) === false ) {
break;
}
}
} else {
for ( var value = obj[0];
i < length && fn.call( value, i, value ) !== false; value = obj[++i] ) {}
}
return obj;
};
/**
* NoOp function (empty)
*/
jQL.noop = function() {};
/**
* Test if the given object is a function
* @param obj
*/
jQL.isFunction = function(obj) {
return toString.call(obj) === "[object Function]";
};
/**
* Test if the given object is an Array
* @param obj
*/
jQL.isArray = function( obj ) {
return toString.call(obj) === "[object Array]";
};
/**
* Test if the given object is an Object
* @param obj
*/
jQL.isPlainObject = function( obj ) {
// Make sure that DOM nodes and window objects don't pass through, as well
if ( !obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) {
return false;
}
// Not own constructor property must be Object
if ( obj.constructor && !hasOwnProperty.call(obj, "constructor")
&& !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) {
return false;
}
// Own properties are enumerated firstly
var key;
for ( key in obj ) {}
return key === undefined || hasOwnProperty.call( obj, key );
};
/**
* Merge two objects into one
* @param first
* @param second
*/
jQL.merge = function( first, second ) {
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;
};
jQL.param = function(params) {
var pList = "";
if (params) {
jQL.each(params, function(val, name) {
pList += (pList.length != 0 ? "&" : "") + name + "=" + encodeURIComponent(val);
});
}
return pList;
};
jQL.evalScripts = function(scripts) {
var head = document.getElementsByTagName("head")[0] || document.documentElement;
for (var s = 0; s < scripts.length; s++) {
var script = document.createElement("script");
script.type = "text/javascript";
if ( gSupportScriptEval ) {
script.appendChild( document.createTextNode( scripts[s].text ) );
} else {
script.text = scripts[s].text;
}
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709).
head.insertBefore( script, head.firstChild );
head.removeChild( script );
}
};
jQL.ready = function() {
isReady = true;
while(readyStack.length > 0) {
var fn = readyStack.shift();
fn();
}
};
var expando = "jQuery" + now(), uuid = 0, windowData = {};
// The following elements throw uncatchable exceptions if you
// attempt to add expando properties to them.
jQL.noData = {
"embed": true,
"object": true,
"applet": true
};
jQL.cache = {};
jQL.data = function( elem, name, data ) {
if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
return;
}
elem = elem == window ?
windowData :
elem;
var id = elem[ expando ];
// Compute a unique ID for the element
if ( !id ) { id = elem[ expando ] = ++uuid; }
// Only generate the data cache if we're
// trying to access or manipulate it
if ( name && !jQuery.cache[ id ] ) {
jQuery.cache[ id ] = {};
}
// Prevent overriding the named cache with undefined values
if ( data !== undefined ) {
jQuery.cache[ id ][ name ] = data;
}
// Return the named cache data, or the ID for the element
return name ?
jQuery.cache[ id ][ name ] :
id;
};
jQL.removeData = function( elem, name ) {
elem = elem == window ?
windowData :
elem;
var id = elem[ expando ];
// If we want to remove a specific section of the element's data
if ( name ) {
if ( jQuery.cache[ id ] ) {
// Remove the section of cache data
delete jQuery.cache[ id ][ name ];
// If we've removed all the data, remove the element's cache
name = "";
for ( name in jQuery.cache[ id ] )
break;
if ( !name ) {
jQuery.removeData( elem );
}
}
// Otherwise, we want to remove all of the element's data
} else {
// Clean up the element expando
try {
delete elem[ expando ];
} catch(e){
// IE has trouble directly removing the expando
// but it's ok with using removeAttribute
if ( elem.removeAttribute ) {
elem.removeAttribute( expando );
}
}
// Completely remove the data cache
delete jQuery.cache[ id ];
}
};
jQL.ajaxSettings = {
url: location.href,
data: {},
type: "GET",
async: true,
username: null,
password: null,
sendFn: null,
status: null,
contentType: "application/x-www-form-urlencoded"
};
jQL.ajax = {
status: -1,
statusText: "",
responseText: null,
responseXML: null,
send: function(opts, sendFn) {
var s = jQuery.extend(opts, jQL.ajaxSettings);
if (!s.url) {
return;
}
// Poll for readyState == 4
var p = jQL.param(s.data);
if (p.length != 0 && s.type === "GET") {
url += (url.indexOf("?") == -1 ? "?" : "&") + p;
}
var req = new XMLHttpRequest();
req.open(s.type, s.url, s.async, s.username, s.password);
if (p.length != 0 || opts && opts.contentType) {
xhr.setRequestHeader("Content-Type", s.contentType);
}
req.send((s.type === "POST" || s.type === "PUT") ? p : null);
if (s.async) {
var xCB = function(xhr) {
var aC = arguments.callee;
if (xhr.status == 200) {
jQL.ajax.complete(xhr, aC.s, aC.cb);
} else {
jQL.ajax.error(xhr, aC.s, aC.cb);
}
};
xCB.cb = sendFn;
xCB.s = s;
var poll = function() {
var aC = arguments.callee;
if (aC.req.readyState != 4) {
setTimeout(aC, 250);
} else {
aC.xcb(aC.req);
}
};
poll.req = req;
poll.xcb = xCB;
setTimeout(poll, 250);
} else {
// synchronous support?
}
},
complete: function(xhr, s, callback) {
jQL.ajax.status = s.status = xhr.status;
var ct = xhr.getResponseHeader("content-type") || "",
xml = ct.indexOf("xml") >= 0,
data = xml ? xhr.responseXML : xhr.responseText;
jQL.ajax.responseText = xhr.responseText;
jQL.ajax.responseXML = xhr.responseXML;
jQL("body", document).trigger("ajaxComplete", [xhr, s]);
if (jQL.isFunction(callback)) {
callback(data, xhr.status);
}
},
error: function(xhr, s, callback) {
jQL.ajax.status = s.status = xhr.status;
jQL.ajax.statusText = xhr.statusText;
jQL("body", document).trigger("ajaxError", [xhr, s]);
if (jQL.isFunction(callback)) {
callback(xhr.status, xhr.statusText);
}
}
};
jQL.post = function(url, data, callback, type) {
if (jQL.isFunction(data)) {
callback = data;
data = {};
}
return jQL.ajax.send({
type: "POST",
url: url,
data: data
}, callback);
};
jQL.makeArray = function( array, results ) {
var ret = results || [];
if ( array != null ) {
// The window, strings (and functions) also have 'length'
// The extra typeof function check is to prevent crashes
// in Safari 2 (See: #3039)
if ( array.length == null || typeof array === "string" || jQuery.isFunction(array) || (typeof array !== "function" && array.setInterval) ) {
push.call( ret, array );
} else {
jQL.merge( ret, array );
}
}
return ret;
};
jQL.inArray = function(e, arr) {
for (var a = 0; a < arr.length; a++) {
if (arr[a] === e) {
return a;
}
}
return -1;
};
jQL.trim = function(str) {
if (str != null) {
return str.toString().replace(/^\s*|\s*$/g,"");
} else {
return "";
}
};
/**
* jQLite instance object
* @private
*/
var jQLp = function() {};
jQLp.prototype = {
selector: "",
context: null,
length: 0,
jquery: "jqlite-1.1.2",
init: function(s, e) {
if (!s) {
return this;
}
if (s.nodeType) {
// A simple node
this.context = this[0] = s;
this.length = 1;
} else if (typeof s === "function") {
// Short-form document.ready()
this.ready(s);
} else {
var els = [];
if (s.jquery && typeof s.jquery === "string") {
// Already jQLite, just grab its elements
els = s.toArray();
} else if (jQL.isArray(s)) {
// An array of elements
els = s;
} else if (typeof s === "string" && jQL.trim(s).indexOf("<") == 0 && jQL.trim(s).indexOf(">") != -1) {
// This is most likely html, so create an element for them
var elm = getParentElem(s);
var h = document.createElement(elm);
h.innerHTML = s;
// Extract the element
els = [h.removeChild(h.firstChild)];
h = null;
} else {
var selectors;
if (s.indexOf(",") != -1) {
// Multiple selectors - split them
selectors = s.split(",");
for (var n = 0; n < selectors.length; n++) {
selectors[n] = jQL.trim(selectors[n]);
}
} else {
selectors = [s];
}
var multi = [];
for (var m = 0; m < selectors.length; m++) {
multi = multi.concat(parseSelector(selectors[m], e));
}
els = multi;
}
push.apply(this, els);
}
return this;
},
// CORE
pushStack: function(elms) {
var ret = jQL(elms);
ret.prevObj = this;
ret.context = this.context;
return ret;
},
each: function(fn) {
return jQL.each(this, fn);
},
size: function() {
return this.length;
},
toArray: function() {
return slice.call( this, 0 );
},
ready: function(fn) {
if (isReady) {
fn();
} else {
readyStack.push(fn);
return this;
}
},
data: function( key, value ) {
if ( typeof key === "undefined" && this.length ) {
return jQuery.data( this[0] );
} else if ( typeof key === "object" ) {
return this.each(function() {
jQuery.data( this, key );
});
}
var parts = key.split(".");
parts[1] = parts[1] ? "." + parts[1] : "";
if ( value === undefined ) {
if ( data === undefined && this.length ) {
data = jQuery.data( this[0], key );
}
return data === undefined && parts[1] ?
this.data( parts[0] ) :
data;
} else {
return this.each(function() {
jQuery.data( this, key, value );
});
}
},
removeData: function( key ) {
return this.each(function() {
jQuery.removeData( this, key );
});
},
// CSS
addClass: function(cName) {
return this.each(function() {
if (this.className.length != 0) {
var cn = this.className.split(" ");
if (jQL.inArray(cName, cn) == -1) {
cn.push(cName);
this.className = cn.join(" ");
}
} else {
this.className = cName;
}
});
},
removeClass: function(cName) {
return this.each(function() {
if (this.className.length != 0) {
var cn = this.className.split(" ");
var i = jQL.inArray(cName, cn);
if (i != -1) {
cn.splice(i, 1);
this.className = cn.join(" ");
}
}
});
},
hasClass: function(cName) {
if (this[0].className.length == 0) {
return false;
}
return jQL.inArray(cName, this[0].className.split(" ")) != -1;
},
isElementName: function(eName) {
return (this[0].nodeName.toLowerCase() === eName.toLowerCase());
},
toggleClass: function(cName) {
return this.each(function() {
if (this.className.length == 0) {
this.className = cName;
} else {
var cn = this.className.split(" ");
var i = jQL.inArray(cName, cn);
if (i != -1) {
cn.splice(i, 1);
} else {
cn.push(cName);
}
this.className = cn.join(" ");
}
});
},
hide: function(fn) {
return this.each(function() {
if (this.style && this.style["display"] != null) {
if (this.style["display"].toString() != "none") {
this._oldDisplay = this.style["display"].toString() || (this.nodeName != "span" ? "block" : "inline");
this.style["display"] = "none";
}
}
if (jQL.isFunction(fn)) {
fn(this);
}
});
},
show: function(fn) {
return this.each(function() {
this.style["display"] = ((this._oldDisplay && this._oldDisplay != "" ? this._oldDisplay : null) || (this.nodeName != "span" ? "block" : "inline"));
if (jQL.isFunction(fn)) {
fn(this);
}
});
},
css: function(sel, val) {
if (typeof sel === "string" && val == null) {
return this[0].style[fixStyleProp(sel)];
} else {
sel = typeof sel === "string" ? makeObj(sel,val) : sel;
return this.each(function() {
var self = this;
if (typeof self.style != "undefined") {
jQL.each(sel, function(key,value) {
value = (typeof value === "number" ? value + "px" : value);
var sn = fixStyleProp(key);
if (!self.style[sn]) {
sn = key;
}
self.style[sn] = value;
});
}
});
}
},