app/assets/javascripts/locomotive/views/editable_elements/iframe_view.js.coffee in locomotivecms-3.0.1 vs app/assets/javascripts/locomotive/views/editable_elements/iframe_view.js.coffee in locomotivecms-3.1.0.rc1
- old
+ new
@@ -15,10 +15,12 @@
reload: ->
$(@el).attr('src', @preview_url)
on_load: (event) ->
+ @register_beforeunload()
+
# Able to get the path to the edit form?
if (path = @edit_view_path())?
@preview_url = @window.document.location.href
if !@startup
@@ -50,9 +52,17 @@
edit: $(@el).data('edit-label')
@page_view.render()
# insert the highlighter CSS (path to the CSS in the iframe data)
window.addStylesheet(@window.document, $(@el).data('style-path'))
+
+ register_beforeunload: ->
+ $(@window).off 'beforeunload', @warn_if_unsaved_content
+ $(@window).on 'beforeunload', @warn_if_unsaved_content
+
+ warn_if_unsaved_content: ->
+ if window.unsaved_content
+ return $('meta[name=unsaved-content-warning]').attr('content')
remove: ->
super()
@page_view.remove() if @page_view?
_.each @tokens, (token) -> PubSub.unsubscribe(token)