1 2/** 3 * Cookie plugin 1.0 4 * 5 * Copyright (c) 2006 Klaus Hartl (stilbuero.de) 6 * Dual licensed under the MIT and GPL licenses: 7 * http://www.opensource.org/licenses/mit-license.php 8 * http://www.gnu.org/licenses/gpl.html 9 * 10 */ 11jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}}; 12; 13(function ($) { 14 15/** 16 * Prevents consecutive form submissions of identical form values. 17 * 18 * Repetitive form submissions that would submit the identical form values are 19 * prevented, unless the form values are different from the previously 20 * submitted values. 21 * 22 * This is a simplified re-implementation of a user-agent behavior that should 23 * be natively supported by major web browsers, but at this time, only Firefox 24 * has a built-in protection. 25 * 26 * A form value-based approach ensures that the constraint is triggered for 27 * consecutive, identical form submissions only. Compared to that, a form 28 * button-based approach would (1) rely on [visible] buttons to exist where 29 * technically not required and (2) require more complex state management if 30 * there are multiple buttons in a form. 31 * 32 * This implementation is based on form-level submit events only and relies on 33 * jQuery's serialize() method to determine submitted form values. As such, the 34 * following limitations exist: 35 * 36 * - Event handlers on form buttons that preventDefault() do not receive a 37 * double-submit protection. That is deemed to be fine, since such button 38 * events typically trigger reversible client-side or server-side operations 39 * that are local to the context of a form only. 40 * - Changed values in advanced form controls, such as file inputs, are not part 41 * of the form values being compared between consecutive form submits (due to 42 * limitations of jQuery.serialize()). That is deemed to be acceptable, 43 * because if the user forgot to attach a file, then the size of HTTP payload 44 * will most likely be small enough to be fully passed to the server endpoint 45 * within (milli)seconds. If a user mistakenly attached a wrong file and is 46 * technically versed enough to cancel the form submission (and HTTP payload) 47 * in order to attach a different file, then that edge-case is not supported 48 * here. 49 * 50 * Lastly, all forms submitted via HTTP GET are idempotent by definition of HTTP 51 * standards, so excluded in this implementation. 52 */ 53Drupal.behaviors.formSingleSubmit = { 54 attach: function () { 55 function onFormSubmit (e) { 56 var $form = $(e.currentTarget); 57 var formValues = $form.serialize(); 58 var previousValues = $form.attr('data-drupal-form-submit-last'); 59 if (previousValues === formValues) { 60 e.preventDefault(); 61 } 62 else { 63 $form.attr('data-drupal-form-submit-last', formValues); 64 } 65 } 66 67 $('body').once('form-single-submit') 68 .delegate('form:not([method~="GET"])', 'submit.singleSubmit', onFormSubmit); 69 } 70}; 71 72})(jQuery); 73;
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.