Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions lib/assets/javascripts/angular-turbolinks.js.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
angular.module('ngTurbolinks', []).run(($location, $rootScope, $http, $q, $compile)->
ngTurbolinks = angular.module('ngTurbolinks', [])

ngTurbolinks.factory 'Turbolinks', ($location, $rootScope, $http, $q, $compile) ->

loadedAssets = null
createDocument = null
Expand Down Expand Up @@ -129,25 +131,24 @@ angular.module('ngTurbolinks', []).run(($location, $rootScope, $http, $q, $compi
xhr_req = $q.defer()

triggerEvent 'page:fetch', url: url
$http({
url: url,
method: 'GET',
headers: {
'Accept' : 'text/html, application/xhtml+xml, application/xml',
promise = $http(
url: url
method: 'GET'
headers:
'Accept' : 'text/html, application/xhtml+xml, application/xml'
'X-XHR-Referer' : referer
},
timeout: xhr_req.promise
}).success((data, status, headers)->
)
promise.success (data, status, headers) ->
triggerEvent 'page:receive'
if doc = processResponse(data, status, headers)
changePage extractTitleAndBody(doc)...
#reflectRedirectedUrl()
triggerEvent 'page:load'
else
document.location.href = url
).error(->
promise.error ->
document.location.href = url
)

# Handle bug in Firefox 26/27 where history.state is initially undefined
historyStateIsDefined =
Expand Down Expand Up @@ -190,11 +191,12 @@ angular.module('ngTurbolinks', []).run(($location, $rootScope, $http, $q, $compi
visit = (url) ->
document.location.href = url

$rootScope.$on("$locationChangeStart", (event, url, prev_url)->
if url == prev_url || !triggerEvent 'page:before-change'
{ visit: visit, triggerEvent: triggerEvent } # Turbolinks

ngTurbolinks.run ($rootScope, Turbolinks) ->
$rootScope.$on "$locationChangeStart", (event, url, prev_url)->
if url == prev_url || !Turbolinks.triggerEvent('page:before-change')
event.preventDefault()
return false

visit(url)
)
)
Turbolinks.visit(url)