-
-
Save davidecavaliere/5939315 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
AUI().use( | |
'aui-base', | |
function(A) { | |
var popClicks = A.all('.pop-click'); | |
var popClickHandle; | |
var togglePopClick = function(event) { | |
event.stopPropagation(); | |
var targetNode = event.target; | |
if (targetNode.hasClass('pop-click-content') || targetNode.ancestor('.pop-click-content')) { | |
return; | |
} | |
var activePopClick = A.one('.pop-click-active'); | |
if (activePopClick) { | |
activePopClick.removeClass('pop-click-active'); | |
} | |
var currentTargetNode = event.currentTarget; | |
if (currentTargetNode.hasClass('pop-click') && (currentTargetNode != activePopClick)) { | |
currentTargetNode.addClass('pop-click-active'); | |
} | |
activePopClick = A.one('.pop-click-active'); | |
if (activePopClick && !popClickHandle) { | |
popClickHandle = A.getDoc().on('click', togglePopClick); | |
} | |
else if (popClickHandle && !activePopClick) { | |
popClickHandle.detach(); | |
popClickHandle = null; | |
} | |
}; | |
popClicks.on('click', togglePopClick); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment