Created
November 14, 2014 13:37
-
-
Save AkA84/e5bf8c626c7936d08391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
Simple popup jQuery widget | |
### | |
$.fn.popup = -> | |
popups = [] | |
# One time binding to document of the handler that listens for clicks | |
# on [data-popup-trigger] elements and outside popup elements | |
do ( -> | |
# Close popups on outside click | |
$(document).on 'click', (event) -> | |
popups.forEach ($popup) => | |
$popupParent = $popup.parent() | |
$popup.hide() if $popup.is(':visible') and !$popupParent.is(event.target) and !$popupParent.has(event.target).length | |
# Open popups on trigger click | |
$(document).on 'click', '[data-popup-target]', (event) -> | |
event.preventDefault() | |
return unless popups.length? | |
$popupTarget = popups.filter ($popup) => | |
$popup.data('popup') is $(this).data('popupTarget') | |
$popupTarget[0].toggle() if $popupTarget.length? | |
) unless popups.length | |
this.each -> | |
$popup = $ this | |
popups.push $popup | |
$popup.on 'click', 'a', (event) -> $popup.hide() # Close popups on link click | |
$('.fbs_popup').eq(0).popup() | |
$('.fbs_popup').eq(1).popup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment