• Stars
    star
    1,017
  • Rank 45,237 (Top 0.9 %)
  • Language
    JavaScript
  • Created about 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Visually show Javascript events on a page

Visual Event - visually inspect Javascript events

Visual Event is a Javascript bookmarklet which provides debugging information about events that have been attached to DOM elements. Visual Event shows:

  • Which elements have events attached to them
  • The type of events attached to an element
  • The code that will be run with the event is triggered
  • The source file and line number for where the attached function was defined (Webkit browsers and Opera only)

In addition to being useful for debugging your own code, Visual Event can be used as an educational tool, showing how many web-sites have been authored.

Make it go!

As Visual Event is a bookmarklet, installing and running it on any web-page is extremely simple:

  • Open the Visual Event bookmarklet page and drag the "Visual Event" link to your bookmark bar
  • Load a web-page which uses one of the supported Javascript libraries
  • Click "Visual Event" in your bookmark bar
  • View the event handlers which are attached to the document elements.

A demo of Visual Event that is automatically loaded is available. This demo uses DataTables to create a test page with a number of events attached to different elements.

How it works

It turns out that there is no standard method provided by the W3C recommended DOM interface to find out what event listeners are attached to a particular element. While this may appear to be an oversight, there was a proposal to include a property called eventListenerList to the level 3 DOM specification, but was unfortunately been removed in later drafts. As such we are forced to looked at the individual Javascript libraries, which typically maintain a cache of attached events (so they can later be removed and perform other useful abstractions).

As such, in order for Visual Event to show events, it must be able to parse the event information out of a Javascript library. Currently the following libraries are supported by Visual Event:

  • DOM 0 events
  • jQuery 1.2+
  • YUI 2
  • MooTools 1.2+
  • Prototype 1.6+
  • Glow

How to get involved

Any help with improvements and suggestions for Visual Event are very welcome indeed! If you hit a specific problem, then please open an issue on GitHub for the problem you are encountering, including a link to the page where the problem occurs. Forks and pull requests are also very much encouraged!

One area which may be of interest to you is how to add support for additional Javascript libraries. The key thing that is needed is access to the event cache that the library uses, since without that it is impossible to determine what nodes have events and the attached code.

The VisualEvent class has a static array called VisualEvent.parsers which is an array of functions - to add a new parser, just push your function onto this array. The function must return a Javascript array of objects with the following parameters:

[
	{
		"node": {element},            // The DOM element that has attached events
		"listeners": [                // Array of attached events
			{
				"type": {string},     // The event type - click, change, keyup etc
				"func": {string},     // The code that will handle the event, from Function.toString()
				"removed": {boolean}, // If the event has been removed or not (typically will be false, but used if the library doesn't remove the event from its cache)
				"source": {string}    // Library name and version that attached the event (e.g. "jQuery 1.7")
			},
			...
		]
	},
	...
]

Building Visual Event

In order to run a local copy of Visual Event you must build it, since this process does file concatenation, which brings in the library parsers to the main file. The build process will also build the JSDoc documentation and compress the Javascript files (unless made with debug).

To build Visual Event, all you need is a system which will run bash scripts and enter the command ./build.sh debug in your terminal. This will create a new directory in the "builds" directory with the correct loader and the build Visual Event directory (note the timestamp is used to help prevent caching issues for the bookmarklet, both during development and when deployed). The following is the usage for the build script:

Visual Event build script - usage:
  ./build.sh [loader-dir] [debug]
    loader-dir - The web-address of the build files. Note that the build
      directory name is automatically appended and \"http:\\\\\" is
      automatically prepended. For example:
        localhost/VisualEvent/builds - default if no option is provided
        sprymedia.co.uk/VisualEvent/builds
    debug - Debug indicator. Will not compress the Javascript

  Example deploy build:
    ./build.sh sprymedia.co.uk/VisualEvent/builds

  Example debug build:
    ./build.sh localhost/VisualEvent/builds debug

The file bookmarklet.html is provided to build your own bookmarklet loader nice and easily. Typically you'll only need to modify the path for the bookmarklet. The link is updated on each keypress and you install it just as you would with any other bookmarklet :-).

About the author

Allan Jardine is a freelance web UI developer, broadcasting from Scotland and just loves creating usable and useful developer tools. If you'd like to work with Allan on a project, please do get in touch!

More Repositories

1

DataTables

Tables plug-in for jQuery
CSS
7,199
star
2

Plugins

Plug-ins for DataTables
JavaScript
1,043
star
3

DataTablesSrc

DataTables source repository
JavaScript
616
star
4

TableTools

Please note that TableTools has now been retired and replaced by the Buttons and Select extensions which offers significant improvements and API integration with the rest of DataTables and the other extensions.
JavaScript
237
star
5

Responsive

Responsive extension for DataTables, providing support for complex tables on all device screen sizes
JavaScript
148
star
6

Buttons

Buttons is an extension for DataTables that adds control buttons to the table.
JavaScript
138
star
7

Scroller

Virtual scrolling plug-in for DataTables
JavaScript
82
star
8

FixedHeader

Fix the header, footer, left or right columns of a table in place, to always show them when scrolling
JavaScript
75
star
9

FixedColumns

Fix one or more columns in place on a scrolling DataTable
JavaScript
62
star
10

ColReorder

Column reordering plug-in for DataTables
TypeScript
57
star
11

Dist-DataTables

JavaScript
47
star
12

Select

Set of selection API methods and buttons for the DataTables library
JavaScript
44
star
13

KeyTable

Provides spreadsheet like navigation and event control for DataTables
JavaScript
36
star
14

ColVis

End user column visibility options plug-in for DataTables
JavaScript
36
star
15

Vue

Vue plugin for DataTables
Vue
35
star
16

Editor-PHP

PHP server-side libraries for Editor
PHP
35
star
17

RowGroup

RowGrouping extension for DataTables
JavaScript
30
star
18

AutoFill

Excel like auto fill interaction controller for DataTables
JavaScript
30
star
19

Dist-DataTables-Bootstrap4

CSS
27
star
20

SearchBuilder

SearchBuilder extension for DataTables
TypeScript
23
star
21

RowReorder

Row reordering extensions for DataTables
JavaScript
22
star
22

SearchPanes

SearchPanes extension for DataTables
JavaScript
19
star
23

Editor-NET

.NET Framework and .NET Core server-side libraries for Editor
C#
15
star
24

Dist-DataTables-DataTables

CSS
15
star
25

Dist-DataTables-Bootstrap

CSS
15
star
26

JSDoc-DataTables

JSDoc3 template for documenting DataTables and its components
JavaScript
12
star
27

Dist-DataTables-SemanticUI

CSS
10
star
28

Dist-DataTables-Buttons

JavaScript
10
star
29

DateTime

Data / time picker used for DataTables.net components
JavaScript
10
star
30

Dist-DataTables-Bootstrap5

CSS
10
star
31

Editor-Node

NodeJS server-side libraries for Editor
TypeScript
9
star
32

Dist-DataTables-Responsive

JavaScript
7
star
33

DataTables-Debug-Client

Client-side debugger for DataTables
TypeScript
6
star
34

CDN-Server

DataTables CDN server
TypeScript
6
star
35

Dist-DataTables-Select

JavaScript
6
star
36

Dist-DataTables-FixedHeader

JavaScript
5
star
37

Dist-DataTables-RowGroup

JavaScript
4
star
38

Dist-DataTables-RowReorder

JavaScript
4
star
39

Dist-DataTables-ColReorder

JavaScript
3
star
40

Dist-DataTables-Responsive-Bootstrap4

CSS
3
star
41

Dist-DataTables-FixedColumns

JavaScript
3
star
42

Dist-DataTables-Scroller

JavaScript
3
star
43

Dist-DataTables-FixedColumns-Bootstrap

CSS
3
star
44

Dist-DataTables-FixedHeader-Bootstrap4

JavaScript
3
star
45

Dist-DataTables-KeyTable

JavaScript
3
star
46

Dist-DataTables-SearchPanes-Bootstrap4

CSS
3
star
47

Dist-DataTables-SearchPanes

JavaScript
3
star
48

Dist-Editor

DataTables Editor - holding package
JavaScript
3
star
49

Dist-DataTables-Select-jQueryUI

CSS
3
star
50

Dist-DataTables-KeyTable-jQueryUI

JavaScript
2
star
51

StateRestore

StateRestore extension for Datatables
JavaScript
2
star
52

Dist-DataTables-AutoFill

JavaScript
2
star
53

Dist-DataTables-Buttons-Bootstrap

CSS
2
star
54

Dist-DataTables-ColReorder-Bootstrap

JavaScript
2
star
55

Dist-DataTables-RowReorder-jQueryUI

JavaScript
2
star
56

Dist-DataTables-SearchBuilder

JavaScript
2
star
57

Dist-DataTables-Buttons-jQueryUI

CSS
2
star
58

Dist-DataTables-AutoFill-Bootstrap

CSS
2
star
59

Dist-DataTables-FixedHeader-jQueryUI

JavaScript
2
star
60

Dist-DataTables-ColReorder-jQueryUI

JavaScript
2
star
61

Type-Detection

JavaScript
2
star
62

Dist-DataTables-RowReorder-Bootstrap4

JavaScript
2
star
63

Dist-DataTables-AutoFill-SemanticUI

CSS
2
star
64

Dist-DataTables-Buttons-Bootstrap5

JavaScript
2
star
65

Dist-DataTables-Buttons-Bootstrap4

CSS
2
star
66

Dist-DataTables-RowReorder-Bootstrap

JavaScript
2
star
67

Dist-DataTables-RowReorder-SemanticUI

JavaScript
2
star
68

Dist-DataTables-Select-SemanticUI

CSS
2
star
69

Dist-DataTables-RowGroup-jQueryUI

JavaScript
2
star
70

Dist-DataTables-FixedColumns-DataTables

CSS
2
star
71

Dist-DataTables-SearchPanes-SemanticUI

CSS
1
star
72

Dist-DataTables-Responsive-DataTables

CSS
1
star
73

Dist-DataTables-SearchPanes-jQueryUI

CSS
1
star
74

Dist-DataTables-Responsive-jQueryUI

CSS
1
star
75

Dist-DataTables-FixedColumns-Bootstrap4

CSS
1
star
76

Dist-DataTables-Buttons-SemanticUI

CSS
1
star
77

Dist-DataTables-Foundation

CSS
1
star
78

Dist-DataTables-Responsive-Bootstrap

CSS
1
star
79

Dist-DataTables-RowReorder-DataTables

JavaScript
1
star
80

project-references-demo

TypeScript
1
star
81

Dist-DataTables-SearchPanes-DataTables

CSS
1
star
82

Dist-DataTables-SearchPanes-Foundation

CSS
1
star
83

Dist-DataTables-Select-Bootstrap4

CSS
1
star
84

Dist-DataTables-jQueryUI

CSS
1
star
85

Dist-DataTables-SearchPanes-Bootstrap

CSS
1
star