Update page URL to match molecule currently displayed

This commit is contained in:
Saul Johnson
2017-08-16 18:46:50 +01:00
parent c3b2f81521
commit 306ce4f22d
2 changed files with 37 additions and 1 deletions
+16 -1
View File
@@ -146,7 +146,21 @@ $(document).ready ->
url = buildSmilesUrl screenWidth, screenHeight, foregroundColor, backgroundColor, currentCompoundSmiles
downloadButton.attr 'download', if smilesMode then 'smiles_molecule' else currentCompoundName
downloadButton.attr 'href', url
# Updates the page URL (query string) according to the currently displayed molecule.
#
updateUrl = ->
params = {
'label': customLabel,
'background': backgroundColor,
'foreground': foregroundColor
}
if smilesMode
params['smiles'] = currentCompoundSmiles
else
params['compound'] = currentCompoundName
setQueryParams params
# Updates the displayed preview.
#
# @param [object] element the element to update
@@ -159,6 +173,7 @@ $(document).ready ->
element.css 'background-position', '50% 50%'
element.css 'background-repeat', 'no-repeat'
updateDownloadLink()
updateUrl()
# Refreshes the preview using the compound name text box.
#
+21
View File
@@ -14,3 +14,24 @@ window.getParameterByName = (name, url) ->
if !results[2]
return ''
decodeURIComponent results[2].replace(/\+/g, ' ')
# Sets the query string on the page without reloading it.
#
# @param [string] str the new query string
#
window.setQueryString = (str) ->
if history.pushState
url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?' + str
window.history.pushState { path: url }, '', url
# Sets the query string on the page without reloading it, according to the properties of an object.
#
# @param [object] params the object containing the keys and values to use
#
window.setQueryParams = (params) ->
str = ''
for k, v of params
if v == '' then continue
if str != '' then str += '&'
str += "#{k}=#{v}"
setQueryString str