jsharmony-cms
Version:
100 lines (83 loc) • 3.6 kB
JavaScript
/*
Copyright 2019 apHarmony
This file is part of jsHarmony.
jsHarmony is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jsHarmony is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this package. If not, see <http://www.gnu.org/licenses/>.
*/
exports = module.exports = function(cms){
var _this = this;
this.loadQueue = [];
this.isLoading = false;
this.defaultLoadObj = {main:1};
this.onSquashedClick = [];
this.onMouseDown = [];
this.onMouseUp = [];
this.onLoadingComplete = [];
this.StartLoading = function(obj, desc){
if(!obj) obj = _this.defaultLoadObj;
var foundObj = false;
for(var i=0;i<this.loadQueue.length;i++){ if(obj===this.loadQueue[i]) foundObj = true; }
if(!foundObj) this.loadQueue.push(obj);
if(this.isLoading) return;
this.isLoading = true;
var loader_obj = document.getElementById('jsHarmonyCMSLoading');
if(loader_obj){
if(cms.isInitialized) loader_obj.style.backgroundColor = 'rgba(0,0,0,0.2)';
if(cms.jsh) cms.jsh.$('#jsHarmonyCMSLoading').fadeIn();
else loader_obj.style.display = 'block';
}
else {
loader_obj = document.createElement('div');
loader_obj.id = 'jsHarmonyCMSLoading';
//loader_obj.style.backgroundColor = 'rgba(0,0,0,0.5)';
loader_obj.style.backgroundColor = 'rgba(255,255,255,1)';
loader_obj.style.position = 'fixed';
loader_obj.style.top = '0px';
loader_obj.style.left = '0px';
loader_obj.style.bottom = '0px';
loader_obj.style.width = '100%';
loader_obj.style.zIndex = 2147483642;
loader_obj.style.cursor = 'wait';
document.body.appendChild(loader_obj);
var loader_img_container = document.createElement('div');
loader_img_container.style.position = 'absolute';
loader_img_container.style.top = '50%';
loader_img_container.style.left = '50%';
loader_obj.appendChild(loader_img_container);
var loader_img = document.createElement('img');
loader_img.src = cms._baseurl + 'images/loading-cms.svg';
loader_img.style.height = '100px';
loader_img.style.width = '100px';
loader_img.style.position = 'relative';
loader_img.style.top = '-50px';
loader_img.style.left = '-50px';
loader_img_container.appendChild(loader_img);
}
};
this.StopLoading = function(obj){
if(!obj) obj = _this.defaultLoadObj;
for(var i=0;i<this.loadQueue.length;i++){ if(obj===this.loadQueue[i]){ this.loadQueue.splice(i, 1); i--; } }
if(this.loadQueue.length) return;
this.isLoading = false;
var triggerLoadingComplete = function(){ for(var i=0;i<_this.onLoadingComplete.length;i++) _this.onLoadingComplete[i](); };
if(cms.jsh){
cms.jsh.$('#jsHarmonyCMSLoading').stop(true).fadeOut('normal', function(){ triggerLoadingComplete(); });
}
else{
document.getElementById('jsHarmonyCMSLoading').style.display = 'none';
triggerLoadingComplete();
}
};
this.ClearLoading = function(){
this.loadQueue = [];
this.StopLoading();
};
};