PageSourceSearch

https://standardelectricals.com/static/version1790868634/frontend/…/Custom_RegisterProductAMC/js/custom.js

js standardelectricals.com collected 2026-10-04 02:36:53 UTC 5,644 bytes, 173 lines download raw bytes

1require([
2	'jquery',
3	'Magento_Customer/js/customer-data',
4	'mage/url'
5], function (
6	$,
7	customerData,
8	urlBuilder
9) {
10	$(document).ready(function () {
11		$('input[name="telephone"],input[name="firstname"],input[name="lastname"],input[name="street[0]"],input[name="street[1]"],input[name="street[2]"],input[name="city"],input[name="postcode"],input[name="alternate_phone_number"]'
12		).on('change','input',function() {
13			$(this).val($(this).val().trim());
14		});
15		// for first name and last name
16		// $('input[name="firstname"],input[name="lastname"]').on('input',function () {
17		// 	var text = $(this).val();
18		// 	var maxlength = 30
19		// 	if(maxlength > 0)
20		// 	{
21		// 		$(this).val(text.substring(0, maxlength));
22		// 	}
23		// });
24		$('input[name="firstname"], input[name="lastname"]').on('input', function () {
25			var firstname = $('input[name="firstname"]').val();
26			var lastname = $('input[name="lastname"]').val();
27			var totalLength = firstname.length + lastname.length;
28			var maxTotalLength = 30;
29			// Adjust lastname if the combined length exceeds max
30			if (totalLength + 1 > maxTotalLength) {
31				if ($(this).attr('name') === 'firstname') {
32					// Typing in firstname
33					var allowedFirstnameLength = maxTotalLength - lastname.length - 1;
34					if (allowedFirstnameLength < 0) {
35						allowedFirstnameLength = 0;
36					}
37					$(this).val(firstname.substring(0, allowedFirstnameLength));
38				} else {
39					// Typing in lastname
40					var allowedLastnameLength = maxTotalLength - firstname.length - 1;
41					if (allowedLastnameLength < 0) {
42						allowedLastnameLength = 0;
43					}
44					$(this).val(lastname.substring(0, allowedLastnameLength));
45				}
46			}
47		});
48
49		//for street
50		$('input[name="street[0]"]').on('input',function () {
51			var text = $(this).val();
52			var maxlength = 40;
53			if(maxlength > 0)
54			{
55				$(this).val(text.substring(0, maxlength));
56			}
57		});
58
59		$('input[name="street[2]"]').on('input',function () {
60			var text = $(this).val();
61			var maxlength = 39;
62			if(maxlength > 0)
63			{
64				$(this).val(text.substring(0, maxlength));
65			}
66		});
67		
68		$('input[name="postcode"],input[name="telephone"],input[name="mobile_number"],input[name="custom_attributes[alternate_phone_number]"],input[name="alternate_phone_number"]').on('input', function() {
69			var ref = $(this);
70			var pincode = ref.val();
71			var len=6;
72			if(ref.attr('name')=="telephone" || ref.attr('name')=="mobile_number" || ref.attr('name')=="custom_attributes[alternate_phone_number]" || ref.attr('name')=="alternate_phone_number"){
73				len=10;
74			}
75			var digitsOnly = pincode.replace(/\D/g, '');
76			// Ensure the length is not greater than 6
77			if (digitsOnly.length > len) {
78				digitsOnly = digitsOnly.substring(0, len);
79				$(this).val(digitsOnly);
80			}
81			if (/^0/.test(pincode)) {
82				digitsOnly = pincode.replace(/^0/, "")
83			}
84			$(this).val(digitsOnly);
85		});
86		
87		function sendAjaxRequest(url, successCallback, errorCallback) {
88			$.ajax({
89				url: url,
90				type: 'POST',
91				dataType: 'json',
92				success: successCallback,
93				error: errorCallback || function (xhr, status, error) {
94					console.error('AJAX Request Failed:', status, error);
95				}
96			});
97		}
98
99		$(document).on('click', '#register-product', function(event) {
100			event.preventDefault();
101			sendAjaxRequest('/registerproduct/api/checkislogin', function (response) {
102				console.log(response);
103				if (response.success) {
104					window.location.href = '/register-product';
105				} else {
106					window.location.href = window.register_url;
107				}
108			});
109		});
110		
111		$(document).on('click', '#support-my-products', function(event) {
112			event.preventDefault();
113			sendAjaxRequest('/registerproduct/api/checkislogin', function (response) {
114				console.log(response);
115				if (response.success) {
116					window.location.href = '/support-my-products';
117				} else {
118					var loginUrl = response.baseUrl;
119					var supportUrl = loginUrl+'support-my-products';
120					window.location.href = loginUrl+'customer/account/login?callback_url='+supportUrl;
121				}
122			});
123		});
124		
125		$(document).on('click', '#service-request', function(event) {
126			event.preventDefault();
127			sendAjaxRequest('/registerproduct/api/checkislogin', function (response) {
128				console.log(response);
129				if (response.success) {
130					window.location.href = '/service-request';
131				} else {
132					var loginUrl = response.baseUrl;
133					var serviceUrl = loginUrl+'service-request';
134					window.location.href = loginUrl+'customer/account/login?callback_url='+serviceUrl;
135				}
136			});
137		});
138
139		$('#amc-extended').on('click', function (event) {
140			event.preventDefault();
141			sendAjaxRequest('/registerproduct/api/checkislogin', function (response) {
142
143				if (response.success) {
144					window.location.href = '/amc-product-selection';
145				} else {
146					window.location.href = '/amc-extended-warranty';
147				}
148			});
149		});
150
151		$(document).on('click', '#amc-buy', function(event) {
152			event.preventDefault();
153			sendAjaxRequest('/registerproduct/api/checkislogin', function (response) {
154				if (response.success) {
155					window.location.href = '/amc-product-selection';
156				} else {
157					window.location.href = window.amc_selection_url;
158				}
159			});
160		});
161
162		// Function to display error messages
163		function displayError(message, errorFieldId) {
164			$('#' + errorFieldId).text(message);
165		}
166
167		// Function to validate email format
168		function isValidEmail(email) {
169			var emailRegex = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
170			return emailRegex.test(email);
171		}
172	});
173});

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.