@@ -66,6 +66,13 @@ function DataView(target, options) {
6666 this . onCopyControlHTMLToConsole = function ( target ) {
6767 } ;
6868
69+ /**
70+ * Method fired when the Clear button is clicked.
71+ * @param {Object } target
72+ */
73+ this . onClearEvents = function ( target ) {
74+ } ;
75+
6976 /**
7077 * Method fired when the Invalidate button is clicked.
7178 * @param {Object } target - target control to be invalidated
@@ -87,6 +94,7 @@ function DataView(target, options) {
8794 this . onControlFocused = options . onControlFocused || this . onControlFocused ;
8895 this . onCopyControlToConsole = options . onCopyControlToConsole || this . onCopyControlToConsole ;
8996 this . onCopyControlHTMLToConsole = options . onCopyControlHTMLToConsole || this . onCopyControlHTMLToConsole ;
97+ this . onClearEvents = options . onClearEvents || this . onClearEvents ;
9098
9199 this . onValueClick = options . onValueClick || this . onValueClick ;
92100
@@ -326,12 +334,12 @@ DataView.prototype._generateHTML = function () {
326334
327335 if ( key === 'actions' && currentObject . data && currentObject . data . length ) {
328336 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+ }
335343 break ;
336344 }
337345
@@ -341,7 +349,25 @@ DataView.prototype._generateHTML = function () {
341349 continue ;
342350 }
343351
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+ }
345371 }
346372
347373 this . _DataViewContainer . innerHTML = html ;
@@ -386,6 +412,70 @@ DataView.prototype._isEditableValue = function (element) {
386412 return element . nodeName === 'VALUE' && element . contentEditable === 'true' ;
387413} ;
388414
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+
389479/**
390480 * Mouse click event handler for the editable values.
391481 * @private
@@ -407,53 +497,12 @@ DataView.prototype._onClickHandler = function () {
407497
408498 DVHelper . toggleCollapse ( target ) ;
409499
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 ) ;
457506 } ;
458507} ;
459508
@@ -522,6 +571,14 @@ DataView.prototype._onCopyElementHTMLToConsole = function (target) {
522571
523572} ;
524573
574+ DataView . prototype . _onClearEvents = function ( target ) {
575+ var controlId = this . _data . own . options . controlId ;
576+
577+ this . onClearEvents ( {
578+ controlId : controlId
579+ } ) ;
580+ } ;
581+
525582/**
526583 * Blur event handler for the editable values.
527584 * @param {element } target - HTML DOM element
0 commit comments