{I" class:ETI"BundledAsset;FI"logical_path;TI"spotlight/form_observer.js;FI" pathname;TI"[/Users/cabeer/Projects/sul/spotlight/app/assets/javascripts/spotlight/form_observer.js;FI"content_type;TI"application/javascript;TI" mtime;Tl+;ØFTI" length;TiÓI" digest;TI"%c356cb95df6ee2e72c2dcf97b9e6c790;FI" source;TI"ÓSpotlight.onLoad(function() { serializeObservedForms(observedForms()); }); // All the observed forms function observedForms(){ return $('[data-form-observer]'); } // Serialize all observed forms on the page function serializeObservedForms(forms){ forms.each(function(){ serializeFormStatus($(this)); unbindObservedFormSubmit(); }); } // Unbind observing form on submit (which we have to do because of turbolinks) function unbindObservedFormSubmit(){ observedForms().each(function(){ $(this).on("submit", function(){ $(this).data("being-submitted", true); }); }); } // Store form serialization in data attribute function serializeFormStatus(form){ form.data("serialized-form", formSerialization(form)); } // Do custom serialization of the sir-trevor form data function formSerialization(form){ var content_editable = []; var i=0; $("[contenteditable='true']", form).each(function(){ content_editable.push("&contenteditable_" + i + "=" + $(this).text()); }); return form.serialize() + content_editable.join(); } // Get the stored serialized form status function serializedFormStatus(form){ return form.data("serialized-form"); } // Check all observed forms on page for status change function observedFormsStatusHasChanged(){ var unsaved_changes = false; observedForms().each(function(){ if ( !$(this).data("being-submitted") ) { if (serializedFormStatus($(this)) != formSerialization($(this))) { unsaved_changes = true; } } }); return unsaved_changes; } // Compare stored and current form serializations // to determine if the form has changed before // unload and before any turbolinks change event $(window).on('beforeunload page:before-change', function(event) { if ( observedFormsStatusHasChanged() ) { var message = "You have unsaved changes. Are you sure you want to leave this page?"; if ( event.type == "beforeunload" ) { return message; }else{ return confirm(message) } } }); ;TI"required_assets_digest;TI"%20b65ea15c5faf015cee690ea9956f60;FI" _version;TI"%64e62ddc273c2f5847f30d698ca14b67;F