Skip to content

Instantly share code, notes, and snippets.

@ehlyzov
Created February 13, 2013 09:09
Show Gist options
  • Select an option

  • Save ehlyzov/4943230 to your computer and use it in GitHub Desktop.

Select an option

Save ehlyzov/4943230 to your computer and use it in GitHub Desktop.
( ($) ->
$.fn.outclick = (func) ->
clickHandler = (e) =>
console.log e
unless e.target == @ or $(e.target).parents().is(@)
@.trigger('outclick')
$(document).one 'outclick', @, (_e, e) =>
$(document).unbind 'click', clickHandler
func(@, _e)
return
$(document).bind 'click', clickHandler
)( jQuery )
jQuery.fn.outclick = (func) ->
$(document).on 'outclick', @selector, (_e, e) ->
unless e.target == this or _.include($(e.target).parents(), this)
func($(this), _e)
return
$(document).click (e) =>
$(@selector).trigger('outclick', e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment