1window.CANDEE = window.CANDEE || {}; 2 3window.CANDEE.markSelect2ShellReady = function(selector) { 4 cQuery(selector).closest('.candee-select2-shell').addClass('candee-select2-ready'); 5}; 6 7window.CANDEE.markFacilitySelectReady = function(selector) { 8 window.CANDEE.markSelect2ShellReady(selector); 9 cQuery(selector).closest('.candee-location-select-shell').addClass('candee-select2-ready'); 10}; 11 12window.CANDEE.captureRequiredSelect2 = function(selector) { 13 cQuery(selector).each(function() { 14 var currentSelect = cQuery(this); 15 16 if (!currentSelect.prop('required') && currentSelect.attr('data-select2-required') !== '1') { 17 return; 18 } 19 20 currentSelect.attr('data-select2-required', '1'); 21 currentSelect.prop('required', false).removeAttr('required'); 22 }); 23}; 24 25window.CANDEE.decorateRequiredSelect2 = function(selector) { 26 cQuery(selector).each(function() { 27 var currentSelect = cQuery(this); 28 var currentSelection = currentSelect.next('.select2-container').find('.select2-selection'); 29 30 if (currentSelect.attr('data-select2-required') !== '1' || !currentSelection.length) { 31 return; 32 } 33 34 currentSelection.attr('aria-required', 'true'); 35 36 currentSelect 37 .off('.candeeRequiredSelect2') 38 .on('change.candeeRequiredSelect2 select2:select.candeeRequiredSelect2 select2:clear.candeeRequiredSelect2', function() { 39 currentSelection.attr('aria-invalid', 'false'); 40 currentSelect.closest('.candee-input-group, .input-field, .select2_container').removeClass('candee_error'); 41 }); 42 }); 43}; 44 45window.CANDEE.initFacilitySelect2 = function(selector, extraOptions) { 46 if (!cQuery.fn || typeof cQuery.fn.select2 !== 'function') { 47 window.CANDEE.markSelect2ShellReady(selector); 48 window.CANDEE.markFacilitySelectReady(selector); 49 return; 50 } 51 52 var selectEl = cQuery(selector).not('[data-candee-select]'); 53 if (!selectEl.length) { 54 return; 55 } 56 57 selectEl.each(function() { 58 var currentSelect = cQuery(this); 59 var shouldRestoreFocus = document.activeElement === currentSelect[0]; 60 var modalContainer = currentSelect.closest('#addUnitModal').find('.modal-container'); 61 62 window.CANDEE.captureRequiredSelect2(currentSelect); 63 64 var renderFacilityOption = function(option) { 65 if (!option || !option.id || !option.text) { 66 return option && option.text ? option.text : ''; 67 } 68 69 var address = cQuery(option.element).data('address'); 70 if (!address) { 71 return option.text; 72 } 73 74 return cQuery( 75 '<div class="candee-select2-option">' + 76 '<span>' + option.text + '</span>' + 77 '<span class="select2-address_desc">' + address + '</span>' + 78 '</div>' 79 ); 80 }; 81 var options = cQuery.extend(true, { 82 placeholder: SHARED.candee_translate('Select your location'), 83 allowClear: true, 84 width: '100%', 85 showAddressOnSelection: false, 86 templateResult: function(option) { 87 return renderFacilityOption(option); 88 }, 89 templateSelection: function(option) { 90 if (!option.id) { 91 return option.text || SHARED.candee_translate('Select your location'); 92 } 93 94 if (options.showAddressOnSelection === true) { 95 return renderFacilityOption(option); 96 } 97 98 return option.text; 99 }, 100 escapeMarkup: function(markup) { 101 return markup; 102 } 103 }, extraOptions || {}); 104 105 if (modalContainer.length) { 106 options.dropdownParent = modalContainer; 107 } 108 109 if (shouldRestoreFocus) { 110 currentSelect.trigger('blur'); 111 } 112 113 if (currentSelect.hasClass('select2-hidden-accessible')) { 114 currentSelect.select2('destroy'); 115 } 116 117 currentSelect.select2(options); 118 119 if (shouldRestoreFocus) { 120 currentSelect.next('.select2-container').find('.select2-selection').trigger('focus'); 121 } 122 123 window.CANDEE.decorateRequiredSelect2(currentSelect); 124 window.CANDEE.markSelect2ShellReady(currentSelect); 125 currentSelect.closest('.candee-location-select-shell').addClass('candee-select2-ready'); 126 }); 127 128 cQuery(document) 129 .off('mousedown.candeeFacilitySelect2 mouseup.candeeFacilitySelect2', '#addUnitModal .select2-dropdown, #addUnitModal .select2-results, #addUnitModal .select2-results__options') 130 .on('mousedown.candeeFacilitySelect2 mouseup.candeeFacilitySelect2', '#addUnitModal .select2-dropdown, #addUnitModal .select2-results, #addUnitModal .select2-results__options', function(event) { 131 event.stopPropagation(); 132 }); 133}; 134 135cQuery(document).ready(function() { 136 var select2Selector = '.select2:not([data-candee-select])'; 137 138 if (!cQuery.fn || typeof cQuery.fn.select2 !== 'function') { 139 cQuery('.candee-select2-shell').addClass('candee-select2-ready'); 140 window.CANDEE.initFacilitySelect2('#loginTheme1 ' + select2Selector, { showAddressOnSelection: true }); 141 return; 142 } 143 144 window.CANDEE.captureRequiredSelect2(select2Selector); 145 cQuery(select2Selector).select2(); 146 cQuery(select2Selector).each(function() { 147 window.CANDEE.decorateRequiredSelect2(this); 148 window.CANDEE.markSelect2ShellReady(this); 149 }); 150 151 window.CANDEE.initFacilitySelect2('#loginTheme1 ' + select2Selector, { showAddressOnSelection: true }); 152});
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.