   'blur change click dblclick error focus input keydown
    keypress keyup load mousedown mousemove mouseout mouseover
    mouseup resize scroll select submit unload'.split /\s+/
+
+# Use native matchesSelector if available, otherwise fall back
+# on jQuery.is (slower, but compatible)
+docEl = document.documentElement
+matches = docEl.matchesSelector || docEl.mozMatchesSelector || docEl.webkitMatchesSelector || docEl.oMatchesSelector || docEl.msMatchesSelector
+matchesSelector = if matches then ((elem, selector) -> matches.call(elem[0], selector)) else ((elem, selector) -> elem.is(selector))
 
 idCounter = 0
 


jQuery.fn.view = -> @data('view')
jQuery.fn.views = -> @toArray().map (elt) -> $(elt).view()
docEl = document.documentElement
matches = docEl.matchesSelector || docEl.mozMatchesSelector || docEl.webkitMatchesSelector || docEl.oMatchesSelector || docEl.msMatchesSelector
jQuery.fn.matching = if matches then ((selector) -> matches.call(@[0], selector)) else jQuery.fn.is

# Trigger attach event when views are added to the DOM
callAttachHook = (element) ->

          element = $(element)
          element.on eventName, (event) -> view[methodName](event, element)

      if matchesSelector(view, selector)
        methodName = view[0].getAttribute(eventName)
        do (methodName) ->
          view.on eventName, (event) -> view[methodName](event, view)
