jQuery.fn.shake=function(interval,distance,times){interval=typeof interval=="undefined"?100:interval;distance=typeof distance=="undefined"?10:distance;times=typeof times=="undefined"?3:times;var jTarget=$(this);jTarget.css('position','relative');for(var iter=0;iter<(times+1);iter++){jTarget.animate({left:((iter%2==0?distance:distance*-1))},interval);} return jTarget.animate({left:0},interval);} $(document).on('click','.showdetails',function(){$('.hide').slideDown();});$(document).on('click','.add',function(){if($(this).attr('data-type')=='tyre'){$('.'+$(this).attr('data-add')).val('Tyre '+$('.issue').val()+' - '+$('.size').val()+' - '+$('.position').val());} if($(this).attr('data-type')=='taillift'){$('.'+$(this).attr('data-add')).val('Tail lift '+$('.issue').val()+' - '+$('.make').val()+' - '+$('.model').val()+' - '+$('.serial').val());} $('.'+$(this).attr('data-add')).parent().before('
We\'ve added the details you entered - add more info if required below
');});$(document).on('focus','.error',function(){$(this).removeClass('error');});$(document).on('click','.register',function(){var exit=false;$('input').each(function(index,data){if($(this).val()==''){$(this).addClass('error');$(this).shake();exit=true;return false;}});if(exit)return false;$('.form-signin').slideUp(function(){$.post('/widget.doregister.php',{fullname:$('.fullname').val(),emailaddress:$('.emailaddress').val(),mobile:$('.mobile').val(),code:$('.code').val()},function(e){$('.register_result').html(e);});});});if($('#splash').length){setTimeout(function(){$('#splash').fadeOut(function(){$('.hide').fadeIn();});},5300);}else{$('.hide').fadeIn();} $(document).on('click','.signin',function(){$.post('/widget.dologin.php',{username:$('.username').val(),password:$('.password').val()},function(data,statusText,xhr){if(data=='200 OK'){window.location='/app/';}else{if($('.error').length){$('.error').remove();} $('.form-signin').before('
Sorry, but that didn\'t work.
');}});});const compressImage=async(file,{quality=1,type=file.type})=>{const imageBitmap=await createImageBitmap(file);const canvas=document.createElement('canvas');canvas.width=imageBitmap.width;canvas.height=imageBitmap.height;const ctx=canvas.getContext('2d');ctx.drawImage(imageBitmap,0,0);const blob=await new Promise((resolve)=>canvas.toBlob(resolve,type,quality));return new File([blob],file.name,{type:blob.type,});};const input=document.querySelector('.my-image-field');input?.addEventListener('change',async(e)=>{const{files}=e.target;if(!files.length)return;text='photos were';if(files.length=='1'){text="photo was";} $('.filetext').html(' '+files.length+' '+text+' added');$('.file').toggleClass('btn-info btn-success');const dataTransfer=new DataTransfer();for(const file of files){if(!file.type.startsWith('image')){dataTransfer.items.add(file);continue;} const compressedFile=await compressImage(file,{quality:0.5,type:'image/jpeg',});dataTransfer.items.add(compressedFile);} e.target.files=dataTransfer.files;});if($('#osm-map').length){if(navigator.geolocation){navigator.geolocation.getCurrentPosition(showPosition,error);}else{$('#osm-map').remove();}} function error(){$('#osm-map').remove();$('.location').parent().before('
We were unable to use your device to get a nearby address, please enter your full location below.
');} function showPosition(position){var element=document.getElementById('osm-map');if(element){element.style='height:300px;';var map=L.map(element);L.tileLayer('//{s}.tile.osm.org/{z}/{x}/{y}.png',{attribution:'© OpenStreetMap contributors'}).addTo(map);var target=L.latLng(position.coords.latitude,position.coords.longitude);$.get('https://api.getAddress.io/nearest/'+position.coords.latitude+'/'+position.coords.longitude+'?api-key=nRl4aDKTS0ubH274hIr6Hg22193',function(data){var json=data;$('.location').val(json.suggestions[0].address);$.get('https://api.getAddress.io/get/'+json.suggestions[0].id+'?api-key=nRl4aDKTS0ubH274hIr6Hg22193',function(data2){var json2=data2;$('.location').val($('.location').val()+', '+json2.postcode);$('.postcode').val(json2.postcode);$('.town').val(json2.town_or_city);$('.location').parent().before('
We\'ve used your device to find a nearby address, edit it below if it\'s not correct.
');});});map.setView(target,17);L.marker(target).addTo(map);}} var typingTimer;var doneTypingInterval=1000;$(document).on('keyup','.fault',function(){clearTimeout(typingTimer);if($(this).val()){typingTimer=setTimeout(doneTyping(),doneTypingInterval);}});function doneTyping(){content=$('.fault').val();$.post('/widget.checkFault.php',{fault:content},function(e){if(e){if(!$.trim($('.flexiModal .modal-content').text())){$('.flexiModal .modal-content').html(e);$('.flexiModal').modal('show');}}});} $(document).on('click','.showdetails',function(){$('.hide').slideDown();});jQuery.fn.shake=function(interval,distance,times){interval=typeof interval=="undefined"?100:interval;distance=typeof distance=="undefined"?10:distance;times=typeof times=="undefined"?3:times;var jTarget=$(this);jTarget.css('position','relative');for(var iter=0;iter<(times+1);iter++){jTarget.animate({left:((iter%2==0?distance:distance*-1))},interval);} return jTarget.animate({left:0},interval);} $(document).on('click','.showdetails',function(){$('.hide').slideDown();});$(document).on('focus','.error',function(){$(this).removeClass('error');});$(document).on('click','.newbreakdown',function(){var exit=false;$('input.check').each(function(index,data){if($(this).val()==''){$(this).addClass('error');$(this).shake();exit=true;return false;}});if(exit)return false;$('.form-signin').slideUp(function(){$.post('/widget.reportbreakdown.php',{fullname:$('.fullname').val(),emailaddress:$('.emailaddress').val(),mobile:$('.mobile').val(),code:$('.code').val(),vehicleID:$('.vehicleID').val(),locationPostcode:$('.postcode').val(),locationSummary:$('.town').val(),trailerNumber:$('.altVehicleID').val(),fault:$('.fault').val(),location:$('.location').val()},function(e){json=$.parseJSON(e);$('.register_result').html(json.success);if(json.success!=''){var data=new FormData();for(var i=0;i<$('input[type=file]').get(0).files.length;++i){data.append('file[]',$('input[type=file]').get(0).files[i]);} data.append('jobid',json.jobid);$.ajax({type:"POST",url:"/widget.uploadPhotos.php",data:data,cache:false,contentType:false,processData:false,success:function(data){}});}});});});