1var loading = {}; 2 3loading.defaultRelative = 'body'; 4 5loading.setup = function(element) { 6 loading.setRelative(element); 7 if (loading.isLoaded()) { 8 return; 9 } 10 11 loading.element = null; 12 loading.loaded = true; 13 loading.showing = false; 14 15 loading.create(); 16} 17 18loading.isLoaded = function() { 19 return loading.loaded; 20} 21 22loading.isShowing = function() { 23 return loading.showing; 24} 25 26loading.canShow = function() { 27 var path = window.location.pathname; 28 29 if (/\/(compra|cliente|pedido|catalogo)\/.*/i.test(path) || /\/(catalogo)\//) { 30 return true; 31 } 32 33 return false; 34} 35 36loading.setRelative = function(element) { 37 element = element || loading.defaultRelative; 38 39 // Caso mobile, sempre será fullscreen 40 if (helper.screenWidth() <= 968) { 41 element = loading.defaultRelative; 42 } 43 44 if (element !== loading.relative) { 45 loading.removeRelativeClass(); 46 loading.showing = false; 47 loading.loaded = false; 48 $(loading.element).remove(); 49 } 50 51 loading.relative = element; 52} 53 54loading.template = function() { 55 var template = '<div id=\'loading\'>'; 56 template += '<div id=\'loader\'>'; 57 template += '<div class=\'spinner\'>'; 58 template += '<div class=\'ball ball-1\'> </div>'; 59 template += '<div class=\'ball ball-2\'> </div>'; 60 template += '<div class=\'ball ball-3\'> </div>'; 61 template += '<div class=\'ball ball-4\'> </div>'; 62 template += '</div>'; 63 template += '</div>'; 64 template += '<div class=\'loading-backdrop\'></div>'; 65 template += '</div>'; 66 67 return template; 68} 69 70loading.create = function() { 71 loading.element = $(loading.template()); 72 $(loading.relative).append(loading.element); 73 74 loading.element.hide(); 75} 76 77/** 78 * Function display the loading fullscreen by default, otherwise display on the element passed by parameter 79 * 80 * Always remember to use 'loading.hide()' on the callback function 81 * @param {string} [element=null] - Element selector, wich the loading will be displayed 82 */ 83loading.show = function(element) { 84 loading.setup(element); 85 if (loading.isShowing() || !loading.canShow()) { 86 return; 87 } 88 89 loading.addRelativeClass(); 90 loading.showing = true; 91 loading.element.show(); 92} 93 94/** 95 * Function hide the actual loading if displayed 96 */ 97loading.hide = function() { 98 loading.setup(); 99 if (!loading.isShowing()) { 100 return; 101 } 102 103 loading.removeRelativeClass(); 104 loading.showing = false; 105 loading.element.hide(); 106} 107 108loading.addRelativeClass = function() { 109 element = loading.relative || loading.defaultRelative; 110 111 $(element).addClass('loading-relative'); 112} 113 114loading.removeRelativeClass = function() { 115 element = loading.relative || loading.defaultRelative; 116 117 $(element).removeClass('loading-relative'); 118}
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.