1var EmailSuggest = function () { 2 3 // "did you mean â¦?" email typo check (#49788): opt-in via data-email-suggest 4 // on frontend email inputs; server endpoint delivers translated messages 5 6 var removeHint = function ($input) { 7 if ($input.data('emailSuggestHint')) { 8 $input.data('emailSuggestHint').remove(); 9 $input.removeData('emailSuggestHint'); 10 } 11 }; 12 13 var showHint = function ($input) { 14 removeHint($input); 15 16 // place hint after the input group (e.g. newsletter) or the input itself 17 var $anchor = $input.closest('.input-group').length ? $input.closest('.input-group') : $input, 18 $hint = $('<small class="help-block email-suggest-hint" aria-live="polite"></small>'); 19 20 $anchor.after($hint); 21 $input.data('emailSuggestHint', $hint); 22 23 return $hint; 24 }; 25 26 var showSuggestion = function ($input, res) { 27 // message contains a %s placeholder â replace it with the clickable suggestion 28 var parts = (res.message || '%s').split('%s'), 29 $link = $('<a href="javascript:;" class="email-suggest-apply"></a>').text(res.suggestion), 30 $hint = showHint($input); 31 32 $hint.append(document.createTextNode(parts[0] || ''), $link, document.createTextNode(parts[1] || '')); 33 34 $link.on('click', function () { 35 // whitelist matches are mx-validated â mark as checked, no re-request 36 $input.val(res.suggestion).data('emailSuggestLast', res.suggestion); 37 removeHint($input); 38 $input.trigger('change'); 39 }); 40 }; 41 42 var handleFields = function () { 43 // namespaced off/on: init() may run twice on some pages â keep the binding idempotent 44 $(document).off('change.emailSuggest').on('change.emailSuggest', 'input[data-email-suggest]', function () { 45 var $input = $(this), 46 value = $.trim($input.val()); 47 48 // skip unchanged values (blur chains re-trigger change, e.g. checkout.js) 49 if (value === $input.data('emailSuggestLast')) { 50 return; 51 } 52 $input.data('emailSuggestLast', value); 53 removeHint($input); 54 55 // skip empty or obviously incomplete input 56 if (value.length < 4 || value.indexOf('@') === -1) { 57 return; 58 } 59 60 // abort a still running check (fast field switches) 61 if ($input.data('emailSuggestXhr')) { 62 $input.data('emailSuggestXhr').abort(); 63 } 64 65 $input.data('emailSuggestXhr', $.post(Config.get('base-url') + '/email/check/', { 66 email: value 67 }, function (res) { 68 if (res.status === 'suggestion' && res.suggestion) { 69 showSuggestion($input, res); 70 } else if (res.status === 'invalid') { 71 showHint($input).addClass('text-danger').text(res.message); 72 } 73 }, 'json')); 74 }); 75 }; 76 77 return { 78 // main function to initiate the module 79 init: function () { 80 handleFields(); 81 } 82 }; 83 84}();
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.