mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
parent
3cd05ae6ae
commit
8d7b2029b8
3 changed files with 12 additions and 2 deletions
|
@ -29,6 +29,7 @@ ajax.defaults =
|
|||
# data
|
||||
# error
|
||||
# headers
|
||||
# progress
|
||||
# success
|
||||
# url
|
||||
|
||||
|
@ -54,6 +55,7 @@ applyCallbacks = (xhr, options) ->
|
|||
return unless options.async
|
||||
|
||||
xhr.timer = setTimeout onTimeout.bind(undefined, xhr, options), options.timeout * 1000
|
||||
xhr.onprogress = options.progress if options.progress
|
||||
xhr.onreadystatechange = ->
|
||||
if xhr.readyState is 4
|
||||
clearTimeout(xhr.timer)
|
||||
|
|
|
@ -94,7 +94,7 @@ class app.models.Doc extends app.Model
|
|||
app.localStorage.set @slug, [@mtime, data]
|
||||
return
|
||||
|
||||
install: (onSuccess, onError) ->
|
||||
install: (onSuccess, onError, onProgress) ->
|
||||
return if @installing
|
||||
@installing = true
|
||||
|
||||
|
@ -112,6 +112,7 @@ class app.models.Doc extends app.Model
|
|||
url: @dbUrl()
|
||||
success: success
|
||||
error: error
|
||||
progress: onProgress
|
||||
timeout: 3600
|
||||
return
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class app.views.OfflinePage extends app.View
|
|||
$.stopEvent(event)
|
||||
doc = @docByEl(link)
|
||||
action = 'install' if action is 'update'
|
||||
doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc))
|
||||
doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc), @onInstallProgress.bind(@, doc))
|
||||
link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…"
|
||||
else if action = link.getAttribute('data-action-all')
|
||||
$.stopEvent(event)
|
||||
|
@ -79,6 +79,13 @@ class app.views.OfflinePage extends app.View
|
|||
el.lastElementChild.textContent = 'Error'
|
||||
return
|
||||
|
||||
onInstallProgress: (doc, event) ->
|
||||
return unless @activated and event.lengthComputable
|
||||
if el = @docEl(doc)
|
||||
percentage = Math.round event.loaded * 100 / event.total
|
||||
el.lastElementChild.textContent = el.lastElementChild.textContent.replace(/(\s.+)?$/, " (#{percentage}%)")
|
||||
return
|
||||
|
||||
onChange: (event) ->
|
||||
if event.target.name is 'autoUpdate'
|
||||
app.settings.set 'manualUpdate', !event.target.checked
|
||||
|
|
Loading…
Reference in a new issue