1$(function() { 2 $('.savesearch-link').click(function (e) { 3 e.preventDefault(); 4 e.stopImmediatePropagation(); 5 6 /* Make sure that all of the configuration options needed exist, using 7 the values from subscribeWidgetSetup, if it exists, or by creating 8 defaults for the subscribe widget here. */ 9 var config = $.extend({ 10 action : 'subscribe', 11 usingJobAlertsManager : false 12 }, typeof subscribeWidgetSetup === 'undefined' ? {} : subscribeWidgetSetup); 13 14 if (j2w.Args.get('useCASWorkflow')) { 15 var frequency, validationResult; 16 var jobAlert = null; 17 18 /* Collect all of the forms needed to create an agent. The selectors here must be very 19 specific as search forms are used and reused on a page (typically in the mobile search menu 20 and in the main body of the page) and a selection-by-id or selection-by-class of the search 21 form itself usually grabs the wrong one. */ 22 var $searchForm = $('#innershell .jobAlertsSearchForm:visible'); 23 var $frequencyForm = $(this).closest('.savesearch-wrapper').find('input[name=frequency]:visible'); 24 25 /* When using the job alert manager, all of the information needed to create an alert 26 can be obtained from form data, and the alert is validated differently. */ 27 if (config.usingJobAlertsManager) { 28 /* Use the information in the combined search forms to populate an agent object. add() 29 combines the multiple form elements into one object for processing. */ 30 jobAlert = j2w.Agent.buildAgentFromSearchForm($searchForm.add($frequencyForm)); 31 32 frequency = jobAlert.getFrequency(); 33 34 validationResult = j2w.Agent.validateAgent(jobAlert); 35 } else { 36 /* For regular subscribe forms, only the frequency is required and needs to be validated. */ 37 jobAlert = j2w.Agent.buildAgentFromSearchForm($frequencyForm); 38 39 var result = j2w.Agent.validateFrequency(jobAlert.getFrequency()); 40 41 /* Manually create a validation object matching that of validateAgent() since 42 validateFrequency() doesn't provide one, so that the validation logic works for either 43 situation. */ 44 validationResult = { 45 valid : !result.length, 46 validations : result 47 }; 48 } 49 50 // If the agent was valid, then proceed with the CAS workflow. 51 if (validationResult.valid) { 52 // Hide any lingering error messages while we process the agent and redirect the user. 53 if (j2w.Args.get('isResponsive')) { 54 $('.frequency-error').addClass('hidden'); 55 } 56 57 /* Since the save search form doesn't contain keywords and location, we've collected them 58 separately above, and pass them along here. For job alert creation on the job alerts 59 manager page, the entire agent is passed along, which affects 60 j2w.User.getAgentProfileForExport(). */ 61 j2w.TC.collectForCASWorkflow({ 62 agent : (config.action === 'alertCreate' && config.usingJobAlertsManager) ? jobAlert : null, 63 emailAddress : '', 64 action : config.action, 65 socialSrc : '', 66 frequency : jobAlert.getFrequency(), 67 keywords : jobAlert.getKeywords(), 68 location : jobAlert.getLocation() 69 }); 70 } else { 71 var aMessages = []; 72 73 if (config.usingJobAlertsManager) { 74 // validationResult does not contain error messages. You have to look them up. 75 aMessages = j2w.Agent.getValidationErrors(validationResult.validations, jsStr); 76 } else { 77 // When not using the job alerts manager, the errors are returned directly. 78 aMessages = validationResult.validations; 79 } 80 81 // Present the error messages from the failed validations based on the platform type. 82 if (j2w.Args.get('isResponsive')) {
83 $('.invalid-feedback').attr( "style", "display: block !important;" ); 84 $("div#savesearch").addClass('was-validated'); 85 $('.frequency-error-message').html(aMessages.join('<br />')); 86 $('.frequencySpinBtn').attr('aria-invalid', "true"); 87 $('.frequencySpinBtn').attr('aria-errormessage', "frequency-error-feedback"); 88 $('.frequencySpinBtn').attr('tabindex', "0"); 89 $('.frequencySpinBtn').focus(); 90 } else { 91 alert(aMessages.join('\n')); 92 } 93 } 94 } else { 95 $(this).parents().siblings('form[class~="emailsubscribe-form"]').slideToggle(250, function () { 96 $(this).find('input[name=email]:visible').focus(); 97 }); 98 } 99 }).parents().siblings('form[class~="emailsubscribe-form"]').hide(); 100});
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.