-
Notifications
You must be signed in to change notification settings - Fork 247
/
engine.js
302 lines (266 loc) · 11.4 KB
/
engine.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
var chapters=document.getElementsByTagName('a');
var anchorContainer= document.createElement("div");
var anchorImage= document.createElement("img");
var anchor= document.createElement("div");
var bookBody = document.getElementsByClassName('book-body');
var currentHeight= 0;
var currentWidth= 0;
// Remove Header number appended by plugin
function removeHeaders(){
var head2 = document.getElementsByTagName('h2');
var head3 = document.getElementsByTagName('h3');
var head4 = document.getElementsByTagName('h4');
for(var i=0; i<head4.length; i++){
var title= head4[i].innerHTML;
var dotpos= 0;
if(title.includes(".")){
dotpos= getPosition(title,".",3);
}
var newTitle= title.substring(dotpos+1,title.length);
head4[i].innerHTML= newTitle;
}
for(var i=0; i<head3.length; i++){
var title= head3[i].innerHTML;
var dotpos= 0;
if(title.includes(".")){
dotpos= getPosition(title,".",2);
}
var newTitle= title.substring(dotpos+1,title.length);
head3[i].innerHTML= newTitle;
}
for(var i=0; i<head2.length; i++){
var title= head2[i].innerHTML;
if(title.includes("-headref")){
// console.log(head2[i],"header");
head2[i].style= "font-size: 0%";
}
var dotpos= 0;
if(title.includes(".")){
dotpos= getPosition(title,".",1);
}
var newTitle= title.substring(dotpos+1,title.length);
head2[i].innerHTML= newTitle;
}
}
// Helps removeHeaders function
function getPosition(string, subString, index) {
return string.split(subString, index).join(subString).length;
}
// Two buttons for anchor element.
var andBut= document.createElement('span');
andBut.style="height: 40px; width: 100px; background-color: grey; display: inline-block; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin: 10px 10px 10px 10px; padding-bottom: 15px;";
andBut.id="andBut";
anchor.id= "anchor";
var andTxt= document.createElement('p');
andTxt.style= "font-size: 13px; font-weight: bold; color: white;";
andTxt.innerHTML= "Android";
var iosTxt= document.createElement('p');
iosTxt.style= "font-size: 13px; font-weight: bold; color: white;";
iosTxt.innerHTML= "iOS";
var iosBut= document.createElement('span');
iosBut.appendChild(iosTxt);
andBut.appendChild(andTxt);
iosBut.style="height: 40px; width: 100px; background-color: #00b386; display: inline-block; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin: 10px 10px 10px 10px; padding-bottom: 15px; margin-left: 30px;";
iosBut.id="iosBut";
//onClick set androidSelected active
iosBut.onclick= function(){
androidSelected= false;
iosBut.style="height: 40px; width: 100px; background-color: #00b386; display: inline-block; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin: 10px 10px 10px 10px; padding-bottom: 15px; margin-left: 30px;";
andBut.style="height: 40px; width: 100px; background-color: grey; display: inline-block; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin: 10px 10px 10px 10px; padding-bottom: 15px;";
}
andBut.onclick= function(){
androidSelected= true;
iosBut.style="height: 40px; width: 100px; background-color: grey; display: inline-block; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin: 10px 10px 10px 10px; padding-bottom: 15px; margin-left: 30px;";
andBut.style="height: 40px; width: 100px; background-color: #00b386; display: inline-block; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin: 10px 10px 10px 10px; padding-bottom: 15px;";
};
// Style anchor and its chilren
anchor.id= "anchor";
anchor.style= "position: fixed; right: 50px;top: 78px;";
anchorContainer.style= "background: url(https://docs.nativebase.io/docs/assets/iosphone.png) no-repeat;padding: 63px 20px 100px 18px; width: 292px; height: 600px;";
anchorContainer.id= "anchorContainer";
anchorImage.id= "anchorImage";
anchorImage.src='';
//append all children to anchor
anchor.appendChild(iosBut);
anchor.appendChild(andBut);
anchor.appendChild(anchorContainer);
var androidSelected= false;
// Will hold our image urls in a filtered manner
var filterListAndroid= [];
var filterListIos= [];
// Check for URL changes every 200ms
setInterval(function(){
currentHeight= window.innerHeight;
currentWidth= window.innerWidth;
if(currentHeight> 830){
anchor.style= "position: fixed; right: 50px;top: 178px";
}
else if(currentHeight< 830 && currentHeight> 725){
anchor.style= "position: fixed; right: 50px;top: 88px";
}
else if(currentHeight< 725){
anchor.style= "position: fixed; right: 50px;top: 80px";
}
if(currentWidth < 800){
// anchorImage.style="width: 125px !important; height: 240px !important";
// andBut.style ="height: 40px; width: 100px; background-color: grey; display: inline-block; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin:10px 10px !important; padding-bottom: 15px;";
// iosBut.style ="height: 40px; width: 100px; background-color: #00b386; display: inline-block ; margin-right: 5px; text-align: center; cursor: pointer; border-radius: 25px; margin:10px 10 px!important; padding-bottom: 15px; margin-left: 10px !important;";
anchor.style= "position: fixed; right: 50px;top: 80px; width:150px;display:none !important ";
// if(androidSelected){
// anchorContainer.style= "background: url(https://docs.nativebase.io/docs/assets/android.png) no-repeat; padding: 30px 0px 20px 10px; width: 150px; height: 300px; background-position:center;text-align:center;margin:0 auto; background-size:100%"
// } else if(!androidSelected){
// anchorContainer.style= "background: url(https://docs.nativebase.io/docs/assets/iosphone.png) no-repeat;padding: 30px 10px 20px 15px; width: 150px; height: 300px; background-position:center;text-align:center;margin:0 auto; background-size:100%"
// }
}
if(window.location.href.includes("Components.html")){
if(window.location.href.includes("#Components") || window.location.href.includes("#ref-components")){
anchorImage.style= "width: 0px; height: 0px;"
}
if(window.innerWidth < 1650)
{
document.getElementsByClassName('page-wrapper')[0].style.width= '70%';
}
else if(window.innerWidth > 1650)
{
document.getElementsByClassName('page-wrapper')[0].style.width= '75%';
}
}
// Set Anchor background Phone image with button changes
if(currentWidth > 830){
if(androidSelected){
anchorContainer.style= "background: url(https://docs.nativebase.io/docs/assets/android.png) no-repeat; padding: 42px 0px 68px 10px; width: 292px; height: 600px;"
} else if(!androidSelected){
anchorContainer.style= "background: url(https://docs.nativebase.io/docs/assets/iosphone.png) no-repeat;padding: 63px 20px 100px 15px; width: 292px; height: 600px;";
}
}
// Hide useless buttons for our big pages
var nowHref= window.location.href;
if(nowHref.includes("Customize.html")){
$('#goTop').hide();
$('.navigation-next').hide();
$('.navigation-prev').hide();
}
if(nowHref.includes("Example.html") || nowHref.includes("Examples.html")){
$('#goTop').hide();
$('.navigation-next').hide();
$('.navigation-prev').hide();
}
if(nowHref.includes("Components.html")){
$('#goTop').hide();
$('.navigation-next').hide();
$('.navigation-prev').hide();
// Fetch Image ID from URL and set respective image
var hash= nowHref.indexOf("#");
var length= nowHref.length;
var pointer= nowHref.substring(hash+1,length);
this.setImage(pointer);
}
},200);
// set image according to pointer received.
function setImage(pointer){
if(androidSelected){
for(var i=0;i< filterListAndroid.length;i++){
if(filterListAndroid[i].alt.includes(pointer)){
if(anchorImage.src !== filterListAndroid[i].src){
anchorImage.src= filterListAndroid[i].src;
anchorImage.style="width: 270px; height: 470px"
anchorContainer.appendChild(anchorImage);
}
}
}
}
else if(!androidSelected){
for(var i=0;i< filterListIos.length;i++){
if(filterListIos[i].alt.includes(pointer)){
if(anchorImage.src !== filterListIos[i].src){
anchorImage.src= filterListIos[i].src;
anchorImage.style="width: 256px; height: 453px"
anchorContainer.appendChild(anchorImage);
}
}
}
}
}
require(['gitbook', 'jQuery'], function(gitbook, $) {
gitbook.events.bind("page.change", function(e, config) {
removeHeaders();
// Useless buttons removed appended by plugins
$('#book-search-input').hide();
$('.navigation-prev').hide();
$('#anchors-navbar').hide();
$('#goTop').hide();
var and=0;
var ios=0;
// Making summary.md image clickable
for(var i=0; i< chapters.length; i++){
if(chapters[i].href.includes("http://nativebase.io/")){
chapters[i].style= "height: 80px";
}
}
// Populate our filter image arrays
var list=document.getElementsByTagName("img");
for(var i=0; i< list.length; i++){
if(list[i].alt.includes("Preview")){
list[i].style.display= "none";
if(list[i].alt.includes("android")){
filterListAndroid[and]= list[i];
and++;
}
else if(list[i].alt.includes("ios")){
filterListIos[ios]= list[i];
ios++;
}
}
}
// set anchor visible for Components page
if(window.location.href.includes("Components.html")){
if(anchorImage.src != '' && anchorImage.src != undefined){
$('.page-wrapper').append(anchor);
$("#anchor").show();
}
// Also show children from summary table
for(var i=0; i< chapters.length; i++){
if(chapters[i].href.includes("Components.html")){
chapters[i].style.display= "inherit";
}
}
}
// Remove anchor for other pages
else if(!(window.location.href.includes("Components.html"))){
$("#anchor").hide();
for(var i=0; i< chapters.length; i++){
if(chapters[i].href.includes("Components.html") && !(chapters[i].href.includes('#Components'))){
chapters[i].style.display= "none";
}
}
}
// Display children from summary table
if(window.location.href.includes("Customize.html")){
for(var i=0; i< chapters.length; i++){
if(chapters[i].href.includes("Customize.html")){
chapters[i].style.display= "inherit";
}}
}
// Hide children from summary table
else if(!(window.location.href.includes("Customize.html"))){
for(var i=0; i< chapters.length; i++){
if(chapters[i].href.includes("Customize.html") && !(chapters[i].href.includes('#Customize'))){
chapters[i].style.display= "none";
}}
}
// Display children from summary table
if(window.location.href.includes("Examples.html") || window.location.href.includes("Example.html")){
for(var i=0; i< chapters.length; i++){
if(chapters[i].href.includes("Example.html")){
chapters[i].style.display= "inherit";
}}
}
// Hide children from summary table
else if(!(window.location.href.includes("Examples.html")) && !(window.location.href.includes("Example.html"))){
for(var i=0; i< chapters.length; i++){
if(chapters[i].href.includes("Example.html")){
chapters[i].style.display= "none";
}}
}
});
});