mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: handle plain readme
This commit is contained in:
parent
77fc4c9583
commit
a95d41fa5c
1 changed files with 33 additions and 30 deletions
|
|
@ -319,37 +319,40 @@ const clippy = createClippy()
|
|||
|
||||
let currentCodeSnippetElement: Element
|
||||
function attachCopySnippet() {
|
||||
const readmeArticleSelector = '.repository-content #readme article'
|
||||
return $(
|
||||
readmeArticleSelector,
|
||||
readmeElement =>
|
||||
readmeElement.addEventListener('mouseover', e => {
|
||||
// only move clippy when mouse is over a new snippet(<pre>)
|
||||
const target = e.target as Element
|
||||
if (target.nodeName === 'PRE') {
|
||||
if (currentCodeSnippetElement !== target) {
|
||||
currentCodeSnippetElement = target
|
||||
/**
|
||||
* <article>
|
||||
* <pre></pre> <!-- case A -->
|
||||
* <div class="highlight">
|
||||
* <pre></pre> <!-- case B -->
|
||||
* </div>
|
||||
* </article>
|
||||
*/
|
||||
if (target.parentNode) target.parentNode.insertBefore(clippy, target)
|
||||
const readmeSelector = '.repository-content #readme'
|
||||
return $(readmeSelector, () => {
|
||||
const readmeArticleSelector = '.repository-content #readme article'
|
||||
$(
|
||||
readmeArticleSelector,
|
||||
readmeElement =>
|
||||
readmeElement.addEventListener('mouseover', e => {
|
||||
// only move clippy when mouse is over a new snippet(<pre>)
|
||||
const target = e.target as Element
|
||||
if (target.nodeName === 'PRE') {
|
||||
if (currentCodeSnippetElement !== target) {
|
||||
currentCodeSnippetElement = target
|
||||
/**
|
||||
* <article>
|
||||
* <pre></pre> <!-- case A -->
|
||||
* <div class="highlight">
|
||||
* <pre></pre> <!-- case B -->
|
||||
* </div>
|
||||
* </article>
|
||||
*/
|
||||
if (target.parentNode) target.parentNode.insertBefore(clippy, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
() => {
|
||||
const readmeSelector = '.repository-content #readme'
|
||||
$(readmeSelector, () =>
|
||||
raiseError(
|
||||
new Error('cannot find mount point for copy snippet button while readme exists'),
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
}),
|
||||
() => {
|
||||
const plainReadmeSelector = '.repository-content #readme .plain'
|
||||
$(plainReadmeSelector, undefined, () =>
|
||||
raiseError(
|
||||
new Error('cannot find mount point for copy snippet button while readme exists'),
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue