1/** 2 * RTEC common: processing state and loading spinner. 3 * Usable on front end and admin. Requires jQuery. 4 */ 5(function($) { 6 'use strict'; 7 8 var SPINNER_HTML = '<div class="rtec-spinner-container"><div class="rtec-spinner-circle"></div></div>'; 9 10 /** 11 * Returns the canonical spinner markup (container + circle). 12 * Use with startProcessing or append manually into a container that has rtec-is-processing. 13 * 14 * @return {string} HTML string 15 */ 16 function spinnerHTML() { 17 return SPINNER_HTML; 18 } 19 20 /** 21 * Start processing state: add spinner and optional wrapper. 22 * 23 * @param {jQuery} $target - Element to wrap or attach spinner to 24 * @param {string} context - 'button' | 'area' | 'element' 25 * @param {boolean} [before=false] - For 'button' only: insert spinner before (true) or after (false) the button 26 */ 27 function startProcessing($target, context, before) { 28 if (before === undefined) { 29 before = false; 30 } 31 if (context === 'button') { 32 $target.attr('aria-busy', 'true'); 33 $target.wrap('<div class="rtec-processing-wrap-flex rtec-is-processing"></div>'); 34 $target.addClass('rtec-fade').prop('disabled', true); 35 if (before) { 36 $target.before(spinnerHTML()); 37 } else { 38 $target.after(spinnerHTML()); 39 } 40 } else if (context === 'area') { 41 $target.wrap('<div class="rtec-processing-wrap rtec-is-processing"></div>'); 42 $target.addClass('rtec-fade'); 43 $target.after(spinnerHTML()); 44 } else if (context === 'element') { 45 $target.addClass('rtec-fade rtec-is-processing'); 46 $target.append(spinnerHTML()); 47 } 48 } 49 50 /** 51 * Stop processing state: remove spinner and wrapper, re-enable button. 52 * Uses a short delay (500ms) before cleanup for a smooth transition. 53 * 54 * @param {jQuery} $target - Same element passed to startProcessing 55 * @param {string} context - Same context as startProcessing: 'button' | 'area' | 'element' 56 */ 57 function stopProcessing($target, context, immediate) { 58 if (immediate === undefined) { 59 immediate = false; 60 } 61 var cleanup = function() { 62 if (context === 'button') { 63 $target.closest('.rtec-processing-wrap-flex').find('.rtec-spinner-container').remove(); 64 $target.unwrap('.rtec-processing-wrap-flex'); 65 $target.removeClass('rtec-fade').prop('disabled', false).attr('aria-busy', 'false'); 66 } else if (context === 'area') { 67 $target.closest('.rtec-processing-wrap').find('.rtec-spinner-container').remove(); 68 $target.removeClass('rtec-fade'); 69 $target.unwrap('.rtec-processing-wrap'); 70 } else if (context === 'element') { 71 $target.find('.rtec-spinner-container').remove(); 72 $target.removeClass('rtec-fade rtec-is-processing'); 73 } 74 }; 75 if (immediate) { 76 cleanup(); 77 return; 78 } 79 setTimeout(cleanup, 500); 80 } 81 82 /** 83 * Show loading on an element: add rtec-is-processing and append spinner. 84 * Use when the spinner should overlay the content (e.g. modal or panel). 85 * 86 * @param {jQuery} $element - Container (should have position: relative or similar) 87 */ 88 function showLoading($element) { 89 $element.addClass('rtec-is-processing'); 90 if ($element.find('.rtec-spinner-container').length === 0) { 91 $element.append(spinnerHTML()); 92 } 93 } 94 95 /** 96 * Hide loading: remove class and fade out then remove spinner. 97 * 98 * @param {jQuery} $element - Same container passed to showLoading 99 */ 100 function hideLoading($element) { 101 $element.removeClass('rtec-is-processing rtec-fade'); 102 $element.find('.rtec-spinner-container').fadeOut(200, function() { 103 $(this).remove(); 104 }); 105 } 106 107 window.RtecCommon = { 108 spinnerHTML: spinnerHTML, 109 startProcessing: startProcessing, 110 stopProcessing: stopProcessing, 111 showLoading: showLoading, 112 hideLoading: hideLoading 113 }; 114})(jQuery);
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.