Skip to content

Commit c795052

Browse files
committed
Testing Edit this page along with select and report feature
1 parent 5d188c5 commit c795052

File tree

7 files changed

+380
-4
lines changed

7 files changed

+380
-4
lines changed

.hintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": [
3+
"development"
4+
],
5+
"hints": {
6+
"meta-viewport": "off",
7+
"axe/text-alternatives": [
8+
"default",
9+
{
10+
"document-title": "off"
11+
}
12+
],
13+
"axe/language": [
14+
"default",
15+
{
16+
"html-has-lang": "off"
17+
}
18+
]
19+
}
20+
}

layouts/_default/baseof.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<!DOCTYPE html>
22
<html>
33
{{- partial "head.html" . -}}
4-
<body>
4+
<body{{ with .File }} data-github-file="{{ .Path }}"{{ end }}>
55
<div class="pf-c-page">
66
{{- partial "header.html" . -}}
77
{{- block "main" . }}
88
<!-- get all the things from the content files -->
99
{{- end }}
1010
</div>
1111
<script src="{{ "js/codeblock.js" | relURL }}"></script>
12+
<script src="{{ "js/select-report-issue-popup.js" | relURL }}"></script>
1213
</body>
1314
<!-- Uncomment when you have sorted out the feedback partials option
1415
<body>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// static/js/bug-reporter.js (or wherever you prefer to store static assets)
2+
3+
document.addEventListener('mouseup', function() {
4+
const selectedText = window.getSelection().toString().trim();
5+
6+
if (selectedText.length > 0) {
7+
// You might want to add a small button or popup here instead of direct confirmation
8+
// For simplicity, we'll keep the confirmation for now.
9+
10+
const currentPageUrl = window.location.href;
11+
const githubFilePath = getGitHubFilePath(); // This will now be more accurate for Hugo
12+
13+
const issueTitle = `Bug Report: Issue on "${selectedText.substring(0, 50).replace(/\n/g, ' ')}..."`;
14+
let issueBody = `
15+
**Description of the issue:**
16+
\`\`\`
17+
${selectedText}
18+
\`\`\`
19+
20+
---
21+
**Context:**
22+
- **Page URL:** ${currentPageUrl}
23+
- **GitHub Source File:** ${githubFilePath}
24+
`;
25+
26+
const encodedTitle = encodeURIComponent(issueTitle);
27+
const encodedBody = encodeURIComponent(issueBody);
28+
29+
const githubRepo = 'validatedpatterns/docs'; // Your GitHub repository
30+
const githubIssueUrl = `https://github.com/${githubRepo}/issues/new?title=${encodedTitle}&body=${encodedBody}`;
31+
32+
const confirmation = confirm("Do you want to report this as a bug on GitHub for the selected text?");
33+
if (confirmation) {
34+
window.open(githubIssueUrl, '_blank');
35+
}
36+
}
37+
});
38+
39+
40+
// Hugo-specific function to get the GitHub file path
41+
function getGitHubFilePath() {
42+
// This assumes you've added a data-github-file attribute to your body or a container.
43+
const bodyElement = document.querySelector('body');
44+
if (bodyElement && bodyElement.dataset.githubFile) {
45+
// Construct the full GitHub blob URL
46+
// Assuming your source files are in the 'content' directory of your repo
47+
// And you're using the 'main' branch
48+
const repoBaseUrl = 'https://github.com/validatedpatterns/docs/blob/main/';
49+
return repoBaseUrl + bodyElement.dataset.githubFile;
50+
}
51+
52+
// Fallback if the data attribute isn't found (shouldn't happen with Hugo setup)
53+
return "Could not determine source file automatically. Please specify if known.";
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// static/js/bug-reporter.js (or wherever you prefer to store static assets)
2+
3+
document.addEventListener('mouseup', function() {
4+
const selectedText = window.getSelection().toString().trim();
5+
6+
if (selectedText.length > 0) {
7+
// You might want to add a small button or popup here instead of direct confirmation
8+
// For simplicity, we'll keep the confirmation for now.
9+
10+
const currentPageUrl = window.location.href;
11+
const githubFilePath = getGitHubFilePath(); // This will now be more accurate for Hugo
12+
13+
const issueTitle = `Bug Report: Issue on "${selectedText.substring(0, 50).replace(/\n/g, ' ')}..."`;
14+
let issueBody = `
15+
**Description of the issue:**
16+
\`\`\`
17+
${selectedText}
18+
\`\`\`
19+
20+
---
21+
**Context:**
22+
- **Page URL:** ${currentPageUrl}
23+
- **GitHub Source File:** ${githubFilePath}
24+
`;
25+
26+
const encodedTitle = encodeURIComponent(issueTitle);
27+
const encodedBody = encodeURIComponent(issueBody);
28+
29+
const githubRepo = 'validatedpatterns/docs'; // Your GitHub repository
30+
const githubIssueUrl = `https://github.com/${githubRepo}/issues/new?title=${encodedTitle}&body=${encodedBody}`;
31+
32+
const confirmation = confirm("Do you want to report this as a bug on GitHub for the selected text?");
33+
if (confirmation) {
34+
window.open(githubIssueUrl, '_blank');
35+
}
36+
}
37+
});
38+
39+
40+
// Hugo-specific function to get the GitHub file path
41+
function getGitHubFilePath() {
42+
// This assumes you've added a data-github-file attribute to your body or a container.
43+
const bodyElement = document.querySelector('body');
44+
if (bodyElement && bodyElement.dataset.githubFile) {
45+
// Construct the full GitHub blob URL
46+
// Assuming your source files are in the 'content' directory of your repo
47+
// And you're using the 'main' branch
48+
const repoBaseUrl = 'https://github.com/validatedpatterns/docs/blob/main/';
49+
return repoBaseUrl + bodyElement.dataset.githubFile;
50+
}
51+
52+
// Fallback if the data attribute isn't found (shouldn't happen with Hugo setup)
53+
return "Could not determine source file automatically. Please specify if known.";
54+
}

layouts/partials/toc.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
<aside class="pf-c-jump-links pf-m-vertical sticky pf-m-expandable pf-m-non-expandable-on-2xl" aria-label="Table of contents">
22
<div class="pf-l-stack pf-m-gutter">
33
<div class="pf-l-stack__item pf-u-text-align-right">
4-
<a href="https://github.com/validatedpatterns/docs/commits/main/content/{{ .File.Path }}"><span class="pf-c-icon pf-m-md" title="View page history"><span class="pf-c-icon__content"><i class="fa-solid fa-clock-rotate-left"></i></span></span></a>
5-
<a href="https://issues.redhat.com/secure/CreateIssueDetails!init.jspa?pid=12325623&summary={{ .Title }}: %3C+Provide+a+brief+description+of+the+issue+%3E&issuetype=1&priority=10200&components=12365975&priority=10200&components=12365975&description=Link+to+page:+{{ .Permalink }}+%0A+%0A+%3C+Provide+a+detailed+description+of+the+issue+with+link+to+the+docs++%3E"><span class="pf-c-icon pf-m-md" title="File a documentation bug"><span class="pf-c-icon__content"><i class="fa-regular fa-bug"></i></span></span></a>
6-
</div>
4+
{{ with .File }}
5+
{{ $githubRepo := "validatedpatterns/docs" }}
6+
{{ $githubBranch := "main" }}
7+
{{ $githubFilePath := .Path }}
8+
<a href="https://github.com/{{ $githubRepo }}/edit/{{ $githubBranch }}/content/{{ $githubFilePath }}" target="_blank" rel="noopener noreferrer">
9+
<span class="pf-c-icon pf-m-md" title="Edit this page">
10+
<span class="pf-c-icon__content"><i class="fa-solid fa-pencil"></i></span>
11+
</span>
12+
</a>
13+
{{ end }}
14+
<a href="https://github.com/validatedpatterns/docs/commits/main/content/{{ .File.Path }}" target="_blank" rel="noopener noreferrer"><span class="pf-c-icon pf-m-md" title="View page history"><span class="pf-c-icon__content"><i class="fa-solid fa-clock-rotate-left"></i></span></span></a>
15+
<a id="report-doc-bug-btn" href="https://jira.example.com/"><span class="pf-c-icon pf-m-md" title="File a documentation bug"><span class="pf-c-icon__content"><i class="fa-regular fa-bug"></i></span></span></a>
16+
</div>
717
<div class="pf-l-stack__item">
818
<div class="pf-c-jump-links__header">
919
<div class="pf-c-jump-links__label">
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// static/js/select-report-issue-hover.js
2+
3+
let reportButton = null;
4+
let buttonTimeout = null;
5+
6+
const BUTTON_FADE_DURATION_MS = 6000; // Button disappears after 4 seconds
7+
8+
function removeReportButton() { //
9+
if (reportButton && reportButton.parentNode) {
10+
reportButton.parentNode.removeChild(reportButton);
11+
reportButton = null;
12+
}
13+
if (buttonTimeout) {
14+
clearTimeout(buttonTimeout);
15+
buttonTimeout = null;
16+
}
17+
}
18+
19+
function showReportButton(x, y, selectedText) {
20+
removeReportButton();
21+
22+
reportButton = document.createElement('button');
23+
reportButton.id = 'bug-report-button';
24+
reportButton.className = 'bug-report-button';
25+
reportButton.innerHTML = 'Report Bug <i class="fa-solid fa-bug"></i>'; // Changed to fa-solid based on your HTML
26+
27+
// Set position to fixed and max z-index (still good practice)
28+
reportButton.style.position = 'fixed';
29+
reportButton.style.left = `${x}px`;
30+
reportButton.style.top = `${y - 40}px`; // Adjust Y to place it above selection
31+
reportButton.style.zIndex = '2147483647'; // Highest possible z-index
32+
33+
// Store selected text and other context data on the button
34+
reportButton.dataset.selectedText = selectedText;
35+
reportButton.dataset.currentPageUrl = window.location.href;
36+
reportButton.dataset.githubFilePath = getGitHubFilePath();
37+
38+
// DO NOT attach a click listener directly to the button here.
39+
// The click will be handled by the document listener below.
40+
41+
document.documentElement.appendChild(reportButton); // Append to HTML element for broadest context
42+
43+
// Start timeout to remove button if not clicked
44+
buttonTimeout = setTimeout(removeReportButton, BUTTON_FADE_DURATION_MS);
45+
}
46+
47+
function getGitHubFilePath() {
48+
const bodyElement = document.querySelector('body');
49+
if (bodyElement && bodyElement.dataset.githubFile) {
50+
const repoBaseUrl = 'https://github.com/validatedpatterns/docs/blob/main/';
51+
return repoBaseUrl + bodyElement.dataset.githubFile;
52+
}
53+
return "Could not determine source file automatically. Please specify if known.";
54+
}
55+
56+
// --- NEW EVENT DELEGATION LOGIC ---
57+
58+
// Listen for clicks on the entire document (or document.body)
59+
// This listener WILL always fire, even if an overlay is present.
60+
document.addEventListener('mouseup', function(event) { // <-- SET BREAKPOINT HERE (Around line 61 in the full code)
61+
const selectedText = window.getSelection().toString().trim(); // <--- ALSO SET A BREAKPOINT ON THIS LINE
62+
// ...
63+
});
64+
// If a reportButton exists AND the click target is that button (or a child of it, like the icon)
65+
// This uses `contains` to check if the click was *inside* the button's DOM subtree.
66+
if (reportButton && reportButton.contains(event.target)) {
67+
event.preventDefault(); // Prevent any default behavior (like text selection or link following)
68+
event.stopPropagation(); // Stop the event from bubbling up further
69+
70+
console.log('BUG REPORT BUTTON CLICKED (via event delegation)!'); // For debugging
71+
72+
// Retrieve data from the button's dataset
73+
const text = reportButton.dataset.selectedText;
74+
const currentPageUrl = reportButton.dataset.currentPageUrl;
75+
const githubFilePath = reportButton.dataset.githubFilePath;
76+
77+
const issueTitle = `Bug Report: Issue on "${text.substring(0, 50).replace(/\n/g, ' ')}..."`;
78+
let issueBody = `
79+
**Description of the issue:**
80+
\`\`\`
81+
${text}
82+
\`\`\`
83+
84+
---
85+
**Context:**
86+
- **Page URL:** ${currentPageUrl}
87+
- **GitHub Source File:** ${githubFilePath}
88+
`;
89+
90+
const encodedTitle = encodeURIComponent(issueTitle);
91+
const encodedBody = encodeURIComponent(issueBody);
92+
93+
const githubRepo = 'validatedpatterns/docs'; // Your GitHub repository
94+
const githubIssueUrl = `https://github.com/${githubRepo}/issues/new?title=${encodedTitle}&body=${encodedBody}`;
95+
96+
window.open(githubIssueUrl, '_blank');
97+
removeReportButton(); // Remove button after opening issue
98+
} else {
99+
// If the button exists but the click was NOT on it, remove it (equivalent to mousedown logic)
100+
removeReportButton();
101+
}
102+
});
103+
104+
// Original mouseup listener (remains the same)
105+
document.addEventListener('mouseup', function(event) {
106+
const selectedText = window.getSelection().toString().trim();
107+
108+
if (selectedText.length > 0) {//
109+
const selection = window.getSelection(); //
110+
if (selection.rangeCount > 0) { //
111+
const range = selection.getRangeAt(0);
112+
const rect = range.getBoundingClientRect();
113+
114+
const x = rect.left + window.scrollX + (rect.width / 2) - 50;
115+
const y = rect.top + window.scrollY;
116+
117+
showReportButton(x, y, selectedText); //
118+
}
119+
} else {
120+
removeReportButton(); //
121+
}
122+
});
123+
124+
// The previous mousedown listener is now essentially replaced by the first part of the new 'click' listener.
125+
// You can remove the old document.addEventListener('mousedown', ...) function if you still have it.

0 commit comments

Comments
 (0)