forked from bebasid/bebasid.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
341 lines (301 loc) · 10.4 KB
/
index.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
window.jQuery = window.$ = require("jquery");
require('waypoints/lib/jquery.waypoints');
require('lazysizes');
var CodeMirror = require('codemirror');
require('codemirror/mode/css/css');
require('magnific-popup');
require('html5shiv');
// import images for lazy Loading
// Work-around until https://www.npmjs.com/package/parcel-plugin-lazy is functional
//import imageURL from '/resources/img/Addons-small.jpg';
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
var waypoint = new window.Waypoint({
element: document.getElementsByClassName('js--section-features'),
handler: function(direction) {
if (direction == "down") {
$('nav').addClass('sticky');
} else {
$('nav').removeClass('sticky');
}
},
offset: '60px'
})
var waypoint = new window.Waypoint({
element: document.getElementsByClassName('js--wp-1'),
handler: function(direction) {
$('.js--wp-1').addClass('animated fadeIn');
},
offset: '50%'
})
var waypoint = new window.Waypoint({
element: document.getElementsByClassName('js--wp-4'),
handler: function(direction) {
$('.js--wp-4').addClass('animated pulse');
},
offset: '50%'
})
/* Scroll on buttons */
$('.js--scroll-to-plans').click(function() {
$('html, body').animate({
scrollTop: $('.js--section-plans').offset().top
}, 1000);
});
$('.js--scroll-to-start').click(function() {
$('html, body').animate({
scrollTop: $('.js--section-features').offset().top
}, 1000);
});
/* Navigation scroll */
$(function() {
$('a[href*=\\#]:not([href=\\#])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
/* Mobile navigation */
$('.js--nav-icon, .js--main-nav a, .logo-black').click(function(element){
var nav = $('.js--main-nav');
var icon = $('.js--nav-icon i');
//Gets the class name of the element that triggered the event
var clicked = element.target.className;
//Exists the function if the menu is closed AND the logo-black element (logo image) was clicked
if (icon.hasClass('ion-navicon-round') && clicked == 'logo-black')
return;
//Opens and closes the menu
if ($(window).width() < 768){
nav.slideToggle(200);
}
//Changes icon states of the menu button
if (icon.hasClass('ion-navicon-round')) {
icon.addClass('ion-close-round');
icon.removeClass('ion-navicon-round');
} else {
icon.addClass('ion-navicon-round');
icon.removeClass('ion-close-round');
}
});
$(window).resize(function(){
var nav = $('.js--main-nav');
var icon = $('.js--nav-icon i');
if ($(window).width() > 767){
nav.css("display", "block");
icon.addClass('ion-close-round');
icon.removeClass('ion-navicon-round');
} else {
nav.css("display", "none");
icon.addClass('ion-navicon-round');
icon.removeClass('ion-close-round');
}
});
/* Arrow Flip */
function switchArrow(arrow) {
var icon = $(arrow);
if (icon.hasClass('ion-ios-arrow-right')) {
icon.addClass('ion-ios-arrow-down');
icon.removeClass('ion-ios-arrow-right');
} else {
icon.addClass('ion-ios-arrow-right');
icon.removeClass('ion-ios-arrow-down');
}
}
$('.js--arrow-icon-1').click(function() {
switchArrow('.js--arrow-icon-1 i');
});
$('.js--arrow-icon-2').click(function() {
switchArrow('.js--arrow-icon-2 i');
});
$('.js--arrow-icon-3').click(function() {
switchArrow('.js--arrow-icon-3 i');
});
$('.js--arrow-icon-4').click(function() {
switchArrow('.js--arrow-icon-4 i');
});
$('.js--arrow-icon-5').click(function() {
switchArrow('.js--arrow-icon-5 i');
});
var code = $('.codemirror-textarea')[0];
var editor_1 = CodeMirror.fromTextArea(code, {
lineNumbers: true,
mode: "css",
theme: "shadowfox"
});
var code = $('.codemirror-textarea')[1];
var readOnlyColors = CodeMirror.fromTextArea(code, {
lineNumbers: true,
mode: "css",
theme: "shadowfox",
readOnly: true
});
$(document).on('click', '.btn-insert-text', function() {
var uct = "/* GPL-3.9 Copyright (C) 2007 Timvde/UserChrome-Tweaks; Code pulled from https://github.com/Timvde/UserChrome-Tweaks */"
var dict = {
'#roundedTabs': ["https://raw.githubusercontent.com/wilfredwee/photon-australis/master/userChrome-dark.css", "/* MIT Copyright (c) 2017 Wilfred Wee; Code pulled from https://raw.githubusercontent.com/wilfredwee/photon-australis/master/userChrome-dark.css */"],
'#hideSidebar': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/sidebar/auto-hide-sidebar.css", uct],
'#bookmarksNewTab': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/toolbars/show-bookmarks-only-on-newtab.css", uct],
'#closeHover': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/tabs/close-button-hover.css", uct],
'#greyscaleFavicons': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/tabs/grayscale-favicon.css", uct],
'#hideFavicons': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/tabs/hide-favicons.css", uct],
'#bottomMacos': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/tabs/tabs-on-bottom-macOS.css", uct],
'#leftClose': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/tabs/x-on-left.css", uct],
'#autoHide': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/toolbars/auto-hide.css", uct],
'#slidingBookmarks': ["https://raw.githubusercontent.com/Timvde/UserChrome-Tweaks/master/toolbars/sliding-bookmarks-bar.css", uct]
}
for (var key in dict) {
if ($(key).prop('checked') == true) {
var url = dict[key][0];
var licence = dict[key][1];
insertText(licence, 1)
readTextFile(url, 1)
}
}
})
function readTextFile(file, num) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
var allText = rawFile.responseText;
insertText(allText, num);
}
}
}
rawFile.send(null);
}
/* Get primary color */
$(document).on('click', '.insert-color', function() {
var accent1 = document.getElementById("accent-1").value;
var accent2 = document.getElementById("accent-2").value;
var accent3 = document.getElementById("accent-3").value;
var shade = document.getElementById("shade").value;
if (accent1 != "#45a1ff") {
insertText("--accent-1: " + accent1 + ";", 0);
}
if (accent2 != "#0a84ff") {
insertText("--accent-2: " + accent2 + ";", 0);
}
if (accent3 != "#0060df") {
insertText("--accent-3: " + accent3 + ";", 0);
}
if (shade == "darker") {
insertText("--tone-1: var(--grey-20);", 0);
insertText("--tone-2: var(--grey-30);", 0);
insertText("--tone-3: var(--grey-40);", 0);
insertText("--tone-4: var(--grey-50);", 0);
insertText("--tone-5: var(--grey-60);", 0);
insertText("--tone-6: var(--grey-70);", 0);
insertText("--tone-7: var(--grey-80);", 0);
insertText("--tone-8: var(--grey-90);", 0);
insertText("--tone-8: #fff;", 0);
}
})
// Begin inputting of clicked text into editor
function insertText(data, num) {
var cm = $(".CodeMirror")[num].CodeMirror;
var doc = cm.getDoc();
var cursor = doc.getCursor(); // gets the line number in the cursor position
var line = doc.getLine(cursor.line); // get the line contents
var pos = {
line: cursor.line
};
if (line.length === 0) {
// check if the line is empty
// add the data
doc.replaceRange(data, pos);
} else {
// add a new line and the data
doc.replaceRange("\n" + data, pos);
}
}
/* Clear Code Editor */
$(document).on('click', '.btn-remove-text', function() {
editor_1.getDoc().setValue('');
})
/* Clear Code Editor */
$(document).on('click', '.btn-remove-code', function() {
readOnlyColors.getDoc().setValue('');
})
/* Clear Checkboxes */
$(document).on('click', '.clear-boxes', function() {
$('.chrome-options input[type=checkbox]').prop('checked', false);
})
/* Reset Colors */
$(document).on('click', '.clear-colors', function() {
document.getElementById("accent-1").value = "#45a1ff";
document.getElementById("accent-2").value = "#0a84ff";
document.getElementById("accent-3").value = "#0060df";
document.getElementById("shade").value = "default";
})
// Function to download data to a file
function download(data, filename, type) {
var file = new Blob([data], {
type: type
});
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else { // Others
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
/* Download CSS */
$(document).on('click', '.download-css', function() {
var data = editor_1.getValue();
download(data, "colorOverrides.css", "css")
})
$(document).on('click', '.download-css-2', function() {
var data = readOnlyColors.getValue();
download(data, "userChrome_customization.css", "css")
})
var gal = document.getElementsByClassName("popup-gallery");
$(gal).magnificPopup({
delegate: 'a',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
},
image: {
tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
titleSrc: function(item) {
return item.el.attr('title') + '<small>by Pat Johnson</small>';
}
}
});
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = "29000000px";
}
});
}