lib/assets/javascripts/up/modal.js.coffee in upjs-rails-0.15.1 vs lib/assets/javascripts/up/modal.js.coffee in upjs-rails-0.16.0
- old
+ new
@@ -41,11 +41,11 @@
\#\#\#\# Closing behavior
By default the dialog automatically closes
-*whenever a page fragment below the dialog is updated*.
+*whenever a page fragment behind the dialog is updated*.
This is useful to have the dialog 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:
@@ -92,17 +92,20 @@
The animation used to open the modal. The animation will be applied
to both the dialog box and the overlay dimming the page.
@param {String} [config.closeAnimation='fade-out']
The animation used to close the modal. The animation will be applied
to both the dialog box and the overlay dimming the page.
+ @param {String} [config.history=true]
+ Whether opening a modal will add a browser history entry.
@stable
###
config = u.config
maxWidth: null
minWidth: null
width: null
height: null
+ history: true
openAnimation: 'fade-in'
closeAnimation: 'fade-out'
closeLabel: '×'
template: (config) ->
"""
@@ -124,11 +127,11 @@
@stable
###
currentUrl = undefined
###*
- Returns the URL of the page below the modal overlay.
+ Returns the URL of the page behind the modal overlay.
@function up.modal.coveredUrl
@return {String}
@experimental
###
@@ -198,15 +201,17 @@
elementRight = parseInt($element.css('right'))
elementRightShift = scrollbarWidth + elementRight
unshiftElement = u.temporaryCss($element, 'right': elementRightShift)
unshiftElements.push(unshiftElement)
- updated = ($modal, animation, animateOptions) ->
- shiftElements()
- $modal.show()
- deferred = up.animate($modal, animation, animateOptions)
- deferred.then -> up.emit('up:modal:opened')
+ updated = (animation, animateOptions) ->
+ $modal = $('.up-modal')
+ if $modal.is(':hidden')
+ shiftElements()
+ $modal.show()
+ deferred = up.animate($modal, animation, animateOptions)
+ deferred.then -> up.emit('up:modal:opened')
###*
Opens the given link's destination in a modal overlay:
var $link = $('...');
@@ -266,11 +271,11 @@
The URL to load.
@param {String} options.target
The CSS selector to extract from the response.
The extracted content will be placed into the dialog window.
@param {Object} options
- See options for [previous `up.modal.open` variant](/up.modal.open).
+ See options for [`up.modal.follow`](/up.modal.follow).
@return {Promise}
A promise that will be resolved when the popup has been loaded and rendered.
@stable
###
visit = (url, options) ->
@@ -293,25 +298,25 @@
animation = u.option(options.animation, $link.attr('up-animation'), config.openAnimation)
sticky = u.option(options.sticky, u.castedAttr($link, 'up-sticky'))
# Although we usually fall back to full page loads if a browser doesn't support pushState,
# in the case of modals we assume that the developer would rather see a dialog
# without an URL update.
- history = if up.browser.canPushState() then u.option(options.history, u.castedAttr($link, 'up-history'), true) 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:modal:open', url: url)
- $modal = createHiddenModal
+ createHiddenModal
selector: selector
width: width
maxWidth: maxWidth
height: height
sticky: sticky
- up.replace selector, url,
- history: history
- insert: -> updated($modal, animation, animateOptions)
+ promise = up.replace(selector, url, history: history, requireMatch: false)
+ promise.then -> updated(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()
@@ -443,10 +448,10 @@
up.on('up:fragment:inserted', (event, $fragment) ->
if contains($fragment)
if newSource = $fragment.attr('up-source')
currentUrl = newSource
- else if !up.popup.contains($fragment)
+ else if !up.popup.contains($fragment) && contains(event.origin)
autoclose()
)
# Close the pop-up overlay when the user presses ESC.
up.bus.onEscape(-> close())