1(function ($) { 2 $("body").append( 3 "<div class='bg-overlay st-site-loader st-animation position-fixed' id='form-loader'><div class='st-loader'>Loading...</div></div>" 4 ); 5 6 function debounce(func, timeout = 300) { 7 let timer; 8 return (...args) => { 9 clearTimeout(timer); 10 timer = setTimeout(() => { 11 func.apply(this, args); 12 }, timeout); 13 }; 14 } 15 16 const searchAutocomplete = debounce(() => { 17 const $school_autocomplete = $( 18 ".school-autocomplete input, input.school-autocomplete" 19 ); 20 21 if (!$school_autocomplete.length) { 22 return; 23 } 24 25 $school_autocomplete.easyAutocomplete({ 26 requestDelay: 500, 27 getValue: "name", 28 adjustWidth: false, 29 url: function (org_name) { 30 var query_str = "?org_name=" + org_name; 31 32 var $org_type_el = $(".org-type select"); 33 if ($org_type_el.length > 0) { 34 query_str += "&org_type=" + $org_type_el.val(); 35 } 36 37 //disabling for now as it is filtering out many schools with different country strings in Salesforce 38 /* 39 var $org_country_el = $(".org-country select"); 40 if ($org_country_el.length > 0 && $org_country_el.val()) { 41 query_str += "&org_country=" + $org_country_el.val(); 42 } 43 */ 44 45 //disabling state filter for now because people are putting their home state and it's filtering out schools they go to in another state 46 /* 47 var $org_state_el = $(".org-state select"); 48 if ($org_state_el.length > 0 && $org_state_el.val()) { 49 query_str += "&org_state=" + $org_state_el.val(); 50 } 51 */ 52 53 if ($("#gform_2, #gform_3").length) { 54 query_str += "&add_last_item=true"; 55 } 56 57 // Show loader when searching school 58 if ( 59 $("#gform_2, #gform_3").length && 60 $("#field_2_14 #school-loading, #field_3_14 #school-loading").length < 61 1 62 ) { 63 if ($("#input_2_14, #input_3_14").val() != "") { 64 $("#field_2_14, #field_3_14").append( 65 '<div id="school-loading">Please wait...</div>' 66 ); 67 68 $("#form-loader").addClass("active"); 69 } 70 } 71 72 // Show loader when searching school for workshop form 73 if ( 74 $("#workshop_form").length && 75 $("#workshop_form #school-loading").length < 1 76 ) { 77 if ($("#workshop_form .school-autocomplete").val() != "") { 78 $("#workshop_form .school-autocomplete").before( 79 '<div id="school-loading"><em>Populating...</em></div>' 80 ); 81 82 // $("#form-loader").addClass("active"); 83 } 84 } 85 86 return ol_sf.school_search_api + query_str; 87 }, 88 list: { 89 maxNumberOfElements: 30, 90 onChooseEvent: handleSchoolSelection, 91 // onSelectItemEvent: handleSchoolSelection, 92 onShowListEvent: function () { 93 $(document).find("#gform_2 #school-loading").remove(); 94 $(document).find("#gform_3 #school-loading").remove(); 95 $(document).find("#workshop_form #school-loading").remove(); 96 $("#form-loader").removeClass("active"); 97 }, 98 onLoadEvent: function () { 99 $(document).find("#gform_2 #school-loading").remove(); 100 $(document).find("#gform_3 #school-loading").remove(); 101 $("#form-loader").removeClass("active"); 102 }, 103 }, 104 }); 105 }, 800); 106 107 //TODO: maybe call this conditionally 108 searchAutocomplete(); 109 110 let handleSchoolSelection = () => { 111 let $selected_school = $( 112 "#gform_3 #input_3_14, #gform_2 #input_2_14" 113 ).getSelectedItemData(); 114 115 if (typeof $selected_school.id !== "undefined") { 116 $("#input_2_26").val($selected_school.id).trigger("change"); 117 $("#input_3_27").val($selected_school.id).trigger("change"); 118 } 119 120 // For workshop form 121 let $ws_form_school = $("#workshop_form input.school-autocomplete"); 122 if (typeof $ws_form_school.val() !== "undefined") { 123 let $ws_form_school_data = $ws_form_school.getSelectedItemData(); 124 $('input[name="sf_org_id"]') 125 .val($ws_form_school_data.id) 126 .trigger("change"); 127 } 128 }; 129 let clearSchoolIdOnTyping = () => { 130 $(".school-autocomplete input").on("keydown", function (event) { 131 if (event.key !== "Enter") { 132 $("#input_2_26").val("").trigger("change"); 133 $("#input_3_27").val("").trigger("change"); 134 135 $(".easy-autocomplete-container ul").html(""); 136 } 137 }); 138 }; 139 140 clearSchoolIdOnTyping(); 141 142 let $school_org_id = $("#input_2_26, #input_3_27"); 143 $school_org_id.on("change", function () { 144 displaySchoolFields(); 145 }); 146 147 $( 148 "#input_2_13, #input_2_14, #input_2_11, #input_3_13, #input_3_14, #input_3_11" 149 ).on("change", function () { 150 displaySchoolFields(); 151 }); 152 153 let displaySchoolFields = () => { 154 let $school_org_id = $("#input_2_26, #input_3_27"); 155 let $school_org = $("#input_2_14, #input_3_14"); 156 157 let $profile_form = false;
158 if ($("#gform_3").length) { 159 $profile_form = true; 160 } 161 162 let $school_fields = $( 163 "#field_2_16, #field_2_17, #field_2_18, #field_2_33, #field_3_16, #field_3_17, #field_3_18, #field_2_27, #field_3_29, #field_3_30" 164 ); 165 let $school_fields_input = $( 166 "#input_2_16, #input_2_17, #input_2_18, #field_2_33, #input_3_16, #input_3_17, #input_3_18, #input_2_27, #input_3_29, #field_3_30" 167 ); 168 169 if ( 170 "0" == $school_org_id.val() || 171 ("" == $school_org_id.val() && 172 "My School/Organization is not listed" == $school_org.val()) 173 ) { 174 $school_fields.show(); 175 $school_fields_input.show(); 176 $school_fields_input.prop("required", true); 177 } else { 178 $school_fields.hide(); 179 $school_fields_input.hide(); 180 $school_fields_input.prop("required", false); 181 } 182 183 let $school_type_population = $( 184 "#field_2_16, #field_2_17, #field_3_16, #field_3_17" 185 ); 186 let $school_type_population_inp = $( 187 "#input_2_16, #input_2_17, #input_3_16, #input_3_17" 188 ); 189 let $profession_value = $("input[name='input_11']:checked").val(); 190 191 let $school_type = $("#input_2_13, #input_3_13").val(); 192 let $school_name = $("#input_2_14, #input_3_14").val(); 193 if ( 194 "My School/Organization is not listed" == $school_name && 195 "" !== $school_name && 196 $.inArray($school_type, [ 197 "Elementary School", 198 "High School", 199 "Middle School", 200 "School District", 201 "College/University", 202 ]) !== -1 && 203 $.inArray($profession_value, ["Parent", "Other Community Member"]) == -1 204 ) { 205 $school_type_population.show(); 206 $school_type_population_inp.show(); 207 $school_type_population_inp.prop("required", true); 208 } else { 209 $school_type_population.hide(); 210 $school_type_population_inp.hide(); 211 $school_type_population_inp.prop("required", false); 212 } 213 214 let $school_fields_to_disable = $( 215 "#field_2_13, #field_2_14, #field_3_13, #field_3_14" 216 ); 217 let $school_fields_input_to_disable = $( 218 "#input_2_13, #input_2_14, #input_3_13, #input_3_14" 219 ); 220 221 if ( 222 $.inArray($profession_value, ["Parent", "Other Community Member"]) != -1 223 ) { 224 $school_fields_to_disable.addClass("hide"); 225 $school_fields_input_to_disable.hide(); 226 $school_fields_input_to_disable.prop("required", false); 227 } else { 228 $school_fields_to_disable.removeClass("hide"); 229 $school_fields_input_to_disable.show(); 230 $school_fields_input_to_disable.prop("required", true); 231 } 232 }; 233 234 displaySchoolFields(); 235 236 // Remove School search field value if no school is selected 237 // $("#input_2_14").on("focusout", function (event) { 238 // if ($("#input_2_26").val() === "") { 239 // $("#input_2_14").val(""); 240 // } 241 // }); 242})(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.