content_type_extras.cancel_button.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (function ($) {
  2. Drupal.behaviors.content_type_extras_cancel_button = {
  3. attach: function(context, settings) {
  4. var cancelButton = $('form.node-form [id^="edit-cancel"]');
  5. if (cancelButton.hasClass('cte-processed')) {
  6. return;
  7. }
  8. else {
  9. var hide_warning = settings.content_type_extras.hide_warning;
  10. cancelButton.addClass('cte-processed');
  11. cancelButton.click(function() {
  12. if (hide_warning == 0) {
  13. var answer = confirm(Drupal.t('Are you sure you want to cancel and lose all changes?'));
  14. if (answer) {
  15. cteExecuteCancel();
  16. }
  17. }
  18. else {
  19. cteExecuteCancel();
  20. }
  21. });
  22. }
  23. function cteExecuteCancel() {
  24. $.QueryString = (function(a) {
  25. if (a == "") return {};
  26. var b = {};
  27. for (var i = 0; i < a.length; ++i) {
  28. var p=a[i].split('=');
  29. if (p.length != 2) continue;
  30. b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
  31. }
  32. return b;
  33. })(window.location.search.substr(1).split('&'))
  34. var baseUrl = document.location.origin;
  35. if ($.QueryString["destination"]) {
  36. var destination = $.QueryString["destination"];
  37. $(location).attr('href', baseUrl + '/' + destination);
  38. }
  39. else {
  40. if (settings.content_type_extras.cancel_location == 'static_path') {
  41. window.location = settings.content_type_extras.location_path;
  42. }
  43. else {
  44. history.go(-1);
  45. }
  46. }
  47. }
  48. }
  49. }
  50. })(jQuery);