-
Notifications
You must be signed in to change notification settings - Fork 0
/
EZcommon.js
4748 lines (4203 loc) · 158 KB
/
EZcommon.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
/*---------------------------------------------------------------------------------------------
If a JavaScript file has the SHARE-IN-MEMORY directive and an HTML file references it
(by using the SCRIPT tag with the SRC attribute), Dreamweaver loads the JavaScript into
a memory location where the code is implicitly included in all HTML files thereafter.
Because JavaScript files that are loaded into this central location share memory, the
files cannot duplicate any declarations. If a share-in-memory file defines a variable
or function and any other JavaScript file defines the same variable or function, a name
conflict occurs. When writing new JavaScript files, be aware of these files and their
naming conventions.
NOTE: remove spaces before and after dashes below to activate directive.
---------------------------------------------------------------------------------------------*/
//SHARE - IN - MEMORY=true
/*---------------------------------------------------------------------------------------------
Global data
---------------------------------------------------------------------------------------------*/
var theForm, theform; //non RZ.??? global page convenience variables
if (typeof(g) == 'undefined') g = {}; //global page object (NOT used by any EZ... functions)
//if (typeof (dw) == 'undefined') dw = {isNotDW: true}; //avoid syntax error: if (!dw) ...
/*from EZcommon.safe.js
if (!window.dw) dw = {isNotDW: true};
if (!EZ.legacy)
EZ.legacy = {getEl:false, getElnull:true, getStyle:false, hasClass:false};
*/
if (typeof(EZ) == 'undefined') EZ = {};
if (!EZ.doc) EZ.doc = {};
if (!EZ.tag) EZ.tag = {};
if (!EZ.global) EZ.global = {};
if (!EZ.constant) EZ.constant = {};
if (!EZ.patterns) EZ.patterns = {};
//----- Misc general purpose global variables
EZ.wait = 0 // restart counter
EZ.errorFlag = false; // set true when error occures
EZ.errorCode = ""; // error code set by some functions
EZ.errorDetail = ""; // error details set for inspector display
EZ.thisFunction = ''; // name of executing function
EZ.cancel = false;
EZ.setupTime = '';
//----- EZgetGlobal keys
EZ.key = {};
EZ.key.codeDocOpened = 'docOpened';
/*******************/
/*BOOKMARK EZ.pref*/
/*****************/
// Stored in: HKEY_CURRENT_USER\Software\Adobe\Dreamweaver...\EZ Preferences
EZ.prefGroup = 'EZ Preferences'
//EZ.pref = EZ.dw.pref;
EZ.pref = dw.pref;
if (!EZ.pref)
{
//EZ.pref = EZ.dw.pref = {};
EZ.pref = dw.pref = {};
EZ.pref.about = 'About';
EZ.pref.debugPages = 'Debug Pages';
EZ.pref.debugMode = 'Debug Mode';
EZ.pref.debugDisabled = 'Debug Disabled';
EZ.pref.debugScriptMRU = 'Debug Script MRU';
EZ.pref.debugScriptHistoryMRU = 'Debug Script History MRU';
EZ.pref.debugScriptPageFilenameMRU = 'Debug Script Page Filename MRU';
EZ.pref.debugScriptPageMRU = 'Debug Script Page MRU';
EZ.pref.debugScriptBufferSize = 'Debug Script Buffer Size';
EZ.pref.debugResultsBufferSize = 'Debug Results Buffer Size';
EZ.pref.debugResultsStringSize = 'Debug Results String Size';
EZ.pref.debugUnitTests = 'Debug Unit Tests';
EZ.pref.displaySourceJavascript = 'Display Source Javascript';
EZ.pref.logging = 'logging';
EZ.pref.logBuffer = 'Log Buffer';
EZ.pref.logMaxsize = 'Log Max Size';
EZ.pref.traceSearch = 'Trace Search';
EZ.pref.httpCallsPause = 'http Calls Pause';
// EZ.pref.consoleNotes = 'consoleNotes'; //let's use debugMode
EZ.pref.enhancedReporting = 'Enhanced Reporting';
EZ.pref.warningMessages = 'Warning Messages';
EZ.pref.displayMaxString = 'Display Max String';
EZ.pref.displayMaxDepth = 'Display Max Depth';
EZ.pref.displayMaxItems = 'Display Max Array Items';
EZ.pref.displayMaxObjects = 'Display Max Objects';
EZ.pref.evalAppendResults = 'Eval Append Results';
EZ.pref.evalWrapResults = 'Eval Wrap Results';
EZ.pref.evalLogResults = 'Eval Log Results';
EZ.pref.workbenchTrace = 'Workbench Trace';
// OLD Code Functions & Bookmarks
EZ.pref.codeDisplayType = 'Code Display Type';
// EZ.pref.codeSortOrder = 'Code Sort Order';
// EZ.pref.codeMostRecent = 'Code Most Recent';
// EZ.pref.codeMostRecentLimit = 'Code Most Recent Limit';
// EZ.pref.codeDebugger = 'Code Debugger';
EZ.pref.codeMostRecentSites = 'Code Most Recent Sites';
EZ.pref.codeEvalScript = 'Code Eval Script';
EZ.pref.codeEvalHistory = 'Code Eval History';
EZ.pref.codeEvalHistoryOptions = 'Code Eval History Options';
EZ.pref.codeSearchScope = 'Code Search Scope';
EZ.pref.codeSearchFileFilter = 'Code Search File Filter';
EZ.pref.codeSearchHistory = 'Code Search History';
EZ.pref.codeSearchHistoryOptions = 'Code Search History Options';
// NEW bookmarks
EZ.pref.bookmarksSort = 'Bookmarks Sort';
EZ.pref.bookmarksRecentEnabled = 'Bookmarks Recent Enabled';
EZ.pref.bookmarksRecentSort = 'Bookmarks Recent Sort';
EZ.pref.bookmarksRecentLimit = 'Bookmarks Recent Limit';
EZ.pref.bookmarksFilterEnabled = 'Bookmarks Filter Enabled';
EZ.pref.bookmarksFilterOver = 'Bookmarks Filter Over';
EZ.pref.bookmarksFilterString = 'Bookmarks Filter String';
EZ.pref.bookmarksFilterType = 'Bookmarks Filter Type';
// functions
EZ.pref.functionsSort = 'Functions Sort';
EZ.pref.functionsRecentEnabled = 'Functions Recent Enabled';
EZ.pref.functionsRecentSort = 'Functions Recent Sort';
EZ.pref.functionsRecentLimit = 'Functions Recent Limit';
EZ.pref.functionsFilterEnabled = 'Functions Filter Enabled';
EZ.pref.functionsFilterOver = 'Functions Filter Over';
EZ.pref.functionsFilterString = 'Functions Filter String';
EZ.pref.functionsFilterType = 'Functions Filter Type';
EZ.pref.functionsShowAnonymous = 'Functions Show Anonymous';
EZ.pref.functionsFilterEnabled = 'Functions Filter Enabled';
EZ.pref.functionsFilterString = 'Functions Filter String';
EZ.pref.functionsFilterType = 'Functions Filter Type';
EZ.pref.functionsInnerDisplayMode = 'Functions Inner Display Mode';
EZ.pref.functionsListWhenInsideOuter= 'Functions List When Inside Outer';
EZ.pref.functionsListAfterOuterClick= 'Functions List After Outer Click';
// bookmarks and functions cache
EZ.pref.functionsLastUrl = 'Functions Last URL';
EZ.pref.bookmarksRecentList = 'Bookmarks Recent List';
EZ.pref.functionsRecentList = 'Functions Recent List';
EZ.pref.functionsInnerList = 'Functions Inner List';
// timelog
EZ.pref.timelog = 'Timelog'
EZ.pref.backupLog = 'backup';
EZ.pref.alerts = 'alerts';
EZ.pref.log = EZ.pref.backupLog; //TODO: clone from final backup
EZ.pref.isCopyBackup = 'isCopyBackup';
// unit test
EZ.pref.testOnlyList = 'Test Only List'
EZ.pref.testSkipList = 'Test Skip List'
EZ.pref.testFolder = 'Test Folder'
EZ.pref.testFilename = 'Test Filename'
EZ.pref.testFunction = 'Test Function'
EZ.pref.testLastRunOk = 'Test Last Run Ok'
EZ.pref.testMarkers = 'Test Markers'
EZ.pref.testOptions = 'Test Options'
EZ.pref.lastSelected = 'Test Selected'
EZ.pref.timelogLastActivity = 'timelogLastActivity';
EZ.pref.timelogSite = 'timelogSite';
EZ.pref.timelogInterval = 1000*60*30;
//not used as of 05-29-2015 EZ or Revize
//EZ.pref.values = {}; //instance values
EZ.pref.defaultValues = { //define default value if not false
logMaxsize : 500000,
bookmarksRecentEnabled : true,
bookmarksRecentLimit : 10,
bookmarksFilterEnabled : true,
bookmarksFilterType : 'exact',
functionsRecentEnabled : true,
functionsRecentLimit : 20,
functionsFilterEnabled : true,
functionsFilterType : 'exact',
functionsInnerDisplayMode: 'all',
functionsListWhenInsideOuter: true,
functionsListAfterOuterClick: true,
cache : false
}
//----- Default DW preference values
EZ.pref.updateLinkswhenfilechange = {group: 'General Preferences',
type: 'int', //default type is string
never: 0, // ??
name:'Update Links when file change'}
//----- Build arrays of variable names and registry keys
EZ.pref._vars = [];
EZ.pref._keys = [];
for (var key in EZ.pref)
{
if (typeof(EZ.pref[key]) != 'object') //EZ preference reg key
EZ.pref._keys.push(EZ.pref[key]);
else if (!EZ.pref[key].name) //skip defaultValues objects
continue;
else //save DW reg key
EZ.pref._keys.push(EZ.pref[key].name);
EZ.pref._vars.push(key); //EZ.pref._keys[variable-name] to lookup reg key
}
EZ.pref.cache = {}; //initially just used by simulator
EZ.pref.loaded = new Date();
}
/*---------------------------------------------------------------------------------------------
GLOBAL CONSTANTS -- TODO: move to EZ.dw..constant
---------------------------------------------------------------------------------------------*/
EZ.constant = {};
EZ.constant.spaces = EZdup(80,' ');
EZ.constant.copyright = String.fromCharCode(169); //© (c)
EZ.constant.tradeemark = String.fromCharCode(8482); //™ tm ™
EZ.constant.DOT = String.fromCharCode(8226);
EZ.constant.EOL = String.fromCharCode(172);
EZ.constant.bigdot = String.fromCharCode(8226); //used for null, empty, more, etc
EZ.constant.more = EZ.constant.bigdot + ' ' + EZ.constant.bigdot + ' ' + EZ.constant.bigdot;
EZ.constant.insert = EZ.constant.more + '][' + EZ.constant.more;
// http:https://www.degraeve.com/reference/specialcharacters.php
// http:https://www.ascii.cl/htmlcodes.htm
EZ.constant.left_angle = String.fromCharCode(171); //« <<
EZ.constant.left_3angles = EZdup(3,EZ.constant.left_angle); //<<<
EZ.constant.right_angle = String.fromCharCode(187); //» >>
EZ.constant.right_3angles = EZdup(3,EZ.constant.right_angle); //>>>
EZ.constant.up_arrow = String.fromCharCode(8583); //↑ ^
EZ.constant.right_arrow = String.fromCharCode(8594); //→ -->
EZ.constant.down_arrow = String.fromCharCode(8595); //↓ v
EZ.constant.left_arrow = String.fromCharCode(8592); //← <--
EZ.constant.CRLF = '\r\n';
if (navigator.platform.toLowerCase().substring(0,3) == 'mac')
{
EZ.platform = 'mac'
EZ.constant.newline = '\r';
}
else
{
EZ.platform = 'win'
EZ.constant.newline = EZ.constant.CRLF;
}
EZ.constant.xmlHeader = '<?xml version="1.0" encoding="utf-8"?>';
//----- FOLDERS
function EZfolders()
{
EZ.constant.configPath = dw ? dw.getConfigurationPath() : '';
if (!dw.isNotDW) //appData path -- not Program Files...Configuration
{
var len = dw.getConfigurationPath().length+1;
EZ.configPathname = document.URL.substr(0,len);
EZ.configPrefix = document.URL.substr(len);
EZ.configPrefix = EZ.configPrefix.replace(/[^\/]/g, '').replace(/\//g, '../');
var dom = dw.getDocumentDOM(EZ.configPrefix + 'Extensions.txt');
EZ.constant.configPath = dom.URL.replace(/(.*\/).*/, '$1');
dw.releaseDocument(dom);
}
if (!dw.isNotDW) //appData path -- not Program Files...Configuration
{
var dom = dw.getDocumentDOM('../Extensions.txt');
EZ.constant.configPath = dom.URL.replace(/(.*\/).*/, '$1');
dw.releaseDocument(dom);
}
EZ.constant.commandsPath = EZ.constant.configPath + "Commands/"
EZ.constant.logPath = EZ.constant.configPath + "Logs/"
EZ.constant.EZpath = EZ.constant.configPath + "Shared/EZ/"
EZ.constant.EZdataPath = EZ.constant.configPath + "Shared/EZ/data/"
EZ.constant.EZimagesPath = EZ.constant.configPath + "Shared/EZ/images/"
//----- FILES
EZ.constant.logfile = "EZlog.htm";
EZ.constant.logfileTemplate = "EZlogTemplate.htm";
EZ.constant.debugHistoryFile = EZ.constant.EZdataPath + 'debugHistory.json';
EZ.constant.debugResultsFile = EZ.constant.EZdataPath + 'debugResults.txt';
}
EZ.configPrefix = '';
EZ.configPathname = '';
if (window.dw && !dw.isNotDW) EZfolders()
/*---------------------------------------------------------------------------------------------
Usually called from body onLoad for common innitialization done for all commands.
EZstart() is called if found after common setup code is completed.
---------------------------------------------------------------------------------------------*/
function EZsetup(group)
{
group = group ? group.toLowerCase() : '';
if (window.dw && dw.isNotDW && typeof(DW) == 'undefined')
{
EZsetup.group = group || '';
return;
}
if (EZgetPref(EZ.pref.debugMode))
{
EZ.debugMode = true;
EZaddClass('body', 'debugBody');
}
if (EZ.floater) group = 'floater'; //recalled floater call
switch (group)
{
case 'nosetup': return true;
case 'floater':
{
EZ.isFloater = EZ.floater = true;
if (dw.getActiveWindow() == null)
{ //floater may only call EZsetup once...
if (!EZ.isFloaterSetup) EZwait(true); //...recall if not setup
return false;
}
if (EZ.isFloaterSetup) return true; //return if already setup
break;
}
case '':
{
}
}
EZ.setupgroup = group;
if (group == 'floater') EZ.isFloaterSetup = true;
var e;
try
{
// Define theForm and theorm convenience globals
if (document.forms[0])
{
theForm = document.forms[0];
theform = theForm;
}
//----- Init fields with name that matches EZ.pref value
EZloadPrefs();
EZ.setupTime = new Date();
EZlog('-', 'started @ ' + EZ.setupTime);
/*----- Set breakpoint, if specified
if (document.URL == EZgetGlobal('breakpointCommand'))
{
var funcName = EZgetGlobal('breakpointFunction');
var script = EZgetGlobal('breakpointScript');
eval( 'script=' + script ); // convert to function object
window[funcName] = script; // overwrite original function
}
*/
//----- Save original display and visibility style properties for all elements
// TODO: too over the top but great test of EZ.getEl()
var tags = document.getElementsByTagName('*');
for (var i=0; i<tags.length; i++)
{
var el = tags[i];
break;
if (!el.style) continue;
if (el == null)
{
debugger;
if (EZ.quit) break;
}
var visibility = EZgetCurrentStyle(el,'visibility');
if (visibility != 'hidden')
visibility = '';
el.EZorigStyle = {display: EZgetStyle(el,'display'), visibility: visibility};
}
//----- Call EZstart()
if (typeof(EZstart) == 'function')
{
//below line did not seem to return true
//var status = EZgetPref(EZ.pref.enhancedReporting,'novalidate');
//if (!dw.isNotDW) // run inside try/catch if enabled
EZstart();
}
}
catch (e)
{
EZexception(e);
}
return true;
}
/*---------------------------------------------------------------------------------------------
If firstArg is typeof boolean, use new functionality as described below:
Always cancel prior pending timeout; then continue or queue this function with
current caller arguments (this instance is often the prior instance).
If firstArg is true, contunue to wait (return true)
otherwise return false indicating no waiting required.
Example Call:
if (EZwait(!g.isSetupDone)) return;
---------------------------------------------------------------------------------------------*/
function EZwait(firstArg,type)
{
//----------------------------------------------
// New functionality (first argument is boolean)
//----------------------------------------------
if (typeof(firstArg) == 'boolean')
{
var ms = type;
if (!ms) ms = 500;
var funcObj = EZwait.caller;
if (funcObj.timeout)
cancelTimeout(funcObj.timeout);
funcObj.timeout = 0;
if (firstArg)
{
// get callers array-like arguments as real array
var args = [].slice.call(arguments.callee.caller.arguments,0);
setTimeout(function(){ funcObj.apply(this,args) }, ms);
}
return firstArg;
}
caller = firstArg; //old functionality argement name
//----------------------------------------------
// Old functionality
//----------------------------------------------
if (!dw) return true; //no document??
if (type.indexOf('inspector') != -1) EZ.isInspector = true;
var cmd = '';
if (typeof(document) == 'object')
cmd = EZgetFileInfo(document.URL).filenameFull;
//----- Determine if floater is loaded (EZsetup() can be called before doc loaded)
var isFloaterLoaded = (window.document && window.document.URL);
//----- If done waiting return false
if (EZ.global.prefs //EZ.global.prefs loaded
&& (!EZ.floater || isFloaterLoaded)) //not floater or floater loaded
{
if (EZ.wait > 0) //should not be true
{
var jsFile = 'unknown'
if (typeof EZfunctionFilename != 'undefined') jsFile = EZfunctionFilename
EZalert( "EZwait: Code (" + EZ.wait + ") Caller: " + caller + "\n\n"
+ "JavaScript File: " + jsFile + "\n\n"
+ "If next screen displays correctly, please provide your Revize software\n"
+ "distributor with the Code, JavaScript file and next screen name." )
}
return false;
}
//----- Bump wait counter
EZ.wait ++;
if (EZ.wait > 10)
{
if ( !confirm("Command waited 5 seconds to start.\n\nContinue waiting?") )
{
window.close();
return true; // Quit waiting
}
else
EZ.wait = 0;
}
//----- Save command properties
EZ.dw.commandType = type ? type : ''; //command type
var currentdocument = false; //assume NOT working on current doc
if (EZ.dw.commandType == 'object'
|| EZ.dw.commandType == 'document')
currentdocument = true;
EZ.dw.currentdocument = currentdocument;
// if not DW simulator, restart caller in half a second
if (!dw.isNotDW) setTimeout(caller, 500);
return !dw.isNotDW; //return true if dw; false for simulator
}
/*---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------*/
function EZrecieveArguments(args,names)
{
return;
EZ.arguments = [].slice.call(args); //all arguments
EZ.arguments = [].slice.call(args).concat()
for (var i=0;i<names.length;i++) //define named arguments
{
var value = EZ.arguments[i];
g[names[i]] = value;
}
}
/*---------------------------------------------------------------------------------------------
Adds standard buttons if not defined; adds debug buttons if debug enabled
----------------
Input Arguments:
----------------
buttons (optional) Array containing 2 elements for each button
(1st is label; 2nd is javascript run when clicked)
e.g. var buttons = ["Run Script", "evalCode();"];
If buttons is null, no buttons are defined (command does not use buttons)
Unless buttons defines OK, Cancel or Help, these buttons are added as follows:
["OK", "process() ||EZobjectTag();"] //added as first button
["Cancel", "window.close();"] //added after all other buttons
["Help", "EZhelp(document.URL);"] // '' '' '' '' ''
"Clear Trace" & "Debugger" buttons are also added if debugMode is enabled.
***** NOTE: only 10 buttons function - (more display but to not function)
---------------------------------------------------------------------------------------------*/
function EZbuttons(buttons)
{
if (!buttons || buttons.constructor != Array)
buttons = []; //init empty array
//----- Process OK button
var idx = buttons.indexOf('OK');
if (idx == -1) //no ok buttons
{
var func = null;
if (typeof(process) == 'function')
func = 'process()';
else if (typeof(EZobjectTag) == 'function')
func = 'EZobjectTag()';
// add OK button to top of buttons array
if (func)
{
//EZfun may have issues in RevizeDialog_sitename or could be issue with setTimeout
//of form: setTimeout(myfunc,0) NOT of form: setTimeout('myfunc()',0)
//OR improper use of EZselectOption() having multiple selected for select-one
//func = 'EZrun("' + func + '")';
buttons.unshift('OK', func);
}
}
else if (!buttons[idx+1])
buttons.splice(idx,2);
//----- Add Cancel and/or Help if not defined
if (buttons.indexOf('Cancel') == -1)
buttons.push('Cancel', "window.close();");
if (buttons.indexOf('Help') == -1)
buttons.push('Help', "EZhelp(document.URL)");
//----- Add 'Clear Trace' & 'Debugger' if debugMode
if (EZisDebug())
{
buttons.push('Clear Trace', "EZlogReset()");
if (buttons.indexOf('Debugger') == -1)
buttons.push('Debugger' , "EZrunCommand('EZdebugger.htm')");
// buttons.push('Debugger' , "EZdebuggerBreakpoint()");
buttons.push('test msg / size', "EZdisplayMessage('long msg ' + EZdup(30,' 1 2 3 4 5 6 7 8 9 0'))");
}
return buttons;
}
/*---------------------------------------------------------------------------------------------
Runs command from callers scope, passing all specified arguments)
command can set returnValue to variable or object to be returned.
---------------------------------------------------------------------------------------------*/
function EZrunCommand(cmdFile)
{
var args = [];
for (var i=1;typeof(EZrunCommand.arguments[i])!='undefined';i++)
if (!isNaN(i)) args.push(EZrunCommand.arguments[i]);
args.push(EZdisplayCaller())
EZsetGlobal('commandStatus','MARKER');
var cmdDOM = EZgetDOM(EZ.constant.commandsPath + cmdFile);
dw.runCommand.apply(EZrunCommand, args);
EZreleaseDOM(cmdDOM);
var commandStatus; //default to undefined
if (EZgetGlobal('commandStatus') != 'MARKER')
commandStatus = EZgetGlobal('commandStatus');
return commandStatus;
}
/*---------------------------------------------------------------------------------------------
Save value of any field with name that matches EZ.pref & close window
---------------------------------------------------------------------------------------------*/
function EZclose(commandStatus)
{
EZsavePrefs();
EZcommandStatus(commandStatus)
window.close();
}
/*---------------------------------------------------------------------------------------------
Save value of any field with name that matches EZ.pref & close window
---------------------------------------------------------------------------------------------*/
function EZcommandStatus(commandStatus)
{
if (!commandStatus)
{
if (typeof(EZ.commandStatus) != 'undefined')
commandStatus = EZ.commandStatus;
else
commandStatus = 'MARKER'; //treated as undefined
}
EZsetGlobal('commandStatus',commandStatus);
}
/*---------------------------------------------------------------------------------------------
return debug status
---------------------------------------------------------------------------------------------*/
function EZisDebug()
{
return true;
if (dw.isNotDW) //if DW simulator, always return true
return true;
else if (EZ.pref && EZ.pref.loaded) //if EZ preferences initialized
return EZgetPref(EZ.pref.debugMode) //...return current setting
else //otherwise return false
return false;
}
/*---------------------------------------------------------------------------------------------
Load pref for all input, select and textarea field tags
---------------------------------------------------------------------------------------------*/
function EZloadPrefs()
{
var fields = EZgetTagsByClassName(['input','select','textarea']);
var fieldsProcessed = {};
for (var i=0;i<fields.length;i++)
{
var field = fields[i];
var key = field.name;
if (!key) continue;
// Determine type and skip if button or image
var type = field.tagName.toLowerCase();
if (field.tagName == 'input')
type = field.type.toLowerCase();
if (/(button|image)/i.test(type)) continue;
if (fieldsProcessed[key]) continue; //radio button already processed
fieldsProcessed[key] = true;
// if known key
if (EZ.pref[key])
{
var value = EZgetPref(EZ.pref[key]);
/* TODO: name was required to get radio value in RevizeBookmarks.js::updatePrefs()
// Find containing form
var form = EZgetParent(field,'form'); //see EZ.getAncestor()
if (form === false) return;
if (!form) continue;
*/
// if all select options stored as pref...
if (field.options && EZ.pref[key+'Options'])
{
var defaultValue = value; //keep 1st option selected
if (field.options.length > 0) value = '';
var options = EZgetPref(EZ.pref[key+'Options']).split(EZ.constant.EOL);
//if (options.length > 0) EZclearList(field);
EZselectInit(field);
for (var i=0;i<options.length;i++)
{
value = options[i];
var text = value;
var offset = value.lastIndexOf(EZ.constant.DOT);
if (offset != -1) //both text and value was saved
{
text = value.substring(0,offset);
value = value.substring(offset+1);
}
var selected = (defaultValue == text);
EZselectOption(field,text,value,selected)
}
if (field.selectedIndex == -1) field.selectedIndex = 0;
EZselectSave(field);
}
// quit if error setting field value and cancel button clicked
else if (EZsetFieldValue(field,value) === false)
break;
}
}
EZ.pref.loaded = true;
}
/*---------------------------------------------------------------------------------------------
Save value of any field with name that matches EZ.pref
If el passed, only update that pref otherwise update pref for all input fields.
---------------------------------------------------------------------------------------------*/
function EZsavePref(field) {return EZsavePrefs(field)}
function EZsavePrefs(field)
{
var fields = [];
if (field)
fields[0] = field;
else
{
var fields = document.getElementsByTagName('input');
fields = [].concat.call( [].slice.call(fields),
[].slice.call( document.getElementsByTagName('select')),
[].slice.call( document.getElementsByTagName('textarea')));
}
var fieldsProcessed = {};
if (fields && fields.length > 0)
{
for (var i=0;i<fields.length;i++)
{
field = EZgetEl(fields[i]);
if (field == null) continue;
//below not needed because skipped if EZ.prefs(key) not defined
//if (field.className && field.className.indexOf('notautopref') != -1) continue;
var type = field.tagName;
if (field.tagName == 'INPUT')
type = field.type;
if (/(button|image)/i.test(type)) continue;
var key = field.name;
if (!key && field[0]) key = field[0].name;
if (!key) continue;
if (fieldsProcessed[key]) continue; //radio button already processed
fieldsProcessed[key] = true;
if (!EZ.pref[key]) continue;
var value = EZgetFieldValue(field);
EZsetPref(EZ.pref[key],value);
// Save all select options if ...Option pref defined
if (field.options && EZ.pref[key+'Options'])
{
var options = [];
for (var i=0;i<field.options.length;i++)
options.push(field.options[i].text + EZ.constant.DOT + field.options[i].value);
EZsetPref(EZ.pref[key+'Options'],options.join(EZ.constant.EOL));
}
}
}
return true;
}
/*---------------------------------------------------------------------------------------------
Use in lieu of "setTimeout( func, 0)" to support enhancedReporting. EZsetup() calls
EZstart() within a try/catch but of course is lost when setTimeout() starts new thread.
This function restablishes try/catch if enhancedReporting is active otherwise continues
in same manner as previously done with setTimeout calls.
If no arguments, call as follows:
EZrun(functionObj); // DCO 11-25-2011: was failing but possible due to
// overteching object scenarios with apply command.
// (setTimeout with this form may have also failed)
EZrun('myfunction()'); // This form resolved issues in some scenarios and
// probably good in all scenarios.
If arguments, use the following syntax:
EZrun( function() {somefunction(arg1,arg2,...)} );
// DCO 11-25-2011: Below statement makes no sense since this is to be used in lieu
// of setTimout; same thread code disabled and tweaked object code for string type.
If functionObj is string, run in current thread
---------------------------------------------------------------------------------------------*/
function EZrun(functionObj,delay)
{
var e;
var enhancedReporting = EZgetPref(EZ.pref.enhancedReporting);
if (!delay) delay = 0;
//----- If functionObj is string...
if (typeof functionObj != 'function')
{
if (enhancedReporting && !dw.isNotDW)
{
setTimeout(function()
{
var e;
try { eval(functionObj); }
catch (e) { EZexception(e); }
}, delay);
}
else
{
try
{
return eval(functionObj);
}
catch (e)
{
EZexception(e);
}
return;
setTimeout( function()
{
eval(functionObj);
}, delay);
}
/****** DCO 11-25-2011: if using in lieu of setTimeout(), should always use new thread
if (enhancedReporting)
{
var e;
try { eval(functionObj); }
catch (e) { EZexception(e); }
}
else
eval(functionObj);
******/
}
//----- If functionObj is function object...
else
{
if (enhancedReporting && !dw.isNotDW)
{
setTimeout( function()
{
var e;
try { functionObj(); }
catch (e) { EZexception(e); }
}, 0);
}
else
{
setTimeout( function()
{
functionObj();
}, 0);
}
}
}
/*---------------------------------------------------------------------------------------------
Simulates JavaScript "debugger" command within the Dreamweaver API framework.
Starts Revize JavaScript debugger at current point in function or if called as command,
runs in global scope and only has access to global functions and data.
--------------------------------------------------
To call from a DW function: eval(EZdebugger(this))
--------------------------------------------------
Captures calling function scope by returning code to the eval command to creates an EZeval(cmd)
function that runs in the calling function scope. The code returned to the eval then starts the
debugger which then uses EZeval() to run commands in the calling function scope.
---------------------------------------------------------------------------------------------*/
function EZdebugger(functionThis,errorCallback)
{
var results,id;
//if (dw.isNotDW) return;
if (EZ.noDebug) return;
var caller = EZdebugger.caller;
var callerStr = caller ? caller.toString() : ''
EZlog('caller', callerStr);
// Define callback function using EZdebuggerEval function as base.
// (used below and by debugger when calling functions)
// Split code before first bracket (i.e. function xxx (...) and code
// between to the first and last brackets
results = EZdebuggerEval.toString().match(/([\s\S]*?)({[\s\S]*})/);
EZdebugger.evalFunction = 'function(cmd)' + results[2] + ';';
//----- Variables passed to EZdebugger or EZdebuggerBreakpoint -----\\
EZdebuggerStart.theCaller = EZdebugger.caller; //needed for hta enviornment
EZdebuggerStart.functionThis = functionThis; //calling function this object
EZdebuggerStart.functionName = '_MAIN_'; //if called from main line
results = callerStr.match(/\s*function\s*(\w*)[\s\(]/);
if (results) //called from function
{
EZdebuggerStart.functionName = results[1]; //function name
if (!EZdebuggerStart.functionName) //blank function name
EZdebuggerStart.functionName = 'anonymous';
}
EZlog('debug function', EZstripConfigPath(document.URL) + '::' + EZdebuggerStart.functionName);
// Default code run after return from debugger in DW environment
EZdebuggerStart.proceed = true;
//----- return script run by the calling eval command -----\\
// assume call is of form: eval(EZdebugger(this))
if (typeof(functionThis) == 'object')
{
var evalFunction = EZdebuggerStart.functionName + '.EZeval=' + EZdebugger.evalFunction;
// For DW enviornment, code run after debugger window closes
var proceedFunc = 'eval(EZdebuggerStart.proceed);';
// For hta enviornment, if return not on same line as EZdebugger(), kill remaining script
// (DW enviornment will move return to next line)
if (dw.isNotDW && !callerStr.match(/eval\(EZdebugger\(this\)\);?\s*return.*/))
proceedFunc = 'die()';
// code run by calling eval command:
// 1) define debugger eval function
// 2) start debugger
// 3) code run after EZdebugger.htm window closes (or immediately for hta)
return evalFunction + 'EZdebuggerStart();' + proceedFunc;
// test code
var callback = 'this.EZdebug=function(cmd){return eval(cmd)}';
EZdebuggerStart.debuggerCall = 'EZdebuggerStart();eval(EZdebuggerStart.proceed)';
EZdebuggerStart.callback = functionThis; //this object of the caller
var callback = 'testit.EZeval=function(cmd){return eval(cmd)}';
return callback + ';' + EZdebuggerStart.debuggerCall;
// prior code
results = EZdebuggerEval.toString().match(/([\s\S]*?)({[\s\S]*})/);
var callback = 'this.EZdebug=function(cmd)' + results[2];
EZdebuggerStart.debuggerCall = 'EZdebuggerStart();eval(EZdebuggerStart.proceed)';
return callback + ';' + EZdebuggerStart.debuggerCall;
/*
"this.EZdebug=function(cmd){
return eval(cmd)
};EZdebuggerStart();eval(EZdebuggerStart.proceed)"
*/
}
//----- When functionThis not specified, run the EZdebuggerBreakpoint() command
// TODO: not complete
else
{
var funcName = EZdebugger.callerStr.match(/function (\w*)/)[1];
EZdebuggerBreakpoint(document.URL,funcName,0,'EZdebugger()');
// Ideally we want to quite javascript processing at this point
die();
//TODO: need to update function so it does not continue
var emptyFunction = new Function('', '');
EZdebugger.caller = emptyFunction(); //does not stop function
return;
}
}
/*---------------------------------------------------------------------------------------------
This function created in caller scope to run script from debugger.
---------------------------------------------------------------------------------------------*/
function EZdebuggerEval(cmd)
{
return eval(cmd)
}
/*---------------------------------------------------------------------------------------------
UNTESTED improved eval function to replace EZdebuggerEval()
---------------------------------------------------------------------------------------------*/
function EZdebuggerEvalBetter(cmd,cmdResults)
{
//cmd = cmd.trim();
var obj; //used to capture cmd results inside eval
if (/^[\[\{]/.test(cmd) || typeof(cmd) == 'object')
cmd = 'obj='+cmd;
else if (!/=/.test(cmd))
{
if (typeof cmd == 'string')
cmd = cmd.toString().replace(/'/g,"\\'");
cmd = 'obj="' + cmd + '"'; //"
}
var results = eval(cmd);
if (/=/.test(cmd)) obj = results;
if (cmdResults)
cmdResults = EZdisplayObject(obj);
return obj;
}
/*---------------------------------------------------------------------------------------------
Starts debugger;
debuggerCall=true when called from EZdebugger.hta to make a function call.
DW framework (i.e. EZdebugger.htm) handles these function calls differently.
Called from code returned by EZdebugger() call after defining eval function therefore
may need to be ignored if debugger already running.
---------------------------------------------------------------------------------------------*/
function EZdebuggerStart(debuggerCall)
{
//if (!EZwarn('EZdebuggerStart: ready to launch JavaScript Debugger')) return;
//----- When called from function being debugged; NOT called from within the debugger
EZ.debugStack = EZgetGlobal('debugStack');
if (!EZ.debugStack)
{
EZ.debugStack = [];
EZsetGlobal('debugStack',EZ.debugStack);
}
//? if (!debuggerCall)
{