Skip to content

Commit f3fb9fc

Browse files
authored
Merge pull request #40 from dotkernel/markdown-controls
Markdown controls
2 parents 0c989a7 + 7f8d23d commit f3fb9fc

2 files changed

Lines changed: 146 additions & 0 deletions

File tree

‎css/docs.css‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,94 @@ i.bi.bi-copy.copy_btn {
651651
color: #1361DF;
652652
}
653653

654+
.md-actions-bar {
655+
display: flex;
656+
justify-content: flex-end;
657+
margin-bottom: .75rem;
658+
}
659+
.md-actions {
660+
position: relative;
661+
}
662+
.md-actions-toggle,
663+
.md-actions-item {
664+
font: inherit;
665+
font-size: 13px;
666+
color: #3c4257;
667+
background: #ffffff;
668+
cursor: pointer;
669+
}
670+
.md-actions-toggle {
671+
display: inline-flex;
672+
align-items: center;
673+
gap: .5rem;
674+
padding: .35rem .5rem .35rem .65rem;
675+
border: 1px solid #d8dbe3;
676+
border-radius: 6px;
677+
}
678+
.md-actions-toggle:hover,
679+
.md-actions-toggle[aria-expanded="true"] {
680+
border-color: rgba(75, 103, 249, 1);
681+
color: rgba(75, 103, 249, 1);
682+
}
683+
.md-actions-toggle-label {
684+
display: inline-flex;
685+
align-items: center;
686+
gap: .4rem;
687+
}
688+
.md-actions-toggle-chev {
689+
display: inline-flex;
690+
padding-left: .4rem;
691+
border-left: 1px solid #e3e5ec;
692+
}
693+
.md-actions .chev {
694+
transition: transform .15s ease-in-out;
695+
}
696+
.md-actions-toggle[aria-expanded="true"] .chev {
697+
transform: rotate(180deg);
698+
}
699+
.md-actions-menu {
700+
position: absolute;
701+
top: calc(100% + 4px);
702+
right: 0;
703+
z-index: 1020;
704+
display: none;
705+
min-width: 235px;
706+
padding: .25rem;
707+
background: #ffffff;
708+
border: 1px solid #e3e5ec;
709+
border-radius: 8px;
710+
box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
711+
}
712+
.md-actions-menu.show {
713+
display: block;
714+
}
715+
.md-actions-item {
716+
display: flex;
717+
align-items: center;
718+
gap: .5rem;
719+
width: 100%;
720+
padding: .45rem .55rem;
721+
border: 0;
722+
border-radius: 6px;
723+
background: transparent;
724+
text-align: left;
725+
text-decoration: none;
726+
white-space: nowrap;
727+
}
728+
.md-actions-item:hover {
729+
color: rgba(75, 103, 249, 1);
730+
background: #f2f4fb;
731+
text-decoration: none;
732+
}
733+
.md-actions-toggle svg,
734+
.md-actions-item svg {
735+
flex: none;
736+
width: 16px;
737+
height: 16px;
738+
stroke-linecap: round;
739+
stroke-linejoin: round;
740+
}
741+
654742
/*RESPONSIVE*/
655743

656744
@media (max-width: 767.98px) {

‎js/docs.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,61 @@ document.addEventListener("DOMContentLoaded", function () {
2525

2626
document.getElementById("current-year").textContent = new Date().getFullYear().toString();
2727
});
28+
29+
function closeMdActionsMenus(except) {
30+
document.querySelectorAll('.md-actions-toggle[aria-expanded="true"]').forEach(function (toggle) {
31+
if (toggle === except) {
32+
return;
33+
}
34+
toggle.setAttribute('aria-expanded', 'false');
35+
toggle.parentNode.querySelector('.md-actions-menu').classList.remove('show');
36+
});
37+
}
38+
39+
function toggleMdActionsMenu(toggle) {
40+
var expanded = toggle.getAttribute('aria-expanded') === 'true';
41+
closeMdActionsMenus(toggle);
42+
toggle.setAttribute('aria-expanded', expanded ? 'false' : 'true');
43+
toggle.parentNode.querySelector('.md-actions-menu').classList.toggle('show', ! expanded);
44+
}
45+
46+
function copyMarkdownPage(button) {
47+
var label = button.querySelector('.label');
48+
var original = label.textContent;
49+
50+
var restore = function (message) {
51+
label.textContent = message;
52+
window.setTimeout(function () {
53+
label.textContent = original;
54+
}, 2000);
55+
};
56+
57+
fetch(button.dataset.copyUrl, {headers: {'Accept': 'text/markdown, text/plain'}})
58+
.then(function (response) {
59+
if (! response.ok) {
60+
throw new Error('HTTP ' + response.status);
61+
}
62+
return response.text();
63+
})
64+
.then(async function (markdown) {
65+
return await navigator.clipboard.writeText(markdown);
66+
})
67+
.then(function () {
68+
restore('Copied!');
69+
})
70+
.catch(function () {
71+
restore('Copy failed');
72+
});
73+
}
74+
75+
document.addEventListener('click', function (event) {
76+
if (! event.target.closest('.md-actions')) {
77+
closeMdActionsMenus();
78+
}
79+
});
80+
81+
document.addEventListener('keydown', function (event) {
82+
if (event.key === 'Escape') {
83+
closeMdActionsMenus();
84+
}
85+
});

0 commit comments

Comments
 (0)