1/** 2 * Contains general utilities. 3 * 4 * @constructor 5 */ 6function GeneralUtility() { 7} 8 9 10 11/** 12 * Initializes bootstrap elements. 13 * 14 * @param {string} type What type of bootstrap to initialize (tab, nav ...) 15 * @param {object} element Element to initialize bootstrap elements for 16 * @returns {void} 17 */ 18GeneralUtility.initializeBootstrap = function(type, element) { 19 if (!element || element === null) { 20 return; 21 } 22}; 23 24 25 26/** 27 * Adds a class to an selector for a certain amout of time, then removes it 28 * again. 29 * 30 * @param {object} element Element to add class to 31 * @param {string} newClass Class to add 32 * @param {int} period (Optional) Live-Time of the class in ms, defaults to 1000ms 33 * @returns {void} 34 */ 35GeneralUtility.addTimedClass = function(element, newClass, period) { 36 if (period === undefined) { 37 period = 1000; 38 } 39 40 if (!element || element.length <= 0 || !newClass) { 41 return; 42 } 43 44 element.addClass(newClass); 45 setTimeout(function() { 46 element.removeClass(newClass); 47 }, period); 48}; 49 50 51 52/** 53 * Destroys an element after time has passed. 54 * 55 * @param {type} element Element to destroy 56 * @param {type} time (Optional) Time after which the element will be destroyed (defaults to 1000) 57 * @param {bool} fase (Optional) Whether to fade out (defaults to true) 58 * @returns {void} 59 */ 60GeneralUtility.destroyAfterTime = function(element, time, fade) { 61 if (time === undefined) { 62 time = 1000; 63 } 64 65 if (fade === undefined) { 66 fade = true; 67 } 68 69 window.setTimeout(function() { 70 if (fade) { 71 element.fadeOut(function() { 72 element.remove(); 73 }); 74 } 75 else { 76 element.remove(); 77 } 78 }, time) 79}; 80 81 82 83/** 84 * Adds a loading spinner to an element. 85 * 86 * @param {object} element Element 87 * @param {string} (Optional) size 'sm', 'md' or 'lg' (defaults to 'md') 88 * @param {boolean} (Optional) doCenter Whether to center the spinner or not (defaults to true) 89 * @param {boolean} (Optional) showOverlay Whether to show a overlay or not (defaults to false) 90 * @returns {object} Newly created spinner container 91 */ 92GeneralUtility.addSpinner = function(element, size, doCenter, showOverlay) { 93 if (size === undefined) { 94 size = 'md'; 95 } 96 if (doCenter === undefined) { 97 doCenter = true; 98 } 99 if (showOverlay === undefined) { 100 showOverlay = false; 101 } 102
103 var spinner = $('<div />', { 104 'class': 'spinner ' + size, 105 'html': '<div class="bounce-1"></div><div class="bounce-2"></div><div class="bounce-3"></div>' 106 }); 107 108 if (doCenter) { 109 spinner.addClass('center'); 110 } 111 112 if (showOverlay) { 113 var container = $('<div />', { 114 'class': 'spinner-overlay' 115 }).appendTo(element); 116 117 container.hide(); 118 container.fadeIn(); 119 container.append(spinner); 120 121 return container; 122 } 123 124 element.append(spinner); 125 return spinner; 126}; 127 128/** 129 * Removes a loading spinner, if existing, from an element. 130 * 131 * @param {object} element Element 132 * @returns {void} 133 */ 134GeneralUtility.removeSpinner = function(element) { 135 element.find('.spinner').remove(); 136 element.find('.spinner-overlay').remove(); 137};
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.