1(function ($) { 2 3 const CurrentPage = window.location.pathname.split("/").pop() 4 const GoogleForms = ['nationalassembly', 5 'nationalassembly', 6 'InterlandAdventure', 7 'curriculum', 8 'teachertraining', 9 'lessons', 10 'year6', 11 'teachertoolkit', 12 'localstorage' 13 ] 14 15 if (GoogleForms.includes(CurrentPage)) { 16 if (localStorage) { 17 $(document).ready(() => { 18 19 //Initialize a localstorage container with the keys we want 20 let initialize = localStorage.getItem("initialize") 21 22 if (initialize !== "true") { 23 localStorage.setItem("first_name", ""); 24 localStorage.setItem("last_name", ""); 25 localStorage.setItem("email", ""); 26 localStorage.setItem("name_of_school_organisation", ""); 27 localStorage.setItem("role", ""); 28 localStorage.setItem("country", ""); 29 localStorage.setItem("county", ""); 30 localStorage.setItem("postcode", ""); 31 localStorage.setItem("initialize", "true"); 32 console.log("initialized localstorage"); 33 } 34 35 //Get localStorage key values 36 const getFirstName = localStorage.getItem("first_name") 37 const getLastName = localStorage.getItem("last_name") 38 const getEmail = localStorage.getItem("email") 39 const getSchoolOrganisationName = localStorage.getItem("name_of_school_organisation") 40 const getRole = localStorage.getItem("role") 41 const getCountry = localStorage.getItem("country") 42 const getCounty = localStorage.getItem("county") 43 const getPostcode = localStorage.getItem("postcode") 44 45 46 //If the key values exist then pre-fill form fields 47 if (getFirstName != null || getFirstName !== "undefined") { 48 if ($("#edit-submitted-contact-details-first-name").length) { 49 $("#edit-submitted-contact-details-first-name").val(getFirstName) 50 } else if ($("#edit-submitted-first-name").length) { 51 $("#edit-submitted-first-name").val(getFirstName) 52 } else if ($("#edit-first-name").length) { 53 $("#edit-first-name").val(getFirstName) 54 } 55 } 56 57 if (getLastName != null || getLastName !== "undefined") { 58 if ($("#edit-submitted-contact-details-last-name").length) { 59 $("#edit-submitted-contact-details-last-name").val(getLastName) 60 } else if ($("#edit-submitted-last-name").length) { 61 $("#edit-submitted-last-name").val(getLastName) 62 } else if ($("#edit-submitted-surname").length) { 63 $("#edit-submitted-surname").val(getLastName) 64 } else if ($("#edit-last-name").length) { 65 $("#edit-last-name").val(getLastName) 66 } 67 } 68 69 if (getEmail != null || getEmail !== "undefined") { 70 if ($("#edit-email").length) { 71 $("#edit-email").val(getEmail) 72 } 73 } 74 75 if (getSchoolOrganisationName !== "" || getSchoolOrganisationName !== "undefined" ) { 76 if ($("#edit-name-of-school-organisation").length) { 77 $("#edit-name-of-school-organisation").val(getSchoolOrganisationName) 78 } else if ($("#edit-submitted-name-of-school-organisation").length) { 79 $("#edit-submitted-name-of-school-organisation").val(getLastName) 80 } 81 } 82 83 if (getRole !== "" || getRole !== "undefined") { 84 if ($("#edit-role").length) { 85 $("#edit-role").val(getRole) 86 } 87 } 88 89 if (getCountry !== null && $("#edit-country").length) { 90 if ($("#edit-country option[value='" + getCountry + "']").length > 0) { 91 $("#edit-country").val(getCountry); 92 } 93 } 94 95 if (getCounty !== null && $("#edit-county").length) { 96 if ($("#edit-county option[value='" + getCounty + "']").length > 0) { 97 $("#edit-county").val(getCounty); 98 } 99 } 100 101 if (getPostcode !== null && $("#edit-postcode").length) { 102 ($("#edit-postcode").val(getPostcode)) 103 } 104 105 106 // On submit, get input values and save to local storage with respective key 107 $(".form-submit").click(function () { 108 // Get values of form input 109 const firstName = () => { 110 if ($("#edit-submitted-contact-details-first-name").length) { 111 return $("#edit-submitted-contact-details-first-name").val() 112 } else if ($("#edit-submitted-first-name").length) { 113 return $("#edit-submitted-first-name").val() 114 } 115 else if ($("#edit-first-name").length) { 116 return $("#edit-first-name").val() 117 } 118 } 119 120 121 const lastName = () => { 122 if ($("#edit-submitted-contact-details-last-name").length) { 123 return $("#edit-submitted-contact-details-last-name").val() 124 } else if ($("#edit-submitted-last-name").length) { 125 return $("#edit-submitted-last-name").val() 126 } else if ($("#edit-submitted-surname").length) { 127 return $("#edit-submitted-surname").val() 128 } 129 else if ($("#edit-last-name").length) { 130 return $("#edit-last-name").val() 131 } 132 } 133 134 const email = () => { 135 if ($("#edit-email").length) { 136 return $("#edit-email").val() 137 } 138 } 139 140 const schoolorganisationName = () => { 141 if ($("#edit-name-of-school-organisation").length) { 142 return $("#edit-name-of-school-organisation").val(); 143 } 144 } 145 146 const role = () => { 147 if ($("#edit-role").length) { 148 return $("#edit-role").val(); 149 } 150 } 151 152 const country = () => { 153 if ($("#edit-country").length) { 154 return $("#edit-country").val(); 155 } 156 } 157 158 const county = () => { 159 if ($("#edit-county").length) { 160 return $("#edit-county").val(); 161 } 162 } 163 const postcode = () => { 164 if ($("#edit-postcode").length) { 165 return $("#edit-postcode").val(); 166 } 167 } 168 169 170 // Store user input data in localStorage object 171 localStorage.setItem("first_name", firstName()); 172 localStorage.setItem("last_name", lastName());
173 localStorage.setItem("email", email()); 174 localStorage.setItem("name_of_school_organisation", schoolorganisationName()); 175 localStorage.setItem("role", role()); 176 localStorage.setItem("country", country()); 177 localStorage.setItem("county", county()); 178 localStorage.setItem("postcode", postcode()); 179 180 }); 181 }); 182 } else { 183 console.error("Local storage is not supported on this browser"); 184 } 185} 186 187})(jQuery);
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.