mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 11:44:21 -05:00
32 lines
763 B
CoffeeScript
32 lines
763 B
CoffeeScript
define [
|
|
], () ->
|
|
class SavingAreaManager
|
|
$el: $('#saving-area')
|
|
|
|
constructor: (@ide) ->
|
|
@unsavedSeconds = 0
|
|
setInterval () =>
|
|
@pollSavedStatus()
|
|
, 1000
|
|
|
|
$(window).bind 'beforeunload', () =>
|
|
@warnAboutUnsavedChanges()
|
|
|
|
pollSavedStatus: () ->
|
|
doc = @ide.editor.document
|
|
return if !doc?
|
|
saved = doc.pollSavedStatus()
|
|
if saved
|
|
@unsavedSeconds = 0
|
|
else
|
|
@unsavedSeconds += 1
|
|
|
|
if @unsavedSeconds >= 4
|
|
$("#savingProblems").text("Saving... (#{@unsavedSeconds} seconds of unsaved changes)")
|
|
$("#savingProblems").show()
|
|
else
|
|
$("#savingProblems").hide()
|
|
|
|
warnAboutUnsavedChanges: () ->
|
|
if @ide.editor.hasUnsavedChanges()
|
|
return "You have unsaved changes. If you leave now they will not be saved."
|