/
app-analyzer-init.js
109 lines (83 loc) · 4.34 KB
/
app-analyzer-init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var app = app || {vars:{},u:{}}; //make sure app exists.
app.rq = app.rq || []; //ensure array is defined. rq = resource queue.
app.rq.push(['extension',0,'store_prodlist','extensions/store_prodlist.js']);
app.rq.push(['extension',0,'store_navcats','extensions/store_navcats.js']);
app.rq.push(['extension',0,'store_search','extensions/store_search.js']);
app.rq.push(['extension',0,'store_product','extensions/store_product.js']);
app.rq.push(['extension',0,'store_crm','extensions/store_crm.js']);
app.rq.push(['extension',0,'analyzer','app-analyzer.js','startMyProgram']);
app.rq.push(['script',0,'resources/jquery.showloading-v1.0.jt.js']);
app.rq.push(['script',0,'resources/jquery.ui.anyplugins.js']); //in zero pass in case product page is first page.
app.rq.push(['script',0,'model.js']); //'validator':function(){return (typeof zModel == 'function') ? true : false;}}
app.rq.push(['script',0,'includes.js']); //','validator':function(){return (typeof handlePogs == 'function') ? true : false;}})
app.rq.push(['script',0,'controller.js']);
/*
This function is overwritten once the controller is instantiated.
Having a placeholder allows us to always reference the same messaging function, but not impede load time with a bulky error function.
*/
app.u.throwMessage = function(m) {
alert(m);
}
app.u.howManyPassZeroResourcesAreLoaded = function(debug) {
var L = app.vars.rq.length;
var r = 0; //what is returned. total # of scripts that have finished loading.
for(var i = 0; i < L; i++) {
if(app.vars.rq[i][app.vars.rq[i].length - 1] === true) {
r++;
}
if(debug) {app.u.dump(" -> "+i+": "+app.vars.rq[i][2]+": "+app.vars.rq[i][app.vars.rq[i].length -1]);}
}
return r;
}
//gets executed once controller.js is loaded.
//check dependencies and make sure all other .js files are done, then init controller.
//function will get re-executed if not all the scripts in app.vars.scripts pass 1 are done loading.
//the 'attempts' var is incremented each time the function is executed.
app.u.initMVC = function(attempts){
app.u.dump("app.u.initMVC activated ["+attempts+"]");
var includesAreDone = true;
//what percentage of completion a single include represents (if 10 includes, each is 10%).
var percentPerInclude = (100 / app.vars.rq.length);
var resourcesLoaded = app.u.howManyPassZeroResourcesAreLoaded();
var percentComplete = Math.round(resourcesLoaded * percentPerInclude); //used to sum how many includes have successfully loaded.
//make sure precentage is never over 100
if(percentComplete > 100 ) {
percentComplete = 100;
}
$('#appPreViewProgressBar').val(percentComplete);
$('#appPreViewProgressText').empty().append(percentComplete+"% Complete");
if(resourcesLoaded == app.vars.rq.length) {
var clickToLoad = false;
if(clickToLoad){
$('#loader').fadeOut(1000);
$('#clickToLoad').delay(1000).fadeIn(1000).click(function() {
app.u.loadApp();
});
} else {
app.u.loadApp();
}
}
else if(attempts > 10) {
app.u.dump("WARNING! something went wrong in init.js");
//this is 10 seconds of trying. something isn't going well.
$('#appPreView').empty().append("<h2>Uh Oh. Something seems to have gone wrong. </h2><p>Several attempts were made to load the store but some necessary files were not found or could not load. We apologize for the inconvenience. Please try 'refresh' and see if that helps.<br><b>If the error persists, please contact the site administrator</b><br> - dev: see console.</p>");
app.u.howManyPassZeroResourcesAreLoaded(true);
}
else {
setTimeout("app.u.initMVC("+(attempts+1)+")",250);
}
}
app.u.loadApp = function() {
//instantiate controller. handles all logic and communication between model and view.
//passing in app will extend app so all previously declared functions will exist in addition to all the built in functions.
//tmp is a throw away variable. app is what should be used as is referenced within the mvc.
app.vars.rq = null; //to get here, all these resources have been loaded. nuke record to keep DOM clean and avoid any duplication.
var tmp = new zController(app);
//instantiate wiki parser.
myCreole = new Parse.Simple.Creole();
}
//Any code that needs to be executed after the app init has occured can go here.
//will pass in the page info object. (pageType, templateID, pid/navcat/show and more)
app.u.appInitComplete = function(P) {
app.u.dump("Executing myAppIsLoaded code...");
}