Skip to content

Preview conversion on mouse-over #51

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ <h3>Privacy</h3>
This is a static website (hosted on <a href="https://pages.github.com/">GitHub Pages</a>) and the conversion happens <a href="https://github.com/curlconverter/curltorequests/blob/master/index.js">entirely in your browser</a> using JavaScript.
</p>
<p class="pt-lg-2">
There is also <a href="https://marketplace.visualstudio.com/items?itemName=curlconverter.curlconverter">a VS Code extension</a> and a command line tool you can install from <a href="https://www.npmjs.com/package/curlconverter">npm</a> with
There is also <a href="https://marketplace.visualstudio.com/items?itemName=curlconverter.curlconverter">an extension for VS Code</a> and a command line tool you can install from <a href="https://www.npmjs.com/package/curlconverter">npm</a> with
</p>
</p>
<code>npm install -g curlconverter</code>
<code class="unselectable">$ </code><code>npm install -g curlconverter</code>
</p>
</div>
<div class="col-sm-6 col-md-4">
Expand Down
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ const changeLanguage = function (language) {
}

const getLanguage = function () {
const languageSelect = document.getElementById('language-select')
return languageSelect.value
return document.getElementById('language-select').value
}

const showIssuePromo = (errorMsg) => {
Expand Down Expand Up @@ -166,11 +165,11 @@ const showExample = function (code) {
convert()
}

const convert = function () {
const convert = function (language) {
let curlCode = document.getElementById('curl-code').value
let generatedCode
let error
const language = getLanguage()
language = language || getLanguage()
let warnings = []

// Convert the placeholder text as a demo
Expand Down Expand Up @@ -243,7 +242,7 @@ if (Object.prototype.hasOwnProperty.call(languages, hash)) {
}

const curlCodeInput = document.getElementById('curl-code')
curlCodeInput.addEventListener('input', convert)
curlCodeInput.addEventListener('input', () => { convert() })

// listen for change in select
const languageSelect = document.getElementById('language-select')
Expand All @@ -264,6 +263,16 @@ for (const navbarItem of languageNavbarItems) {
changeLanguage(language)
convert()
})

navbarItem.addEventListener('mouseenter', function (e) {
e.preventDefault()
const language = e.target.href.split('#')[1]
convert(language)
})
navbarItem.addEventListener('mouseout', function (e) {
e.preventDefault()
convert()
})
}

const getExample = document.getElementById('get-example')
Expand Down
9 changes: 9 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ pre {
.github-fork-ribbon:before {
background-color: #333;
}

.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}