1// ssr_scripts_front.js 2/* 3Author: Saad Amin 4Website: http://www.saadamin.com 5Description: Front-end script for Student Result or Employee Database plugin. 6*/ 7 8jQuery(document).ready(function ($) { 9 /** 10 * Adjust Layout Based on Window Width 11 */ 12 function adjustLayout() { 13 if ($("div.result_div").width() < 700) { 14 $(".std_input").css({ 15 "max-width": "100%", 16 "width": "100%", 17 "margin-right": "auto" 18 }); 19 $("div.result_box div.sep").css({ 20 padding: "0 20px", 21 "margin-bottom": "10px" 22 }); 23 $(".std_title").css({ 24 "margin-left": "auto" 25 }); 26 } else { 27 $(".std_input").css({ 28 "max-width": "350px", 29 "margin-right": "20px" 30 }); 31 $("div.result_box div.sep").css({ 32 padding: "auto", 33 "margin-bottom": "auto" 34 }); 35 $(".std_title").css({ 36 "margin-left": "20px" 37 }); 38 } 39 } 40 41 /** 42 * Initialize Layout Adjustment 43 */ 44 $(window).on("load", adjustLayout); 45 $(window).resize(adjustLayout); 46 47 /** 48 * Debounce Timer Variable 49 */ 50 var debounceTimer; 51 52 /** 53 * Handle Keypress Event on Input Field 54 */ 55 $("#rues").css({ opacity: 1 }); 56 57 $("#rues").keypress(function () { 58 console.log("Key pressed"); 59 60 // Hide message box and show loading circle 61 $("#ssr_msgbox").hide(); 62 $("#ssr_frnt_circle").show(); 63 $(".result_box").css({ opacity: 1 }); 64 65 // Clear existing debounce timer 66 if (debounceTimer) { 67 clearTimeout(debounceTimer); 68 } 69 70 // Set new debounce timer 71 debounceTimer = setTimeout(function () { 72 // Show all result fields initially 73 for (var i = 1; i <= 13; i++) { 74 $("#ssr_r_f_" + i).show(); 75 } 76 77 var postID = $.trim($("#rues").val()); 78 console.log("Started with input length: " + postID.length); 79 80 if (postID.length > 0) { 81 $.ajax({
82 url: SSR_Ajax.root + "v2/ssr_find_all/", 83 method: "GET", // Changed to GET for 'READABLE' REST route 84 // No need to set nonce for public endpoints 85 data: { postID: postID }, 86 dataType: "text", // Force response to be treated as text to handle mixed content 87 success: function(response) { 88 // Step 1: Find the start of the JSON object 89 var jsonStart = response.indexOf('{'); 90 if (jsonStart !== -1) { 91 var jsonString = response.substring(jsonStart); 92 try { 93 // Step 2: Parse the JSON string 94 var parsedResponse = JSON.parse(jsonString); 95 96 // Check if the response indicates success 97 if (parsedResponse.success === true) { 98 console.log("Parsed JSON Response:", parsedResponse); 99 100 // Step 3: Access the data under the "0" key 101 var data = parsedResponse["0"]; 102 103 if (data) { 104 // Populate input fields with response data 105 $("#rid2").val(data.rid || ''); 106 $("#rn2").val(data.roll || ''); 107 $("#stn2").val(data.stdname || ''); 108 $("#stfn2").val(data.fathersname || ''); 109 $("#stpy2").val(data.pyear || ''); 110 $("#stcgpa2").val(data.cgpa || ''); 111 $("#stsub2").val(data.subject || ''); 112 $("#stsub3").val(data.dob || ''); 113 $("#stsub4").val(data.gender || ''); 114 $("#stsub5").val(data.address || ''); 115 $("#stsub6").val(data.mnam || ''); 116 $("#stsub7").val(data.c1 || ''); 117 $("#stsub8").val(data.c2 || ''); 118 119 // Handle Image Display 120 if ($("#st_img2").length) { 121 if (data.image && data.image.length > 0) { 122 $("#st_img2").attr("src", data.image).show(); 123 } else { 124 $("#st_img2").hide(); 125 } 126 } 127 128 // Hide fields with empty values 129 for (var i = 2; i <= 8; i++) { 130 var fieldVal = $("#stsub" + i).val(); 131 if (!fieldVal || fieldVal.length < 1) { 132 $("#ssr_r_f_" + (i + 5)).hide(); 133 } 134 } 135 136 // Hide loading circle and message box 137 $("#ssr_frnt_circle").hide(); 138 $(".result_box").css({ opacity: 1 }); 139 $("#ssr_msgbox").hide(); 140 } else { 141 console.warn("No data found under key '0' in the JSON response."); 142 handleNotFound(); 143 } 144 } else { 145 console.log("Operation not successful. Handling as not found."); 146 handleNotFound(); 147 } 148 } catch (e) { 149 // Step 4: Handle JSON parse errors 150 console.error("JSON parse error:", e); 151 console.log("Full Response Received:", response); 152 // Optionally, display an error message to the user 153 $("#ssr_msgbox").text("An error occurred while processing the data.").show(); 154 $("#ssr_frnt_circle").hide(); 155 } 156 } else { 157 // Handle case where no JSON object is found in the response 158 console.error("No JSON found in the response."); 159 console.log("Full Response Received:", response); 160 // Optionally, display an error message to the user 161 $("#ssr_msgbox").text("Invalid server response. Please try again later.").show(); 162 $("#ssr_frnt_circle").hide(); 163 } 164 165 // Helper function to handle "not found" scenarios 166 function handleNotFound() { 167 console.log("Data not found."); 168 $(".result_box").css({ opacity: 0 }); 169 $("#ssr_msgbox").show(); 170 $("#ssr_frnt_circle").hide(); 171 } 172 }, 173 error: function(jqXHR, textStatus, errorThrown) { 174 console.error("AJAX Error:", textStatus, errorThrown); 175 // Optionally, display an error message to the user 176 $("#ssr_msgbox").text("Failed to retrieve data. Please check your connection and try again.").show(); 177 $("#ssr_frnt_circle").hide(); 178 } 179}); 180 181 } else { 182 console.log("Empty input"); 183 $(".result_box").css({ opacity: 0 }); 184 $("#ssr_msgbox").hide(); 185 $("#ssr_frnt_circle").hide(); 186 } 187 }, 1000); // 1 second debounce 188 });
189 190 /** 191 * Prevent Space Character in Input Field 192 */ 193 $("#rues").keydown(function (event) { 194 if (event.keyCode === 32) { // 32 is the keycode for space 195 event.preventDefault(); 196 } 197 }); 198});
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.