Sha256: d516c36ee1081649f9dde2206581de2a4a0cbd429dde68e2f912e669699bf5a9
Contents?: true
Size: 953 Bytes
Versions: 27
Compression:
Stored size: 953 Bytes
Contents
/** * Module dependencies. */ var delegate = require('delegate'); var url = require('url'); /** * Handle link delegation on `el` or the document, * and invoke `fn(e)` when clickable. * * @param {Element|Function} el or fn * @param {Function} [fn] * @api public */ module.exports = function(el, fn){ // default to document if ('function' == typeof el) { fn = el; el = document; } delegate.bind(el, 'a', 'click', function(e){ if (clickable(e)) fn(e); }); }; /** * Check if `e` is clickable. */ function clickable(e) { if (1 != which(e)) return; if (e.metaKey || e.ctrlKey || e.shiftKey) return; if (e.defaultPrevented) return; // target var el = e.target; // check target if (el.target) return; // x-origin if (url.isCrossDomain(el.href)) return; return true; } /** * Event button. */ function which(e) { e = e || window.event; return null == e.which ? e.button : e.which; }
Version data entries
27 entries across 14 versions & 1 rubygems