lib/assets/javascripts/angular-turbolinks.js.coffee in angular-turbolinks-0.0.3 vs lib/assets/javascripts/angular-turbolinks.js.coffee in angular-turbolinks-0.0.4
- old
+ new
@@ -1,11 +1,10 @@
-angular.module('ngTurbolinks', []).run(($location, $rootScope, $http, $q)->
+angular.module('ngTurbolinks', []).run(($location, $rootScope, $http, $q, $compile)->
loadedAssets = null
createDocument = null
xhr_req = null
- referer = null
triggerEvent = (name, data) ->
event = document.createEvent 'Events'
event.data = data if data
event.initEvent name, true, true
@@ -15,11 +14,11 @@
value = document.cookie.match(new RegExp(name+"=(\\w+)"))?[1].toUpperCase() or ''
document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/'
value
rememberReferer = ->
- referer = document.location.href
+ window.referer = document.location.href
processResponse = (responseText, status, headers)->
clientOrServerError = ->
400 <= status < 600
@@ -95,11 +94,11 @@
if current.token? and latest? and current.token isnt latest
current.node.setAttribute 'content', latest
changePage = (title, body, csrfToken, runScripts) ->
document.title = title
- document.documentElement.replaceChild body, document.body
+ angular.element("body").html($compile("<div id=\"turbolinks_content\">"+body.innerHTML+"</div>")($rootScope))
CSRFToken.update csrfToken if csrfToken?
executeScriptTags() if runScripts
currentState = window.history.state
triggerEvent 'page:change'
triggerEvent 'page:update'
@@ -124,13 +123,15 @@
xhr_req.resolve() if xhr_req
xhr_req = $q.defer()
triggerEvent 'page:fetch', url: url
- $http.get(url, {
+ $http({
+ url: url,
+ method: 'GET',
headers: {
- 'Accept' : 'text/html, application/xhtml+xml, application/xml'
- 'X-XHR-Referer' : referer
+ 'Accept' : 'text/html, application/xhtml+xml, application/xml',
+ 'X-XHR-Referer' : window.referer
},
timeout: xhr_req.promise
}).success((data, status, headers)->
triggerEvent 'page:receive'
if doc = processResponse(data, status, headers)