1$(document).ready(function () { 2 3 var modalTriggerBts = $('a[data-type="cd-modal-trigger"]'), 4 coverLayer = $('.cd-cover-layer'); 5 6 /* 7 convert a cubic bezier value to a custom mina easing 8 http://stackoverflow.com/questions/25265197/how-to-convert-a-cubic-bezier-value-to-a-custom-mina-easing-snap-svg 9 */ 10 var duration = 600, 11 epsilon = (1000 / 60 / duration) / 4, 12 firstCustomMinaAnimation = bezier(.63, .35, .48, .92, epsilon); 13 14 modalTriggerBts.each(function () { 15 initModal($(this)); 16 }); 17 18 function initModal(modalTrigger) { 19 var modalTriggerId = modalTrigger.attr('id'), 20 modal = $('.cd-modal[data-modal="' + modalTriggerId + '"]'), 21 svgCoverLayer = modal.children('.cd-svg-bg'), 22 paths = svgCoverLayer.find('path'), 23 pathsArray = []; 24 //store Snap objects 25 pathsArray[0] = Snap('#' + paths.eq(0).attr('id')), 26 pathsArray[1] = Snap('#' + paths.eq(1).attr('id')), 27 pathsArray[2] = Snap('#' + paths.eq(2).attr('id')); 28 29 //store path 'd' attribute values 30 var pathSteps = []; 31 pathSteps[0] = svgCoverLayer.data('step1'); 32 pathSteps[1] = svgCoverLayer.data('step2'); 33 pathSteps[2] = svgCoverLayer.data('step3'); 34 pathSteps[3] = svgCoverLayer.data('step4'); 35 pathSteps[4] = svgCoverLayer.data('step5'); 36 pathSteps[5] = svgCoverLayer.data('step6'); 37 38 //open modal window 39 modalTrigger.on('click', function (event) { 40 event.preventDefault(); 41 modal.addClass('modal-is-visible'); 42 coverLayer.addClass('modal-is-visible'); 43 animateModal(pathsArray, pathSteps, duration, 'open'); 44 }); 45 46 //close modal window 47 modal.on('click', '.modal-close', function (event) { 48 event.preventDefault(); 49 modal.removeClass('modal-is-visible'); 50 coverLayer.removeClass('modal-is-visible'); 51 animateModal(pathsArray, pathSteps, duration, 'close'); 52 }); 53 } 54 55 function animateModal(paths, pathSteps, duration, animationType) { 56 var path1 = (animationType == 'open') ? pathSteps[1] : pathSteps[0], 57 path2 = (animationType == 'open') ? pathSteps[3] : pathSteps[2], 58 path3 = (animationType == 'open') ? pathSteps[5] : pathSteps[4]; 59 paths[0].animate({'d': path1}, duration, firstCustomMinaAnimation); 60 paths[1].animate({'d': path2}, duration, firstCustomMinaAnimation); 61 paths[2].animate({'d': path3}, duration, firstCustomMinaAnimation); 62 } 63 64 function bezier(x1, y1, x2, y2, epsilon) { 65 //https://github.com/arian/cubic-bezier 66 var curveX = function (t) { 67 var v = 1 - t; 68 return 3 * v * v * t * x1 + 3 * v * t * t * x2 + t * t * t; 69 }; 70 71 var curveY = function (t) { 72 var v = 1 - t; 73 return 3 * v * v * t * y1 + 3 * v * t * t * y2 + t * t * t; 74 }; 75 76 var derivativeCurveX = function (t) { 77 var v = 1 - t; 78 return 3 * (2 * (t - 1) * t + v * v) * x1 + 3 * (-t * t * t + 2 * v * t) * x2; 79 }; 80 81 return function (t) { 82 83 var x = t, t0, t1, t2, x2, d2, i; 84 85 // First try a few iterations of Newton's method -- normally very fast. 86 for (t2 = x, i = 0; i < 8; i++) { 87 x2 = curveX(t2) - x; 88 if (Math.abs(x2) < epsilon) return curveY(t2); 89 d2 = derivativeCurveX(t2); 90 if (Math.abs(d2) < 1e-6) break; 91 t2 = t2 - x2 / d2; 92 } 93 94 t0 = 0, t1 = 1, t2 = x; 95 96 if (t2 < t0) return curveY(t0); 97 if (t2 > t1) return curveY(t1); 98 99 // Fallback to the bisection method for reliability. 100 while (t0 < t1) { 101 x2 = curveX(t2); 102 if (Math.abs(x2 - x) < epsilon) return curveY(t2); 103 if (x > x2) t0 = t2; 104 else t1 = t2; 105 t2 = (t1 - t0) * .5 + t0; 106 } 107 108 // Failure 109 return curveY(t2); 110 111 }; 112 }; 113 114 115 // Codyhouse contact form 116 if ($('.floating-labels').length > 0) floatLabels(); 117 118 function floatLabels() { 119 var inputFields = $('.floating-labels .cd-label').next(); 120 inputFields.each(function () { 121 var singleInput = $(this); 122 //check if user is filling one of the form fields 123 checkVal(singleInput); 124 singleInput.on('change keyup', function () { 125 checkVal(singleInput); 126 }); 127 }); 128 } 129 130 function checkVal(inputField) { 131 (inputField.val() == '') ? inputField.prev('.cd-label').removeClass('float') : inputField.prev('.cd-label').addClass('float'); 132 } 133 134 $('input[data-rule=number]').keyup(function () { 135 // store current positions in variables 136 var start = this.selectionStart, 137 end = this.selectionEnd; 138 139 var val = parseInt($(this).val()); 140 $(this).val(isNaN(val) ? '' : val); 141 142 // restore position from variable 143 this.setSelectionRange(start, end); 144 }); 145 146 function feedback(data) { 147 if (typeof(data) === 'object') 148 new PNotify({ 149 title: data.title, 150 text: data.message, 151 type: data.type 152 }); 153 } 154 155 var form = $('.contact-form'); 156 157 // get request min price 158 var request_min_price = form.find('input[name=request_min_price]'); 159 request_min_price = request_min_price.length ? parseInt(request_min_price.val()) : 0; 160 var currency = form.find('input[name=offerCurrency]').val(); 161 if (isNaN(request_min_price)) { 162 request_min_price = 0; 163 } 164
165 //-- 5.12 validate and submit contact us form 166 form.validate({ 167 rules: { 168 phoneRequest: { 169 // required: true, 170 email: true 171 }, 172 nameRequest: { 173 // required: true 174 }, 175 textRequest: { 176 required: { 177 param: false, 178 depends: function () { 179 return $('input[name=offerRequest]').val() > 0; 180 } 181 } 182 }, 183 telRequest: { 184 pattern: '^\\d{10,13}$', 185 }, 186 offerRequest: { 187 min: { 188 param: request_min_price, 189 depends: function () { 190 return request_min_price > 0; 191 } 192 }, 193 required: { 194 param: true, 195 depends: function () { 196 return request_min_price > 0; 197 } 198 } 199 } 200 }, 201 messages: { 202 phoneRequest: { 203 // required: langVars.messages.phoneRequest.required, 204 email: langVars.messages.phoneRequest.email 205 }, 206 nameRequest: { 207 // required: langVars.messages.nameRequest.required 208 }, 209 textRequest: { 210 required: langVars.messages.textRequest.required 211 }, 212 telRequest: { 213 pattern: langVars.messages.telRequest.pattern 214 }, 215 offerRequest: { 216 min: langVars.messages.offerRequest.min + request_min_price + currency, 217 required: langVars.messages.offerRequest.required 218 } 219 }, 220 // messages: ruMessages, 221 submitHandler: function () { 222 //-- show loading 223 $('.contact-notif').show().html('<label class="loading-contact">' + langVars.notifications.pleaseWait + '</label>'); 224 $('.loading-contact').fadeIn('fast'); 225 226 $.ajax({ 227 url: form.attr('action'), 228 jsonp: "cb", 229 dataType: "jsonp", 230 data: form.serializeArray(), 231 timeout: 60000, 232 error: function () { 233 $('.loading-contact').fadeOut('fast', function () { 234 $('.contact-notif').html('<label class="contact-notif-error">' + langVars.notifications.error + '.</label>'); 235 }); 236 }, 237 success: function (data) { 238 239 feedback(data); 240 241 var isSuccess = data.type.toUpperCase() !== 'ERROR'; 242 //reset form 243 if (isSuccess) { 244 var clear_def_price = false; 245 form.trigger('reset'); 246 var inputs = $('input[name=offerRequest]'); 247 if (inputs.length) { 248 if (inputs.val()) { 249 inputs.prev().addClass('float'); 250 } 251 if (clear_def_price) { 252 inputs.val(''); 253 } 254 } 255 } 256 257 //-- hide loading 258 $('.loading-contact').fadeOut('fast', function () { 259 //-- show notif 260 $('.contact-notif').html(isSuccess 261 ? '<label class="contact-notif-success">' + langVars.notifications.thanks + '</label>' 262 : '<label class="contact-notif-error">' + langVars.notifications.error + '.</label>' 263 ); 264 $('.contact-notif-success').fadeIn('fast').delay(5000).fadeOut('fast', function () { 265 $(this).remove(); 266 $('.loading-contact').remove(); 267 }); 268 }); 269 } 270 }); 271 272 return false;
273 } 274 }); 275//-- end validate and submit contact us form 276});
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.