lib/assets/javascripts/up/popup.js.coffee in upjs-rails-0.15.1 vs lib/assets/javascripts/up/popup.js.coffee in upjs-rails-0.16.0
- old
+ new
@@ -29,11 +29,11 @@
\#\#\#\# Closing behavior
The popup closes when the user clicks anywhere outside the popup area.
By default the popup also closes
-*whenever a page fragment below the popup is updated*.
+*whenever a page fragment behind the popup is updated*.
This is useful to have the popup interact with the page that
opened it, e.g. by updating parts of a larger form or by signing in a user
and revealing additional information.
To disable this behavior, give the opening link an `up-sticky` attribute:
@@ -56,11 +56,11 @@
@stable
###
currentUrl = undefined
###*
- Returns the URL of the page or modal below the popup.
+ Returns the URL of the page or modal behind the popup.
@function up.popup.coveredUrl
@return {String}
@experimental
###
@@ -78,16 +78,19 @@
The animation used to close a popup.
@param {String} [config.position='bottom-right']
Defines where the popup is attached to the opening element.
Valid values are `bottom-right`, `bottom-left`, `top-right` and `top-left`.
+ @param {String} [config.history=false]
+ Whether opening a popup will add a browser history entry.
@stable
###
config = u.config
openAnimation: 'fade-in'
closeAnimation: 'fade-out'
position: 'bottom-right'
+ history: false
reset = ->
close()
config.reset()
@@ -97,11 +100,11 @@
when "bottom-right"
right: linkBox.right
top: linkBox.top + linkBox.height
when "bottom-left"
left: linkBox.left
- top: linkBox.bottom + linkBox.height
+ top: linkBox.top + linkBox.height
when "top-right"
right: linkBox.right
bottom: linkBox.top
when "top-left"
left: linkBox.left
@@ -156,26 +159,30 @@
$popup.appendTo(document.body)
rememberHistory()
$popup.hide()
$popup
- updated = ($link, $popup, position, animation, animateOptions) ->
- $popup.show()
- setPosition($link, $popup, position)
- deferred = up.animate($popup, animation, animateOptions)
- deferred.then -> up.emit('up:popup:opened')
- deferred
-
+ updated = ($link, position, animation, animateOptions) ->
+ $popup = $('.up-popup')
+ if $popup.is(':hidden')
+ $popup.show()
+ setPosition($link, $popup, position)
+ deferred = up.animate($popup, animation, animateOptions)
+ deferred.then -> up.emit('up:popup:opened')
+
###*
Attaches a popup overlay to the given element or selector.
Emits events [`up:popup:open`](/up:popup:open) and [`up:popup:opened`](/up:popup:opened).
@function up.popup.attach
@param {Element|jQuery|String} elementOrSelector
@param {String} [options.url]
@param {String} [options.position='bottom-right']
+ Defines where the popup is attached to the opening element.
+
+ Valid values are `bottom-right`, `bottom-left`, `top-right` and `top-left`.
@param {String} [options.animation]
The animation to use when opening the popup.
@param {Number} [options.duration]
The duration of the animation. See [`up.animate`](/up.animate).
@param {Number} [options.delay]
@@ -190,29 +197,28 @@
A promise that will be resolved when the popup has been loaded and rendered.
@stable
###
attach = (linkOrSelector, options) ->
$link = $(linkOrSelector)
+ $link.length or u.error('Cannot attach popup to non-existing element %o', linkOrSelector)
options = u.options(options)
url = u.option(options.url, $link.attr('href'))
selector = u.option(options.target, $link.attr('up-popup'), 'body')
position = u.option(options.position, $link.attr('up-position'), config.position)
animation = u.option(options.animation, $link.attr('up-animation'), config.openAnimation)
sticky = u.option(options.sticky, u.castedAttr($link, 'up-sticky'))
- history = if up.browser.canPushState() then u.option(options.history, u.castedAttr($link, 'up-history'), false) else false
+ history = if up.browser.canPushState() then u.option(options.history, u.castedAttr($link, 'up-history'), config.history) else false
animateOptions = up.motion.animateOptions(options, $link)
close()
if up.bus.nobodyPrevents('up:popup:open', url: url)
- $popup = createHiddenPopup($link, selector, sticky)
-
- up.replace(selector, url,
- history: history
- insert: -> updated($link, $popup, position, animation, animateOptions)
- )
+ createHiddenPopup($link, selector, sticky)
+ promise = up.replace(selector, url, history: history, requireMatch: false)
+ promise.then -> updated($link, position, animation, animateOptions)
+ promise
else
# Although someone prevented the destruction, keep a uniform API for
# callers by returning a Deferred that will never be resolved.
u.unresolvableDeferred()
@@ -307,18 +313,23 @@
Opens this link's destination of in a popup overlay:
<a href="/decks" up-popup=".deck_list">Switch deck</a>
If the `up-sticky` attribute is set, the dialog does not auto-close
- if a page fragment below the popup overlay updates:
+ if a page fragment behind the popup overlay updates:
<a href="/decks" up-popup=".deck_list">Switch deck</a>
<a href="/settings" up-popup=".options" up-sticky>Settings</a>
@selector a[up-popup]
- @param [up-sticky]
@param [up-position]
+ Defines where the popup is attached to the opening element.
+
+ Valid values are `bottom-right`, `bottom-left`, `top-right` and `top-left`.
+ @param [up-sticky]
+ If set to `true`, the popup remains
+ open even if the page changes in the background.
@stable
###
up.on('click', 'a[up-popup]', (event, $link) ->
event.preventDefault()
if $link.is('.up-current')
@@ -337,10 +348,10 @@
up.on('up:fragment:inserted', (event, $fragment) ->
if contains($fragment)
if newSource = $fragment.attr('up-source')
currentUrl = newSource
- else
+ else if contains(event.origin)
autoclose()
)
# Close the pop-up overlay when the user presses ESC.
up.bus.onEscape(-> close())