Surcharge du javascript.
Ai enlevé preque toutes les références à jquery. M'en rete qu'une mais ça va aps être trop dur je pense
This commit is contained in:
parent
c0e89b87b2
commit
ba99fab587
13 changed files with 22308 additions and 53 deletions
33
src/js/code.js
Normal file
33
src/js/code.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
(function() {
|
||||
window.onload = function() {
|
||||
new ClipboardJS('.copy', {
|
||||
target: function(trigger) {
|
||||
return trigger.nextElementSibling;
|
||||
}
|
||||
}).on('success', function(e) {
|
||||
showTooltip(e.trigger, 'Copied!');
|
||||
e.clearSelection();
|
||||
}).on('error', function(e) {
|
||||
console.error('Action:', e.action);
|
||||
console.error('Trigger:', e.trigger);
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
const btns = document.querySelectorAll('.copy');
|
||||
|
||||
btns.forEach(( el ) => {
|
||||
el.addEventListener('animationend', clearTooltip);
|
||||
});
|
||||
});
|
||||
|
||||
function showTooltip(e, msg) {
|
||||
e.setAttribute('class', 'copy-btn copy tooltipped');
|
||||
e.setAttribute('aria-label', msg);
|
||||
}
|
||||
|
||||
function clearTooltip(e) {
|
||||
e.currentTarget.setAttribute('class', 'copy-btn copy');
|
||||
e.currentTarget.setAttribute('aria-label', 'Copy this code.');
|
||||
}
|
||||
})();
|
22
src/js/headerlink.js
Normal file
22
src/js/headerlink.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
(function() {
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
const targetElements = document.querySelector('main').querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||
|
||||
targetElements.forEach(( el ) => {
|
||||
if (el.id) {
|
||||
const headerlink = document.createElement('a');
|
||||
headerlink.setAttribute('class', 'headerlink');
|
||||
headerlink.setAttribute('href', '#' + el.id);
|
||||
headerlink.setAttribute('title', 'Permalink to this headline');
|
||||
|
||||
const icon = document.createElement('i');
|
||||
icon.setAttribute('class', 'fas fa-hashtag');
|
||||
icon.setAttribute('aria-hidden', 'true');
|
||||
|
||||
headerlink.append(icon);
|
||||
|
||||
el.append(headerlink);
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
18
src/js/keydown-nav.js
Normal file
18
src/js/keydown-nav.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
(function() {
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
const nav_prev = document.querySelector('.nav-prev');
|
||||
const nav_next = document.querySelector('.nav-next');
|
||||
|
||||
// prev links - left arrow key
|
||||
document.addEventListener( 'keydown', event => {
|
||||
if (nav_prev && event.key === 'ArrowLeft') {
|
||||
location.href = nav_prev.getAttribute('href');
|
||||
}
|
||||
|
||||
// next links - right arrow key
|
||||
if (nav_next && event.key === 'ArrowRight') {
|
||||
location.href = nav_next.getAttribute('href');
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
4
src/js/main.js
Normal file
4
src/js/main.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
require( './sidebar-menu.js' );
|
||||
require( './keydown-nav.js' );
|
||||
require( './headerlink.js' );
|
||||
require( './code.js' );
|
22
src/js/sidebar-menu.js
Normal file
22
src/js/sidebar-menu.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
(function() {
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
let slideMenu = document.querySelector(".slide-menu");
|
||||
slideMenu.addEventListener("click", function(event) {
|
||||
let target = event.target;
|
||||
if (target.classList.contains("mark")) {
|
||||
event.preventDefault()
|
||||
let subMenu = target.parentNode.parentNode.querySelector(".sub-menu");
|
||||
let text = "";
|
||||
if (target.innerHTML === "-") {
|
||||
text = "+";
|
||||
subMenu.style.display = "none";
|
||||
}
|
||||
if (target.innerHTML === "+") {
|
||||
text = "-";
|
||||
subMenu.style.display = "unset";
|
||||
}
|
||||
target.innerHTML = text;
|
||||
}
|
||||
})
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue