Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
841 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,22 @@ | ||
{{#if isType}} | ||
<section class="docstring docstring-type"> | ||
{{this.hint.description}} | ||
</section> | ||
{{else}} | ||
<div class="detail-header"> | ||
{{#if this.isModule}} | ||
<h2>{{this.hint.title}}</h2> | ||
{{else}} | ||
<h1 class="signature"> | ||
{{this.hint.title}} | ||
<div class="version-info">{{this.hint.version}}</div> | ||
<div class="specs">{{this.hint.signatureSpecs}}</div> | ||
</h1> | ||
{{/if}} | ||
</div> | ||
{{#if this.hint.description}} | ||
<section class="docstring"> | ||
{{this.hint.description}} | ||
</section> | ||
{{/if}} | ||
{{/if}} |
This file contains 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,4 @@ | ||
<div id="tooltip"> | ||
<div class="tooltip-body"></div> | ||
<iframe class="tooltip-iframe"></iframe> | ||
</div> |
This file contains 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,38 @@ | ||
|
||
// Dependencies | ||
// ------------ | ||
|
||
/** | ||
* Extracts info about a function, callback or a type defined inside a module. | ||
* | ||
* @param {Object} element jQuery selector pointing to a div containing relevant data | ||
* | ||
* @returns {Object} hint info object | ||
*/ | ||
function extractFunctionHint (element) { | ||
const signatureSpecs = element.find('.specs').text() | ||
const title = element.find('h1').text() | ||
const description = element.find('.docstring > p:first').text() | ||
|
||
return { | ||
kind: 'function', | ||
title: title.trim(), | ||
signatureSpecs: signatureSpecs.trim(), | ||
description: description.trim() | ||
} | ||
} | ||
|
||
function extractModuleHint (content) { | ||
content.find('h1:first > *').remove() | ||
|
||
return { | ||
kind: 'module', | ||
title: content.find('h1:first').text().trim(), | ||
description: content.find('#moduledoc p:first').text().trim() | ||
} | ||
} | ||
|
||
// Public Methods | ||
// -------------- | ||
|
||
export {extractModuleHint, extractFunctionHint} |
This file contains 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,94 @@ | ||
// Dependencies | ||
// ------------ | ||
|
||
import {extractModuleHint, extractFunctionHint} from './hints-extraction' | ||
import $ from 'jquery' | ||
|
||
// Constants | ||
// --------- | ||
|
||
const contentInner = '.content-inner' | ||
const projectMetaTag = 'meta[name="project"]' | ||
const message = {hint: {}, ready: false, requestId: null} | ||
|
||
/** | ||
* Will try to extract hint info, and if successful triggers a message to the parent page. | ||
*/ | ||
function sendHint () { | ||
const params = new URLSearchParams(window.location.search) | ||
const requestId = params.get('requestId') | ||
const hash = window.location.hash | ||
const content = $(contentInner) | ||
let hint = null | ||
|
||
if (!params.has('hint')) { return } | ||
|
||
if (!requestId) { return } | ||
|
||
const infoElement = descriptionElementFromHash(hash) | ||
|
||
if (infoElement && infoElement.length > 0) { | ||
hint = extractFunctionHint(infoElement) | ||
} else if (isModulePage()) { | ||
hint = extractModuleHint(content) | ||
} | ||
|
||
if (!hint) { return } | ||
|
||
hint.version = getProjectVersion() | ||
|
||
postMessage(hint, requestId) | ||
} | ||
|
||
/** | ||
* Sends a message (containing everything needed to display a tooltip hint) to the parent page. | ||
*/ | ||
function postMessage (hint, requestId) { | ||
if (window.self !== window.parent) { | ||
message.hint = hint | ||
message.ready = true | ||
message.requestId = requestId | ||
window.parent.postMessage(message, '*') | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the current page is dedicated to a module. | ||
* | ||
* @returns {boolean} `true` if current page contains module documentation. | ||
*/ | ||
function isModulePage () { | ||
return $(contentInner).find('#moduledoc').length > 0 | ||
} | ||
|
||
/** | ||
* Constructs a jQuery selector targeting an element | ||
* | ||
* @param {Object} params URLSearchParams object, parsed parameters from the URL | ||
* | ||
* @returns {object} jquery selector | ||
*/ | ||
function descriptionElementFromHash (hash) { | ||
if (!hash) { return null } | ||
hash = hash.substr(1) // removes the `#` in `#hash` | ||
|
||
if (!hash) { return null } | ||
hash = $.escapeSelector(hash) | ||
|
||
if (!hash) { return null } | ||
|
||
return $(`#${hash}.detail`) | ||
} | ||
|
||
function getProjectVersion () { | ||
return $(projectMetaTag).attr('content') | ||
} | ||
|
||
// Public Methods | ||
// -------------- | ||
|
||
export function initialize () { | ||
$(document).ready(function () { | ||
sendHint() | ||
}) | ||
} |
Oops, something went wrong.