lib/assets/javascripts/up/modal.js.coffee in upjs-rails-0.12.1 vs lib/assets/javascripts/up/modal.js.coffee in upjs-rails-0.12.2
- old
+ new
@@ -66,39 +66,58 @@
<div class="up-modal-content"></div>
</div>
</div>
"""
- currentSource = undefined
+ ###*
+ Returns the source URL for the fragment displayed in the current modal overlay,
+ or `undefined` if no modal is currently open.
+ @method up.modal.url
+ @return {String}
+ the source URL
+ ###
+ currentUrl = undefined
+
+ ###*
+ Returns the URL of the page below the modal overlay.
+
+ @method up.modal.coveredUrl
+ @return {String}
+ @protected
+ ###
+ coveredUrl = ->
+ $modal = $('.up-modal')
+ $modal.attr('up-covered-url')
+
reset = ->
close()
- currentSource = undefined
+ currentUrl = undefined
config.reset()
templateHtml = ->
template = config.template
if u.isFunction(template)
template(config)
else
template
rememberHistory = ->
- $popup = $('.up-modal')
- $popup.attr('up-previous-url', up.browser.url())
- $popup.attr('up-previous-title', document.title)
+ $modal = $('.up-modal')
+ $modal.attr('up-covered-url', up.browser.url())
+ $modal.attr('up-covered-title', document.title)
discardHistory = ->
- $popup = $('.up-modal')
- $popup.removeAttr('up-previous-url')
- $popup.removeAttr('up-previous-title')
+ $modal = $('.up-modal')
+ $modal.removeAttr('up-covered-url')
+ $modal.removeAttr('up-covered-title')
createHiddenModal = (options) ->
$modal = $(templateHtml())
$modal.attr('up-sticky', '') if options.sticky
- $modal.attr('up-previous-url', up.browser.url())
- $modal.attr('up-previous-title', document.title)
+ $modal.attr('up-covered-url', up.browser.url())
+ $modal.attr('up-covered-title', document.title)
$dialog = $modal.find('.up-modal-dialog')
$dialog.css('width', options.width) if u.isPresent(options.width)
$dialog.css('max-width', options.maxWidth) if u.isPresent(options.maxWidth)
$dialog.css('height', options.height) if u.isPresent(options.height)
$content = $modal.find('.up-modal-content')
@@ -136,19 +155,19 @@
updated = ($modal, animation, animateOptions) ->
shiftElements()
$modal.show()
deferred = up.animate($modal, animation, animateOptions)
- deferred.then -> up.bus.emit('up:modal:opened')
+ deferred.then -> up.emit('up:modal:opened')
###*
Opens the given link's destination in a modal overlay:
var $link = $('...');
up.modal.follow($link);
- Any option attributes for [`a[up-modal]`](#a.up-modal) will be honored.
+ Any option attributes for [`a[up-modal]`](/a.up-modal) will be honored.
\#\#\#\# Events
- Emits an [event](/up.bus) `up:modal:open` when the modal
is starting to open.
@@ -160,27 +179,27 @@
The link to follow.
@param {String} [options.target]
The selector to extract from the response and open in a modal dialog.
@param {Number} [options.width]
The width of the dialog in pixels.
- By [default](#up.modal.defaults) the dialog will grow to fit its contents.
+ By [default](/up.modal.config) the dialog will grow to fit its contents.
@param {Number} [options.height]
The width of the dialog in pixels.
- By [default](#up.modal.defaults) the dialog will grow to fit its contents.
+ By [default](/up.modal.config) the dialog will grow to fit its contents.
@param {Boolean} [options.sticky=false]
If set to `true`, the modal remains
open even if the page changes in the background.
@param {Object} [options.history=true]
Whether to add a browser history entry for the modal's source URL.
@param {String} [options.animation]
The animation to use when opening the modal.
@param {Number} [options.duration]
- The duration of the animation. See [`up.animate`](/up.motion#up.animate).
+ The duration of the animation. See [`up.animate`](/up.animate).
@param {Number} [options.delay]
- The delay before the animation starts. See [`up.animate`](/up.motion#up.animate).
+ The delay before the animation starts. See [`up.animate`](/up.animate).
@param {String} [options.easing]
- The timing function that controls the animation's acceleration. [`up.animate`](/up.motion#up.animate).
+ The timing function that controls the animation's acceleration. [`up.animate`](/up.animate).
@return {Promise}
A promise that will be resolved when the modal has finished loading.
###
follow = (linkOrSelector, options) ->
options = u.options(options)
@@ -203,11 +222,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 [previous `up.modal.open` variant](/up.modal.open).
###
visit = (url, options) ->
options = u.options(options)
options.url = url
open(options)
@@ -248,21 +267,10 @@
# Although someone prevented the destruction, keep a uniform API for
# callers by returning a Deferred that will never be resolved.
$.Deferred()
###*
- Returns the source URL for the fragment displayed in the current modal overlay,
- or `undefined` if no modal is currently open.
-
- @method up.modal.source
- @return {String}
- the source URL
- ###
- source = ->
- currentSource
-
- ###*
Closes a currently opened modal overlay.
Does nothing if no modal is currently open.
\#\#\#\# Events
@@ -271,26 +279,26 @@
- Emits an [event](/up.bus) `modal:closed` when the closing
animation has finished and the modal has been removed from the DOM.
@method up.modal.close
@param {Object} options
- See options for [`up.animate`](/up.motion#up.animate)
+ See options for [`up.animate`](/up.animate)
###
close = (options) ->
$modal = $('.up-modal')
if $modal.length
if up.bus.nobodyPrevents('up:modal:close', $element: $modal)
options = u.options(options,
animation: config.closeAnimation,
- url: $modal.attr('up-previous-url')
- title: $modal.attr('up-previous-title')
+ url: $modal.attr('up-covered-url')
+ title: $modal.attr('up-covered-title')
)
- currentSource = undefined
+ currentUrl = undefined
deferred = up.destroy($modal, options)
deferred.then ->
unshifter() while unshifter = unshiftElements.pop()
- up.bus.emit('up:modal:closed')
+ up.emit('up:modal:closed')
deferred
else
# Although someone prevented the destruction, keep a uniform API for
# callers by returning a Deferred that will never be resolved.
$.Deferred()
@@ -352,11 +360,11 @@
</div>
</div>
</div>
If you want to change the design beyond CSS, you can
- configure Up.js to [use a different HTML structure](#up.modal.config).
+ configure Up.js to [use a different HTML structure](/up.modal.config).
\#\#\#\# Closing behavior
By default the dialog automatically closes
@@ -395,11 +403,11 @@
)
up.on('up:fragment:inserted', (event, $fragment) ->
if contains($fragment)
if newSource = $fragment.attr('up-source')
- currentSource = newSource
+ currentUrl = newSource
else if !up.popup.contains($fragment)
autoclose()
)
# Close the pop-up overlay when the user presses ESC.
@@ -426,11 +434,13 @@
visit: visit
follow: follow
open: -> up.error('up.modal.open no longer exists. Please use either up.modal.follow or up.modal.visit.')
close: close
- source: source
+ url: -> currentUrl
+ coveredUrl: coveredUrl
config: config
defaults: -> u.error('up.modal.defaults(...) no longer exists. Set values on he up.modal.config property instead.')
contains: contains
+ source: -> up.error('up.popup.source no longer exists. Please use up.popup.url instead.')
)(jQuery)