-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorio.js
213 lines (144 loc) · 4.72 KB
/
tutorio.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
console.log('TUTORIO START');
/* loadScripts from another files */
var _URL = "http://mroczna.stronazen.pl/";
//var _URL = "";
var _includePATH = "tutorio-inc/";
var _tplPATH = "tutorio-inc/tpl";
var _jsonPATH = "tutorio-inc/json";
var _eventsPATH = "tutorio-inc/events";
/* SCRIPT INCLUDE */
var loadScriptQueue = {};
function loadScript(url, callback)
{
if(loadScriptQueue[url]){
callback();
}else{
loadScriptQueue[url] = true;
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.id = url;
script.type = 'text/javascript';
script.src = url;
script.onreadystatechange = callback;
script.onload = callback;
head.appendChild(script);
}
}
/*function reloadScript(url){
var element = document.getElementById(url);
element.outerHTML = "";
delete element;
console.log(loadScriptQueue);
}*/
function recreateNode(el, withChildren) {
if (withChildren) {
el.parentNode.replaceChild(el.cloneNode(true), el);
} else {
var newEl = el.cloneNode(false);
while (el.hasChildNodes()) newEl.appendChild(el.firstChild);
el.parentNode.replaceChild(newEl, el);
}
}
/* ----------------------------------------------------------- */
/* EXAMPLE */
/*loadScript("example.js",function(){
alert('download-script-init');
});*/
/* init firebase */
/*loadScript("https://www.gstatic.com/firebasejs/3.6.3/firebase.js",function(){
var config = {
apiKey: "AIzaSyDdb230Z84rg8b4_tObGZCa7cwF7HvxO6s",
authDomain: "tutorio-f07f8.firebaseapp.com",
databaseURL: "https://tutorio-f07f8.firebaseio.com",
storageBucket: "tutorio-f07f8.appspot.com",
messagingSenderId: "9098244104"
};
//firebase.initializeApp(config);
var provider = new firebase.auth.FacebookAuthProvider();
provider.setCustomParameters({
'display': 'popup'
});
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Facebook Access Token. You can use it to access the Facebook API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
//var contactsRef = firebase.child('contacts');
});*/
/* ----------------------------------------------------------- */
var main_target;
var set_step;
var storage_obj;
var app_obj;
document.addEventListener("DOMContentLoaded", function(event) {
main_target = document.getElementsByTagName('body')[0];
/* API */
loadScript(_URL+_includePATH+"api.js",function(){
console.log('api.js loaded');
});
/* RUN APP */
/* init preloader */
loadScript(_URL+_includePATH+"preloader.js",function(){
main_target.appendChild(preloader);
//document.getElementsByTagName('body')[0].appendChild(preloader);
/* AJAX init */
loadScript(_URL+_includePATH+"xhr.js",function(){
/* TPL library */
loadScript(_URL+_includePATH+"dotjs.min.js",function(){
/* Load bottom bar */
load_content(function(res) {
/* Load sidebar */
load_content(function(res) {
/* Register app object */
loadFile(function(res) {
app_obj = JSON.parse(res);
}, _URL+_jsonPATH+"/app.json", null, function(res) {console.log(res)}, "GET");
/* Load tutorials */
if( storage('check','storage_obj') == undefined){
loadFile(function(res) {
load_sidebar_unit(storage_obj = JSON.parse(res));
}, _URL+_jsonPATH+"/wordpress-example-tuts.json", null, function(res) {console.log(res)}, "GET");
}else{
storage('load','storage_obj');
load_sidebar_unit(storage_obj);
}
},"sidebar.html",{},main_target);
},"bottom-bar.html",{'title':'TUTOR.IO'},main_target);
load_content(function(res) {
},"modal.html",{},main_target);
load_content(function(res) {
},"targeter.html",{},main_target);
load_content(function(res) {
},"app-object-preview.tpl",{},main_target);
/* load sound */
/* TODO cross browser problem */
/*load_content(function(res) {
},"sound-set.html",{},main_target);*/
});
});
});
var load_sidebar_unit = function(res){
/* Load sidebar unit */
load_content(function(res) {
/* Load events */
loadScript(_URL+_eventsPATH+"/sidebar-events.js",function(){
sidebar_events();
});
/* bottombar events */
loadScript(_URL+_eventsPATH+"/bottombar-events.js",function(){
bottombar_events();
});
},"sidebar-unit.html",storage_obj,document.getElementById('io-sidebar-list'));
}
});