1var CONTACTS_FRONTEND_AJAX = '/ajax/intouch/contacts'; 2 3mwListForm = function ($form) { 4 5 var $class = { 6 7// ---- PROPERTIES ---- 8 9 ajax : mwAjax, // Ajax constructor 10 11// ---- METHODS ---- 12 13 state : function ($el, $state) { 14 15 // State can be loading/idle 16 17 if ( $state ) { 18 19 $el.find('.mwFormSubmit').animate({ opacity: 0 }, 300); 20 $el.find('.mwFormLoader').fadeIn(300); 21 22 // Classic compatable 23 $el.find('.mwFormSubmitRow .mwInput.Button').fadeOut(300); 24 $el.find('.mwFormSubmitRow .mwInput.Loader').fadeIn(300); 25 26 } else { //If loader 27 28 $el.find('.mwFormSubmit').animate({ opacity: 1 }, 300); 29 $el.find('.mwFormLoader').fadeOut(300); 30 31 // Classic compatable 32 $el.find('.mwFormSubmitRow .mwInput.Button').fadeIn(300); 33 $el.find('.mwFormSubmitRow .mwInput.Loader').fadeOut(300); 34 35 } //IF idle 36 37 }, //FUNC state 38 39 submit : function () { 40 41 var $this = this; 42 43 44 // Getting form elements 45 var $el = _jq($form); 46 var $sn = $el.attr('id'); 47 var $status = $el.find('.mwFormStatus'); 48 49 // Cleaning status 50 $status.html(''); 51 52 // Cleaning status and validations 53 $status.html(''); 54 setValidations($el, {}); 55 56 // Setting loading state 57 $this.state($el, true); 58 59 // Getting form url 60 var $url = $el.attr('action') || CONTACTS_FRONTEND_AJAX + '/submit'; 61 62 $this.ajax($url, $el, false) 63 64 .success( function ($data) { 65 66 // Not hiding loader if redirecting or reloading 67 // Othewise hiding 68 69 if ( $data.redirect ) 70 window.location.href = $data.redirect; 71 else 72 $this.state($el, false); 73 74 }) //FUNC mwAjax.success 75 76 .error( function ($data) { 77 78 // Error causes idling 79 $this.state($el, false); 80 81 // Setting status if error returned 82 $status.html( mwError($data.status.text) ); 83 84 // Lasy support for recaptcha 85 // Need to reset captcha on errors 86 //ToDo: Inputs based customization 87 try { 88 89 if ( typeof(grecaptcha) !== UNDEFINED ) 90 grecaptcha.reset(); 91 92 } catch ( $msg ) { 93 94 } //TRY 95 96 // Each validation message should be captured 97 if ( $data._validations && $data._validations[$sn] ) { 98 99 // Manually processing messages yet. 100 // ToDo: Implement erorrs handling API for frontend 101 102 // Looping through each failed field and each message for that field 103 // All validatinos are indexed by form ID 104 for ( var $field in $data._validations[$sn] ) { 105 for ( var $msg in $data._validations[$sn][$field] ) { 106 107 // Appending each message to status area 108 $status.append( mwError($data._validations[$sn][$field][$msg]) ); 109 110 } //FOR each message for field 111 } //FOR each fail field 112 113 } //IF validations come 114 115 }) //FUNC mwAjax.error.callback 116 117 .stop( function () { 118 119 // ---- Scrolling to form top ---- 120 121 // Giving some space above form (for titles/headers) 122 var $delta = 100; 123 124 // Floating height can be specified in page template 125 var $f = jQuery('DIV[data-floatHeight]'); 126 127 if ( $f.length ) { 128 129 $delta += $f.attr('data-floatHeight')*1; 130 131 } else { //IF height specified 132 133 // If not specified directly - trying to get some common 134 var $f = jQuery('.menuWrap'); 135 if ( $f.css('position') == 'fixed' ) 136 $delta += $f.height(); 137 138 } //If nothing found 139 140 // Animating to show errors 141 jQuery('html, body').animate({ 142 scrollTop: jQuery('#' + $sn).offset().top - $delta 143 }, 300); //jQuery.animate.options 144 145 }) //FUNC mwAjax.stop 146 147 .go(); 148 149 return false; 150 151 } //FUNC submit 152 153// ---- END ---- 154 155 } //CLASS mwListForm 156 157 return $class; 158} //CONSTRUCTOR mwListForm
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.