1var signatures = []; 2 3(function($) { 4 5 'use strict'; 6 7 // Main function to initialize signature fields 8 $.fn.wpcf7InitSignatures = function() { 9 10 signatures = []; 11 12 return this.each(function(i, form){ 13 14 $(form).find('.wpcf7-form-control-signature-global-wrap').each(function(j, wrapper){ 15 var $canvas = $(wrapper).find('canvas'), 16 $clear = $(wrapper).find('input[type=button]'), 17 id = $(wrapper).data('field-id'), 18 input = document.getElementById("wpcf7_input_" + id), 19 canvas = $canvas[0]; 20 21 sigFieldRatio(canvas); 22 23 // Options 24 var options = []; 25 options['penColor'] = $canvas.data("color"); 26 options['backgroundColor'] = $canvas.data("background"); 27 28 // Extra options 29 var extras = $canvas.data("extras"); 30 if (extras != null && typeof(extras) != 'undefined'){ 31 for (var key in extras) { 32 if (extras.hasOwnProperty(key)) { 33 options[key] = extras[key]; 34 } 35 } 36 } 37 38 // Canvas init 39 var signature = new SignaturePad(canvas, options); 40 41 // Push field elements into global variable 42 var sigObj = new Wpcf7Signature(signature, canvas, input, options); 43 signatures.push(sigObj); 44 45 sigObj.setValue(); 46 47 // Clear event listener 48 $clear.on("click", function(){ 49 sigObj.clear(); 50 }); 51 52 // Trigger change event on input field when signature changed 53 $clear.on("mouseup", function(){ 54 sigObj.change(); 55 }); 56 57 // Submit Event Listener 58 $(form).on('submit', function(){ 59 sigObj.beforeSubmit(); 60 }); 61 62 }); 63 64 }); 65 } 66 67 // Resize canvas fields 68 $.fn.wpcf7ResizeSignatures = function(){ 69 70 $(".wpcf7-form-control-signature-input-wrap").each(function(i){ 71 signatures[i].resize(); 72 }); 73 74 return this; 75 } 76 77 // Globally clear fields (on form submit for exemple) 78 $.fn.wpcf7ClearSignatures = function(){ 79 80 $(".wpcf7-form-control-signature-input-wrap").each(function(i){ 81 signatures[i].clear(); 82 }); 83 84 return this; 85 } 86 87 $(function() { 88 $('div.wpcf7 > form').wpcf7InitSignatures(); 89 }); 90 91 // CF7 v4.9 callbacks 92 $(document).on( 'wpcf7mailsent', function( event ) { 93 94 // Clearing signatures 95 $('div.wpcf7 > form').wpcf7ClearSignatures(); 96 }); 97 98})(jQuery); 99 100 101var Wpcf7Signature = (function() { 102 var signature, canvas, input, options; 103 104 function Wpcf7Signature(signature, canvas, input, options){ 105 this.signature = signature; 106 this.canvas = canvas; 107 this.input = input; 108 this.options = options; 109 } 110 111 // Set Canvas value if needed 112 Wpcf7Signature.prototype.setValue = function() { 113 114 if(this.input.value != ''){ 115 this.signature.fromDataURL(this.input.value); 116 } 117 } 118 119 // Trigger Change event 120 Wpcf7Signature.prototype.change = function() { 121 122 this.beforeSubmit(); 123 124 if (document.createEvent) { 125 var changeEvent = document.createEvent("HTMLEvents"); 126 changeEvent.initEvent("change", false, true); 127 this.input.dispatchEvent(changeEvent); 128 } else { 129 this.input.fireEvent("onchange"); 130 } 131 } 132 133 // Copy sig value to input field 134 Wpcf7Signature.prototype.beforeSubmit = function() { 135 if (!this.signature.isEmpty()){ 136 this.input.value = this.signature.toDataURL(); 137 }else{ 138 this.input.value = ""; 139 } 140 }; 141 142 // Clear a single signature field 143 Wpcf7Signature.prototype.clear = function() { 144 this.signature.clear(); 145 this.input.value = ""; 146 }; 147 148 // Dealing with window size and device ratio 149 Wpcf7Signature.prototype.resize = function(clear) { 150 sigFieldRatio(this.canvas); 151 152 if (clear){ 153 this.sigFieldClear(); 154 } 155 }; 156 157 return Wpcf7Signature; 158})(); 159 160// Set field ratio 161function sigFieldRatio( canvas ) { 162 163 var ratio = Math.max(window.devicePixelRatio || 1, 1); 164 canvas.width = canvas.offsetWidth * ratio; 165 canvas.height = canvas.offsetHeight * ratio; 166 canvas.getContext("2d").scale(ratio, ratio); 167};
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.