-
Notifications
You must be signed in to change notification settings - Fork 8
定義語自動リンク: 自動リンクおよびdfn要素のスタイルの設定 #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* Note: The tooltip element will be directly added to the top level of <body> */ | ||
| #kunai-ui-tooltip { | ||
| text-decoration: none!important; font-weight: normal!important; font-style: normal!important; | ||
| width: max-content; max-width: 40em; | ||
| border: 1px solid black; padding: 0.2rem 0.4rem; margin: 0; | ||
| background-color: white; color: black; text-decoration: none; font-size: 0.9rem; | ||
| position: fixed; box-shadow: 2px 2px 2px 0 rgba(128, 128, 128, 0.6); | ||
| cursor: default; | ||
| opacity: 0; z-index: -1; | ||
| transition: opacity .3s linear .5s, z-index 0s linear .8s; | ||
| } | ||
| #kunai-ui-tooltip:before { | ||
| content: attr(data-desc); | ||
| } | ||
| #kunai-ui-tooltip.kunai-ui-tooltip-revealed { | ||
| opacity: 1; z-index: 1000000; | ||
| transition: opacity .3s linear 0s, z-index 0s linear 0s; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,53 @@ | ||
| import * as Badge from './badge' | ||
| import {Tooltip} from './tooltip' | ||
|
|
||
|
|
||
| const _hitElementRects = (elem, x, y) => { | ||
| for (const rect of elem.getClientRects()) | ||
| if (rect.left <= x && x <= rect.right && rect.top <= y && y <= rect.bottom) | ||
| return rect | ||
| return null | ||
| } | ||
|
|
||
| class Content { | ||
| constructor(log) { | ||
| this.log = log.makeContext('Content') | ||
| this.log.debug('initialzing...') | ||
|
|
||
| this.log.debug(`found ${Badge.sanitize($('main[role="main"] div[itemtype="http://schema.org/Article"] .content-body span.cpp'))} badges`) | ||
|
|
||
| this.setupTooltip() | ||
| } | ||
|
|
||
| setupTooltip() { | ||
| const tooltip = new Tooltip(document) | ||
| let target = null | ||
|
|
||
| $('a[data-desc]').on({ | ||
| mouseover: function(e) { | ||
| const rect = _hitElementRects(this, e.clientX, e.clientY) | ||
| if (rect) { | ||
| target = this | ||
| tooltip.show(this.dataset.desc, e.clientX, e.clientY, rect) | ||
| } | ||
| }, | ||
| mouseout: function() { | ||
| if (this === target) { | ||
| target = null | ||
| tooltip.hide() | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| const checkScroll = function(e) { | ||
| if (target !== null && !_hitElementRects(target, e.clientX, e.clientY)) { | ||
| target = null | ||
| tooltip.hide() | ||
| } | ||
| } | ||
| window.addEventListener('scroll', checkScroll, true) | ||
| window.addEventListener('resize', checkScroll) | ||
| } | ||
| } | ||
|
|
||
| export {Content} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| class Tooltip { | ||
| /** | ||
| * ツールチップを構築します。 | ||
| * @param {Document} [_document] - 表示対象のドキュメント | ||
| * @param {object} [config] - 設定 | ||
| */ | ||
| constructor(_document, config) { | ||
| this.document = _document || document | ||
| this.view = this.document.defaultView || window | ||
| this.config = { | ||
| horizontalMargin: 8, // (設定) ツールチップ配置時のビューポート横余白 | ||
| verticalMargin: 8, // (設定) ツールチップ配置時のビューポート縦余白 | ||
| verticalOffset: 2, // (設定) ツールチップと対象要素の縦の距離 | ||
| tooltipId: 'kunai-ui-tooltip', | ||
| tooltipClassRevealed: 'kunai-ui-tooltip-revealed' | ||
| } | ||
| if (config) | ||
| Object.assign(this.config, config) | ||
|
|
||
| this.span = document.createElement('span') | ||
| this.span.id = this.config.tooltipId | ||
| this.document.body.appendChild(this.span) | ||
| } | ||
|
|
||
| _place(x, y) { | ||
| // 物理ピクセル位置にぴったり合わせる | ||
| const pixelRatio = this.view.devicePixelRatio | ||
| x = Math.round(x * pixelRatio) / pixelRatio | ||
| y = Math.round(y * pixelRatio) / pixelRatio | ||
|
|
||
| this.span.style.left = `${x}px` | ||
| this.span.style.top = `${y}px` | ||
| this.span.classList.add(this.config.tooltipClassRevealed) | ||
| } | ||
|
|
||
| /** | ||
| * マウス位置および対象領域を元にして、ツールチップを適切な位置に表示します。 | ||
| * @param {string} desc - 表示する文字列 | ||
| * @param {number} mouseX - ビューポート内のマウス位置X | ||
| * @param {number} mouseY - ビューポート内のマウス位置Y | ||
| * @param {DOMRect} rect - 表示対象オブジェクトの領域 | ||
| * | ||
| */ | ||
| show(desc, mouseX, mouseY, rect) { | ||
| // 幾何情報の取得 | ||
| this.span.dataset.desc = desc | ||
| const tw = this.span.offsetWidth // ツールチップの表示幅 | ||
| const th = this.span.offsetHeight // ツールチップの表示高さ | ||
| const vw = this.document.documentElement.clientWidth // スクロールバーを除くビューポートの幅 | ||
| const vh = this.document.documentElement.clientHeight // スクロールバーを除くビューポートの高さ | ||
|
|
||
| // 位置の決定 | ||
| let x = Math.max(this.config.horizontalMargin, Math.min(vw - tw - this.config.horizontalMargin, mouseX)) | ||
| let y = rect.top - this.config.verticalOffset - th | ||
| if (y < this.config.verticalMargin) { | ||
| y = rect.bottom + this.config.verticalOffset | ||
| if (y + th > vh - this.config.verticalMargin) | ||
| y = mouseY + this.config.verticalOffset | ||
| } | ||
|
|
||
| this._place(x, y) | ||
| } | ||
|
|
||
| /** | ||
| * ツールチップを隠します。 | ||
| */ | ||
| hide() { | ||
| this.span.classList.remove(this.config.tooltipClassRevealed) | ||
| } | ||
| } | ||
|
|
||
| export {Tooltip} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.