1/** 2 * @file 3 * Stops page from changing when user is posting. 4 */ 5 6(function($, Drupal, drupalSettings) { 7 Drupal.node_edit_protection = {}; 8 var click = false; 9 // Allow Submit/Edit button. 10 var edit = false; 11 // Dirty form flag. 12 Drupal.behaviors.nodeEditProtection = { 13 /** 14 * @param contentType 15 * @param context 16 */ 17 protectForm: function(contentType, context) { 18 19 // If they leave an input field, assume they changed it. 20 $("." + contentType + "-form :input", context).each(function() { 21 $(this).blur(function() { 22 edit = true; 23 }); 24 }); 25 26 // Let all form submit buttons through. 27 $("." + contentType + "-form input[type='submit'], ." + contentType + "-form button[type='submit']", context).each(function() { 28 $(this).addClass('node-edit-protection-processed'); 29 $(this).click(function() { 30 click = true; 31 }); 32 }); 33 34 // Catch all links and buttons EXCEPT for "#" links. 35 $("a, button, input[type='submit']:not(.node-edit-protection-processed), button[type='submit']:not(.node-edit-protection-processed)", context) 36 .each(function() { 37 $(this).click(function() { 38 // Return when a "#" link is clicked so as to skip the 39 // window.onbeforeunload function. 40 if (edit && $(this).attr("href") != "#") { 41 return 0; 42 } 43 }); 44 }); 45 46 // Handle backbutton, exit etc. 47 window.onbeforeunload = function() { 48 // Add CKEditor support. 49 if (typeof (CKEDITOR) != 'undefined' && typeof (CKEDITOR.instances) != 'undefined') { 50 for (var i in CKEDITOR.instances) { 51 if (CKEDITOR.instances[i].checkDirty()) { 52 edit = true; 53 break; 54 } 55 } 56 } 57 if (edit && !click) { 58 click = false; 59 return (Drupal.t("Les modifications que vous avez apportées ne seront peut-être pas enregistrées.")); 60 } 61 } 62 }, 63 attach : function(context) { 64 this.protectForm('node', context); 65 } 66 }; 67})(jQuery, Drupal, drupalSettings);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.