lib/assets/javascripts/up/popup.js.coffee in upjs-rails-0.7.5 vs lib/assets/javascripts/up/popup.js.coffee in upjs-rails-0.7.6
- old
+ new
@@ -23,10 +23,12 @@
###
up.popup = (->
u = up.util
+ currentSource = undefined
+
config =
openAnimation: 'fade-in'
closeAnimation: 'fade-out'
position: 'bottom-right'
@@ -158,13 +160,11 @@
@method up.popup.source
@return {String}
the source URL
###
source = ->
- $popup = $('.up-popup')
- unless $popup.is('.up-destroying')
- $popup.find('[up-source]').attr('up-source')
+ currentSource
###*
Closes a currently opened popup overlay.
Does nothing if no popup is currently open.
@@ -178,17 +178,31 @@
options = u.options(options,
animation: config.closeAnimation,
url: $popup.attr('up-previous-url'),
title: $popup.attr('up-previous-title')
)
+ currentSource = undefined
up.destroy($popup, options)
autoclose = ->
unless $('.up-popup').is('[up-sticky]')
+ discardHistory()
close()
-
+
###*
+ Returns whether the given element or selector is contained
+ within the current popup.
+
+ @methods up.popup.contains
+ @param {String} elementOrSelector
+ @protected
+ ###
+ contains = (elementOrSelector) ->
+ $element = $(elementOrSelector)
+ $element.closest('.up-popup').length > 0
+
+ ###*
Opens the target of this link in a popup overlay:
<a href="/decks" up-modal=".deck_list">Switch deck</a>
If the `up-sticky` attribute is set, the dialog does not auto-close
@@ -217,12 +231,14 @@
unless $target.closest('.up-popup').length || $target.closest('[up-popup]').length
close()
)
up.bus.on('fragment:ready', ($fragment) ->
- unless $fragment.closest('.up-popup').length
- discardHistory()
+ if contains($fragment)
+ if newSource = $fragment.attr('up-source')
+ currentSource = newSource
+ else
autoclose()
)
# Close the pop-up overlay when the user presses ESC.
up.magic.onEscape(-> close())
@@ -245,7 +261,8 @@
open: open
close: close
source: source
defaults: defaults
+ contains: contains
)()