-
Notifications
You must be signed in to change notification settings - Fork 229
/
jq.js
1939 lines (1700 loc) · 50.9 KB
/
jq.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
//For jQuery 1.3.2
dojo.provide("dojox.jq");
dojo.require("dojo.NodeList-traverse");
dojo.require("dojo.NodeList-manipulate");
dojo.require("dojo.io.script");
/*
To get jquery tests to pass:
- add spaces between span>form selectors, other ones like one,two
- .last() instead of :last
- $("<div>").find("#foo") does not work unless the div is attached to the body.
- trigger .test not work
- No jquery.Event thing.
- jQuery.ajax() modifies incoming arguments?
- test framework not good for our io methods, async, poll.
- Dojo ajax is async: we fire ajaxStop more than jquery.
- jquery makes assumptions of a value to set for an element
by inserting an element and checking display. Does not seem to
account for nested styles, only captures generic tag name style off
of body. Why can't we just set display to empty?
OK for failures:
- test("jQuery.ajax - beforeSend, cancel request (#2688)"
We cancel the deferred which triggers error and complete callbacks.
Looked at jquery code for:
- how it handled text(): did not use textContent/innerText, but use recursive look over childNodes and nodeValue,
so it may have impact on how <br> is serialized, but it has uniform behavior across browsers.
- Looked at trigger: how it triggered actions on dom nodes. This seemed unsafe.
*/
/*
dojo.query differences that cause some tests to fail:
- does not support XML queries
- $("#sap>form") does not find a match but $("#sap > form") does. Similar issue with comma instead of > (see is() tests)
- "$("form:last") should return the last form object, not if that particular form is that last related
to its siblings? Same issue with :first?
- $("p").filter("#ap, #sndp"): filter does not work.
- dojo.NodeList uses d.NodeList a few places in the code. Would be nice to use a ctor that can be configured.
That would make the filter function operate better.
- filterQueryResult, cannot handle queries like "p, div"? See andSelf test with parents().
- adjacent "p + p" not supported?
= a:only-child not supported?
- nth(1)
- even/odd
- eq/gt/lt
- #form :radio:checked does not run the first :radio psuedo selector? Seems to be a general issue where only the last pseud
is run. For example, "#form :checked:radio" does only the radio pseudo.
*/
(function(){
//Enable io topic publishing. But don't mask the original definition of ioPublish from the doc parser.
/*===== var ioPublish = dojo.config.ioPublish; =====*/
dojo.config.ioPublish = true;
/*===== dojo.config.ioPublish = ioPublish; =====*/
//Support stuff for toDom
var selfClosedTags = "|img|meta|hr|br|input|";
function toDom(/*String*/html, /*Document?*/doc){
//summary converts HTML string into DOM nodes.
//Make sure html is a string.
html += "";
//Convert <tag/> into <tag></tag>
html = html.replace(/<\s*(\w+)([^\/\>]*)\/\s*>/g, function(tag, name, contents){
if(selfClosedTags.indexOf("|" + name + "|") == -1){
return "<" + name + contents + "></" + name + ">";
}else{
return tag;
}
});
return dojo._toDom(html, doc);
}
function cssNameToJs(name){
var index = name.indexOf("-");
if(index != -1){
//Strip off beginning dash
if(index == 0){
name = name.substring(1);
}
name = name.replace(/-(\w)/g, function(match, match1){
return match1.toUpperCase();
});
}
return name;
}
var _old$ = dojo.global.$;
var _oldJQuery = dojo.global.jQuery;
var $ = dojo.global.$ = dojo.global.jQuery = function(){
var arg = arguments[0];
if(!arg){
return $._wrap([], null, $);
}else if(dojo.isString(arg)){
if(arg.charAt(0) == "<"){
//String of html that needs nodes created.
arg = toDom(arg);
//If a DocumentFragment, convert to use its children
//since we want to treat all top level nodes as elements
//in the NodeList array.
if(arg.nodeType == 11){
arg = arg.childNodes;
}else{
return $._wrap([arg], null, $);
}
//Use end case of nodelist to finish work.
}else{
//Normal dojo.query selector.
//Switch out query's NodeList constructor to be our specialized
//NodeList constructor.
var listCtor = dojo._NodeListCtor;
dojo._NodeListCtor = $;
//If the second arg is one of our fake NodeLists then
//use the first parent for the call.
var arg2 = arguments[1];
if(arg2 && arg2._is$){
arg2 = arg2[0];
}else if(dojo.isString(arg2)){
arg2 = dojo.query(arg2)[0];
}
var nl = dojo.query.call(this, arg, arg2);
dojo._NodeListCtor = listCtor;
return nl;
}
}else if(dojo.isFunction(arg)){
//The addOnLoad case
$.ready(arg);
return $;
}else if(arg == document || arg == window){
//If the arg is the document or window,
//then just use it directly.
return $._wrap([arg], null, $);
}else if(dojo.isArray(arg)){
//Input is a plain array.
//Filter out duplicates.
var ary = [];
for(var i = 0; i < arg.length; i++){
if(dojo.indexOf(ary, arg[i]) == -1){
ary.push(arg[i]);
}
}
return $._wrap(arg, null, $);
}else if("nodeType" in arg){
//A DOM Node
return $._wrap([arg], null, $);
}
//A native NodeList that does not conform to dojo.isArray().
//Convert it to a workable array and create new NodeList.
return $._wrap(dojo._toArray(arg), null, $);
};
//Set up plugin extension point.
var nlProto = dojo.NodeList.prototype;
//Need a delegate, because at least one method conflicts with jquery
//API: attr(name) in jQuery only returns a single, first value, where
//dojo.attr will return an array.
var f = $.fn = $.prototype = dojo.delegate(nlProto);
//_wrap is required for proper use in dojo.query, but the _adaptAs* methods
//do not have to placed on $ -- they can be used directly off dojo.NodeList.
$._wrap = dojo.NodeList._wrap;
//Add in some pseudos selectors
var headerRegExp = /^H\d/i;
var pseudos = dojo.query.pseudos;
dojo.mixin(pseudos, {
has: function(name, condition){
return function(elem){
return $(condition, elem).length;
}
},
visible: function(name, condition){
return function(elem){
return dojo.style(elem, "visible") != "hidden" && dojo.style(elem, "display") != "none";
}
},
hidden: function(name, condition){
return function(elem){
return elem.type == "hidden" || dojo.style(elem, "visible") == "hidden" || dojo.style(elem, "display") == "none";
}
},
selected: function(name, condition){
return function(elem){
return elem.selected;
}
},
checked: function(name, condition){
return function(elem){
return elem.nodeName.toUpperCase() == "INPUT" && elem.checked;
}
},
disabled: function(name, condition){
return function(elem){
return elem.getAttribute("disabled");
}
},
enabled: function(name, condition){
return function(elem){
return !elem.getAttribute("disabled");
}
},
input: function(name, condition){
return function(elem){
var n = elem.nodeName.toUpperCase();
return n == "INPUT" || n == "SELECT" || n == "TEXTAREA" || n == "BUTTON";
}
},
button: function(name, condition){
return function(elem){
return (elem.nodeName.toUpperCase() == "INPUT" && elem.type == "button") || elem.nodeName.toUpperCase() == "BUTTON";
}
},
header: function(name, condition){
return function(elem){
return elem.nodeName.match(headerRegExp);
}
}
//TODO: implement :animated
});
//Add the input type selectors to pseudos
var inputPseudos = {};
dojo.forEach([
"text", "password", "radio", "checkbox", "submit", "image", "reset", "file"
], function(type) {
inputPseudos[type] = function(name, condition){
return function(elem){
return elem.nodeName.toUpperCase() == "INPUT" && elem.type == type;
}
};
});
dojo.mixin(pseudos, inputPseudos);
//Set up browser sniff.
$.browser = {
mozilla: dojo.isMoz,
msie: dojo.isIE,
opera: dojo.isOpera,
safari: dojo.isSafari
};
$.browser.version = dojo.isIE || dojo.isMoz || dojo.isOpera || dojo.isSafari || dojo.isWebKit;
//Map back into dojo
//Hmm maybe this is not so good. Dojo
//modules may still be holding on to old
//dojo (example: the d._NodeListCtor in query.js)
//dojo = dojo.mixin($, dojo);
// Add $.ready
$.ready = $.fn.ready = function(callback){
dojo.addOnLoad(dojo.hitch(null, callback, $));
return this;
}
//START jquery Core API methods
//http://docs.jquery.com/Core
f._is$ = true;
f.size = function(){return this.length; };
$.prop = function(node, propCheck){
//TODO: not sure about this one, could not find the docs?
if(dojo.isFunction(propCheck)){
return propCheck.call(node);
}else{
return propCheck;
}
}
$.className = {
add: dojo.addClass,
remove: dojo.removeClass,
has: dojo.hasClass
};
$.makeArray = function(thing){
if(typeof thing == "undefined"){
return [];
}else if(thing.length && !dojo.isString(thing) && !("location" in thing)){
//Location check was for excluding window objects that have a length.
return dojo._toArray(thing);
}else{
return [thing];
}
}
$.merge = function(ary1, ary2){
//Alters first array by adding in the element.
var args = [ary1.length, 0];
args = args.concat(ary2);
ary1.splice.apply(ary1, args);
return ary1;
}
$.each = function(/*Array||ArrayLike*/list, /*Function*/cb){
//each differs from dojo.NodeList.forEach in that
//"this" is the current cycled node. Breaking
//the loop is also possible. Also, index is first arg
//to the callback.
if(dojo.isArrayLike(list)){
for(var i = 0; i < list.length; i++){
if(cb.call(list[i], i, list[i]) === false){
break;
}
}
}else if(dojo.isObject(list)){
for(var param in list){
if(cb.call(list[param], param, list[param]) === false){
break;
}
}
}
return this;
};
f.each = function(/*Function*/cb){
return $.each.call(this, this, cb);
};
//f.length already implemented by NodeList
f.eq = function(){
//Direct copy of dojo.NodeList.at, but want
//to use our NodeList class.
var nl = $();
dojo.forEach(arguments, function(i) { if(this[i]) { nl.push(this[i]); } }, this);
return nl; // dojo.NodeList
};
f.get = function(/*Number*/index){
if(index || index == 0){
return this[index];
}
return this;
};
f.index = function(arg){
//Hmm, allows passing in a $ nodelist. Apparently in that
//case take the first item in that array and match
if(arg._is$){
arg = arg[0];
}
return this.indexOf(arg);
}
//.data implementation
var dataStore = [];
var dataId = 0;
var dataAttr = dojo._scopeName + "DataId";
var getDataId = function(node){
var id = node.getAttribute(dataAttr);
if(!id){
id = dataId++;
node.setAttribute(dataAttr, id);
}
}
var getData = function(node){
var data = {};
if(node.nodeType == 1){
var id = getDataId(node);
data = dataStore[id];
if(!data){
data = dataStore[id] = {};
}
}
return data;
}
$.data = function(/*DOMNode*/node, /*String*/name, /*String*/value){
var result = null;
if(name == "events"){
//Special case "events", since jquery tests seem to use it to
//get the event handler storage for jquery. So for jquery apps
//"events" is probably a reserved word anyway.
result = listeners[node.getAttribute(eventAttr)];
var isEmpty = true;
if(result){
for(var param in result){
isEmpty = false;
break;
}
}
return isEmpty ? null : result;
}
var data = getData(node);
if(typeof value != "undefined"){
data[name] = value;
}else{
result = data[name];
}
return value ? this : result;
}
$.removeData = function(/*DOMNode*/node, /*String*/name){
var data = getData(node);
delete data[name];
if(node.nodeType == 1){
var isEmpty = true;
for(var param in data){
isEmpty = false;
break;
}
if(isEmpty){
node.removeAttribute(dataAttr);
}
}
return this;
}
f.data = function(/*String*/name, /*String*/value){
var result = null;
this.forEach(function(node){
result = $.data(node, name, value);
});
return value ? this : result;
}
f.removeData = function(/*String*/name){
this.forEach(function(node){
$.removeData(node, name);
});
return this;
}
function jqMix(obj, props){
// summary:
// an attempt at a mixin that follows
// jquery's .extend rules. Seems odd. Not sure how
// to resolve this with dojo.mixin and what the use
// cases are for the jquery version.
// Copying some code from dojo._mixin.
if(obj == props){
return obj;
}
var tobj = {};
for(var x in props){
// the "tobj" condition avoid copying properties in "props"
// inherited from Object.prototype. For example, if obj has a custom
// toString() method, don't overwrite it with the toString() method
// that props inherited from Object.prototype
if(x !== '__proto__ ' && ((tobj[x] === undefined || tobj[x] != props[x])) && props[x] !== undefined && obj != props[x]){
if(dojo.isObject(obj[x]) && dojo.isObject(props[x])){
if(dojo.isArray(props[x])){
obj[x] = props[x];
}else{
obj[x] = jqMix(obj[x], props[x]);
}
}else{
obj[x] = props[x];
}
}
}
// IE doesn't recognize custom toStrings in for..in
if(dojo.isIE && props){
var p = props.toString;
if(typeof p == "function" && p != obj.toString && p != tobj.toString &&
p != "\nfunction toString() {\n [native code]\n}\n"){
obj.toString = props.toString;
}
}
return obj; // Object
}
f.extend = function(){
var args = [this];
args = args.concat(arguments);
return $.extend.apply($, args);
}
$.extend = function(){
//Could have multiple args to mix in. Similar to dojo.mixin,
//but has some different rules, and the mixins all get applied
//to the first arg.
var args = arguments, finalObj;
for(var i = 0; i < args.length; i++){
var obj = args[i];
if(obj && dojo.isObject(obj)){
if(!finalObj){
finalObj = obj;
}else{
jqMix(finalObj, obj);
}
}
}
return finalObj;
}
$.noConflict = function(/*Boolean*/extreme){
var me = $;
dojo.global.$ = _old$;
if(extreme){
dojo.global.jQuery = _oldJQuery;
}
return me;
}
//END jquery Core API methods
//START jquery Attribute API methods
//http://docs.jquery.com/Attributes
f.attr = function(name, value){
//The isObject tests below are to weed out where something
//like a form node has an input called "action" but we really
//want to get the attribute "action". But in general, favor
//a property value over a DOM attribute value.
if(arguments.length == 1 && dojo.isString(arguments[0])){
//The get case, return first match.
var first = this[0];
//Weed out empty nodes
if(!first){
return null;
}
var arg = arguments[0];
//favor properties over attributes.
var attr = dojo.attr(first, arg);
var prop = first[arg];
if((arg in first) && !dojo.isObject(prop) && name != "href"){
return prop;
}else{
return attr || prop;
}
}else if(dojo.isObject(name)){
//A setter, using an object.
for(var param in name){
this.attr(param, name[param]);
}
return this;
}else{
//The setter case. Figure out if value is a function.
var isFunc = dojo.isFunction(value);
this.forEach(function(node, index){
var prop = node[name];
if((name in node) && !dojo.isObject(prop) && name != "href"){
node[name] = (isFunc ? value.call(node, index) : value);
}else if(node.nodeType == 1){
dojo.attr(node, name, (isFunc ? value.call(node, index) : value));
}
});
return this;
}
}
f.removeAttr = function(name){
this.forEach(function(node, index){
var prop = node[name];
if((name in node) && !dojo.isObject(prop) && name != "href"){
delete node[name];
}else if(node.nodeType == 1){
if(name == "class"){
//TODO: push this fix into dojo.removeAttr
node.removeAttribute(name);
}else{
dojo.removeAttr(node, name);
}
}
});
return this;
}
//addClass, removeClass exist in dojo.NodeList. toggleClass in jQuery case
//just means add/remove the classname if it missing/exists. So need custom override.
f.toggleClass = function(/*String*/name, /*Expression?*/condition){
var hasCondition = arguments.length > 1;
this.forEach(function(node){
dojo.toggleClass(node, name, hasCondition ? condition : !dojo.hasClass(node, name));
});
return this;
}
//Action depends on arguments: if an array of functions do one thing,
//If no args, do a display toggle,
//If an expression, something that evaluates to true or false,
//then toggle display accordingly.
//If first arg is a String/Number, then do animation. Second arg
//is an optional callback.
f.toggle = function(){
//If more than two args and we have a function as first arg, then
//probably the onclick toggle variant: takes variable args that are
//functions and cycles through them on click actions.
var args = arguments;
if(arguments.length > 1 && dojo.isFunction(arguments[0])){
var index = 0;
var func = function(){
var result = args[index].apply(this, arguments);
index += 1;
if(index > args.length - 1){
index = 0;
}
};
return this.bind("click", func);
}else{
//The display/hide/show case.
var condition = arguments.length == 1 ? arguments[0] : undefined;
this.forEach(function(node){
var result = typeof condition == "undefined" ? dojo.style(node, "display") == "none" : condition;
var action = (result ? "show" : "hide");
var nl = $(node);
nl[action].apply(nl, args);
});
return this;
}
}
//hasClass just returns true if any of the nodes has the class.
f.hasClass = function(/*String*/name){
return this.some(function(node){
return dojo.hasClass(node, name);
});
}
//use the html method from dojo.NodeList-manipulate.
f.html = f.innerHTML;
//END jquery Attribute API methods
//START jquery Traversing API methods
//http://docs.jquery.com/Traversing
dojo.forEach(["filter", "slice"], function(item){
f[item] = function(){
//Convert the "this" value for functions passed in:
var nl;
if(dojo.isFunction(arguments[0])){
var origFunc = arguments[0];
arguments[0] = function(item, index){
return origFunc.call(item, item, index);
}
}
if(item == "filter" && dojo.isString(arguments[0])){
var nl = this._filterQueryResult(this, arguments[0]);
}else{
var oldCtor = dojo._NodeListCtor;
dojo._NodeListCtor = f;
//Need to wrap in a $() call since internally some
//dojo.NodeList functions reference dojo.NodeList directly.
//Need to get a configurable constructor for dojo.NodeList.
nl = $(nlProto[item].apply(this, arguments));
dojo._NodeListCtor = oldCtor;
}
return nl._stash(this);
}
});
f.map = function(/*Function*/callback){
//Hmm, this is not like array map/dojo.map where you get one item back for
//each input.
return this._buildArrayFromCallback(callback);
}
$.map = function(/*Array*/ary, /*Function*/callback){
//Hmm, this is not like array map/dojo.map where you get one item back for
//each input.
return f._buildArrayFromCallback.call(ary, callback);
}
$.inArray = function(value, /*Array*/ary){
return dojo.indexOf(ary, value);
}
f.is = function(query){
return (query ? !!this.filter(query).length : false);
}
//TODO: probably a better way to do this.
f.not = function(){
var notList = $.apply($, arguments);
//TODO: another place where if dojo.NodeList can configure a constructor,
//then we could avoid the $() wrapper below.
var nl = $(nlProto.filter.call(this, function(node){
return notList.indexOf(node) == -1;
}));
return nl._stash(this);
}
f.add = function(){
return this.concat.apply(this, arguments);
}
function iframeDoc(/*DOMNode*/iframeNode){
// summary:
// Returns the document object associated with the iframe DOM Node argument.
//Taken from dojo.io.iframe.doc(). Needed for contents() function below.
var doc = iframeNode.contentDocument || // W3
(
(
(iframeNode.name) && (iframeNode.document) &&
(document.getElementsByTagName("iframe")[iframeNode.name].contentWindow) &&
(document.getElementsByTagName("iframe")[iframeNode.name].contentWindow.document)
)
) || // IE
(
(iframeNode.name)&&(document.frames[iframeNode.name])&&
(document.frames[iframeNode.name].document)
) || null;
return doc;
}
f.contents = function(){
var ary = [];
this.forEach(function(node){
if(node.nodeName.toUpperCase() == "IFRAME"){
var doc = iframeDoc(node);
if(doc){
ary.push(doc);
}
}else{
//TODO: code similar to children() function. Refactor?
var children = node.childNodes;
//Using for loop for better speed.
for(var i = 0; i < children.length; i++){
ary.push(children[i]);
}
}
});
return this._wrap(ary)._stash(this);
}
f.find = function(/*String*/query){
var ary = [];
this.forEach(function(node){
if(node.nodeType == 1){
ary = ary.concat(dojo._toArray($(query, node)));
}
});
return this._getUniqueAsNodeList(ary)._stash(this);
}
f.andSelf = function(){
return this.add(this._parent);
}
//END jquery Traversing API methods
//START jquery Manipulation API methods
//http://docs.jquery.com/Manipulation
f.remove = function(/*String?*/query){
//Override NodeList-manipulate's remove so we can remove data.
var nl = (query ? this._filterQueryResult(this, query) : this);
//Remove data
nl.removeData();
//Remove event listeners.
//TODO! do this, once event stuff is built out.
//Remove the items from the DOM, but keep them in this
//node list.
nl.forEach(function(node){
node.parentNode.removeChild(node);
});
return this;
}
//START jquery CSS API methods
//http://docs.jquery.com/CSS
$.css = function(/*DOMNode*/node, /*String|Object*/name, /*String|Number?*/value){
name = cssNameToJs(name);
//Hmm, dojo.style does an arguments. length check.
var result = (value ? dojo.style(node, name, value) : dojo.style(node, name));
return result;
}
f.css = function(/*String|Object*/name, /*String|Number?*/value){
if(dojo.isString(name)){
//Convert name to JS name if needed.
name = cssNameToJs(name);
if(arguments.length == 2){
//set the value. Cannot directly delegate to
//this.style, since non-element nodes may be in the mix?
//this.contents() in particular will return some funky stuff.
//Need to be sure to add "px" if appropriate.
if(!dojo.isString(value) && name != "zIndex"){
value = value + "px";
}
this.forEach(function(node){
if(node.nodeType == 1){
dojo.style(node, name, value);
}
});
return this;
}else{
//return the value
value = dojo.style(this[0], name);
//Need to be sure to add "px" if appropriate.
if(!dojo.isString(value) && name != "zIndex"){
value = value + "px";
}
return value;
}
}else{
for(var param in name){
this.css(param, name[param]);
}
return this;
}
}
function doBox(/*NodeList*/nl, /*String*/boxType, /*String*/prop, /*String||Number*/value){;
if(value){
//Set height for all elements.
var mod = {};
mod[prop] = value;
nl.forEach(function(node){
dojo[boxType](node, mod);
});
return nl;
}else{
//Just get first node's height.
//Hmm. width is negative when element is display none in FF3?
return Math.abs(Math.round(dojo[boxType](nl[0])[prop]));
}
}
f.height = function(value){
return doBox(this, "contentBox", "h", value);
}
f.width = function(value){
return doBox(this, "contentBox", "w", value);
}
function getDimensions(/*DOMNode*/node, /*String*/type, /*Boolean*/usePadding, /*Boolean*/useBorder, /*Boolean*/useMargin){
// summary:
// sums up the different parts of the width/height based on arguments.
//If hidden, temporarily show it, do measurements then close.
var rehide = false;
if((rehide = node.style.display == "none")){
node.style.display = "block";
}
var cs = dojo.getComputedStyle(node);
var content = Math.abs(Math.round(dojo._getContentBox(node, cs)[type]));
var pad = usePadding ? Math.abs(Math.round(dojo._getPadExtents(node, cs)[type])) : 0;
var border = useBorder ? Math.abs(Math.round(dojo._getBorderExtents(node, cs)[type])) : 0;
var margin = useMargin ? Math.abs(Math.round(dojo._getMarginExtents(node, cs)[type])) : 0;
if(rehide){
node.style.display = "none";
}
return pad + content + border + margin;
}
f.innerHeight = function(){
return getDimensions(this[0], "h", true);
}
f.innerWidth = function(){
return getDimensions(this[0], "w", true);
}
f.outerHeight = function(useMargin){
return getDimensions(this[0], "h", true, true, useMargin);
}
f.outerWidth = function(useMargin){
return getDimensions(this[0], "w", true, true, useMargin);
}
//END jquery CSS API methods
//START jquery Events API methods
//http://docs.jquery.com/Events
//ready() already defined above.
//Event plumbing.
var listeners = [];
var listenId = 1;
var eventAttr = dojo._scopeName + "eventid";
var currentEvtData;
function getNonNamespacedName(/*String*/evtName){
// summary:
// gets name of the event before the first ".".
//The $$ stuff is special ids used to create unique names
//for bound functions that did not have a unique namespace name.
evtName = evtName.split("$$")[0];
var dotIndex = evtName.indexOf(".");
if(dotIndex != -1){
evtName = evtName.substring(0, dotIndex);
}
return evtName;
}
function domConnect(/*DOMNode*/node, /*String*/evtName){
// summary:
// handles creating the connection with a real DOM event.
//This work should only be done one time per evName type.
//If the event if an ajax event, use dojo.subscribe instead.
if(evtName.indexOf("ajax") == 0){
return dojo.subscribe(topics[evtName], function(dfd, res){
var fakeEvt = new $.Event(evtName);
if("ajaxComplete|ajaxSend|ajaxSuccess".indexOf(evtName) != -1){
triggerHandlers(node, [fakeEvt, dfd.ioArgs.xhr, dfd.ioArgs.args]);
}else if(evtName == "ajaxError"){
triggerHandlers(node, [fakeEvt, dfd.ioArgs.xhr, dfd.ioArgs.args, res]);
}else{
//ajaxStart|ajaxStop
triggerHandlers(node, [fakeEvt]);
}
});
}else{
return dojo.connect(node, "on" + evtName, function(e){
triggerHandlers(node, arguments);
}); //Object
}
}
//Event object for compatibility for some tests.
$.Event = function(/*String*/type){
//Allow for calling function without "new"
if(this == $){
return new $.Event(type);
}
if(typeof type == "string"){
this.type = type.replace(/!/, "");
}else{
dojo.mixin(this, type);
}
this.timeStamp = (new Date()).getTime();
this._isFake = true;
this._isStrict = (this.type.indexOf("!") != -1);
}
var ep = $.Event.prototype = {
preventDefault: function(){
this.isDefaultPrevented = this._true;
},
stopPropagation: function(){
this.isPropagationStopped = this._true;
},
stopImmediatePropagation: function(){
this.isPropagationStopped = this._true;
this.isImmediatePropagationStopped = this._true;
},
_true: function(){ return true; },
_false: function(){ return false; }
}
dojo.mixin(ep, {
isPropagationStopped: ep._false,
isImmediatePropagationStopped: ep._false,
isDefaultPrevented: ep._false
});
function makeTriggerData(data, type){
// summary:
// makes sure that the data array is copied
// and has an event as the first arg. If this function generates
// a fake event (known by the data[0]._isFake property being true)
// then the data[0].target needs to be set by the consumer of this function.
data = data || [];
data = [].concat(data);
//If first data item is not an event, make one up.
//Need to set up target: prop in the consumers of this
//function.
var evt = data[0];
if(!evt || !evt.preventDefault){
evt = type && type.preventDefault ? type : new $.Event(type);
data.unshift(evt);
}
return data;
}
var triggerHandlersCalled = false;
function triggerHandlers(/*DOMNode*/node, /*Array*/data, /*Function?*/extraFunc){