2013-07-27 05:00:45 +02:00
|
|
|
angular.module('ponyfm').directive 'pfmPopup', () ->
|
|
|
|
(scope, element, attrs) ->
|
|
|
|
$popup = $ '#' + attrs.pfmPopup
|
|
|
|
$element = $ element
|
|
|
|
$popup.remove()
|
|
|
|
open = false
|
|
|
|
|
|
|
|
documentClickHandler = () ->
|
|
|
|
return if !open
|
|
|
|
$popup.removeClass 'open'
|
|
|
|
open = false
|
|
|
|
|
|
|
|
$(document.body).bind 'click', documentClickHandler
|
|
|
|
|
|
|
|
$(document.body).append $popup
|
|
|
|
|
|
|
|
$(element).click (e) ->
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
|
|
|
|
if open
|
|
|
|
open = false
|
|
|
|
$popup.removeClass 'open'
|
|
|
|
return
|
|
|
|
|
|
|
|
$popup.addClass 'open'
|
2013-07-28 06:37:32 +02:00
|
|
|
|
|
|
|
position = $element.offset()
|
|
|
|
left = position.left
|
|
|
|
right = left + $popup.width()
|
|
|
|
windowWidth = $(window).width() - 15
|
|
|
|
if right > windowWidth
|
|
|
|
left -= right - windowWidth
|
|
|
|
|
2013-07-27 05:00:45 +02:00
|
|
|
$popup.css
|
|
|
|
top: position.top + $element.height() + 10
|
2013-07-28 06:37:32 +02:00
|
|
|
left: left
|
2013-07-27 05:00:45 +02:00
|
|
|
|
|
|
|
open = true
|
|
|
|
|
|
|
|
scope.$on '$destroy', () ->
|
|
|
|
$(document.body).unbind 'click', documentClickHandler
|
|
|
|
$popup.remove()
|