Warning: The use of pointer-events in CSS for non-SVG elements is experimental. The feature used to be part of the CSS 3 UI draft specification but, due to many open issues, has been postponed to CSS 4.
class AnchorDisablerconstructor: (selector = 'a.disabled') ->$(selector).click(@onClick).keyup(@onKeyup).focus(@onFocus)
isStillDisabled: (ev) =>### since disabled can be a class or an attribute, and it can be dynamically removed, always recheck on a watched event ###target = $(ev.target)return true if target.hasClass('disabled')return true if target.attr('disabled') is 'disabled'return false
onFocus: (ev) =>### if an attempt is made to focus on a disabled element, just move it along to the next focusable one. ###return unless @isStillDisabled(ev)
focusables = $(':focusable')return unless focusables
current = focusables.index(ev.target)next = (if focusables.eq(current + 1).length then focusables.eq(current + 1) else focusables.eq(0))
next.focus() if next
onClick: (ev) =># disabled could be dynamically removedreturn unless @isStillDisabled(ev)
ev.preventDefault()return false
onKeyup: (ev) =>
# 13 is the JavaScript key code for Enter. We are only interested in disabling that, so get out fastcode = ev.keyCode or ev.whichreturn unless code is 13
# disabled could be dynamically removedreturn unless @isStillDisabled(ev)
ev.preventDefault()return false