mirror of
https://github.com/bckelley/avogadrio.git
synced 2026-08-24 02:04:11 -05:00
Update page URL to match molecule currently displayed
This commit is contained in:
+16
-1
@@ -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.
|
||||
#
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user