We originally wrote `undefined` in CoffeeScript. CoffeeScript compiled it to `void 0` when generating the JavaScript files. However, the reason to do so was the `undefined` variable was mutable before ECMAScript 5. Using `undefined` is more intuitive, and nowadays there's no reason to use `void 0`.
33 lines
992 B
JavaScript
33 lines
992 B
JavaScript
(function() {
|
|
"use strict";
|
|
App.WatchFormChanges = {
|
|
forms: function() {
|
|
return $("form[data-watch-changes]");
|
|
},
|
|
msg: function() {
|
|
return $("[data-watch-form-message]").data("watch-form-message");
|
|
},
|
|
hasChanged: function() {
|
|
return App.WatchFormChanges.forms().is(function() {
|
|
return $(this).serialize() !== $(this).data("watchChanges");
|
|
});
|
|
},
|
|
checkChanges: function() {
|
|
if (App.WatchFormChanges.hasChanged()) {
|
|
return confirm(App.WatchFormChanges.msg());
|
|
} else {
|
|
return true;
|
|
}
|
|
},
|
|
initialize: function() {
|
|
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(function() {
|
|
$(this).data("watchChanges", $(this).serialize());
|
|
});
|
|
}
|
|
};
|
|
}).call(this);
|