From 8e49dba577feabfe5ed9a5600bbe10d5dd505ea4 Mon Sep 17 00:00:00 2001 From: Saul Johnson Date: Mon, 14 Aug 2017 17:11:24 +0100 Subject: [PATCH 1/2] Make download button a download hyperlink --- src/coffee/main.coffee | 20 ++++++++++++-------- src/less/main.less | 7 +++++-- templates/index.html.twig | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/coffee/main.coffee b/src/coffee/main.coffee index e6edc9e..320f359 100644 --- a/src/coffee/main.coffee +++ b/src/coffee/main.coffee @@ -18,6 +18,9 @@ $(document).ready -> # Element to use for wallpaper preview. previewElement = $ 'body, html' + + # Download button element. + downloadButton = $ '.download-btn' # Error message elements. errorRows = $ '.row-error' @@ -110,6 +113,14 @@ $(document).ready -> failPreviewSmiles = -> invalidCompoundSmilesMessage.show() + # Updates the download link according to the currently displayed molecule. + # + updateDownloadLink = -> + url = buildUrl screenWidth, screenHeight, foregroundColor, backgroundColor, currentCompoundName + if smilesMode + url = buildSmilesUrl screenWidth, screenHeight, foregroundColor, backgroundColor, currentCompoundSmiles + downloadButton.attr 'href', url + # Updates the displayed preview. # # @param [object] element the element to update @@ -121,6 +132,7 @@ $(document).ready -> element.css 'background-color', "##{background}" element.css 'background-position', '50% 50%' element.css 'background-repeat', 'no-repeat' + updateDownloadLink() # Refreshes the preview using the compound name text box. # @@ -172,14 +184,6 @@ $(document).ready -> smilesMode = true errorRows.hide() checkSmiles getCompoundSmiles(), refreshPreviewSmiles, failPreviewSmiles - - # Download button should open rendered image for download. - - $('.download-btn').on 'click', (e) -> - url = buildUrl screenWidth, screenHeight, foregroundColor, backgroundColor, currentCompoundName - if smilesMode - url = buildSmilesUrl screenWidth, screenHeight, foregroundColor, backgroundColor, currentCompoundSmiles - window.open url # Grab initial values from text boxes. currentCompoundName = compoundTextBox.val() diff --git a/src/less/main.less b/src/less/main.less index 5d43cad..af64d0f 100644 --- a/src/less/main.less +++ b/src/less/main.less @@ -15,15 +15,16 @@ hr { margin-bottom: 5px; } -button { +button, a.download-btn { border: 1px solid @button-border; border-radius: 5px; background: @button-background; text-shadow: none; padding: 5px 10px 5px 10px; + color: #fff; } -button:hover { +button:hover, a.download-btn:hover { background: @button-background-hover; } @@ -104,7 +105,9 @@ input[type=text] { } .download-btn { + display: block; width: 100%; + text-align: center; } // Logo. diff --git a/templates/index.html.twig b/templates/index.html.twig index 8e96503..7e160a5 100644 --- a/templates/index.html.twig +++ b/templates/index.html.twig @@ -121,7 +121,7 @@
- + Download!
From 7e389813914f2cc0b05107e12229ee36c81744ff Mon Sep 17 00:00:00 2001 From: Saul Johnson Date: Mon, 14 Aug 2017 17:15:15 +0100 Subject: [PATCH 2/2] Set filename according to molecule name if available --- src/coffee/main.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coffee/main.coffee b/src/coffee/main.coffee index 320f359..ab2eb5f 100644 --- a/src/coffee/main.coffee +++ b/src/coffee/main.coffee @@ -119,6 +119,7 @@ $(document).ready -> url = buildUrl screenWidth, screenHeight, foregroundColor, backgroundColor, currentCompoundName if smilesMode url = buildSmilesUrl screenWidth, screenHeight, foregroundColor, backgroundColor, currentCompoundSmiles + downloadButton.attr 'download', if smilesMode then 'smiles_molecule' else currentCompoundName downloadButton.attr 'href', url # Updates the displayed preview.