1jQuery( function( $ ) { 2 'use strict'; 3 4 ;( function ( document, window, index ) { 5 // feature detection for drag&drop upload 6 var isAdvancedUpload = function() { 7 var div = document.createElement( 'div' ); 8 return ( ( 'draggable' in div ) || ( 'ondragstart' in div && 'ondrop' in div ) ) && 'FormData' in window && 'FileReader' in window; 9 }(); 10 11 // applying the effect for every form 12 var forms = document.querySelectorAll( '.box' ); 13 Array.prototype.forEach.call( forms, function( form ) { 14 var input = form.querySelector( 'input[type="file"]' ), 15 label = form.querySelector( 'label' ), 16 errorMsg = form.querySelector( '.box__error span' ), 17 restart = form.querySelectorAll( '.box__restart' ), 18 droppedFiles = false, 19 showFiles = function( files ) { 20 label.textContent = files.length > 1 ? ( input.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', files.length ) : files[ 0 ].name; 21 }, 22 triggerFormSubmit = function() { 23 var event = document.createEvent( 'HTMLEvents' ); 24 event.initEvent( 'submit', true, false ); 25 form.dispatchEvent( event ); 26 }; 27 28 // letting the server side to know we are going to make an Ajax request 29 var ajaxFlag = document.createElement( 'input' ); 30 ajaxFlag.setAttribute( 'type', 'hidden' ); 31 ajaxFlag.setAttribute( 'name', 'ajax' ); 32 ajaxFlag.setAttribute( 'value', 1 ); 33 form.appendChild( ajaxFlag ); 34 35 // automatically submit the form on file select 36 input.addEventListener( 'change', function( e ) { 37 showFiles( e.target.files ); 38 }); 39 40 // drag&drop files if the feature is available 41 if( isAdvancedUpload ) { 42 form.classList.add( 'has-advanced-upload' ); // letting the CSS part to know drag&drop is supported by the browser 43 44 [ 'drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave', 'drop' ].forEach( function( event ) { 45 form.addEventListener( event, function( e ) { 46 // preventing the unwanted behaviours 47 e.preventDefault(); 48 e.stopPropagation(); 49 }); 50 }); 51 [ 'dragover', 'dragenter' ].forEach( function( event ) { 52 form.addEventListener( event, function() { 53 form.classList.add( 'is-dragover' ); 54 }); 55 }); 56 [ 'dragleave', 'dragend', 'drop' ].forEach( function( event ) { 57 form.addEventListener( event, function() { 58 form.classList.remove( 'is-dragover' ); 59 }); 60 }); 61 form.addEventListener( 'drop', function( e ) { 62 e.dataTransfer.clearData(); 63 droppedFiles = e.dataTransfer.files; // the files that were dropped 64 showFiles( droppedFiles ); 65 }); 66 } 67 68 $( 'body' ).on( 'click', '.finalized_order', function( e ) { 69 $('.popup-wrapper .loader').css('display','block'); 70 var ajaxData = new FormData( form ); 71 72 if( typeof $( 'input[name=files]' )[0].files[0] != 'undefined' ) { 73 74 ajaxData.append( 'image', $( 'input[name=files]' )[0].files[0] ); 75 if( typeof $( 'input[name=files]' )[0].files[0] == 'undefined' ){ 76 $( '.popup-wrapper .error' ).show().delay( 2000 ).slideUp(); 77 return false; 78 } 79 } else if( droppedFiles ) { 80 81 Array.prototype.forEach.call( droppedFiles, function( file ) { 82 ajaxData.append( 'image', file ); 83 }); 84 85 if( typeof file == 'undefined' ) { 86 $( '.popup-wrapper .error' ).show().delay( 2000 ).slideUp(); 87 return false; 88 } 89 } 90 91 ajaxData.append( 'action', 'kwp_yape_peru_qr_code' ); 92 93 $.ajax({
94 url:kwajaxurl.ajaxurl, 95 type:'POST', 96 processData: false, 97 contentType: false, 98 data: ajaxData, 99 success: function( response ) { 100 if( response == 'yes' ){ 101 $('.place-order button, #place_order').removeClass('yape_peru'); 102 $('.popup-wrapper').hide(); 103 $('.place-order button, #place_order').trigger('click'); 104 } else { 105 $("form.box")[0].reset(); 106 $('.popup-wrapper .error').show().html(kwp_translate.kwp_pqr_upload_images).delay(2000).slideUp(); 107 } 108 $('.popup-wrapper .loader').css('display','none'); 109 } 110 }); 111 }); 112 113 // if the form was submitted 114 form.addEventListener( 'submit', function( e ) { 115 // preventing the duplicate submissions if the current one is in progress 116 if( form.classList.contains( 'is-uploading' ) ) return false; 117 118 form.classList.add( 'is-uploading' ); 119 form.classList.remove( 'is-error' ); 120 121 if( isAdvancedUpload ) { 122 e.preventDefault(); 123 124 // gathering the form data 125 var ajaxData = new FormData( form ); 126 if( droppedFiles ) { 127 Array.prototype.forEach.call( droppedFiles, function( file ) { 128 ajaxData.append( input.getAttribute( 'name' ), file ); 129 }); 130 } 131 132 // ajax request 133 var ajax = new XMLHttpRequest(); 134 ajax.open( form.getAttribute( 'method' ), form.getAttribute( 'action' ), true ); 135 136 ajax.onload = function() { 137 form.classList.remove( 'is-uploading' ); 138 if( ajax.status >= 200 && ajax.status < 400 ) { 139 var data = JSON.parse( ajax.responseText ); 140 form.classList.add( data.success == true ? 'is-success' : 'is-error' ); 141 if( !data.success ) errorMsg.textContent = data.error; 142 } 143 else alert( 'Error. Please, contact the webmaster!' ); 144 }; 145 146 ajax.onerror = function() { 147 form.classList.remove( 'is-uploading' ); 148 alert( 'Error. Please, try again!' ); 149 }; 150 151 ajax.send( ajaxData ); 152 } 153 else // fallback Ajax solution upload for older browsers 154 { 155 var iframeName = 'uploadiframe' + new Date().getTime(), 156 iframe = document.createElement( 'iframe' ); 157 158 $iframe = $( '<iframe name="' + iframeName + '" style="display: none;"></iframe>' ); 159 160 iframe.setAttribute( 'name', iframeName ); 161 iframe.style.display = 'none'; 162 163 document.body.appendChild( iframe ); 164 form.setAttribute( 'target', iframeName ); 165 166 iframe.addEventListener( 'load', function() { 167 var data = JSON.parse( iframe.contentDocument.body.innerHTML ); 168 form.classList.remove( 'is-uploading' ) 169 form.classList.add( data.success == true ? 'is-success' : 'is-error' ) 170 form.removeAttribute( 'target' ); 171 if( !data.success ) errorMsg.textContent = data.error; 172 iframe.parentNode.removeChild( iframe ); 173 }); 174 } 175 }); 176 177 // restart the form if has a state of error/success 178 Array.prototype.forEach.call( restart, function( entry ) { 179 entry.addEventListener( 'click', function( e ) { 180 e.preventDefault(); 181 form.classList.remove( 'is-error', 'is-success' ); 182 input.click(); 183 }); 184 }); 185 186 // Firefox focus bug fix for file input 187 input.addEventListener( 'focus', function(){ input.classList.add( 'has-focus' ); }); 188 input.addEventListener( 'blur', function(){ input.classList.remove( 'has-focus' ); }); 189 190 }); 191 }( document, window, 0 ));
192 193 $( document ).ajaxComplete( function( event, request, options ) { 194 var selectedValue = $( 'form.checkout .wc_payment_methods input[name^="payment_method"]:checked' ).val(); 195 if ( selectedValue == 'wocommerce_yape_peru' ) { 196 $( '.place-order button, #place_order' ).addClass( 'yape_peru' ); 197 } 198 }); 199 200 $( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() { 201 var choosenPaymentMethod = $( 'input[name^="payment_method"]:checked' ).val(); 202 if( choosenPaymentMethod == 'wocommerce_yape_peru' ){ 203 $( '.place-order button, #place_order' ).addClass( 'yape_peru' ); 204 } else { 205 $( '.place-order button, #place_order' ).removeClass( 'yape_peru' ); 206 } 207 }); 208 209 $( 'body' ).on( 'click', '.yape_peru', function(e) { 210 e.preventDefault(); 211 $( '.popup-wrapper' ).show(); 212 $( '.first-step .woocommerce-Price-amount' ).remove(); 213 214 var priceLimit = $( '.first-step' ).data( 'price-limit' ); 215 if( priceLimit ) { 216 $( '.first-step .popup-price-wrapper' ).append( $( '.order-total .woocommerce-Price-amount' ).first().clone() ); 217 $( '.first-step .popup-price-wrapper .woocommerce-Price-currencySymbol' ).remove(); 218 var getPrice = $( '.first-step .popup-price-wrapper' ).text(); 219 if( getPrice ) { 220 if( parseFloat( priceLimit ) < parseFloat( getPrice ) && parseFloat( priceLimit ) != parseFloat( getPrice ) ) { 221 $( '.first-step .message-limit-amount' ).show(); 222 $( '.first-step .btn-continue' ).remove(); 223 } else { 224 $( '.first-step .message-limit-amount' ).hide(); 225 $( '.first-step .btn-continue' ).remove(); 226 $( '.first-step' ).append( '<button class="btn-continue bt
226n_submit">'+kwp_translate.kwp_pqr_btn_continue+'</button>' ); 227 } 228 } 229 } else { 230 $( '.first-step .btn-continue' ).remove(); 231 $( '.first-step' ).append( '<button class="btn-continue btn_submit">'+kwp_translate.kwp_pqr_btn_continue+'</button>' ); 232 } 233 $( '.first-step .price' ).append( $( '.order-total .woocommerce-Price-amount' ).first().clone() ); 234 }); 235 236 $( '.popupCloseButton' ).click(function(){ 237 $( '.second-step' ).css( 'display','none' ); 238 $( '.popup-wrapper .error' ).css( 'display','none' ); 239 $( '.first-step' ).css( 'display','block' ); 240 $( '.popup-wrapper' ).hide(); 241 }); 242 243 $( '.first-step' ).on( 'click', '.btn-continue', function (){ 244 $( '.second-step' ).show(); 245 $( '.first-step' ).hide(); 246 }); 247 248 $( '.box__button' ).click(function(e){ 249 e.preventDefault(); 250 $( '.box__file' ).trigger( 'click' ); 251 }); 252 253});
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.