1/* global jQuery */ 2/* global pirateFormsObject */ 3 4(function($, pf){ 5 6 $( document ).ready( function () { 7 onDocumentReady(); 8 }); 9 10 $( window ).load( function () { 11 onWindowLoad(); 12 }); 13 14 function onDocumentReady() { 15 'use strict'; 16 17 // file upload behavior. 18 $( '.pirate-forms-file-upload-button' ).on( 'click', function () { 19 var $button = $( this ); 20 $button.parent().find( 'input[type=file]' ).on( 'change', function () { 21 $button.parent().find( 'input[type=text]' ).val( $( this ).val() ).change(); 22 } ); 23 $button.parent().find( 'input[type=file]' ).focus().click(); 24 } ); 25 26 $( '.pirate-forms-file-upload-input' ).on( 'click', function () { 27 $( this ).parent().find( '.pirate-forms-file-upload-button' ).trigger( 'click' ); 28 } ); 29 $( '.pirate-forms-file-upload-input' ).on( 'focus', function () { 30 $( this ).blur(); 31 } ); 32 33 // show errors. 34 var session_var = pf.errors; 35 if( (typeof session_var !== 'undefined') && (session_var !== '') && (typeof $('#contact') !== 'undefined') && (typeof $('#contact').offset() !== 'undefined') ) { 36 $('html, body').animate({ 37 scrollTop: $('#contact').offset().top 38 }, 'slow'); 39 } 40 41 // support ajax forms. 42 $('.pirate-forms-submit-button-ajax').closest('form').submit(function(){ 43 var form = $(this); 44 var formData = new FormData(form[0]); 45 ajaxStart( form ); 46 47 // remove the dynamic containers. 48 $('div.pirate-forms-ajax').remove(); 49 50 $.ajax({ 51 url: pf.rest.submit.url, 52 data: formData, 53 type: 'POST', 54 dataType: 'json', 55 contentType: false, 56 processData: false, 57 beforeSend: function ( xhr ) { 58 xhr.setRequestHeader( 'X-WP-Nonce', pf.rest.nonce ); 59 }, 60 success: function(data){ 61 //console.log("success"); 62 //console.log(data); 63 form.find('input').val(''); 64 form.find('select').val(''); 65 form.find('input[type="checkbox"]').removeAttr('checked'); 66 form.find('input[type="radio"]').removeAttr('checked'); 67 var $time = new Date().getTime(); 68 69 if(data.message){ 70 form.closest('.pirate_forms_wrap').before('<div id="' + $time + '" class="pirate-forms-ajax pirate-forms-ajax-thankyou"></div>'); 71 $('#' + $time).append(data.message); 72 }else if(data.redirect){ 73 location.href = data.redirect; 74 } 75 }, 76 error: function(data){ 77 //console.log("no"); 78 //console.log(data); 79 if(data.responseJSON){ 80 var $time = new Date().getTime(); 81 form.closest('.pirate_forms_wrap').prepend('<div id="' + $time + '" class="pirate-forms-ajax pirate-forms-ajax-errors"></div>'); 82 $('#' + $time).append(data.responseJSON.error); 83 } 84 }, 85 complete: function(){ 86 ajaxStop( form ); 87 } 88 }); 89 90 return false; 91 }); 92 93 } 94 95 function onWindowLoad() { 96 'use strict'; 97 if ( $( '.pirate_forms_wrap' ).length ) { 98 $( '.pirate_forms_wrap' ).each( function () { 99 var formWidth = $( this ).innerWidth(); 100 var footerWidth = $( this ).find( '.pirate-forms-footer' ).innerWidth(); 101 if ( footerWidth > formWidth ) { 102 $( this ).find( '.contact_submit_wrap, .form_captcha_wrap, .pirateform_wrap_classes_spam_wrap' ).css( {'text-align' : 'left', 'display' : 'block' } ); 103 } 104 } ); 105 } 106 } 107 108 function ajaxStart(element) { 109 $(element).fadeTo( 'slow', 0.5 ); 110 } 111 112 function ajaxStop(element) { 113 $(element).fadeTo( 'fast', 1 ); 114 } 115 116})(jQuery, pirateFormsObject);
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.