Code Monkey home page Code Monkey logo

visualevent's Introduction

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!

visualevent's People

Contributors

allanjard avatar amacfie avatar idnovate avatar koalabear84 avatar lingo avatar nbubna avatar trias avatar valtido avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

visualevent's Issues

deactivating VE2 but shortcuts stay active

Steps to reproduce:

  1. get a website with a textfield and start VE2 on it
  2. deactivate VE2
  3. enter for example 'h' in the textfield
  4. the VE2 help starts

Corresponding actions happens for 'r' and 'space' as well.

Add Dojo support

Would be good is the Dojo library events were also available.

Script won't load with HTTPS

Both the bookmarklet and the script itself explicitly uses HTTP requests which is unnecessary.

From

var protocol = window.location.protocol === 'file:' ?
'http:' : '';
var url = protocol+'//www.sprymedia.co.uk/VisualEvent/VisualEvent_Loader.js';
//var url = protocol+'//localhost/VisualEvent/builds/VisualEvent_Loader.js';
:

    var protocol = window.location.protocol === 'file:' ?
        'http:' : '';
    var url = protocol+'//www.sprymedia.co.uk/VisualEvent/VisualEvent_Loader.js';
    //var url = protocol+'//localhost/VisualEvent/builds/VisualEvent_Loader.js';

This is unnecessary as using

<script src='//www.sprymedia.co.uk/VisualEvent/VisualEvent_Loader.js'/>

automatically requests the page using the current protocol -- file, http or https. The sprymedia site has HTTPS available, so this won't be a problem either.

Similar segment appears in the actual code around

protocol = window.location.protocol === 'file:' ?
'http:' : '';
.

Bug with SyntaxHighlighter

Steps to reproduce:

  1. load VE2 on a site
  2. unload VE2 on this site
  3. load VE2 again
  4. any lightbox will show the javascript code without the SytanxHighlighter and there is no scrollbar for long lines of code

Any link should open in new tab/window

VisualEvent generates some dynamic links which open in current tab/window. Not very smart :-)

All your links (including to your website) should have a target="_blank" attribute.

elements[elements.length-1] sometimes undefined

I'm not entirely sure how this occurs, but in the setup at my work's website using jQuery 2, a fatal JS error is thrown, meaning the overlays don't show at all. This is the offending code:

if ( elements[ elements.length-1 ].listeners.length === 0 ) {
        elements.splice( elements.length-1, 1 );
}

To fix it, we just need to change it to the following:

if ( typeof elements[ elements.length-1 ] != 'undefined' && elements[ elements.length-1 ].listeners.length === 0 ) {
            elements.splice( elements.length-1, 1 );
}

I absolutely love visual event!

Finding events inside a shadow element

Consider the following.

<sometag .... >
   --shadowRoot--
         <style>...</style>
        <a id="test"></a>
        <script>
              $('a').on('click', function(event){  ....  })
       </script>
</sometag>

The problem is, these event's are not picked up from the VisualEvent:

Here is a way to find elements inside a shadowRoot element.

var all = document.querySelectorAll("*");
var length =  all.length
for(i= 0; i < length; i++){
  if(all[i],shadowRoot) all.concat(all[i].shadowRoot.querySelectorAll("*"));
}

Of course this is a quick and dirty way of archiving this, but may need a bit more thought and work on to it.

Let me know your thoughts.

Standalone distribution

Hi!

This tool is really awesome, but we'd like to use it on a site without access to the internet, while running on the server (aka no using the file or http protocol to fetch js and css). I managed to cobble something together by using the .sh-script in this repo and hardocing a path to the js and css, but if a standalone tarball or something could be provided, that'd be awesome.

Add colour meaning to VE2 help page and Readme.markdown

On the old VE page the different colour codes are explained (blue = mouse event and so on).
It would be nice to have the explanation added to the help page for a quick lookup and to the Readme.markdown for new users who see VE2 for the first time. Thanks. :)

Add Native DOM Support

It would be nice to have the ability to fetch events registered at the DOM level with attachEvent/addEventListener.

How can I find out EXACTLY what is being triggered from Visual Event?

Here's my scenario...

I'm trying to track down and if needs be fire the event manually.

Screenshot 2019-10-23 at 12 57 46

Visual Event says there's a "change" event on select#Size.single-option-selector. If I click trigger event it works as expected.

If I try and do

$('select#Size.single-option-selector').change(); or $('select#Size.single-option-selector').trigger('change');

it does nothing, so I need to figure out exactly what that "trigger event" is doing so I can manually do the same thing

Link to file:row on firebug

Hi

I don't know how it does, but if you use firebug and do a

console.log(function_name); 

you can see a clickable function definition (there isn't the body). If you click you go directly on the script tab at the exact file/row.

It would be assome if - when you use VE in conjunction with firebug - can do the same thing

Retrieve the function that *bind* the event

It would be a killer feature to find what bind a function to an event.

Let's say I have this code

// somewhere.js
function on_click() {
// do something
}

// somewhereelse.js
function bind_events() {
$('a').click(on_click);
}

sometimes what I really want is bind_events, not on_click

If possible: Who did the binding of the event?

This is a feature request.

While debugging events it is so cool the stuff which VisualEvent does in the current version, however to make it even more cool this could be added:

Tracking of the binding process, that is: I could see in VisualEvent which code (where with link) did the binding of the event. "Who is watching?" - so that can backtrack events to the part of the code which has added the event. An example could be:

function clickHandler() {
  // I'm the handler
}

$(function() {
  // Im am binding the handler to elements
 $('li').on('click', clickHandler);
});```

I do not know if that is possible, but hey it would be a great feature! :-)

/Sten

nested DOM objects can't be seen.

So, I have a dropdown that is activated by a click event via jquery. The dropdown, when it is expanded has a couple of items that I want to show the events for and currently it doesn't seem possible. Would it be possible to allow the click event to happen and then show the events for the nested DOM objects?

I'm currently working off of the master branch.

Support AngularJS events

Is it possible to get the information needed for Visual Event from Angular, and if so, lets use it!

Lightbox gets debugged after trigger being fired

Steps to reproduce:

  1. mouseover over an event
  2. fire the trigger of this event
  3. move the mouse somwhere different, so the lightbox of the event disappears
  4. move the mouse back in the area where the lightbox disappeared and no other event is visible
  5. in the top left corner a lightbox appears showing only "Node: div#Event_Lightbox"

Differentiate between delegated events and their host event

jQuery delegated events are shown a little confusingly in Visual Event at the moment.

What happens is that it shows the parent event (i.e. the one that jQuery actually attaches to the DOM) and the elements that would trigger the event handler - so, for example if you have a UL with 5 LI tags in it, and attach a delegate event handler to the LIs with the UI as the host, you would see six events in Visual Event.

While this is sort of correct, Visual Event could do a better job of explaining what is going on (currently it shows 'live' text - this should be updated for newer jQuery). It would also be good to update the counters in the bar at the bottom of the window so say how many actual event handlers there are and how many delegated events handlers on child elements - ideally with a way to enable and disable each view so you can filter the view yourself to what you want.

Other libraries probably also have something similar, but lets start with jQuery...

jQuery.noConflict() on load

VisualEvent uses jQuery, but calls jQuery.noConflict() only on VisualEvent.close(). This causes conflicts with running Prototype-based scripts while VisualEvent is loaded and active.

Not working anymore

I don't know why, but it is not working anymore with jquery events, can someone check it please?

jQuery parser finds custom Array.prototype methods

jQuery parser in jQueryGeneric() has for ... in loop on array of event handlers. When oEvents is Array (at least in jQuery 1.6.4) and some custom methods are added to Array.prototype (e.g. shuffle etc.), they all are enumerated in this loop and added as handlers for this particular event:

                for ( j in oEvents ) {
                    var aNodes = [];
                    ...
                        aNodes.push( eventAttachedNode ); // aNodes.push("keydown");
                        ...
                        if ( typeof oEvents[j].origHandler != 'undefined' ) { // typeof oEvents.shuffle.origHandler === 'undefined'
                            func = oEvents[j].origHandler.toString();
                        }
                        else if ( typeof oEvents[j].handler != 'undefined' ) { // typeof oEvents.shuffle.handler === 'undefined'
                            func = oEvents[j].handler.toString();
                        }
                        else {
                            func = oEvents[j].toString(); // func = Array.prototype.shuffle.toString();
                        }
                        ...

If oEvents is Array in all jQuery versions then better will be usual for loop.

Issue in Chrome caused by JavaScript 'indexOf' method

I have the following 'indexOf' polyfill defined in one of my javascript files (because IE 7 doesn't support it natively):

if (!Array.indexOf) {
Array.prototype.indexOf = function (obj, start) { //implementation not relevant }
}

Only in Chrome (I'm using the latest version), when I use Visual Event (either versions), the 'indexOf' method is shown as a 'click' event on all anchor tags (in Firefox it's working fine). I'm using jQuery 1.6.4.

This is the description of the event shown by Visual Event:

click event subscribed by jQuery 1.6.4 (trigger event)
Function defined on line 55 in overrides.js

Hope this helps.

Thanks for this tool, it helps me a lot in optimizing my website!

problem with headless browsers

Hi,
You done a great job on visual event. i have no problem using it in normal browsers, but it seems to have problem with headless browsers like phantomjs. after injecting VisualEvent_Loader.js nothing happens.

P.S: sorry for my bad English

[enhancement] Add missing bower.json.

Hey, maintainer(s) of DataTables/VisualEvent!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library DataTables/VisualEvent is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "DataTables/VisualEvent",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Hover Events

I find it impossible to hold the visual event window in one place.

Do you think you can change the event instead of hover, to be onclick, or maybe add a shortcut to hold the window open until user closes it???

I keep trying to chase the window with my mouse it's really frustrating :(

Same event is reported multiple times (duplication)

As per below screenshot:

image

The four "mousedown" events listed there all contain the exact same text. Additionally, each of the events contains four instances of "line 12 in inline script".

Expected: a single "mousedown" event with a single "function could originate" line.

Parser for Prototype 1.7

Current Prototype events parser is working only for versions 1.6.X. In Prototype 1.7 event registry was changed, so I wrote new parser:

(function(window, document, $, VisualEvent) {

  function dumpListeners(event) {
    var listeners = [];

    for (var eventType in event) {
      var handlers = event[eventType];

      for (var i = 0, len = handlers.length; i < len; i++) {
        listeners.push({
          "type": eventType,
          "func": handlers[i].handler.toString(),
          "removed": false,
          "source": 'Prototype 1.7+'
        });
      }
    }

    return listeners;
  }

  VisualEvent.parsers.push(function() {
    if (typeof Prototype == 'undefined') {
      return [];
    }

    var elements = [], event;

    for (var e in Event.cache) {
      event = Event.cache[e];
      elements.push({
        "node": event.element,
        "listeners": dumpListeners(event)
      });
    }

    return elements;
  });

})(window, document, jQuery, VisualEvent);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.