lib/assets/javascripts/up/flow.js.coffee in upjs-rails-0.2.1 vs lib/assets/javascripts/up/flow.js.coffee in upjs-rails-0.2.2
- old
+ new
@@ -1,12 +1,20 @@
###*
Changing page fragments programmatically
========================================
+
+This module contains Up's core functions to insert, change
+or destroy page fragments.
-TODO: Write some documentation
-
-
+\#\#\# Incomplete documentation!
+
+We need to work on this page:
+
+- Explain the UJS approach vs. pragmatic approach
+- Examples
+
+
@class up.flow
###
up.flow = (->
u = up.util
@@ -47,22 +55,31 @@
selector = if u.presence(selectorOrElement)
selectorOrElement
else
u.createSelectorFromElement($(selectorOrElement))
-
- if u.isMissing(options.history) || u.castsToTrue(options.history)
- options.history = url
-
- if u.isMissing(options.source) || u.castsToTrue(options.source)
- options.source = url
- u.get(url, selector: selector)
- .done (html) -> implant(selector, html, options)
- .fail(u.error)
+ u.ajax(
+ url: url,
+ selector: selector
+ )
+ .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)
+ 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)
+
###*
- Replaces the given selector with the same selector from the given HTML string.
+ Replaces the given selector with the same CSS selector from the given HTML string.
@method up.flow.implant
@protected
@param {String} selector
@param {String} html