Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cd3876f
Popovers - first draft
archdragon Mar 31, 2019
bdb3fcd
Popovers - first draft
archdragon Mar 31, 2019
cea0c25
Draft WIP
archdragon Apr 13, 2019
8b299f8
Send html via postMessage
archdragon Jun 7, 2019
28f530d
Update position calculation
archdragon Jun 8, 2019
f3ff27b
Add basic page summary
archdragon Jun 9, 2019
63a3c5c
Fix display flow and add night mode colors
archdragon Jun 11, 2019
78cd814
Improve typespecs handling
archdragon Jun 11, 2019
bd81f8f
Update popover positioning and typespecs description handling
archdragon Jun 13, 2019
6fef38c
Add switch button base, fix sizing issues for types
archdragon Jun 13, 2019
b29f2cb
Rename and restructure he code
archdragon Jun 15, 2019
a2af1d4
Rename 'popover' to 'tooltip', add comments
archdragon Jun 16, 2019
2e18170
Add documentation
archdragon Jun 16, 2019
f4d0ae9
Add specs
archdragon Jun 17, 2019
ec2ef35
Remove console log
archdragon Jun 17, 2019
ed9f533
Remove console log
archdragon Jun 17, 2019
3e59e68
Fix extractions bugs
archdragon Jun 17, 2019
3110911
Revert changes made to mix.lock and webpack settings
archdragon Jun 17, 2019
1e34431
Update formatters
archdragon Jun 17, 2019
ceed935
Revert changes made to mix.lock and webpack settings
archdragon Jun 17, 2019
9fe2f7e
Fix footer link naming
archdragon Jun 18, 2019
13e1bd3
Update assets/js/tooltips/tooltips.js
archdragon Jun 18, 2019
52a2d9f
Update assets/js/tooltips/tooltips.js
archdragon Jun 18, 2019
da90eb1
Add version info, simplify type extranction, fix history bug
archdragon Jul 1, 2019
69d7cd1
Handle whitespaces in specs, cleanup
archdragon Jul 4, 2019
c7b859d
Update formatters
archdragon Jul 4, 2019
a3dcaf1
Style tweaks
archdragon Jul 4, 2019
e2adae8
Add extra docs, adjust display delay
archdragon Jul 4, 2019
e1846cf
Use encoded name in hash
archdragon Jul 10, 2019
06948c1
Use encoded name in hash
archdragon Jul 10, 2019
b1930c9
Cleanup formatters after rebase
archdragon Jul 10, 2019
e144216
Decode name in hash
archdragon Jul 10, 2019
88b5405
Add support for arity variants
archdragon Jul 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {initialize as initNightMode} from './night'
import {initialize as initMakeup} from './makeup'
import {initialize as initKeyboardShortcuts} from './keyboard-shortcuts'
import {initialize as initQuickSwitch} from './quick-switch'
import {initialize as initTooltips} from './tooltips/tooltips'
import {initialize as initHintsPage} from './tooltips/hints-page'

window.$ = $

Expand Down Expand Up @@ -67,5 +69,8 @@ $(() => {
initMakeup()
initKeyboardShortcuts()
initQuickSwitch()
initTooltips()
initHintsPage()

hljs.initHighlighting()
})
2 changes: 1 addition & 1 deletion assets/js/keyboard-shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const keyboardShortcuts = [
// State
// -----

// Stores shortcut info to prevent multiple activations ok keyDown event
// Stores shortcut info to prevent multiple activations on keyDown event
let shortcutBeingPressed = null

// Local Methods
Expand Down
20 changes: 20 additions & 0 deletions assets/js/templates/tooltip-body.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{#if isType}}
<section class="docstring docstring-type">
{{this.hint.description}}
</section>
{{else}}
<div class="detail-header">
<h1 class="signature">
{{this.hint.title}}
<div class="version-info">{{this.hint.version}}</div>
</h1>
{{#unless this.isModule}}
<div class="specs">{{this.hint.signatureSpecs}}</div>
{{/unless}}
</div>
{{#if this.hint.description}}
<section class="docstring">
{{this.hint.description}}
</section>
{{/if}}
{{/if}}
4 changes: 4 additions & 0 deletions assets/js/templates/tooltip-layout.handlebars
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>
38 changes: 38 additions & 0 deletions assets/js/tooltips/hints-extraction.js
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}
107 changes: 107 additions & 0 deletions assets/js/tooltips/hints-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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 = decodeURI(hash)
hash = $.escapeSelector(hash)

if (!hash) { return null }

const mainSelector = $(`#${hash}.detail`)

if (mainSelector.length > 0) {
return mainSelector
} else {
return $(`.detail > span#${hash}`).parent()
}
}

/**
* Grabs project version name from the meta tag.
*
* @returns {string} Project version name (ie. "Elixir v1.2.3")
*/
function getProjectVersion () {
return $(projectMetaTag).attr('content')
}

// Public Methods
// --------------

export function initialize () {
$(document).ready(function () {
sendHint()
})
}
Loading