Skip to content

Instantly share code, notes, and snippets.

@ivaravko
Created August 2, 2012 10:59
Show Gist options
  • Save ivaravko/3236244 to your computer and use it in GitHub Desktop.
Save ivaravko/3236244 to your computer and use it in GitHub Desktop.
Browser API wishlist

Browser API wishlist

Native event delegation

Browsers could do so much more to optimize delegated handlers at a lower level. Most of the CSS selector parsing and grouping optimizations could be applied here. No javascript code ever has to be invoked if the selector doesn't match.

document.addDelegatedEventListener("mouseover", ".tooltip", listener)

Possibly coming with Web Components.

document.listen({selector: ".tooltip", type: "mouseover", handler: handler})

XHR requested location

Theres no way to figure what URL you ended up at if the request follows a redirect.

XMLHttpRequest#requestLocation

popstate state unique ids

Useful when storing associated state data. Like a cached dom fragments associated with previous pages.

Adding (new Date).getTime() to the state object is a current workaround.

PopStateEvent#direction

The direction (forward or back) that triggered the popstate event. Useful for sliding animations.

window.onpopstate = function(event) {
  event.direction #=> "back"
}

Element#simulateClick

Smarter click simulating. Theres more to it than firing a 'click' event and changing location.href unless default was prevented. Equivalent of WebKit dispatchSimulatedClick.

target.simulateClick()

Access mouse position outside mouse event handler

Sometimes you just need to know where the mouse is at a given moment rather than anytime it changes.

window.mouse.clientY
window.mouse.screenY

Current workaround:

var lastMouseMoveEvent;
window.addEventListener('mousemove', function(event) { lastMouseMoveEvent = event }, true);

Mousing/keyboard mode detection

Kinda specific to OSX, the cursor will be hidden when you start typing. This feature is provided by setHiddenUntilMouseMoves. Useful for detecting "typing" and "keyboard nav" modes vs mousing.

window.isMouseHidden()
window.addEventListener("mousehide", ...)
window.addEventListener("mouseshow", …)

Adoption of KeyboardEvent.char and KeyboardEvent.key

Finally get away from this keyCode nonsense. Its standarized as part of DOM Level 3 Events but hardly any browsers support it yet.

Better hotkey support

We have accesskeys, but they require ctrl+. Supporting any modifier would be nice.

<input type=search hotkey="s">

transitionStart event

The missing complement to transitionEnd.

See http://snook.ca/archives/javascript/preparetransition-jquery-plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment