sonata_admin_js_jquery.confirmExit_7.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*!
  2. * jQuery confirmExit plugin
  3. * https://github.com/dunglas/jquery.confirmExit
  4. *
  5. * Copyright 2012 Kévin Dunglas <dunglas@gmail.com>
  6. * Released under the MIT license
  7. * http://www.opensource.org/licenses/mit-license.php
  8. */
  9. (function ($) {
  10. $.fn.confirmExit = function() {
  11. $(this).attr('data-original', $(this).serialize());
  12. $(this).on('submit', function() {
  13. $(this).removeAttr('data-original');
  14. });
  15. return $(this);
  16. }
  17. $(window).on('beforeunload', function(event) {
  18. var e = event || window.event,
  19. message = window.SONATA_TRANSLATIONS.CONFIRM_EXIT,
  20. changes = false
  21. ;
  22. $('form[data-original]').each(function() {
  23. if ($(this).attr('data-original') !== $(this).serialize()) {
  24. changes = true;
  25. return;
  26. }
  27. });
  28. if (changes) {
  29. // For old IE and Firefox
  30. if (e) {
  31. e.returnValue = message;
  32. }
  33. return message;
  34. }
  35. });
  36. })(jQuery);