lib/assets/javascripts/up/flow.js.coffee in upjs-rails-0.3.3 vs lib/assets/javascripts/up/flow.js.coffee in upjs-rails-0.4.0
- old
+ new
@@ -58,33 +58,42 @@
selectorOrElement
else
u.createSelectorFromElement($(selectorOrElement))
if !up.browser.canPushState() && !u.castsToFalse(options.history)
- up.browser.loadPage(url, u.only(options, 'method'))
+ if !options.preload
+ up.browser.loadPage(url, u.only(options, 'method'))
return
+
+ request =
+ url: url
+ method: options.method
+ selector: selector
- u.ajax(
- url: url,
- selector: selector,
- u.only(options, 'method')
- )
- .done (html, textStatus, xhr) ->
+ promise = up.proxy.ajax(request)
+
+ promise.done (html, textStatus, xhr) ->
# The server can send us the current path using a header value.
# This way we know the actual URL if the server has redirected.
if currentLocation = u.locationFromXhr(xhr)
+ u.debug('Location from server: %o', currentLocation)
+ newRequest =
+ url: currentLocation
+ method: u.methodFromXhr(xhr)
+ selector: selector
+ up.proxy.alias(request, newRequest)
url = currentLocation
-
if u.isMissing(options.history) || u.castsToTrue(options.history)
options.history = url
-
if u.isMissing(options.source) || u.castsToTrue(options.source)
options.source = url
-
- implant(selector, html, options)
- .fail(u.error)
+ implant(selector, html, options) unless options.preload
+ promise.fail(u.error)
+
+ promise
+
###*
Replaces the given selector with the same CSS selector from the given HTML string.
@method up.flow.implant
@protected
@@ -110,11 +119,11 @@
# jQuery cannot construct transient elements that contain <html> or <body> tags,
# so we're using the native browser API to grep through the HTML
htmlElement = u.createElementFromHtml(html)
# TODO: extract title from HTTP header
- options.title ||= htmlElement.querySelector("title")?.textContent
+ options.title ||= htmlElement.querySelector("title")?.textContent
for step in implantSteps(selector, options)
# Before we select a replacement target, ensure that all transitions
# and animations have been run. Finishing a transition usually removes
@@ -125,16 +134,16 @@
$old =
# always prefer to replace content in popups or modals
u.presence($(".up-popup " + step.selector)) ||
u.presence($(".up-modal " + step.selector)) ||
u.presence($(step.selector)) ||
- u.error("Could not find selector (#{step.selector}) in current body HTML")
+ u.error('Could not find selector %o in current body HTML', step.selector)
if fragment = htmlElement.querySelector(step.selector)
$new = $(fragment)
swapElements $old, $new, step.pseudoClass, step.transition, options
else
- u.error("Could not find selector (#{step.selector}) in response (#{html})")
+ u.error("Could not find selector %o in response %o", step.selector, html)
elementsInserted = ($new, options) ->
options.insert?($new)
if options.history
document.title = options.title if options.title
@@ -169,10 +178,10 @@
# get marked as .up-destroying right away.
destroy $old, animation: ->
$new.insertAfter($old)
elementsInserted($new, options)
if $old.is('body') && transition != 'none'
- u.error('Cannot apply transitions to body-elements', transition)
+ u.error('Cannot apply transitions to body-elements (%o)', transition)
up.morph($old, $new, transition)
implantSteps = (selector, options) ->
transitionString = options.transition || options.animation || 'none'
comma = /\ *,\ */