Files
nairobi/app/assets/javascripts/watch_form_changes.js.coffee
Javi Martín 86e704d8a4 Use strict mode in JavaScript
Strict mode is supported by 98% of the browsers, including Internet
Explorer 10, and it helps developers avoid common JavaScript pitfalls.
2019-09-11 03:14:17 +02:00

29 lines
746 B
CoffeeScript

"use strict"
App.WatchFormChanges =
forms: ->
return $("form[data-watch-changes]")
msg: ->
return $("[data-watch-form-message]").data("watch-form-message")
hasChanged: ->
App.WatchFormChanges.forms().is ->
$(this).serialize() != $(this).data("watchChanges")
checkChanges: ->
if App.WatchFormChanges.hasChanged()
confirm(App.WatchFormChanges.msg())
else
true
initialize: ->
if App.WatchFormChanges.forms().length == 0 || App.WatchFormChanges.msg() == undefined
return
$(document).off("page:before-change").on("page:before-change", App.WatchFormChanges.checkChanges)
App.WatchFormChanges.forms().each ->
form = $(this)
form.data("watchChanges", form.serialize())