@@ -66,6 +66,13 @@ function DataView(target, options) {
66
66
this . onCopyControlHTMLToConsole = function ( target ) {
67
67
} ;
68
68
69
+ /**
70
+ * Method fired when the Clear button is clicked.
71
+ * @param {Object } target
72
+ */
73
+ this . onClearEvents = function ( target ) {
74
+ } ;
75
+
69
76
/**
70
77
* Method fired when the Invalidate button is clicked.
71
78
* @param {Object } target - target control to be invalidated
@@ -87,6 +94,7 @@ function DataView(target, options) {
87
94
this . onControlFocused = options . onControlFocused || this . onControlFocused ;
88
95
this . onCopyControlToConsole = options . onCopyControlToConsole || this . onCopyControlToConsole ;
89
96
this . onCopyControlHTMLToConsole = options . onCopyControlHTMLToConsole || this . onCopyControlHTMLToConsole ;
97
+ this . onClearEvents = options . onClearEvents || this . onClearEvents ;
90
98
91
99
this . onValueClick = options . onValueClick || this . onValueClick ;
92
100
@@ -326,12 +334,12 @@ DataView.prototype._generateHTML = function () {
326
334
327
335
if ( key === 'actions' && currentObject . data && currentObject . data . length ) {
328
336
for ( var action = 0 ; action < currentObject . data . length ; action ++ ) {
329
- var currentAction = currentObject . data [ action ] ;
330
- var disclaimer = currentAction === 'Focus' ? 'When focusing an element, to see the visual focus, you need to close the DevTools panel.' : '' ;
331
- html += DVHelper . addDisclaimer ( disclaimer ) ;
332
- html += this . _addSectionTitle ( { options : { title : currentAction + ' control' } } ,
333
- DVHelper . addToolsButtons ( viewObjects . own ? viewObjects . own . options : { } , currentAction ) ) ;
334
- }
337
+ var currentAction = currentObject . data [ action ] ;
338
+ var disclaimer = currentAction === 'Focus' ? 'When focusing an element, to see the visual focus, you need to close the DevTools panel.' : '' ;
339
+ html += DVHelper . addDisclaimer ( disclaimer ) ;
340
+ html += this . _addSectionTitle ( { options : { title : currentAction + ' control' } } ,
341
+ DVHelper . addToolsButtons ( viewObjects . own ? viewObjects . own . options : { } , currentAction ) ) ;
342
+ }
335
343
break ;
336
344
}
337
345
@@ -341,7 +349,25 @@ DataView.prototype._generateHTML = function () {
341
349
continue ;
342
350
}
343
351
344
- html += this . _addSectionTitle ( currentObject , this . _generateHTMLSection ( currentObject ) ) ;
352
+ html += this . _addSectionTitle ( currentObject , this . _generateHTMLSection ( currentObject ) ) ;
353
+
354
+ // Check if there are fired events and display Clear button
355
+ if ( key === 'fired' ) {
356
+ var clearButton = '<button class="tools-button clear-events-btn" id="control-clear">Clear Events</button>' ;
357
+
358
+ html += this . _addSectionTitle (
359
+ {
360
+ options : {
361
+ title : 'Clear Fired Events' ,
362
+ controlId : 'clear-events' // Add a control ID
363
+ }
364
+ } ,
365
+ DVHelper . addToolsButtons (
366
+ viewObjects . own ? viewObjects . own . options : { controlId : 'clear-events' } ,
367
+ 'Clear'
368
+ )
369
+ ) ;
370
+ }
345
371
}
346
372
347
373
this . _DataViewContainer . innerHTML = html ;
@@ -386,6 +412,70 @@ DataView.prototype._isEditableValue = function (element) {
386
412
return element . nodeName === 'VALUE' && element . contentEditable === 'true' ;
387
413
} ;
388
414
415
+ // ===== Helper Methods =====
416
+ // These methods help to break down the complexity
417
+
418
+ DataView . prototype . _handleEditableValue = function ( targetElement ) {
419
+ if ( this . _isEditableValue ( targetElement ) ) {
420
+ this . _onBlurHandler ( targetElement ) ;
421
+ DVHelper . selectEditableContent ( targetElement , this . _selectValue ) ;
422
+ this . _selectValue = false ;
423
+ }
424
+ } ;
425
+
426
+ DataView . prototype . _handleClickableValue = function ( targetElement , event ) {
427
+ if ( targetElement . nodeName === 'CLICKABLE-VALUE' ) {
428
+ var attributes = event . target . attributes ;
429
+ var key = attributes . key . value ;
430
+ var parent = attributes . parent . value ;
431
+ var currData = this . getData ( ) ;
432
+ var eventData ;
433
+
434
+ if ( currData [ parent ] ) {
435
+ eventData = DVHelper . getObjectProperty ( currData [ parent ] . data , key ) . eventData ;
436
+ } else {
437
+ eventData = DVHelper . getObjectProperty ( currData , parent + key ) . eventData ;
438
+ }
439
+
440
+ this . onValueClick ( {
441
+ target : key ,
442
+ data : eventData
443
+ } ) ;
444
+ }
445
+ } ;
446
+
447
+ DataView . prototype . _handleSelectElement = function ( targetElement ) {
448
+ if ( targetElement . nodeName === 'SELECT' ) {
449
+ this . _onChangeHandler ( targetElement ) ;
450
+ }
451
+ } ;
452
+
453
+ DataView . prototype . _handleInputElement = function ( targetElement ) {
454
+ if ( targetElement . nodeName === 'INPUT' ) {
455
+ this . _onCheckBoxHandler ( targetElement ) ;
456
+ }
457
+ } ;
458
+
459
+ DataView . prototype . _handleButtonClick = function ( targetElement ) {
460
+ if ( targetElement . nodeName === 'BUTTON' ) {
461
+ switch ( targetElement . id ) {
462
+ case 'control-invalidate' : this . _onInvalidateElement ( targetElement ) ; break ;
463
+ case 'control-focus' : this . _onFocusElement ( targetElement ) ; break ;
464
+ case 'control-copy to console' : this . _onCopyElementToConsole ( targetElement ) ; break ;
465
+ case 'control-copy html to console' : this . _onCopyElementHTMLToConsole ( targetElement ) ; break ;
466
+ case 'control-clear' : this . _onClearEvents ( targetElement ) ; break ;
467
+ }
468
+ }
469
+ } ;
470
+
471
+ DataView . prototype . _handleControlIdSpan = function ( targetElement ) {
472
+ if ( targetElement . nodeName === 'SPAN' && targetElement . classList . contains ( 'controlId' ) ) {
473
+ this . _onCopyElementToConsole ( targetElement ) ;
474
+ }
475
+ } ;
476
+
477
+ // ===== End of Helper Methods =====
478
+
389
479
/**
390
480
* Mouse click event handler for the editable values.
391
481
* @private
@@ -407,53 +497,12 @@ DataView.prototype._onClickHandler = function () {
407
497
408
498
DVHelper . toggleCollapse ( target ) ;
409
499
410
- if ( that . _isEditableValue ( targetElement ) ) {
411
- that . _onBlurHandler ( targetElement ) ;
412
- DVHelper . selectEditableContent ( targetElement , that . _selectValue ) ;
413
- that . _selectValue = false ;
414
- }
415
-
416
- if ( targetElement . nodeName === 'CLICKABLE-VALUE' ) {
417
- var attributes = event . target . attributes ;
418
- var key = attributes . key . value ;
419
- var parent = attributes . parent . value ;
420
- var currData = that . getData ( ) ;
421
- var eventData ;
422
-
423
- if ( currData [ parent ] ) {
424
- eventData = DVHelper . getObjectProperty ( currData [ parent ] . data , key ) . eventData ;
425
- } else {
426
- // In case of event listeners
427
- eventData = DVHelper . getObjectProperty ( currData , parent + key ) . eventData ;
428
- }
429
-
430
- that . onValueClick ( {
431
- target : key ,
432
- data : eventData
433
- } ) ;
434
- }
435
-
436
- if ( targetElement . nodeName === 'SELECT' ) {
437
- that . _onChangeHandler ( targetElement ) ;
438
- }
439
-
440
- if ( targetElement . nodeName === 'INPUT' ) {
441
- that . _onCheckBoxHandler ( targetElement ) ;
442
- }
443
-
444
- if ( targetElement . nodeName === 'BUTTON' ) {
445
- switch ( targetElement . id ) {
446
- case 'control-invalidate' : that . _onInvalidateElement ( targetElement ) ; break ;
447
- case 'control-focus' : that . _onFocusElement ( targetElement ) ; break ;
448
- case 'control-copy to console' : that . _onCopyElementToConsole ( targetElement ) ; break ;
449
- case 'control-copy html to console' : that . _onCopyElementHTMLToConsole ( targetElement ) ; break ;
450
- }
451
- }
452
-
453
- if ( targetElement . nodeName === 'SPAN' && targetElement . classList . contains ( 'controlId' ) ) {
454
- that . _onCopyElementToConsole ( targetElement ) ;
455
- }
456
-
500
+ that . _handleEditableValue ( targetElement ) ;
501
+ that . _handleClickableValue ( targetElement , event ) ;
502
+ that . _handleSelectElement ( targetElement ) ;
503
+ that . _handleInputElement ( targetElement ) ;
504
+ that . _handleButtonClick ( targetElement ) ;
505
+ that . _handleControlIdSpan ( targetElement ) ;
457
506
} ;
458
507
} ;
459
508
@@ -522,6 +571,14 @@ DataView.prototype._onCopyElementHTMLToConsole = function (target) {
522
571
523
572
} ;
524
573
574
+ DataView . prototype . _onClearEvents = function ( target ) {
575
+ var controlId = this . _data . own . options . controlId ;
576
+
577
+ this . onClearEvents ( {
578
+ controlId : controlId
579
+ } ) ;
580
+ } ;
581
+
525
582
/**
526
583
* Blur event handler for the editable values.
527
584
* @param {element } target - HTML DOM element
0 commit comments