-
Notifications
You must be signed in to change notification settings - Fork 0
/
EZdeleteme.js
6896 lines (6109 loc) · 213 KB
/
EZdeleteme.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
/*global
EZgetTagType,
EZselectScroll,
EZnone,
EZ, dw:true, DWfile, e:true, g */
var e;
(function jshint_globals_not_used() { //global variables and functions defined but not used
e = [
e, g, dw, DWfile]
});
//_________________________________________________________________________________________________
e = function _____EZfunctions_EZstack_____() {} //convenience for DW functions list
//_________________________________________________________________________________________________
/*--------------------------------------------------------------------------------------------------
EZ.getFunctionName(skip, rtnObj)
Originally created for EZ.capture() including EZ.techSupport() new capture and EZ.fault() interfaces.
Consolidates a lot of function and call statement parsing as well as new logic to derive fn from
call stack when function name property is blank (e.g. closures and Object properties).
Works quite well when called with fn String or Regex -- using know stack position -- Chrome always
has fn name on call stack (even for unnmed fn) will use variable or Object key assigned to function.
Is not nested name.
ARGUMENTS:
fn (optional) specifies function or fn name -- If blank or omitted get immediate caller.
(String) name or regular expression of stack line immediately proceeding the function
(RegExp) name returned.
(Function) return name for this function -- if the function does not have name property,
the stack is searched for matching function (stack name must have global scope)
If not found on stack, the script containing the function is searched for the
variable or Object key containing function statement.
rtnObj (optional) If Object, following fn properties returned:
filename:
lineno:
column:
TODO: ...
statement: string containing call statement
argNames: Array containing named arguments on function state
callNames: Array containing variable names from call statement or json
representaion of expression if call argument not a variable
script: function script if available
arguments: current fn arguments Object if from is function -or-
fn name has global scope
RETURNS:
specified from function name
rtnObj set to fn properties descibed above
TODO:
only implemented funtionality used by EZ.capture
find function name by recursively looking for macth to an Object in the from context.
--------------------------------------------------------------------------------------------------*/
EZ.functions.getName = function EZfunctions_getName(fn, rtnObj)
{
var isNext = false
switch (EZ.getType(fn, NaN))
{ //sort arguments
case 'String':
case 'RegExp':
isNext = true; //next fn on stack
break;
case 'Number': //no of fn before us on stack
case 'Function': //get name for specified fn
break; //good as-is
case 'Array':
case 'Object': //fn omitted
{
rtnObj = fn;
fn = 0;
break;
}
default: //including NaN
fn = 0; //immediate caller on stack
}
var name, stack;
while (true)
{
if (typeof(fn) == 'function')
name = fn.name || fn.displayName;
if (name) break;
//column 20 when w/o tabs else column 14
stack = EZ.stack(fn, isNext); //get fn from stack
if (!stack.fault)
{
name = stack.get('name');
if (name) break;
}
//TODO: not tested
//name = EZ.functions.mapName(fn);
//if (name) break;
return ''; //fn name not found
}
//-------------------------------------------------\\
//----- return fn properties if rtnObj supplied -----\\
//-----------------------------------------------------\\
while (typeof(rtnObj) == 'object')
{
if (!stack) stack = EZ.stack(name);
if (stack.fault) break; //bail if fn name not found on stack
var url = stack.get('url'); //call stack url, lineno, column
url = url.replace(/(http:.*?)\/(?=\w+\.(js|htm|html|php|jsp|asp))/g, '.../'); //TODO: ??
rtnObj.url = url;
rtnObj.lineno = stack.get('lineno');
rtnObj.column = stack.get('column');
/*TODO: needs work -- but EZ.capture not using yet
var args = EZ.stack.get('arguments',stack,fn); //get fn and call statement arguments
if (!args) break; //bail if not available
//save fn statement
rtnObj.arguments = []; //save json of call arguments values
for (var i=0; i<args.length; i++)
rtnObj.arguments[i] = EZ.stringify(args[i], '*');
*/
break;
}
//==========
return name;
//==========
}
/*--------------------------------------------------------------------------------------------------
EZ.functions.mapName(fn)
Find function name the hard way (from script)
First look in function map for matching function script. If not found, scan each script until a
match is found -- as each script is scanned, its added to map to avoid scanning more than once.
ARGUMENTS:
fn
RETURNS:
function name if found
TODO:
NOT TESTED -- does not appear needed for EZ.capture on chrome -- stack has name
(not nested name but so what)
stript comments
EZ.functionMap = EZ.functionMap || {scripts:[]};
name = EZ.functionMap[fn];
if (!name && !EZ.functionMap.scripts.includes(options.url))
{ //index fn script file if not done yet
var fnList = EZ.getFunctionList(options.url);
EZ.functionMap = EZ.functionMap.concat(fnList.xxx);
EZ.functionMap.scripts.push(options.url);
name = EZ.functionMap[fn];
}
--------------------------------------------------------------------------------------------------*/
EZ.functions.add = function EZfunctions_add(fn, name /* values */, url, lineno, column)
{
var map = EZ.functions();
var idx = map.list.includes(fn);
if (idx != -1) return;
idx = map.list.push(fn) - 1;
var code = map.code[idx] = fn.toString().trim();
//cross ref to related: EZ.getFunction, EZ.getFunctionParts, function EZgetFunction
//EZ.patterns.funcParts, EZ.patterns.functionStatement, EZ.patterns.functionnDetail
e = /function\s*(\w*)\s*\((.*?)\)[^{]*{([\s\S]*)}/
e = /function\s*(\w*)\s*\((.*?)\)[^{]*{\s*([\s\S]*)}/; //from EZ.clone
var pattern = /(function\s*(\w+?)?\s*(\([\w,\s]*?\))\s*)([\s\S]*)/
var labels = 'statement, name, argNames, script';
var matches = code.matchPlus(pattern, labels);
var info = map.info[idx] = {
statement: matches[1],
name: matches[2] || name,
arguments: matches[3].split(/\s*,\s*/),
url: url || '',
lineno: lineno || '',
column: column || '',
names: []
}
e = [name, fn.name, info.name]
e.forEach(function(name)
{
if (!name || info.names.includes(name)) return;
map.names[name] = idx;
info.names.push(name);
});
}
/*--------------------------------------------------------------------------------------------------
EZ.functions.get(values)
find or add fn values.name to functions.map -- values: name, url, lineno, column
var script = DWfile.read(values.url)
--------------------------------------------------------------------------------------------------*/
EZ.functions.find = function EZfunctions_find(values)
{
var name = values.name;
var map = EZ.functions();
var idx = map.list.indexOf(name);
if (idx == -1)
{ //update map if not done and script supplied
//var fnCode = fn + ''; //fn script from dom
[].some.call(document.scripts, function(script)
{
if (EZ.hasClass(script, 'EZmapped')) return;
var src = script.src || script.innerHTML;
if (src)
{
var fnList = EZ.getFunctionList(src);
script = fnList.script.split('\n');
fnList.forEach(function(fn) //for each fn found . . .
{
var code = script.slice(fn.lineno, fn.linenoEnd);
//remove code before fn statement
code[0] = code[0].replace(/.*?(function[\s\S]*)/, '$1');
code = code.join('\n').trim();
//var idx = map.code.indexOf(code);
if (!map.code[code])
{
map.code[code] = fn.nestedName;
///if (code == fnCode)
///name = p.nestedName;
}
else
{
}
});
if (name) return true
}
EZ.addClass(script, 'EZmapped');
if (name) return true
});
}
if (values)
{
Object.keys(values).forEach(function(key)
{
var value = values[key];
if (key != name)
map.info[idx][key] = value || map.info[idx][key];
else if (!map.names.includes(value))
{
map.names[value] = idx;
map.info.names.push(value);
}
});
}
}
/*----------------------------------------------------------------------------------
test wrapper fn -- global scope
//if (EZ.capture.check(this)) {return EZ.capture()} else if (EZ.test.debug()) debugger;
----------------------------------------------------------------------------------*/
EZ.functions.getNameStackTest = function(action, name, rtnObj)
{
var pattern = /(http:.*?)\/(?=\w+\.(js|htm|html|php|jsp|asp))/g;
var fnName = 'EZ.functions.getNameStackTest';
/*
at Object.EZfunctions_getName:664 (.../EZcommonParse.js:664)
at myfn:774 (.../EZcommonParse.js:774)
at EZ.functions.getNameStackTest:786 (.../EZcommonParse.js:786)
at EZtest_run:525 (.../EZtest_assistant_run.js:525)
at EZ.functions.getNameStackTest.test:821 (.../EZcommonParse.js:821)
at .../EZtest_assistant_run.js:65
*/
var myfn = function()
{
var stack = new Error().stack.replace(pattern, '.../');
EZ.test.note(stack.split('\n').slice(1).join('\n'));
return EZ.functions.getName('', rtnObj);
}
var myNew = function()
{
this.objfn = function()
{
return EZ.functions.getName('', rtnObj);
}
}
switch (action) //which fn calls EZ.functions.getName()
{
case 'myfn': return myfn(); //fn with local scope
case 'myNew':
{
var my = new myNew()
return my.objfn();
}
default:
fnName = EZ.functions.getName(name, rtnObj);
return fnName;
}
}
/*--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------*/
EZ.functions.getNameStackTest.test = function()
{
var notefn = function(testrun, phase)
{
e = testrun;
if (phase == 'final')
return testrun.testNote;
}
var rtnObj = {};
var fn = EZ.functions.getNameStackTest;
var fnName = 'EZ.functions.getNameStackTest';
var pattern = '/EZ.functions.getNameStack/';
var regex = /EZ.functions.getNameStack/;
/*
at Function.EZstack [as stack] (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/js/EZbase.js:817:11)
at Object.EZfunctions_getName [as getName] (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/js/EZcommonParse.js:659:14)
at myfn (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/js/EZcommonParse.js:774:23)
at EZ.functions.getNameStackTest (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/js/EZcommonParse.js:786:24)
at Function.EZtest_run [as run] (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/html/EZtest_assistant_run.js:537:37)
at Function.EZ.functions.getNameStackTest.test [as testScript] (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/js/EZcommonParse.js:821:10)
at http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/html/EZtest_assistant_run.js:65:11"
*/
EZ.test.only(5)
//________________________________________________________________________________________
//EZ.test.settings({group:'get EZtest_run'})
EZ.test.options({ex:'EZfunctions_getName'})
EZ.test.run('', fn , rtnObj)
//________________________________________________________________________________________
EZ.test.options({ex:'EZ.functions.getNameStackTest'})
EZ.test.run('', fnName)
EZ.test.options({ex:'EZ.functions.getNameStackTest'})
EZ.test.run('', pattern , rtnObj)
EZ.test.options({ex:'EZ.functions.getNameStackTest'})
EZ.test.run('', regex)
//________________________________________________________________________________________
EZ.test.options({notefn:notefn, ex:'myfn'})
EZ.test.run('myfn', '', rtnObj )
EZ.test.options({ex:'myNew.objfn'})
EZ.test.run('myNew', '', rtnObj)
//________________________________________________________________________________________
EZ.test.skip(999)
}
/*--------------------------------------------------------------------------------------------------
EZ.stack([sliceTo,] [stack])
Always removes messages at top of stack (and line containing EZstack function if stack not supplied)
ARGUMENTS:
sliceTo (optional) specifies lines removed from top of stack if supplied as follows:
(Number) number of lines removed after messages -- can be 0
(String) specifies function name -- all lines preceeding the last line containing
(RegExp) the specified name are removed.
(function) All lines proceeding last occurance are removed -OR- all lines if function
NOT found. The function must have name property or global scope.
stack (optional) If omitted current stack is used with messages and EZstack line are removed.
can be stack (Array or String) or function. If function, all lines proceeding
function are removed from current stack before removing lines specified by "sliceTo"
RETURNS:
stack as Array with lines removed as explained above and the following named Array properties:
messages all messages at top of stack as Array if any otherwise undefined
fault EZfault Object if any exceptions occured
TODO:
Creates new stack object containing the following properties:
* name, url, linenno, column parsed from stack
* statement, argNames, callNames, callTypes come from fn script
* callee: fn Object if supplied or name on top fn on stack has global scope
TODO: -or- useMap is true
* arguments comes from function arguments property
always added if fn argument is fn or name on stack has global scope
is json representation of currents values from arguments stack
--------------------------------------------------------------------------------------------------*/
EZ.stack = function EZstack(sliceTo,stack,options,caller)
{
if ( !(this instanceof arguments.callee) )
{ //if not called as constructor...
var caller = arguments.callee.caller;
return new EZ.stack(sliceTo,stack,options,caller);
}
if (EZ.getConstructorName(sliceTo) == 'EZstack')
{ //is 1st arg prior EZstack Object
options = stack;
stack = sliceTo;
sliceTo = 0;
}
if (EZ.getConstructorName(stack) == 'EZstack')
{ //use prior stack if supplied
this.lines = stack.lines;
this.fnValues = stack.fnValues;
}
else
{
options = stack;
stack = '';
}
options = EZ.options(options, 'useMap');
this.lines = stack ? [] : new Error().stack.split('\n');
this.fn = null; //fn object if available
this.values = {
nestedName: '', //from fnList if requested TODO:
name: '', //parsed from call stack
lineno: '',
column: '',
url: '',
statement: '', //parsed from fn script if avail
argNames: [], // ''
arguments: null, //parsed from caller script if avail -- TODO:
callNames: [], // ''
callTypes: [], // ''
stale: true //get() clears -- sliceTo() resets to true
}
//options = options && typeof(options) == 'object' ? options : {useMap: Boolean(options)}
var init = function(caller)
{
//-------------------------------------------------\\
//----- map unique functions on arguments stack -----\\
//-----------------------------------------------------\\
var processed = []; //avoid circular loop
for (var fn = caller; fn != null; fn = fn.caller)
{
if (processed.includes(fn)) break;
processed.push(fn);
EZ.functions.add(fn) //add to fn list if not there
}
/*
Error
at eval (eval at evaluate (unknown source), <anonymous>:1:1)
at new EZstack (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/js/EZcommonParse.js:206:2)
at Function.EZstack [as stack] (http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/js/EZcommonParse.js:176:10)
at Function.EZfunctions_getName [as getName] EZcommonParse.js:91:20)
at EZ.functions.getNameStackTest EZcommonParse.js:597:26)
at Function.EZtest_run [as run] EZtest_assistant_run.js:537:37)
at Function.EZ.functions.getNameStackTest.test [as testScript] EZcommonParse.js:624:10)
at http:https://localhost:8080/revize/dw.Configuration/Shared/EZ/html/EZtest_assistant_run.js:65:11
*/
if (!stack)
{
this.sliceTo(/EZstack/, true);
void(0)
}
this.sliceTo(sliceTo, options);
return this;
}
//________________________________________________________________________________________
/**
* slice stack lines upto fn if after omitted or false otherwise slice thru fn.
* if fn is number, it specifies number of lines == same as stack.lines.slice(#) except
* messages are 1st prepended to stack.messages.
*
* if fn is typeof function or string slice up to fisrt occurance if RegExp slice upto
* last occurance.
*
* returns true if fn found otherwise false
* stack.fault set to EZfault object if js error occurs -- usually bad RegExp
*/
this.sliceTo = function(fn, after /* todo */)
{
var fn, name, count;
var options = EZ.options(after, 'after');
var stack = this;
if (!isNaN(fn))
fn = parseInt(fn) || 0;
switch (EZ.getType(fn))
{
case 'Number':
{
count = fn + 1;
fn = '';
break;
}
case 'String':
case 'RegExp':
{
name = fn;
fn = '';
break;
}
case 'Function':
{
stack.fn = fn;
name = fn.name || fn.displayName;
break;
}
default:
{
return false;
}
}
var lines = stack.lines.slice(); //clone stack.lines
var messages = []; //remove messages
while (lines.length && !lines[0].includes(' at '))
messages.push(lines.shift())
try //slice
{
var isFound = false;
if (count !== undefined) //specified # lines
{
isFound = true;
lines = lines.slice(count);
}
else if (name) //slice to name
{
var pattern = name;
if (EZ.getType(pattern) == 'RegExp')
pattern = pattern.source.replace(/\//g, '\\/'); //.replace(/\\/g, '\\\\');
else if (/^(["'])(.*?)\1$/.test(name))
pattern = pattern.substr(1).clip();
pattern = pattern.replace(/\/(.*)\/.*/, '$1');
pattern = "([\\s\\S]*)" //before line -- always dropped
+ "( at ((Function|Object)\\.)?"
+ pattern + ".*\\s*)" //thru end of to line
// + "( [\\s\\S]*)"
// + "(\\s*?)( [\\s\\S]*)"; //after line -- always kept
// think above had rest group wrong
+ "( [\\s\\S]*"
+ "(\\s*?)( [\\s\\S]*))"; //after line -- always kept
var lines = lines.join('\n');
lines = lines.replace(RegExp(pattern), function(all, before, line, fngroup, fn, rest)
{
isFound = true;
return (options.after ? '' : line) + rest;
});
lines = lines.split('\n');
if (!isFound)
return false;
}
else //slice to fn with unknown name
{
//var map = {}
//var notGlobal = false;
var lines = stack.lines.slice(0);
while (true)
{
var fn;
isFound = !lines.some(function(line)
{
var pattern = /[\s\S]*\s+at ((Function|Object)\.)?(\S+)/;
var results = line.match(pattern);
while (results && results[3])
{
var stackName = results[3] || '';
if (!stackName) break; //ignore stack lines w/o function name
if (name != stackName)
{ //if names don't match, compare fn Object
fn = stackName.ov();
if (fn != sliceTo) return;
}
return true;
}
lines.shift(); //remove next line from stack returned
});
if (!isFound) return false;
if (fn)
stack.fn = fn;
break;
}
}
}
catch (e)
{
stack.fault = EZ.techSupport(e,this);
return false;
}
stack.values.stale = true;
stack.lines = lines;
if (messages.length)
stack.messages = messages.concat(stack.messages || []);
return stack;
}
//__________________________________________________________________________________________________
/**
* update stack.fn properties if stale then return property specified by key or all if key omitted.
* when properties stale or do not exist update using fn if supplied or updated EZ.functions.map().
at EZfunctions_getName:660 (.../EZcommonParse.js:660)
at myfn:1133 (.../EZcommonParse.js:1133)
at EZ.functions.getNameStackTest:1145 (.../EZcommonParse.js:1145)
at EZtest_run:525 (.../EZtest_assistant_run.js:525)
at EZ.functions.getNameStackTest.test:1190 (.../EZcommonParse.js:1190)
at .../EZtest_assistant_run.js:65 "
*/
this.get = function(key, fn, options)
{
var stack = this;
if (typeof(key) == 'function')
{
options = fn;
fn = key;
key = '';
}
if (typeof(fn) != 'function')
{
options = fn;
fn = '';
}
key = key || '';
options = EZ.options(options, 'map')
var values = stack.values;
while (!values || values.stale)
{
values = {};
var line = stack.lines[0];
if (!line) break; //bail if no stack line (i.e. only messages or length = 0)
var results = line.match(/[\s\S]*\s+at ((Function|Object)\.)?(\S+)(.*)/);
while (results) //at least fn name found from top of stack
{
values = stack.values = {};
values.name = results[3] || '';
if (!fn) //if fn not supplied, try name in global scoope
fn = values.name.ov()
results = (results[4] || '').match(/.*\((.*\..*?):(.*)\)/);
if (!results) break; //bail if parse for url... failed
var url = results[1] || '';
values.url = url;
var lineCol = results[2].split(':');
values.lineno = Number(lineCol[0]) || '';
values.column = Number(lineCol[1]) || '';
break;
}
fn = fn || stack.fn;
if (fn)
EZ.functions.add(fn, values);
else if (key == 'arguments')
{
fn = EZ.functions.find(values);
}
stack.fn = fn || stack.fn || ''; //update stack fn if changed
break;
}
return key ? values[key] : values;
}
init.call(this, caller);
}
//_________________________________________________________________________________________________
e = function _____EZget_set_____() {} //convenience for DW functions list
//_________________________________________________________________________________________________
/*---------------------------------------------------------------------------------------------
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 = window.EZgetEl = function EZgetEl(selectors, nodes)
{
var settings = EZ.is(nodes, EZ.getEl.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
}
//======================================================================================
// NON-legacy -- probably used by default since at least Jan 2016
// updated: 09-09-2016: fixed 2nd arg =null to return false if notFound (not EZnone)
//======================================================================================
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 (!_EZgetEl_getDescendants(tags, settings.roots))
break;
if (settings.nodes.length)
_EZgetEl_getDescendants(tags, settings.nodes);
break;
}
//----------------------------------------------------------------------------------
//----- Full selection algorithm
//----------------------------------------------------------------------------------
[].every.call(settings.selectors, function _forEverySpecifiedSelector(sel)
{
if (!_EZgetEl_isSelectorType(sel) || sel == null) return true; //skip invalid type
sel = EZ.toArray(sel, false); //TODO ','
[].every.call(settings.selectors, function _forEveryCommaDelimitedSelector(sel)
{
if (!_EZgetEl_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 . . .
_EZgetEl_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??
&& _EZgetEl_getDescendants(sel,root))
if (_EZgetEl_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 = _EZgetEl_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 (_EZgetEl_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 = _EZgetEl_getFormField(sel,root)
if (e != null)
{
if (_EZgetEl_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) && _EZgetEl_getDescendants(e,root) != null)
{
if (_EZgetEl_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 (_EZgetEl_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 (_EZgetEl_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';
var notFound = '.notFound'.ov(settings, 'EZnone');
tags = notFound == 'EZnone'
? [EZ.none(settings)] //EZnone() 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
*/
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.
*
*/
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) 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