1(function (window, document) { 2 var namespace = window.EditorumUi = window.EditorumUi || {}; 3 var internals = namespace.__internals = namespace.__internals || {}; 4 5 function showToggleErrorMessage() { 6 if (typeof namespace.showFlashMessages === 'function') { 7 namespace.showFlashMessages([{ 8 type: 'danger', 9 messages: ['Unable to update status. Please try again.'], 10 timer: 4000 11 }]); 12 } 13 } 14 15 function syncArchiveToggleState(element, isArchived, text) { 16 if (!element) { 17 return; 18 } 19 20 if (typeof text === 'string' && text.length) { 21 element.textContent = text; 22 } 23 24 element.classList.add('workspace-badge', 'workspace-badge-toggle'); 25 element.classList.remove('workspace-badge--default', 'workspace-badge--success', 'workspace-badge--warning', 'workspace-badge--danger', 'red-text'); 26 element.classList.add(isArchived ? 'workspace-badge--warning' : 'workspace-badge--success'); 27 element.setAttribute('aria-pressed', isArchived ? 'true' : 'false'); 28 element.setAttribute('data-archive-active', isArchived ? 'true' : 'false'); 29 } 30 31 function requestArchiveToggle(url, onSuccess, onError) { 32 if (typeof window.fetch === 'function') { 33 window.fetch(url, { 34 credentials: 'same-origin', 35 headers: { 36 'X-Requested-With': 'XMLHttpRequest' 37 } 38 }).then(function (response) { 39 if (!response.ok) { 40 throw new Error('Request failed'); 41 } 42 43 return response.json(); 44 }).then(onSuccess).catch(onError); 45 return; 46 } 47 48 onError(); 49 } 50 51 function initArchiveStatusToggles(root) { 52 internals.each(internals.queryAll('.js-archive[data-href]', root || document), function (toggle) { 53 if (toggle.dataset.edArchiveToggleBound === 'true') { 54 return; 55 } 56 57 syncArchiveToggleState( 58 toggle, 59 toggle.getAttribute('data-archive-active') === 'true' || toggle.classList.contains('red-text'), 60 (toggle.textContent || '').trim() 61 ); 62 63 toggle.dataset.edArchiveToggleBound = 'true'; 64 toggle.setAttribute('type', 'button'); 65 toggle.setAttribute('role', 'button'); 66 67 toggle.addEventListener('click', function (event) { 68 var nextUrl = toggle.getAttribute('data-href'); 69 var previousText = (toggle.textContent || '').trim(); 70 var previousState = toggle.getAttribute('data-archive-active') === 'true'; 71 72 event.preventDefault(); 73 74 if (!nextUrl || toggle.getAttribute('aria-busy') === 'true') { 75 return; 76 } 77 78 toggle.setAttribute('aria-busy', 'true'); 79 toggle.textContent = '...'; 80 81 requestArchiveToggle(nextUrl, function (data) { 82 syncArchiveToggleState(toggle, !!(data && data.archived), data && data.text ? data.text : previousText); 83 toggle.removeAttribute('aria-busy'); 84 }, function () { 85 syncArchiveToggleState(toggle, previousState, previousText); 86 toggle.removeAttribute('aria-busy'); 87 showToggleErrorMessage(); 88 }); 89 }); 90 }); 91 } 92 93 function initSharedLayout(options) { 94 var settings = options || {}; 95 96 if (typeof internals.initBootstrapCompat === 'function') { 97 internals.initBootstrapCompat(); 98 } 99 100 if (typeof internals.patchSelectpickerTitles === 'function') { 101 internals.patchSelectpickerTitles(); 102 } 103 104 if (typeof internals.initPopupLinks === 'function') { 105 internals.initPopupLinks(settings.popupOptions || {}); 106 } 107 108 if (typeof internals.initDateInputHelpers === 'function') { 109 internals.initDateInputHelpers(settings.dateSelector || 'div.date'); 110 } 111 112 if (typeof internals.initScrollToTop === 'function') { 113 internals.initScrollToTop(settings.scrollToTop || {}); 114 } 115
116 if (typeof internals.initCheckboxGroups === 'function') { 117 internals.initCheckboxGroups(); 118 } 119 120 if (typeof internals.initRadioButtonGroups === 'function') { 121 internals.initRadioButtonGroups(); 122 } 123 124 initArchiveStatusToggles(settings.root || document); 125 126 if (settings.flashMessages && settings.flashMessages.length) { 127 internals.showFlashMessages(settings.flashMessages); 128 } 129 } 130 131 internals.initArchiveStatusToggles = initArchiveStatusToggles; 132 internals.initSharedLayout = initSharedLayout; 133})(window, document);
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.