-
Notifications
You must be signed in to change notification settings - Fork 0
/
EZgetset.try1.js
2213 lines (1971 loc) · 78.9 KB
/
EZgetset.try1.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
/**************************************************************************************
EZ.getEl, upgraded and moved to EZget_set.js
***************************************************************************************/
/*---------------------------------------------------------------------------------------------
For new organizational structure, functions moved to one of the following files:
EZ/RZprototypes.js (same file) and should also match EASY.prototypes.js
prototypes and related functions
EZ/RZgetset.js (same file) future replacement for EASY.core.js::EZ(...)
EZ/RZcommon.js (same file) common functions from RevizeCommon.js non-dreamweaver specific
and partial port of EASY.js functions
EZdwutils.js (latest) Dreamweaver/Revize specific functions: e.g. getDOM()
RZdwutils.js (legacy) old versions of DW functions used by Revize Extension
----------------------------------------------------------------------------------------------
Define global varibles if not defined -- EZ() requires EZprototypes.js
It is simply defined here to properly initialize the global EZ object as a function.
---------------------------------------------------------------------------------------------*/
/*global
EZgetTagType,
EZ, dw:true, e:true */
/*global EZnone, EZtoArray, EZis, EZisEl, EZgetPref, EZsetPref, EZsetValue */
var e;
(jshint_globals_not_used = function jshint_globals_not_used() { //global variables and functions defined but not used
e = [e]
});
if (!window.dw) dw = {isNotDW: true};
if (!EZ.dw)
{ //global data shared by all commands
EZ.dw = window.dw ? dw.constructor.EZ : {};
if (!EZ.dw) EZ.dw = dw.constructor.EZ = {};
}
EZ.legacy = EZ.merge(EZ.legacy,
{
//EZisEmpty: false,
//EZgetEl:true,
//EZgetEl_notFound:null,
//EZgetStyle:false,
//EZhasClass:false,
'':''
});
/*---------------------------------------------------------------------------------------------
EZ.getEl(selectors, doc) -- FULL FUNCTIONALITY --
If multiple elements match the selector or the selector is a collection al elements, only the
1st element is returned. If the selector is an array, all elements matching all non-empty
selectors is returned. To always get a single element for selector arrays, use EZ._().
if no element is found matching any of specified selectors, a generic element is returned not
connected to anything visible. It has all the most common properties and attibutes of any tag.
This avoids js errors when subsequent code assumes an element or field is returned which often
happens when selectors are mis-spelled or elements are deleted w/o deleting all related script.
Only enough selectors are tried until one or moe elements match form fields or elements
UNLESS called from EZ.getAll() in which case all selectors are processed. In either case,
selectors are used until match found for fieldname, id, tagName or className in that order.
ARGUMENTS:
selectors one or more html elements or a comma delimited string of selector(s), or array
of elements and selectors (only one element or selector allow per array item)
doc (optional) root element used to locate elements matching specified selectors
defaults to document if only 2 args and 2nd arg is options
options (optional) determines how many elements are returned and/or an array containing
(last arg) one or more elements is returned as explained below:
false only one element returned
true only 1st element found is returned as single element array
@ all elements matching any of the selectors always returned as
array even if none are found
default =true when selectors arg is array =false otherwise
RETURNS:
either single element or array of elements matching one or more selectors -- if no elements
are found matching any of the supplied selectors, a pseudo element is created and returned.
TODO:
support selector prefixes and only try matching associated type:
"#" element id -- "." className -- "@" fieldName -- "<" tagName with or w/o ">" suffix
when id or field name specified, only select if under doc root
compound seelectors e.g. #someid.li ul
multiple arguments containing more selectors ??
// determine if stopping after 1st match or using all all selectors
var patternfunction = /function\s*(\w*)\s*\((.*?)\)[^{]*{\s*([\s\S]*)}/;
var callerName = EZ.matchPlus(arguments.callee.caller, patternfunction)[1];
var stopAfterFirst = /^(RZ|EZ)_$/.test(callerName) //always stop if caller EZ._()
|| /^(RZ|EZ)\$$/.test(callerName) //never stop if caller EZ$() or ...
|| (!EZ.is(els) && els.length > 1); //...multiple selectors but not els
--------------------------------------------------------------------------------------------------*/
EZ.getEl = function EZgetEl(selectors, nodes)
{
var settings = EZ.is(nodes, EZgetEl.getSettings)
? EZ.merge(nodes, {selectors:selectors}) //called with pre-defined settings
: new EZ.getEl.getSettings(this, arguments); //breakpoint for settings not defined
/** PARTIAL LIST OF SETTINGS:
*
* one:T/F only return 1st html element found -- all:T/F return Array of all tags for all selectors
*
* root(s) starting dom nodes -- nodes: additional starting nodes -- doc: legacy single root
*
* selectors: Array of selectors: only first match unless specified as Array (implicit all:true)
*
* notFound: object returned if no tags found: EZnone by default -- null if nodes=null
*/
//--------------------------------------------------------------------
// legacy code -- doc must be document object
// use above new code for correct doc value
//--------------------------------------------------------------------
if (settings.legacy)
{
var doc = settings.doc;
var els = settings.selectors[0];
for (var i=0; i<els.length; i++)
{
var el = els[i] || '';
if (el == null) continue;
if (typeof(el) != 'object' && doc.forms.length && doc.forms[0][el])
el = doc.forms[0][el]; //el is form field
if (typeof(el) != 'object') //if not object, try as id
el = doc.getElementById(el + '');
if (el == null)
{
var tags = document.getElementsByTagName(els[i]+'');
if (tags.length) return tags[0];
}
if (el) return el; //return if element
}
return null; //null if el not found
}
//--------------------------------------------------------------------
// newest code
//--------------------------------------------------------------------
var tags = [];
//----- Nothing selected
while (settings.selectors.length > 0 && settings.roots.length > 0)
{
//----------------------------------------------------------------------------------
//----- FAST SELECT: all selectors are elements
//----------------------------------------------------------------------------------
if (EZ.isEl(settings.selectors)) //nodes exploded && (!settings.nodes.length || EZ.isEl(settings.nodes)))
{ //keep tags in default or specified root(s)
tags = settings.selectors;
if (!EZ.getEl_getDescendants(tags, settings.roots))
break;
if (settings.nodes.length)
EZ.getEl_getDescendants(tags, settings.nodes);
break;
}
//----------------------------------------------------------------------------------
//----- Full selection algorithm
//----------------------------------------------------------------------------------
[].every.call(settings.selectors, function forEverySpecifiedSelector(sel)
{
if (!EZ.getEl_isSelectorType(sel) || sel == null) return true; //skip invalid type
sel = EZ.toArray(sel, false); //TODO ','
[].every.call(settings.selectors, function forEveryCommaDelimitedSelector(sel)
{
if (!EZ.getEl_isSelectorType(sel) || sel == null) return true;
return [].every.call(settings.roots, function forEveryRootElement(root)
{
//-----------------------------------------------------------------------------
// recursively call EZ.getEl() for chained selections from:
// optional nodes argument when called from context element...
// ...fully exploded into elements by getSettings()
// -AND/OR- by space delimited selectors ... exploded below
//-----------------------------------------------------------------------------
var chainedSelections = EZ.toArray(sel,' ');
sel = chainedSelections.pop(); //remove single selector or last in chain
[
settings.nodes, //1st apply nodes selector
chainedSelections //selector(s) exploded except last one
].forEach(function forEachChain(nodes)
{
if (nodes.length > 0) debugger;
if (EZ.quit) return false;
//for ALL nodes and chained selections . . .
nodes.forEach(function forEachChainedSelector(node)
{ //get and save ALL matching tags . . .
EZ.getEl_addElements(nodes, EZ.getEl(node, settings.baseSetting));
}); //last selector applied to all matches
});
//----- if selector is element, array of elements or html collection
if (EZ.isEl(sel) //...only add elements descendant of roots??
&& EZ.getEl_getDescendants(sel,root))
if (EZ.getEl_addElements(sel)) return;
//----------------------------------------------------------------------------
// for compound selector (e.g #footer.div.input) keep checking until any part
// of selectors does not match or all parts checked.
//-----------------------------------------------------------------------------
var parts = EZ.getEl_getCompoundParts(sel);
if (!parts) parts = [];
if (parts.length > 1) debugger;
if (EZ.quit) return false;
return parts.every(function forEverySelectorPart(sel)
{
if (sel == null) return false; //invalid compound
if (EZ.isArray(sel)) //sel is Array of parts if compound . . .
{
return sel.every(function forEveryMatchingPart(sel)
{
if (!sel) return true; //continue empty or EZnone selector
el = EZ.getEl(el, settings.baseSettings);
if (!el.length) //if not found, break out of loop
return false;
if (EZ.getEl_addElements(el)) //also break if one is enough
return false;
});
}
//??? NOTE: below code is only run via recursive if above compound code runs
var e, prefix = '';
if (typeof(sel) == 'string')
{
var groups = sel.matchPlus(/([#.<@])?(.*?)(>|$)/);
prefix = groups[1]; //if selector qualified with: # . < -or- @
sel = groups[2]; //remove qualifier
}
if ('@'.indexOf(prefix) < 1)
{ //try for form field match
e = EZ.getEl_getFormField(sel,root)
if (e != null)
{
if (EZ.getEl_addElements(e)) //quit if one is enough
return false;
}
}
if ('#'.indexOf(prefix) < 1)
{ //try for id match
e = EZ.getEl.getDocument(root).getElementById(sel);
if (EZ.isEl(e) && EZ.getEl_getDescendants(e,root) != null)
{
if (EZ.getEl_addElements(e)) //quit if one is enough
return false;
}
}
if ('<'.indexOf(prefix) < 1)
{ //try as tagName
e = root.getElementsByTagName(sel);
if (EZ.isEl(e))
{
if (EZ.getEl_addElements(e)) //quit if one is enough
return false;
}
}
if ('.'.indexOf(prefix) < 1)
{ //try as css class
e = root.getElementsByClassName(sel)
if (EZ.isEl(e))
{
if (EZ.getEl_addElements(e)) //quit if one is enough
return false;
}
}
return true; //breakpoint here for not found or selecting all
}); //end of compound parts
}); //end of roots
}); //end of comma delimited selector
}); //end of selectors
break;
} //end Fast or Full selection
//----- Set tags to settings.notFound if no tags selected
if (!tags.length)
{
var notFound = '.notFound'.ov(settings) || 'EZnone';
tags = notFound == 'EZnone'
? [EZ.none(settings)] //EZ.none() pseudo tag is default
: typeof(settings.notFound) == 'object'
? settings.notFound //e.g. [] or {} and null
: [settings.notFound]; //Array if notFound is not object
}
else
tags = tags.removeDups();
EZ.tags = tags;
EZ.el = tags[0];
//================================================================================
if (settings.one && tags != null) //if returning 1st tag...
return EZ.bindElements(tags[0]) //...bind 1st tag if not yet bound
else //if returning Array or html collection...
return EZ.bindElements(tags) //...bind Array/collection and tags
//================================================================================
/**
* Add nodes to tags array, return true to continue selecting elements
*/
EZ.getEl.addElements = function EZgetEl_addElements(nodes)
{
if (nodes == null) return true;
if (settings.asis && !tags.length && EZ.isArrayLike(nodes))
tags = nodes; //save html collection as is if no other tags
else
{
if (!EZ.isArrayLike(tags)) //html collection...
tags = [].slice.call(tags); //...copy to new Array
EZ.toArray(nodes).forEach(function(el)
{
tags.push(el) //add each node to tags
});
}
return !settings.all; //return true to quit selecting more nodes
}
/**
* return selector parts as Array of selectors for compound selectors
* otherwise return selection as single element Array.
*
*/
EZ.getEl.getCompoundParts = function EZgetEl_getCompoundParts(sel)
{
if (typeof(sel) != 'string') return [sel]; //return if not string
if (/:\]\[]/.test(sel)) return undefined; //unsupported selector char
if (!/[#.:\]\[\w\d]/.test(sel)) return null; //invalid selector char
var groups = sel.matchPlus(/(\S)(([#.])([\w\d]*))/);
if (!groups == false) return [sel]; //if nothing found, not compound
var parts = [];
if (/^[\w\d]/.test(groups[0])) //1st part is tag
parts.push('<' + groups.shift());
while (groups.length) //process remaining parts
{
var prefix = groups.shift();
if (!groups.length) return null; //invalid if last taken
if (/^[\w\d]/.test(groups[0])) return null; //invalid if not followed by word
parts.push(prefix + groups.shift());
}
return parts;
}
/**
* Get html collection of all form field(s) matching selector -- return any that are decendents
* of element that called EZ.getEl() -or- all elements if EZ.getEl() was not called from element.
*
* return null if none found or none are decendents otherwise return those that are decendents.
*/
EZ.getEl.getFormField = function EZgetEl_getFormField(sel,root)
{
var tags = [];
[].every.call(EZ.getEl.getDocument(root).forms, function forEveryForm(form)
{
if (!form[sel]) return true; //keep looking until field(s) found
if (false && !tags.length)
tags = EZ.toArrayLike(form[sel]); //retain html collection
else
{
tags = [].slice.call(tags);
tags = tags.concat(EZ.toArray(form[sel]));
}
//tags.push(form[sel]);
if (EZ.getEl_getDescendants(tags,root) == null)
return true; //keep looking if no tags are descendants
});
return (tags.length > 0) ? tags : null;
}
/**
* return tags that are decendents of element that called EZ.getEl()
disabled this test
-OR- all tags returned when
* EZ.getEl() not called from an element i.e. EZgetEl.settingsroot is document object.
*/
EZ.getEl.getDescendants = function EZgetEl_getDescendants(tags, root)
{
if (tags == null) return tags; // || root == document //could have diff document
tags = EZ.toArray(tags, false);
for (var idx=tags.length-1; idx>=0; idx--)
{
//if (root.indexOf(tags[0].ownerDocument) != -1) continue;
if (!EZ.isAncestor(tags[idx], root))
Array.prototype.splice.call(tags, idx, 1); //remove tags[idx] is not decendent
}
return (tags.length > 0) ? tags : null;
}
/**
* return true if valid variable typeof and valid element, Array or collection of elements
* TODO: ^([.#a-zA-Z0-9_:[\])])+[,><a-zA-Z0-9_~=\"\":[\] ]*?$
*/
EZ.getEl.isSelectorType = function EZgetEl_isSelectorType(sel)
{
if ((!sel && sel !== '0')
|| 'string number object'.indexOf(typeof(sel)) == -1)
return false; //skip empty or EZnone selector
if (typeof(sel) == 'object' && !EZ.isEl(sel))
return false;
return true;
}
}
//_____________________________________________________________________________________________
EZgetEl.test = function ()
{
/*global
tstArrayObj, tstArrayObj.abc, tstFn, tstObj, tstObjArrayLike, tstObjArrayLike.xyz,
tstObjEmptyArray, t_doc, t_html, t_head, t_title, t_body, t_wrap, t_labels, t_inputs,
t_forms, t_fm, t_none, t_tags, t_array, t_divs, t_radios, t_radio01, t_label_some,
t_mixed, t_idandclass
*/
(function jshint_globals_not_used() { //global variables and functions defined but not used
e = [
tstArrayObj, tstArrayObj.abc, tstFn, tstObj, tstObjArrayLike, tstObjArrayLike.xyz,
tstObjEmptyArray, t_doc, t_html, t_head, t_title, t_body, t_wrap, t_labels, t_inputs,
t_forms, t_fm, t_none, t_tags, t_array, t_divs, t_radios, t_radio01, t_label_some,
t_mixed, t_idandclass
]})
EZ.test.run("----- backup copy of saved data -----", {EZ: {note:'not chained selector'}});
if (true) return;
var ex_radios = [].slice.call(t_radios);
EZ.test.run(['EZtest_radio'], {EZ: {ex:ex_radios, note:'selector: radio group name'}});
EZ.test.run(['test_id1'],t_wrap, {EZ: {ex:t_idandclass, note:'id AND class'}});
EZ.test.run('input',t_wrap, {EZ: {ex:t_inputs[0], note:'field'}});
EZ.test.run('EZTEST_TAG' ,t_wrap, {EZ: {ex:t_tags[0], note:'tag' }});
EZ.test.run('EZtest_class0',t_wrap, {EZ: {ex:t_tags[0], note:'class'}});
EZ.test.run('test_id1',t_wrap, {EZ: {ex:t_labels[1], note:'id selector'}});
EZ.test.run('.test_id1',t_wrap, {EZ: {ex:t_inputs[3], note:'class not id' }});
EZ.test.run('@input',t_wrap, {EZ: {ex:t_inputs[0], note:'field'}});
EZ.test.run('<tags',t_wrap, {EZ: {ex:t_tags[0], note:'tag' }});
EZ.test.run('.class1',t_wrap, {EZ: {ex:t_tags[1], note:'class'}});
//EZ.test.run(tags.EZ, '', {EZ: {ex:t_none, note:'' }});
EZ.test.run(null, {EZ: {ex:t_none, note:'' }});
EZ.test.run(0, {EZ: {ex:t_none, note:'' }});
EZ.test.run('0', {EZ: {ex:t_none, note:'' }});
EZ.test.run('tag', {EZ: {ex:t_tags[0], note:'' }});
EZ.test.run(['tag'], {EZ: {ex:t_tags, note:'' }});
EZ.test.run(['tag'],false, {EZ: {ex:t_tags[0], note:'' }});
EZ.test.run('tag', true, {EZ: {ex:t_tags, note:'' }});
EZ.test.run('tag', false, {EZ: {ex:t_tags[0], note:'' }});
EZ.test.run('tag', null, {EZ: {ex:t_tags, note:'' }});
EZ.test.run('notags', {EZ: {ex:t_none, note:'' }});
EZ.test.run('notags', null, {EZ: {ex:null, note:'' }});
EZ.test.run('div', t_tags[1], {EZ: {ex:t_divs[1] }});
EZ.test.run('div', {EZ: {ex:t_divs }});
EZ.test.run('radio','div', {EZ: {ex:t_radios[1] }});
EZ.test.run('radio',t_tags[1], {EZ: {ex:t_radio01, }});
EZ.test.run('radio', {EZ: {ex:t_radio01, ctx:t_tags[1] }});
//not sure how these should work -- convert to chained ??
EZ.test.run('radio',t_divs[1], {EZ: {ex:null, ctx:t_tags[1] }});
EZ.test.run('radio','div', {EZ: {ex:null, ctx:t_tags[1] }});
EZ.test.run('radio','notag', {EZ: {ex:null, ctx:t_tags[1] }});
note = 'not document descendant'
var div = document.createElement('div'); //alot more descendand scenarios
EZ.test.run(EZgetEl, div, {EZ: {ex:null, note:note}} );
}
EZ.test.run("----- backup copy of saved data -----", {EZ: {note:'not chained selector'}});
if (true) return;
var ex_radios = [].slice.call(t_radios);
EZ.test.run(['EZtest_radio'], {EZ: {ex:ex_radios, note:'selector: radio group name'}});
EZ.test.run(['test_id1'],t_wrap, {EZ: {ex:t_idandclass, note:'id AND class'}});
EZ.test.run('input',t_wrap, {EZ: {ex:t_inputs[0], note:'field'}});
EZ.test.run('EZTEST_TAG' ,t_wrap, {EZ: {ex:t_tags[0], note:'tag' }});
EZ.test.run('EZtest_class0',t_wrap, {EZ: {ex:t_tags[0], note:'class'}});
EZ.test.run('test_id1',t_wrap, {EZ: {ex:t_labels[1], note:'id selector'}});
EZ.test.run('.test_id1',t_wrap, {EZ: {ex:t_inputs[3], note:'class not id' }});
EZ.test.run('@input',t_wrap, {EZ: {ex:t_inputs[0], note:'field'}});
EZ.test.run('<tags',t_wrap, {EZ: {ex:t_tags[0], note:'tag' }});
EZ.test.run('.class1',t_wrap, {EZ: {ex:t_tags[1], note:'class'}});
//EZ.test.run(tags.EZ, '', {EZ: {ex:t_none, note:'' }});
EZ.test.run(null, {EZ: {ex:t_none, note:'' }});
EZ.test.run(0, {EZ: {ex:t_none, note:'' }});
EZ.test.run('0', {EZ: {ex:t_none, note:'' }});
EZ.test.run('tag', {EZ: {ex:t_tags[0], note:'' }});
EZ.test.run(['tag'], {EZ: {ex:t_tags, note:'' }});
EZ.test.run(['tag'],false, {EZ: {ex:t_tags[0], note:'' }});
EZ.test.run('tag', true, {EZ: {ex:t_tags, note:'' }});
EZ.test.run('tag', false, {EZ: {ex:t_tags[0], note:'' }});
EZ.test.run('tag', null, {EZ: {ex:t_tags, note:'' }});
EZ.test.run('notags', {EZ: {ex:t_none, note:'' }});
EZ.test.run('notags', null, {EZ: {ex:null, note:'' }});
EZ.test.run('div', t_tags[1], {EZ: {ex:t_divs[1] }});
EZ.test.run('div', {EZ: {ex:t_divs }});
EZ.test.run('radio','div', {EZ: {ex:t_radios[1] }});
EZ.test.run('radio',t_tags[1], {EZ: {ex:t_radio01, }});
EZ.test.run('radio', {EZ: {ex:t_radio01, ctx:t_tags[1] }});
//not sure how these should work -- convert to chained ??
EZ.test.run('radio',t_divs[1], {EZ: {ex:null, ctx:t_tags[1] }});
EZ.test.run('radio','div', {EZ: {ex:null, ctx:t_tags[1] }});
EZ.test.run('radio','notag', {EZ: {ex:null, ctx:t_tags[1] }});
note = 'not document descendant'
var div = document.createElement('div'); //alot more descendand scenarios
EZ.test.run(EZgetEl, div, {EZ: {ex:null, note:note}} );
}
/**
* return document object for el
*/
EZ.getEl.getDocument = function EZgetElGetDocument(el)
{
return EZ.is(el, document.constructor)
? el //el is document object
: el.ownerDocument
|| document; //safety for expected
}
/*---------------------------------------------------------------------------------------------
* 1st arg is always selector(s); if more optional arguments . . .
*
* options last arg if boolean, null or any non-dom html object*
* defaultOptions 2nd arg if more than 2 args and any non-dom html object*
*
* nodes 2nd arg when 2nd arg is NOT options, defaultOptions,
* undefined, null or blank -and- IS dom html element object*
* or selector specified as string or Array otherwise...
* default: document
*
* NOTE: * EZ.isNonElObject() or EZ.isEl() used to determine if dom object or not
-----------------------------------------------------------------------------------*/
EZ.getEl.getSettings = function EZgetElGetSettings(ctx, args)
{
//----- context root element(s) -- EZget/EZset pass context elements as nodes
this.roots = ctx == window || typeof(ctx) == 'function' ? []
: EZ.toArray(ctx); //breakpoint here for element context
var args = args.length ? [].slice.call(args) : ['']; //get real non-empty Array
//----- get defaultOptions -- its last arg if object containing defaults property
var defaultOptions = '.defaults'.ov(args[args.length-1])
? args.pop().defaults
: '';
//----- get options -- its now last arg if any of following:
var options = args[args.length-1];
options = (options === true) ? {all: true, one:false}
: (options === false) ? {all: false, one:true}
: (options === null) ? {notFound: false}
: EZ.isObject(options) ? options
: ''; //breakpoint here for options NOT found
if (options)
args.pop(); //breakpoint here for options found
//----- get selectors argement -- now next item in args --
this.selectors = args.shift();
var isMultipleSelectors = (EZ.isArray(this.selectors) && !EZ.isEl(this.selectors));
//keep ArrayLike html collection...
this.selectors = EZ.toArray(this.selectors, false); //...so it can returned "as is"
//----- get nodes argument -- now next item in args
this.nodes = EZ.toArray(args.shift()); //clone nodes html collection as...
//...real Array its not returned
//---------------------------------------------------------------------------------
// set overrideable options to specified value or defaults
//---------------------------------------------------------------------------------
var settings = { //value or object returned when no tags found
notFound: 'EZ.legacy.EZgetEl.notFound'.ov('EZnone'),
uniqueEZnone: false, //use unique EZnone when needed
all: isMultipleSelectors, //return all tags found by all selectors
one: !isMultipleSelectors, //return 1st tag found only 1st tag of collection
asis: false, //html colections returned as is
legacy: options ? false : 'EZ.legacy.EZgetEl'.ov(false)
}
this.baseSettings = EZ.merge({mergeOptions:{append:false}}, settings, defaultOptions, options);
EZ.merge(this, this.baseSettings);
// base settings for recursive calls to EZ.getEl()
this.baseSettings = EZ.merge(settings, {legacy:false, notFound:[], all:true, one:false});
//----- get elements for any context roots and/or nodes not specified as elements
EZ.getEl.getElements(this.roots, this.baseSettings, document);
EZ.getEl,getElements(this.nodes, this.baseSettings, this.roots);
//------ if roots not specified, use for nodes if specified
if (!this.roots.length && this.nodes.length > 0)
{
this.roots = this.nodes;
this.nodes = [];
}
if (!this.roots.length)
this.roots = [document];
if (this.selectors.length > 1
|| (this.nodes && this.nodes.length > 0) //if not moved to roots
|| (this.roots.length > 1 || !EZ.is(this.doc,document.constructor)))
this.legacy = false;
if (this.legacy)
this.doc = this.roots[0];
//_________________________________________________________________________________
/**
* recursive calls to EZ.getEl() to find elements for non-element selectors
* no nodes filter, array of all selections, empty array if no tags found.
* Uses pre-defined settings so EZ.getEl_getSettings() is not called again.
*/
function EZgetEl_getElements(tags, baseSettings, roots)
{
if (!tags) return;
if (!EZ.isArrayLike(tags) && !EZ.isEl(tags)) return;
if (EZ.isArrayLike(tags) && tags.length == 0) return;
var root = roots && roots.length && roots.length > 0 ? roots : document;
var settings = EZ.merge({mergeOptions:{maxdepth:0}}, baseSettings, {roots:root})
for (var idx=tags.length-1; idx>=0; idx--) //for each tag in reverse order
{
var el = tags[idx]; //replace each non-el selector with 0+ html elements
if (!EZ.isEl(el))
{
el = EZ.getEl(el, settings);
var spliceArgs = [].concat([idx,1], [].slice.call(el) );
Array.prototype.splice.apply(tags, spliceArgs);
}
}
}
}
}
/*-----------------------------------------------------------------------------------
EZ.none([selector(s)) -- return pseudo HTML element object
EZ.() variant return null if no elements found -OR-
Used to create
Custom toString() and valueOf() functions return "" and false respectfully ...BUT...
if (!EZ.none()) IS true*
if (!EZ.none() == false) -and- if (!EZ.none() === false) work just fine!!!
EZ.isFalse(EZ.none()) / EZ.isFalse(EZ.none()) return false or true as expected.
ARGUMENTS:
settings 1st arg if EZgetEl_settings
selectors
isUnique 1st arg if true -- create new EZnone element created
TODO: currently creates new shared EZnone
RETURNS:
new or existing EZnone
*JavaScript spec requires "if (Expression)..." or similar conditional be evaluated
as true when the expression is an Object ... dating back to the beginning of time.
-----------------------------------------------------------------------------------*/
EZ.none = function EZnone(/* [settings | selectors | isUnique] */)
{
var args = [].slice.call(arguments);
if (!args.length) args.push('');
var settings = EZ.is(args[0],EZgetEl.settings) ? args.shift() : '';
var isUnique = settings ? '.uniqueEZnone'.ov(settings) : args.shift();
var isOops = isUnique !== false;
var selectors = EZ.toArray('.selectors'.ov(settings, 'unknown'));
var item = EZ.collapse(selectors); //1st selector
if (!EZ.none) EZ.none = {}
if (!EZ.none.nextId) EZ.none.nextId = 0;
if (!EZ.noneTags) // create pseudo parent for EZnone tags
{
EZ.noneTags = document.getElementById('EZnone');
if (!EZ.noneTags)
{
EZ.noneTags = EZ.none_createElement('pre');
EZ.noneTags.setAttribute('id', 'EZnone');
}
var textNode = document.createTextNode('...');
EZ.noneTags.appendChild(textNode);
EZ.noneTags.style.fontFamily = 'monospace';
isUnique = true;
}
var node = EZ.noneTags.lastChild;
if (isUnique || EZ.noneTags.childNodes.length == 0)
{ //create new pseudo node returned
var id = '';
var name = '';
node = EZ.none_createElement('select');
node.setAttribute('id', id);
node.setAttribute('name', name);
node.style.width = '0px'; //fastselect loses attributes and styles
node.style.height = '0px';
node.style.border = '0px';
node.style.margin = '0px';
node.style.padding = '0px';
node.style.display = 'none';
node.valueOf = function()
{
/// console.log('valueOf()');
return null;
}
node.toString = function()
{
/// console.log('toString'); return this.textContent;
}
EZ.noneTags.appendChild(node);
// add attributes used by most most tags
var attributes = ('accept accept-charset accesskey action align allowtransparency alt '
+ 'border bottom center charset checked class cols coords disabled enctype '
+ 'frameborder height href hspace id justify label left longdesc '
+ 'marginheight marginwidth maxlength method middle multiple name onreset onsubmit '
+ 'readonly rel rev right rows scrolling selected shape size src style '
+ 'target title top type usemap value vspace width wrap' ).split(" ");
for (var i=0; i<attributes.length; i++)
if (!node.getAttribute(attributes[i]))
node.setAttribute(attributes[i],'');
node.checked = false;
EZ.bindElements(node);
}
//----- Save selectors and stackTrace that created EZnone
var e, msg = '';
if (isOops && 'EZ.beep.options.EZnone'.ov())
EZ.oops('EZnone selectors', selectors);
// try
// {
// /// undefined['EZnone'];
// }
// catch (e)
// {
// var ee;
// try
// {
// var stack = (e.stack+'').formatStack(1);
// var calledFrom = stack[1];
// stack[0] = selectors. join(', '); //replace msg
// var logStack = stack.slice(); //full stack for log
//
// //for html text: drop all but last EZ.(and anounymous functions ??)
// stack.splice(0,0,'-'.dup(50));
// stack[2] = '-'.dup(50) + '+';
//
// var fromIdx = 3;
// var lastEZ = '';
// while (/(at |\.)(EZ)/.test(stack[fromIdx])
// && stack[fromIdx].indexOf('.test') == -1)
// lastEZ = stack.splice(fromIdx,1);
// stack[fromIdx] = '...' + stack[fromIdx].trim() + '...'
// if (lastEZ)
// stack.splice(fromIdx,0,lastEZ[0]); //put last one back
//
// /// console.log({'EZnone for selector':selectors+'', 'in':calledFrom, 'stacktrace':logStack});
//
// var msg = stack.join('\n');
// EZ.noneTagsReferences = EZ.collapseMessages(EZ.noneTagsReferences, calledFrom, msg);
// msg = EZ.collapseMessages(EZ.noneTagsReferences);
//
// msg = msg.replace(/@.*?@:\s*/g, '');
// msg = msg.replace(/,\s*----[\s\S]*+/g, ',\n').replace(/+/g, '');
// msg = msg.replace(/x (\d*)/g, '-- $1 TIMES');
//
// EZ.noneTags.firstChild.textContent = '\nSELECTORS NOT FOUND . . .\n' + msg;
// }
// catch (ee)
// {
// EZ.techSupport(ee);
// }
// }
//======================
return node;
//======================
/**
*
*/
function EZnone_createElement(tagName)
{
var node = document.createElement(tagName);
node.undefined = true;
node.className = 'EZnone';
return node;
}
}
EZ.noneTags.appendChild(node);
// add attributes used by most most tags
var attributes = ('accept accept-charset accesskey action align allowtransparency alt '
+ 'border bottom center charset checked class cols coords disabled enctype '
+ 'frameborder height href hspace id justify label left longdesc '
+ 'marginheight marginwidth maxlength method middle multiple name onreset onsubmit '
+ 'readonly rel rev right rows scrolling selected shape size src style '
+ 'target title top type usemap value vspace width wrap' ).split(" ");
for (var i=0; i<attributes.length; i++)
if (!node.getAttribute(attributes[i]))
node.setAttribute(attributes[i],'');
node.checked = false;
EZbindElements(node);
}
//----- Save selectors and stackTrace that created EZnone
var e, msg = '';
if (isOops && 'EZ.beep.options.EZnone'.ov())
EZ.oops('EZnone selectors', selectors);
// try
// {
// /// undefined['EZnone'];
// }
// catch (e)
// {
// var ee;
// try
// {
// var stack = (e.stack+'').formatStack(1);
// var calledFrom = stack[1];
// stack[0] = selectors. join(', '); //replace msg
// var logStack = stack.slice(); //full stack for log
//
// //for html text: drop all but last EZ (and anounymous functions ??)
// stack.splice(0,0,'-'.dup(50));
// stack[2] = '-'.dup(50) + '+';
//
// var fromIdx = 3;
// var lastEZ = '';
// while (/(at |\.)(EZ)/.test(stack[fromIdx])
// && stack[fromIdx].indexOf('.test') == -1)
// lastEZ = stack.splice(fromIdx,1);
// stack[fromIdx] = '...' + stack[fromIdx].trim() + '...'
// if (lastEZ)
// stack.splice(fromIdx,0,lastEZ[0]); //put last one back
//
// /// console.log({'EZnone for selector':selectors+'', 'in':calledFrom, 'stacktrace':logStack});
//
// var msg = stack.join('\n');
// EZ.noneTagsReferences = EZcollapseMessages(EZ.noneTagsReferences, calledFrom, msg);
// msg = EZcollapseMessages(EZ.noneTagsReferences);
//
// msg = msg.replace(/@.*?@:\s*/g, '');
// msg = msg.replace(/,\s*----[\s\S]*+/g, ',\n').replace(/+/g, '');
// msg = msg.replace(/x (\d*)/g, '-- $1 TIMES');
//
// EZ.noneTags.firstChild.textContent = '\nSELECTORS NOT FOUND . . .\n' + msg;
// }
// catch (ee)
// {
// EZ.techSupport(ee);
// }
// }
//======================
return node;
//======================
}
/*---------------------------------------------------------------------------------------------
Return number occurances of chars (default char is dash)
---------------------------------------------------------------------------------------------*/
String.prototype.dup = function(number)
{
return EZ.dup(number,this);
}
EZ.dup = function EZdup(number,char)
{
var value = ''
if (!char) char = '-';
for (var i=0;i<number;i++)
value += char;
return value;
}
/*______________________________________________________________________________________________
functions ported from EASY js -- new functions and updates to be ported back to EASY js
______________________________________________________________________________________________*/
/*---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------*/
EZ.isTrueLike = function EZisTrueLike(value, options)
{
if (EZ.isTrueLike) return EZ.isTrueLike(value, options);
if (value === true || value === 'true'
|| value === 'on' || value === 'yes') return true;
if (typeof(value) == 'object' && !EZ.isNone(value)) return true;
return false;
}
/*---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------*/
EZ.isFalseLike = function EZisFalseLike(value)
{
if (value === false || value === 'false'
|| value === null || value == EZ.undefined
|| value === 'off' || value === 'no' || value === '') return true;
if (EZ.isNone(value)) return true;
return false;
}
/*---------------------------------------------------------------------------------------------
return true if trueLike; false if falseLike otherwise value
zero is NOT falseLike
---------------------------------------------------------------------------------------------*/
EZ.trueFalseValue = function EZtrueFalseValue(value)
{
if (EZ.isTrueLike(value)) return true;
if (EZ.isFalseLike(value)) return false;
return value;
}
/*---------------------------------------------------------------------------------------------
EZ.isTrue(value,options) --
Always returns true of false unless zerovalue:'value'
TODO: when should zero be interpreted as false -- why not just use: if (value)...
-or- EZ.trueFalseValue()
For value: true, 'true', 'on', 'yes', typeof(object or function) -- return true
For value: false, 'false', 'off', 'no' or EZ.isNone(value) -- return false
otherwise return value
---------------------------------------------------------------------------------------------*/
EZ.isTrue = function EZisTrue(value, options)
{
//11-03-2015: causes infinite loop
//if (EZ.isTrue) return EZ.isTrue(value, options);
options = options || {zerovalue:false}
if (EZ.isTrueLike(value)) return true;
if (EZ.isFalseLike(value)) return false;
switch(options.zerovalue + '')
{
case 'false' : return false;
case 'true' : return true;
case 'value' :
default : return value;
}
}
/*---------------------------------------------------------------------------------------------
EZ.isNone(value)
Does not use EZ.getOptions() -- can be used during options setup
---------------------------------------------------------------------------------------------*/
EZ.isNone = function EZisNone(value)
{
if (typeof(value) == 'unknown' || value === undefined || value === null)
return true;
switch(typeof value)
{
case 'string' : return value === '';
case 'number' : return isNaN(value);
case 'boolean':
case 'function': return false;
case 'object':
{
if (EZ.isArrayLike(value)) return (value.length === 0);
if (value.undefined) return true;
//e.g. IE events
if (value.constructor != Object || !value.hasOwnProperty) return false;
for (var p in value) //if any object property/element found, not none
if (value.hasOwnProperty(p)) return false;
return true; //empty object considered none
}
}
return true; //unexpected scenario -- everything should be covered above
}