Requires

Provides

Commands.js

Document catches the clicks and creates pseudo-widgets on demand

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 23
  2. 24
  3. 25
  4. 26
  5. 27
  6. 28
  7. 29
  8. 30
LSD.Document.Commands = new Class({ options: { events: { element: { 'click': 'onClick' } } },

Single relay click listener is put upon document. It spy for all clicks and elements finds out if any links were clicked. If the link is not widget, the listener creates a lightweight link class instance and calls click on it to trigger commands and interactions.

This way there’s no need to preinitialize all link handlers, and only instantiate class when the link was actually clicked.

  1. 42
  2. 43
  3. 44
  4. 45
  5. 46
  6. 47
  7. 48
  8. 49
  9. 50
onClick: function(event) { var link = (LSD.toLowerCase(event.target.tagName) == 'a') ? event.target : Slick.find(event.target, '! a'); if (!link) return; if (link.retrieve('widget')) return; var node = link.retrieve('node') if (!node) link.store('node', node = new LSD.Node.Link(link)); node.click(event); } });