Skip to content

Commit af8ab09

Browse files
committed
Testing Edit this page along with select and report feature
1 parent 34b73c7 commit af8ab09

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

layouts/_default/baseof.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{{- end }}
1010
</div>
1111
<script src="{{ "js/codeblock.js" | relURL }}"></script>
12+
{{ partial "select-report-issue.html" }}
1213
</body>
1314
<!-- Uncomment when you have sorted out the feedback partials option
1415
<body>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script>
2+
(function () {
3+
document.addEventListener('mouseup', function (e) {
4+
const selection = window.getSelection().toString().trim();
5+
6+
// Avoid adding the button repeatedly
7+
const existing = document.getElementById('report-issue-btn');
8+
if (existing) existing.remove();
9+
10+
if (selection.length > 0) {
11+
const reportBtn = document.createElement('button');
12+
reportBtn.innerText = 'Report Issue';
13+
reportBtn.id = 'report-issue-btn';
14+
15+
Object.assign(reportBtn.style, {
16+
position: 'absolute',
17+
top: `${e.pageY + 10}px`,
18+
left: `${e.pageX}px`,
19+
zIndex: 1000,
20+
background: '#e53935',
21+
color: '#fff',
22+
border: 'none',
23+
borderRadius: '4px',
24+
padding: '6px 10px',
25+
boxShadow: '0 2px 4px rgba(0,0,0,0.2)',
26+
fontSize: '14px',
27+
cursor: 'pointer',
28+
});
29+
30+
document.body.appendChild(reportBtn);
31+
32+
reportBtn.addEventListener('click', () => {
33+
const pageUrl = window.location.href;
34+
const issueBody = `**Issue found on:** ${pageUrl}\n\n**Selected text:**\n\`\`\`\n${selection}\n\`\`\``;
35+
const issueUrl = `https://github.com/validatedpatterns/docs/issues/new?title=Content+Issue&body=${encodeURIComponent(issueBody)}`;
36+
window.open(issueUrl, '_blank');
37+
reportBtn.remove();
38+
});
39+
40+
document.addEventListener('click', function handler(ev) {
41+
if (ev.target !== reportBtn) {
42+
reportBtn.remove();
43+
document.removeEventListener('click', handler);
44+
}
45+
});
46+
}
47+
});
48+
})();
49+
</script>

static/js/select-create-issue.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
document.addEventListener('mouseup', function (e) {
2+
const selection = window.getSelection().toString().trim();
3+
4+
// Prevent multiple buttons
5+
const existing = document.getElementById('report-issue-btn');
6+
if (existing) existing.remove();
7+
8+
if (selection.length > 0) {
9+
const reportBtn = document.createElement('button');
10+
reportBtn.innerText = 'Report Issue';
11+
reportBtn.id = 'report-issue-btn';
12+
Object.assign(reportBtn.style, {
13+
position: 'absolute',
14+
top: `${e.pageY}px`,
15+
left: `${e.pageX}px`,
16+
zIndex: 1000,
17+
background: '#f44336',
18+
color: 'white',
19+
border: 'none',
20+
borderRadius: '4px',
21+
padding: '6px 10px',
22+
cursor: 'pointer',
23+
});
24+
25+
document.body.appendChild(reportBtn);
26+
27+
reportBtn.onclick = () => {
28+
const pageUrl = window.location.href;
29+
const issueBody = `**Issue found on:** ${pageUrl}\n\n**Selected text:**\n\`\`\`\n${selection}\n\`\`\``;
30+
const issueUrl = `https://github.com/validatedpatterns/docs/issues/new?title=Content+Issue&body=${encodeURIComponent(issueBody)}`;
31+
window.open(issueUrl, '_blank');
32+
reportBtn.remove();
33+
};
34+
35+
// Hide the button if clicking elsewhere
36+
document.addEventListener('click', function removeButton(clickEvent) {
37+
if (clickEvent.target !== reportBtn) {
38+
reportBtn.remove();
39+
document.removeEventListener('click', removeButton);
40+
}
41+
});
42+
}
43+
});

0 commit comments

Comments
 (0)