-
Notifications
You must be signed in to change notification settings - Fork 0
/
snippets.js
92 lines (70 loc) · 2.73 KB
/
snippets.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
/**
* Simulate a click event.
* @public
* @param {Element} elem the element to simulate a click on
*/
var simulateClick = function (elem) {
// Create our event (with options)
var evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
// If cancelled, don't dispatch our event
var canceled = !elem.dispatchEvent(evt);
};
//Get form by name
const el = document.forms["query-form"];
el.onsubmit = function () {
var emailCookie = document.getElementById("field4").value;
document.cookie = `email=${emailCookie}`; //set client cookie
}
//Setting Cookies
document.cookie = `email=${emailCookie}`; //set client cookie
//Get absolute URL
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
// Usage
getAbsoluteUrl('/something'); // https://davidwalsh.name/something
//Toggle and Close Menu
function toggleHeaderMenu() {
if (0 == document.getElementsByClassName("ss-inner-contents-active").length) {
document.getElementById("ssMenu").classList.toggle("ss-menu-wrapper-active");
for (var e = document.getElementsByClassName("ss-inner-contents"), t = 0; t < e.length; t++) setTimeout(function (e) {
e.classList.add("ss-inner-contents-active")
}, 325, e[t])
} else {
for (e = document.getElementsByClassName("ss-inner-contents"), t = 0; t < e.length; t++) e[t].classList.remove("ss-inner-contents-active");
setTimeout(function () {
document.getElementById("ssMenu").classList.toggle("ss-menu-wrapper-active")
}, 325)
}
}
//Check if Jquery is loaed
window.onload = function() {
if (window.jQuery) {
// jquery loaded
}
}
// TODO FINISH DROP-DOWN CONVERSION TO VANILLA
jQuery(document).ready(function (e) {
e(".menu-item a").click(function () {
e(this).closest("li").children("ul").length && (e(this).closest(".chevron>a:first-of-type:after").display = "none", e(this).closest("li").children("ul").toggleClass("active"), e(this).closest("li").children("ul").slideToggle(300))
})
});
// Check user agent
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){// some code..}
//Split Number into array
var n = 12;
var digits = (""+n).split("");
//OR
function numberToArray(number) {
let array = number.toString().split("");//stringify the number, then make each digit an item in an array
return array.map(x => '<span>'+parseInt(x)+'</span>');//convert all the items back into numbers
}