PageSourceSearch

https://byjus.com/wp-content/themes/html5blank-stable/js/search-bar.js

js byjus.com collected 2026-09-24 08:27:44 UTC 8,717 bytes, 233 lines download raw bytes

1var WIDGETS = {
2	// this function will take care of search submit
3	searchWidget: function () {
4		function searchInputValiadation(se, sf) {
5			var sel_value = se.val().trim();
6			se.val(sel_value);
7			var msg = "";
8			var reg_exp = /\`|\~|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\+|\=|\[|\{|\]|\}|\||\\|\'|\<|\,|\.|\>|\?|\/|\""|\;|\:/g;
9			se.siblings(".input-error-msg").remove();
10			if (!sel_value || sel_value === null) {
11				msg = "Search keyword is required.";
12			} else if (sel_value.indexOf("byjus.com/") != -1) {
13				sel_value = sel_value
14					.split("byjus.com/")[1]
15					.split("/")
16					.join(" ");
17				se.val(sel_value.trim());
18			// } else if (sel_value.match(reg_exp)) {
19			// 	msg = "Special characters not allowed.";
20			// } else if (sel_value.length > 50) {
21			// 	msg = "Allowed maximum 50 characters only.";
22			}
23
24			if (msg) {
25				se.addClass("input-error").removeClass("input-valid");
26				se.after('<div class="input-error-msg">' + msg + "</div>");
27				return false;
28			} else {
29				se.removeClass("input-error");
30				se.addClass("input-valid");
31				return true;
32			}
33			return false;
34		}
35
36		// desktop
37		var se = jQuery("#search-widget input");
38		var sf = jQuery("#search-widget form");
39		se.on("blur change", function (e) {
40			searchInputValiadation(se, sf);
41		});
42
43		sf.submit(function (e) {
44			if (!searchInputValiadation(se, sf)) {
45				e.preventDefault();
46			} else {
47				if (GA_FLAG)
48					ga(
49						"send",
50						"event",
51						"SearchWidget",
52						"On search form submit",
53						"Search Keyword: " + se.val() + ",Page Url: " + C_URL
54					);
55			}
56		});
57
58		// mobile
59		var se_m = jQuery("#search-bar-m input");
60		var sf_m = jQuery("#search-bar-m form");
61		se_m.on("blur change", function (e) {
62			searchInputValiadation(se_m, sf_m);
63		});
64
65		sf_m.submit(function (e) {
66			if (!searchInputValiadation(se_m, sf_m)) {
67				e.preventDefault();
68			} else {
69				if (GA_FLAG)
70					ga(
71						"send",
72						"event",
73						"SearchWidget",
74						"On search form submit",
75						"Search Keyword: " + se.val() + ",Page Url: " + C_URL
76					);
77			}
78		});
79	},
80	// this function will take care of search submit
81	joinByjusFormSubmitForm: function (e, ele) {
82		e.preventDefault();
83		var sel = jQuery(ele);
84		sel
85			.find('input[name="mx_Inbound_Enquiry_Date"]')
86			.val(UTILITIES.getCurrentDateTime("yyyy-mm-dd hh:mm:ss-UTC")); // setting current time
87		var formInputs = sel.find(".form-group input");
88		var formSelect = sel.find(".form-group select");
89		if ((sel.find(".form-group input.input-valid").length == formInputs.length) && sel.find(".form-group select.input-valid")) {
90			UTILITIES.addToastMessage(
91				'page-form-popup-and-widget-0',
92				"Form details are submitting.."
93			);
94
95			sel
96				.find('button[type="submit"]')
97				.attr('disabled', true)
98				.html("Loading.."); // TO disable submit button
99			// Changed grade & LS table name & pageId
100			sel = getLSTableIdByGradeName(sel);
101			// to call LS API
102			var post_data = sel.serialize();
103			//Adding value for utm parameters
104			var utmSource, utmCampaign, utmContent, getWebsite;
105			utmSource = UTILITIES.getParameterByName('utm_source', C_URL);
106			utmCampaign = UTILITIES.getParameterByName('utm_campaign', C_URL);
107			utmContent = UTILITIES.getParameterByName('utm_content', C_URL);
108			getWebsite = UTILITIES.getParamValueByName('Website', post_data);
109			var gclid = UTILITIES.getParamValueByName('gclid', C_URL);
110			post_data += '&SourceCampaign=' + (utmCampaign ? utmCampaign : "") + '&SourceMedium=' + (utmSource ? utmSource : "") + '&SourceContent=' + (utmContent ? utmContent : "") + (gclid ? '&mx_Gclid=' + gclid : '');
111			if (!getWebsite) {
112				post_data += '&Website=' + escape(C_URL);
113			} else {
114				post_data = UTILITIES.updateParamValueByName(post_data, "Website", escape(C_URL));
115			}
116             post_data += '&slugName='+ "pageWidgetForm";
117			 post_data += '&Website_URL='+ visitedURL;
118			 post_data += '&Platform='+ (typeof navigator.isMobile != 'undefined' ? (navigator.isMobile ? "website_mobile" : "website_desktop") : "");
119			 post_data += '&Lead_Magnet_Type='+ "SIDEBAR_JOIN_BYJUS_FORM";
120			 post_data += '&Device_Details='+ (typeof navigator.detectDeviceAgent != "undefined" ? navigator.detectDeviceAgent : "");
121			 post_data += '&Device_UserAgent='+ (typeof navigator.userAgent != "undefined" ? navigator.userAgent : "");
122			function findAndReplaceEmptyKeyValuePair(str) { // 
123				var arrayOfKeyValue = str.split('&')
124				var arrayOfKeyValueLength = arrayOfKeyValue.length;
125				var finalArray = [];
126				for (var i = 0; i < arrayOfKeyValueLength; i++) {
127					if (arrayOfKeyValue[i].indexOf('=') !== arrayOfKeyValue[i].length - 1) {
128						finalArray.push(arrayOfKeyValue[i])
129					}
130				}
131				finalArray = [...new Set(finalArray)];
132				return finalArray.join('&');
133			}
134            
135
136			jQuery.ajax({
137				type:'POST',
138				url: COMMON_UTILS_ENDPOINT_KEY + "leads/",
139                data: findAndReplaceEmptyKeyValuePair(post_data),
140				complete: function (xhr,status) {
141
142						if (xhr.status === 200) {
143							UTILITIES.removeToastMessage('page-form-popup-and-widget-0');
144							sel.addClass('hidden');
145							if (!sel.find('.register-form-widget-success-block').length) {
146								var successHtml = '' +
147									'<div class="register-form-widget-success-block">' +
148									'<div class="text-center success-message">' +
149									'<svg style="width:60px;height:60px" viewBox="0 0 24 24">
149<path fill="green" d="M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4M11,16.5L6.5,12L7.91,10.59L11,13.67L16.59,8.09L18,9.5L11,16.5Z" /></svg>' +
150									'<br>';
151								// check Instance name then display success msg
152								if (INSTANCE_NAME === 'free-ias-prep') {
153									jQuery("#register-modal-widget").addClass('submitted-successfully');
154									successHtml += ' <h4>Congrats! You\'re a step closer to your IAS dream</h4>' +
155										'Our mentors shall get in touch with you soon to help you plan your preparation better.' +
156										' Good Luck!'
157								} else {
158									successHtml = successHtml + ' <h4>Thank you for connecting with BYJU\'S!!,</h4> Our Counsellors will get in touch with you soon and help you get started with your ' +
159										FORM_NAME + ' Preparation';
160								}
161								successHtml += '</div>' +
162									'</div>';
163								sel.after(successHtml);
164							} else {
165								sel.find('.register-form-widget-success-block').removeClass('hidden');
166							}
167
168							if (sel.attr('id') == 'register-popup-form-widget') { // identifying is it popup
169								UTILITIES.setCookie(
170									"pagebformypopupj",
171									1,
172									15
173								); // on successfully submition of page form popup we are not showing this popup for next 15 days.
174
175								GA_FLAG && ga("send", "event", INSTANCE_NAME + " Popup Form Successful", "Form Submission activity created Successfully", "URL: " + C_URL); // GA
176							}
177						} else {
178							UTILITIES.addToastMessage(
179								'page-form-popup-and-widget-0',
180								   xhr.responseJSON.message
181							); // on fail showing error toast message. Please try again later!
182
183							GA_FLAG && ga("send", "event", INSTANCE_NAME + " Popup Form Failed", "Form Submission activity created Failed", "URL: " + C_URL); // GA
184						}
185					
186				}
187			});
188		} else {
189			e.preventDefault();
190			formInputs.each(function (i, ele) {
191				jQuery(ele).blur();
192			});
193			formSelect.blur();
194		}
195
196		//ga
197		if (GA_FLAG) {
198			var formId = jQuery(ele).attr('id');
199			if (formId === 'register-popup-form-widget') {
200				ga("send", "event", "Form Popup Button Click: " + FORM_NAME, "On Submitting Form", "Form Values: " + jQuery(ele).serialize());
201			} else if (formId === 'join-byjus-form-widget') {
202				ga("send", "event", "Join BYJU'S Form Button Click: " + FORM_NAME, "On Submitting Form", "Form Values: " + jQuery(ele).serialize());
203			}
204		}
205
206	}
207};
208function getLSTableIdByGradeName(obj) {
209	var gradeNameEle = obj.find('[name="grade"]'); //GR-288: this would always return the jquery object even if the children is not found
210	if (gradeNameEle.val() !== null) {
211		var pageIDTableNameCourseName = gradeNameEle.find('option:selected').attr('data-value');
212		//GR-288: adding a check for pages that do not have grades drop down
213		if (pageIDTableNameCourseName) {
214			var courseNames = pageIDTableNameCourseName.split('_');
215			if (courseNames[0] != 'undefined') {
216				obj.find('[name="mx_Course_Name"]').val(courseNames[0]);
217			}
218			if (courseNames[1] != 'undefined') {
219				obj.find('[name="MXHOrgCode"]').val(courseNames[1]);
220			}
221			if (courseNames[2] != 'undefined') {
222				obj.find('[name="MXHLandingPageId"]').val(courseNames[2]);
223			}
224
225		}
226
227	}
228	return obj;
229}
230jQuery(document).ready(function () {
231	WIDGETS.searchWidget();
232
233})

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.