-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
217 lines (194 loc) Β· 7.53 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Animated URL</title>
<link rel="stylesheet" href="style.css">
<script src="./customNavigate.js"></script>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/monaco-editor/min/vs/loader.js"></script>
</head>
<body>
<h1 align="center" style="opacity: 70%">Animated URL</h1>
<div align="center">
Demo Click on the link below to see the animation on URL <br/><br/>
<a class="link" href="/someLink.html">someLink</a> |
<a class="link" href="/someLink/subLink.html">Nested someLink</a> |
<a class="link" href="/anotherLink.html">anotherLink</a> |
<a class="link" target="_blank" href="https://github.com/abhaygupta08">Abhay Gupta (target blank)</a>
</div>
<div style="margin-top: 4rem;" align="center">
<button class="cdnLink"><span>Copy CDN Link</span> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button>
</div>
<div style="margin-top: 0rem;margin-bottom: 5rem;">
<div class="wrapper">
<div class="editor">
<div class="editor__code">
<div id="editorCode"></div>
</div>
</div>
<div class="buttons">
<button class="button" id="editorCopyClipboard">Copy Javascript Function</button>
<button class="button" ><a style="text-decoration: none; color: white;" target="_blank" href="/customNavigate.js" download="customNavigate.js">Download File</a></button>
</div>
</div>
<div class="wrapper"
>
<div class="usage">
<br/>
<br/>
<h3>Usage :</h3>
<br/>
<code>
const anchor = document.querySelector('a');<br/>
anchor.addEventListener("click", (e) => {<br/>
 e.preventDefault();<br/>
 customNavigate(<br/>
  anchor.href.replace(window.location.origin, ""),<br/>
  anchor.target<br/>
 );<br/>
});<br/>
</code>
</div>
</div>
<hr>
<br>
<div align="center">
<div><a class="github-button" href="https://github.com/abhaygupta08/Animated-URL" data-icon="octicon-star" data-size="large" aria-label="Star abhaygupta08/Animated-URL on GitHub">Star</a>
<a class="github-button" href="https://github.com/abhaygupta08/Animated-URL/fork" data-icon="octicon-repo-forked" data-size="large" aria-label="Fork abhaygupta08/Animated-URL on GitHub">Fork</a>
<a class="github-button" href="https://github.com/abhaygupta08" data-size="large" data-show-count="true" aria-label="Follow @abhaygupta08 on GitHub">Follow @abhaygupta08</a>
</div>
<div>
<a class="link" style=" font-weight : bold; " href="https://github.com/abhaygupta08/Animated-URL" target="_blank" > git / Animated-URL</a>
</div>
</div>
<script src="./script.js"></script>
<script>
const cdnLink = document.querySelector(".cdnLink");
cdnLink.onclick = () => {
copyToClipboard('https://raw.githubusercontent.com/abhaygupta08/Animated-URL/main/customNavigate.js');
const cdnLinkText = 'https://raw.githubusercontent.com/abhaygupta08/Animated-URL/main/customNavigate.js';
cdnLink.innerHTML = "Copied !";
cdnLink.disabled = true;
setTimeout(() => {
cdnLink.disabled = false;
cdnLink.innerHTML = `<span>Copy CDN Link</span> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>`
}, 500);
};
// Initial data
const JS_CODE = (
`/**
* Author: Abhay Gupta
* Source Code: https://github.com/abhaygupta08/Animated-URL
*
* It navigates to the given href by deleting the current path and then appending the given href
* @param [href] - The URL to navigate to.
* @param [target=_self] - The target attribute specifies where to open the linked document.
* @returns undefined.
*/
function customNavigate(href = "", target = "_self") {
const TYPING_SPEED = 100;
if (target === "_blank") {
window.open(href, "_blank");
return;
}
// remove event start
console.log("Navigating back");
const curentLocation = window.location.href;
const pathToDelete = curentLocation.replace(window.location.origin, "");
let tempS = "";
for (let i = pathToDelete.length - 1; i >= 0; i--) {
tempS = pathToDelete.substring(0, i);
const newURL = tempS;
setTimeout(() => {
history.replaceState(null, null, newURL);
if (i === 0) {
console.log("Navigated back");
}
}, TYPING_SPEED * (pathToDelete.length - i));
}
// append
setTimeout(() => {
console.log("Navigating to " + href);
let s = "";
for (let i = 0; i < href.length; i++) {
if (i == 0 && href[i] == "/") {
if (href.length == 1) {
window.location.href = href;
}
continue;
}
s += href[i];
const newURL = s;
setTimeout(() => {
window.history.replaceState({}, null, "/" + newURL);
if (i == href.length - 1) {
// event ended
console.log("Navigated to " + href);
window.location.href = href;
}
}, TYPING_SPEED * i);
}
}, TYPING_SPEED * (pathToDelete.length + 1));
}
`);
// Elements
const editorCode = document.getElementById("editorCode");
const editorCopyButton = document.getElementById('editorCopyClipboard');
// Monaco loader
require.config({
paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor/min/vs" }
});
window.MonacoEnvironment = {
getWorkerUrl: function (workerId, label) {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
self.MonacoEnvironment = {
baseUrl: 'https://cdn.jsdelivr.net/npm/monaco-editor/min/'
};
importScripts('https://cdn.jsdelivr.net/npm/monaco-editor/min/vs/base/worker/workerMain.js');`)}`;
}
};
// Monaco init
require(["vs/editor/editor.main"], function () {
createEditor(editorCode);
});
function createEditor(editorContainer) {
let editor = monaco.editor.create(editorContainer, {
value: JS_CODE,
language: "javascript",
minimap: { enabled: true },
automaticLayout: true,
contextmenu: false,
fontSize: 12,
scrollbar: {
useShadows: false,
vertical: "visible",
horizontal: "visible",
horizontalScrollbarSize: 12,
verticalScrollbarSize: 12
}
});
editorCopyButton.onclick = () => {
copyToClipboard(editor.getValue());
const editorCopyButtonText = editorCopyButton.innerHTML;
editorCopyButton.innerHTML = "Copied!";
editorCopyButton.disabled = true;
setTimeout(() => {
editorCopyButton.disabled = false;
editorCopyButton.innerHTML = editorCopyButtonText
}, 500);
}
}
function copyToClipboard(str) {
const el = document.createElement("textarea");
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand("copy");
document.body.removeChild(el);
}
</script>
</body>
</html>