harryfear

webuy

Dec 11th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.32 KB | None | 0 0
  1. <style>
  2. /* CSS variables for our form */
  3. #fluentform_1 {
  4. --yellow-plate: #FFFF00; /* Yellow background on field */
  5. --message-area-background: #f9f9f9;
  6. --message-area-border: #CED4DA;
  7. }
  8.  
  9. /* Import a number plate-like font */
  10. @import url('https://fonts.googleapis.com/css2?family=Inconsolata:wght@800&display=swap');
  11.  
  12. /* By default hide the Fluentform container class */
  13. #fluentform_1 .dvla_deets {
  14. display:none;
  15. background: var(--message-area-background);
  16. padding: 20px 20px 20px 34px;
  17. border: 1px solid var(--message-area-border);
  18. border-radius: 3px;
  19. }
  20. #fluentform_1 input[name="reg_input"] {
  21. text-transform: uppercase; /* Make the text uppercase in the */
  22. font-weight:bold; /* Embolden the text */
  23. background:var(--yellow-plate);
  24. font-family: 'Inconsolata', monospace;
  25. font-size: 30px;
  26. }
  27. #fluentform_1 .hidden { /* The hidden RAW data form field */
  28. visibility:hidden; /* Hide, but allow it to be updated programatically like it's a text area field still */
  29. position:absolute; /* Remove its dimensions */
  30. }
  31. </style>
  32.  
  33. <script>
  34. // Javascript variables
  35. $keyWaitTimeMiliSeconds = 1000; // How long to wait after the input field changes before actioning (ms)
  36. $interpretDVLAKeys = {
  37.  
  38. /* Car data values listed here will be printed on frontend using the translation value provided */
  39. // The front end will print out in the order of the below values
  40. // Commented out lines won't show on the frontend
  41.  
  42. //registrationNumber: "Car Registration Number",
  43. colour: "Colour",
  44. make: "Make",
  45. yearOfManufacture: "Year of Manufacture",
  46. engineCapacity: "Engine Capacity",
  47. fuelType: "Fuel Type",
  48. motStatus: "MOT Status",
  49. //motExpiryDate: "MOT Expiry Date",
  50. //monthOfFirstRegistration: "First Registration Date",
  51. //dateOfLastV5CIssued: "Last V5 Issued Date",
  52. //taxDueDate: "Road Tax Due Date",
  53. //taxStatus: "Road Tax Status",
  54. //co2Emissions: "CO2 Emissions (g/km)"
  55.  
  56. }; // https://stackoverflow.com/a/1168814/1625909
  57.  
  58. // Import our PHP variables to the client side
  59. var fluentform_id = "1";
  60. var input_box_name = "reg_input";
  61. var message_container_class = "dvla_deets";
  62. var hidden_field = "hidden";
  63. var DVLA_api_key = "oGvaZPoDZm5h3qg04Rhfn7H0hvoCSMZe3kAA8giH";
  64.  
  65. jQuery(document).ready(function( $ ) {
  66.  
  67. //console.log('Script running');
  68.  
  69. var input_field = $('#fluentform_'+fluentform_id+' input[name="'+input_box_name+'"]');
  70. var message_space = $('#fluentform_'+fluentform_id+' .'+message_container_class);
  71.  
  72. // Wait for the user to finish typing https://schier.co/blog/wait-for-user-to-stop-typing-using-javascript
  73. let timeout = null;
  74. let reg = "";
  75. $(input_field).on("change paste keyup", function (e) {
  76. clearTimeout(timeout);
  77. timeout = setTimeout(function () {
  78.  
  79. //console.log('Input Value:', $(input_field).val());
  80.  
  81. $reg_sanitize = $(input_field).val(); // Clean up the input text
  82. $reg_sanitize = $reg_sanitize.replace(/ /g,''); // Remove spaces https://stackoverflow.com/a/6623263/1625909
  83. $reg_sanitize = $reg_sanitize.replace(/[^a-zA-Z0-9 _]/g, ''); // Keep only A-Z/0-9 https://stackoverflow.com/a/45960810/1625909
  84. $reg_sanitize = $reg_sanitize.toUpperCase(); // Make uppercase
  85.  
  86. // To minimize requests, we'll check if we've already just had this reg before proceeding
  87. if (reg === $reg_sanitize) {
  88. // Old value
  89. //console.log('Old value');
  90. } else {
  91. // New value to poll for
  92. //console.log('New value');
  93. if ($reg_sanitize.trim()) {
  94.  
  95. //console.log('Sanitized Input Value:', $reg_sanitize);
  96.  
  97. // Set it, if not blank ^
  98. reg = $reg_sanitize;
  99.  
  100. // Reset the message area and hidden field
  101. $(message_space).empty();
  102. $('input[name="'+hidden_field+'"]').val('');
  103.  
  104. // Begin our AJAX work
  105. //var settings =
  106.  
  107. $.ajax({
  108. "async": true,
  109. //"url": "https://cors-anywhere.herokuapp.com/https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles",
  110. "url": "https://www.wepayyoumore.co.uk/proxy.php",
  111. "method": "POST",
  112. "headers": {
  113. "X-Proxy-URL": "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles",
  114. "x-api-key": DVLA_api_key,
  115. "Content-Type": "application/json",
  116. },
  117. "processData": false,
  118. "data": "{\"registrationNumber\": \"" + $reg_sanitize + "\"}", // https://stackoverflow.com/a/51915181/1625909
  119. success: function (result) {
  120. window.lookup_result = result;
  121. //console.table(lookup_result);
  122.  
  123. $.each(lookup_result, function(key, value){
  124. // Print verbose to hidden field
  125. $('textarea[name="'+hidden_field+'"]')
  126. .val( $('textarea[name="'+hidden_field+'"]').val() + key + ": " + value + "\n\r");
  127.  
  128. }); // End each loop
  129. //alert( $('textarea[name="'+hidden_field+'"]').val() );
  130.  
  131. $.each($interpretDVLAKeys, function(key, value){
  132. $(message_space).append(
  133. "<b>"
  134. + value
  135. + "</b>: "
  136. + lookup_result[key]
  137. + '<br>'
  138. );
  139. });
  140.  
  141. $(message_space).slideDown();
  142. },
  143. error: function (response) {
  144. //alert( "Request failed: " + response );
  145. }
  146. });
  147.  
  148. }
  149. }
  150.  
  151. }, $keyWaitTimeMiliSeconds);
  152. });
  153.  
  154. });
  155. </script>
  156.  
  157.  
  158. <style>
  159. /* CSS variables for our form */
  160. form.homepage_form_mod {
  161. --yellow-plate: #FFFF00; /* Yellow background on field */
  162. --message-area-background: #f9f9f9;
  163. --message-area-border: #CED4DA;
  164. }
  165.  
  166. form.homepage_form_mod input[type="text"] {
  167. text-transform: uppercase; /* Make the text uppercase in the */
  168. font-weight:bold; /* Embolden the text */
  169. background:var(--yellow-plate);
  170. font-family: 'Inconsolata', monospace;
  171. font-size: 30px;
  172. border: none;
  173. border-radius: 13px;
  174. padding: 10px 25px 13px 25px;
  175. max-width: 100%;
  176. }
  177.  
  178. form.homepage_form_mod input[type="text"]::placeholder {
  179. font-size: 24px;
  180. }
  181.  
  182. form.homepage_form_mod input[type="submit"] {
  183. color: #ffffff!important;
  184. border-color: rgba(0,0,0,0);
  185. border-radius: 15px;
  186. font-size: 24px;
  187. background-color: #632984;
  188. display: block;
  189. margin: 16px auto 0px;
  190. padding: 15px 26px;
  191. }
  192. </style>
  193.  
  194. <script>
  195. // Import our PHP variables to the client side
  196. var form_destination = "/get-a-valuation/";
  197. var form_class_name = "." + "homepage_form_mod";
  198. var fluentform_id = "1";
  199. var input_box_name = "reg_input";
  200.  
  201. jQuery(document).ready(function( $ ) {
  202.  
  203. var input_field = $('#fluentform_'+fluentform_id+' input[name="'+input_box_name+'"]');
  204.  
  205. $.extend({
  206. getUrlVars: function(){
  207. var vars = [], hash;
  208. var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  209. for(var i = 0; i < hashes.length; i++)
  210. {
  211. hash = hashes[i].split('=');
  212. vars.push(hash[0]);
  213. vars[hash[0]] = hash[1];
  214. }
  215. return vars;
  216. },
  217. getUrlVar: function(name){
  218. return $.getUrlVars()[name];
  219. }
  220. });
  221.  
  222. if ( $(form_class_name) ) {
  223. $(form_class_name).attr('action',form_destination);
  224. console.log('Updated homepage form destination');
  225. }
  226.  
  227. if ($.getUrlVar( input_box_name ) != null) {
  228. console.log('URL param present');
  229. $(input_field).trigger("change");
  230. }
  231.  
  232. });
  233. </script>
  234.  
Advertisement
Add Comment
Please, Sign In to add comment