-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathapp-quickstart-init.js
187 lines (153 loc) · 9.14 KB
/
app-quickstart-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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
myApp.rq.push(['script',0,(document.location.protocol == 'file:') ? myApp.vars.testURL+'jsonapi/config.js' : myApp.vars.baseURL+'jsonapi/config.js',function(){
//in some cases, such as the zoovy UI, zglobals may not be defined. If that's the case, certain vars, such as jqurl, must be passed in via P in initialize:
// myApp.u.dump(" ->>>>>>>>>>>>>>>>>>>>>>>>>>>>> zGlobals is an object");
myApp.vars.username = zGlobals.appSettings.username.toLowerCase(); //used w/ image URL's.
//need to make sure the secureURL ends in a / always. doesn't seem to always come in that way via zGlobals
myApp.vars.secureURL = zGlobals.appSettings.https_app_url;
myApp.vars.domain = zGlobals.appSettings.sdomain; //passed in ajax requests.
myApp.vars.jqurl = (document.location.protocol === 'file:') ? myApp.vars.testURL+'jsonapi/' : '/jsonapi/';
}]); //The config.js is dynamically generated.
myApp.rq.push(['extension',0,'order_create','extensions/checkout/extension.js']);
myApp.rq.push(['extension',0,'cco','extensions/cart_checkout_order.js']);
myApp.rq.push(['extension',0,'store_routing','extensions/store_routing.js']);
myApp.rq.push(['extension',0,'store_prodlist','extensions/store_prodlist.js']);
myApp.rq.push(['extension',0,'store_navcats','extensions/store_navcats.js']);
myApp.rq.push(['extension',0,'store_search','extensions/store_search.js']);
myApp.rq.push(['extension',0,'store_product','extensions/store_product.js']);
myApp.rq.push(['extension',0,'cart_message','extensions/cart_message/extension.js']);
myApp.rq.push(['extension',0,'store_crm','extensions/store_crm.js']);
myApp.rq.push(['extension',0,'store_tracking','extensions/store_tracking.js']);
myApp.rq.push(['extension',0,'quickstart','app-quickstart.js','startMyProgram']);
//myApp.rq.push(['extension',0,'entomologist','extensions/entomologist/extension.js']);
//myApp.rq.push(['extension',0,'tools_animation','extensions/tools_animation.js']);
// 201405 - Deprecated for Universal Analytics
//myApp.rq.push(['extension',1,'google_analytics','extensions/partner_google_analytics.js','startExtension']);
//myApp.rq.push(['extension',1,'tools_ab_testing','extensions/tools_ab_testing.js']);
//myApp.rq.push(['extension',0,'partner_addthis','extensions/partner_addthis.js']);
//myApp.rq.push(['extension',1,'resellerratings_survey','extensions/partner_buysafe_guarantee.js','startExtension']); /// !!! needs testing.
//myApp.rq.push(['extension',1,'buysafe_guarantee','extensions/partner_buysafe_guarantee.js','startExtension']);
//myApp.rq.push(['extension',1,'powerReviews_reviews','extensions/partner_powerreviews_reviews.js','startExtension']);
//myApp.rq.push(['extension',0,'magicToolBox_mzp','extensions/partner_magictoolbox_mzp.js','startExtension']); // (not working yet - ticket in to MTB)
myApp.rq.push(['script',0,myApp.vars.baseURL+'resources/jquery.showloading-v1.0.jt.js']); //used pretty early in process..
myApp.rq.push(['script',0,myApp.vars.baseURL+'resources/jquery.ui.anyplugins.js']); //in zero pass because it's essential to rendering and error handling.
myApp.rq.push(['script',0,myApp.vars.baseURL+'resources/tlc.js']); //in zero pass cuz you can't render a page without it..
myApp.rq.push(['css',1,myApp.vars.baseURL+'resources/anyplugins.css']);
myApp.rq.push(['script',0,myApp.vars.baseURL+'resources/jsonpath.0.8.0.js']); //used pretty early in process..
//once peg is loaded, need to retrieve the grammar file. Order is important there. This will validate the file too.
myApp.u.loadScript(myApp.vars.baseURL+'resources/peg-0.8.0.js',function(){
myApp.model.getGrammar(myApp.vars.baseURL+"resources/pegjs-grammar-20140203.pegjs");
}); // ### TODO -> callback on RQ.push wasn't getting executed. investigate.
//gets executed from app-admin.html as part of controller init process.
//progress is an object that will get updated as the resources load.
/*
'passZeroResourcesLength' : [INT],
'passZeroResourcesLoaded' : [INT],
'passZeroTimeout' : null //the timeout instance running within loadResources that updates this object. it will run indef unless clearTimeout run here OR all resources are loaded.
*/
myApp.u.showProgress = function(progress) {
function showProgress(attempt) {
if(progress.passZeroResourcesLength == progress.passZeroResourcesLoaded) {
//All pass zero resources have loaded.
//the app will handle hiding the loading screen.
myApp.u.appInitComplete();
}
else if(attempt > 150) {
//hhhhmmm.... something must have gone wrong.
clearTimeout(progress.passZeroTimeout); //end the resource loading timeout.
$('.appMessaging','#appPreView').anymessage({'message':'Init failed to load all the resources within a reasonable number of attempts.','gMessage':true,'persistent':true});
}
else {
var percentPerInclude = (100 / progress.passZeroResourcesLength);
var percentComplete = Math.round(progress.passZeroResourcesLength * percentPerInclude); //used to sum how many includes have successfully loaded.
// dump(" -> percentPerInclude: "+percentPerInclude+" and percentComplete: "+percentComplete);
$('#appPreViewProgressBar').val(percentComplete);
$('#appPreViewProgressText').empty().append(percentComplete+"% Complete");
attempt++;
setTimeout(function(){showProgress(attempt);},250);
}
}
showProgress(0)
}
//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)
myApp.u.appInitComplete = function() {
// myApp.u.dump("Executing myAppIsLoaded code...");
myApp.ext.order_create.checkoutCompletes.push(function(vars,$checkout){
dump(" -> begin checkoutCOmpletes code: "); dump(vars);
var cartContentsAsLinks = encodeURIComponent(myApp.ext.cco.u.cartContentsAsLinks(myApp.data[vars.datapointer].order));
//append this to
$("[data-app-role='thirdPartyContainer']",$checkout).append("<h2>What next?</h2><div class='ocm ocmFacebookComment pointer zlink marginBottom checkoutSprite '></div><div class='ocm ocmTwitterComment pointer zlink marginBottom checkoutSprit ' ></div><div class='ocm ocmContinue pointer zlink marginBottom checkoutSprite'></div>");
$('.ocmTwitterComment',$checkout).click(function(){
window.open('http://twitter.com/home?status='+cartContentsAsLinks,'twitter');
window[myApp.vars.analyticsPointer]('send', 'event','Checkout','User Event','Tweeted about order');
});
//the fb code only works if an appID is set, so don't show banner if not present.
if(myApp.u.thisNestedExists("zGlobals.thirdParty.facebook.appId") && typeof FB == 'object') {
$('.ocmFacebookComment',$checkout).click(function(){
myApp.ext.quickstart.thirdParty.fb.postToWall(cartContentsAsLinks);
ga('send','event','Checkout','User Event','FB message about order');
window[myApp.vars.analyticsPointer]('send', 'event','Checkout','User Event','FB message about order');
});
}
else {$('.ocmFacebookComment').hide()}
});
//Cart Messaging Responses.
myApp.cmr.push(['chat.join',function(message){
if(message.FROM == 'ADMIN') {
var $ui = myApp.ext.quickstart.a.showBuyerCMUI();
$("[data-app-role='messageInput']",$ui).show();
$("[data-app-role='messageHistory']",$ui).append("<p class='chat_join'>"+message.FROM+" has joined the chat.<\/p>");
$('.show4ActiveChat',$ui).show();
$('.hide4ActiveChat',$ui).hide();
}
}]);
myApp.cmr.push(['goto',function(message,$context){
var $history = $("[data-app-role='messageHistory']",$context);
$P = $("<P>")
.addClass('chat_post')
.append("<span class='from'>"+message.FROM+"<\/span> has sent over a "+(message.vars.pageType || "")+" link for you within this store. <span class='lookLikeLink'>Click here<\/span> to view.")
.on('click',function(){
showContent(myApp.ext.quickstart.u.whatAmIFor(message.vars),message.vars);
});
$history.append($P);
$history.parent().scrollTop($history.height());
}]);
}
//this will trigger the content to load on app init. so if you push refresh, you don't get a blank page.
//it'll also handle the old 'meta' uri params.
//this will trigger the content to load on app init. so if you push refresh, you don't get a blank page.
//it'll also handle the old 'meta' uri params.
myApp.router.appendInit({
'type':'function',
'route': function(v){
return {'init':true} //returning anything but false triggers a match.
},
'callback':function(f,g){
dump(" -> triggered callback for appendInit");
g = g || {};
if(g.uriParams.seoRequest){
showContent(g.uriParams.pageType, g.uriParams);
}
else if (g.uriParams.marketplace){
var infoObj = {"pid":g.uriParams.product};
if(g.uriParams.sku){
infoObj.sku = g.uriParams.sku;
}
showContent("product",infoObj);
}
else if(document.location.hash) {
myApp.u.dump('triggering handleHash');
myApp.router.handleHashChange();
}
else {
//IE8 didn't like the shortcut to showContent here.
myApp.ext.quickstart.a.showContent('homepage');
}
if(g.uriParams && g.uriParams.meta) {
myApp.ext.cco.calls.cartSet.init({'want/refer':infoObj.uriParams.meta,'cartID':_app.model.fetchCartID()},{},'passive');
}
if(g.uriParams && g.uriParams.meta_src) {
myApp.ext.cco.calls.cartSet.init({'want/refer_src':infoObj.uriParams.meta_src,'cartID':_app.model.fetchCartID()},{},'passive');
}
}
});