mirror of
https://github.com/bckelley/avogadrio.git
synced 2026-08-24 10:14:10 -05:00
Accept query params to set initial preview state
This commit is contained in:
+34
-1
@@ -118,6 +118,14 @@ $(document).ready ->
|
|||||||
regex = /^([^J][a-z0-9@+\-\[\]\(\)\\\/%=#$]{0,})$/ig
|
regex = /^([^J][a-z0-9@+\-\[\]\(\)\\\/%=#$]{0,})$/ig
|
||||||
if regex.test smiles then success() else fail()
|
if regex.test smiles then success() else fail()
|
||||||
|
|
||||||
|
# Checks if a string is a valid hex color.
|
||||||
|
#
|
||||||
|
# @param [string] color the color to check
|
||||||
|
#
|
||||||
|
checkColor = (color) ->
|
||||||
|
regex = /^(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$/ig
|
||||||
|
regex.test color
|
||||||
|
|
||||||
# Actions to take when we refresh the preview.
|
# Actions to take when we refresh the preview.
|
||||||
|
|
||||||
# Shows the invalid compound name error message.
|
# Shows the invalid compound name error message.
|
||||||
@@ -173,6 +181,14 @@ $(document).ready ->
|
|||||||
modeAwareRefreshPreview = ->
|
modeAwareRefreshPreview = ->
|
||||||
if smilesMode then refreshPreviewSmiles() else refreshPreviewCompoundName()
|
if smilesMode then refreshPreviewSmiles() else refreshPreviewCompoundName()
|
||||||
|
|
||||||
|
passedForeground = getParameterByName 'foreground'
|
||||||
|
if passedForeground != null && checkColor(passedForeground)
|
||||||
|
foregroundColor = passedForeground
|
||||||
|
|
||||||
|
passedBackground = getParameterByName 'background'
|
||||||
|
if passedBackground != null && checkColor(passedBackground)
|
||||||
|
backgroundColor = passedBackground
|
||||||
|
|
||||||
# Let's initialize the color pickers.
|
# Let's initialize the color pickers.
|
||||||
|
|
||||||
$('.picker-fg').spectrum
|
$('.picker-fg').spectrum
|
||||||
@@ -180,7 +196,7 @@ $(document).ready ->
|
|||||||
clickoutFiresChange: true
|
clickoutFiresChange: true
|
||||||
chooseText: 'Update'
|
chooseText: 'Update'
|
||||||
preferredFormat: 'hex'
|
preferredFormat: 'hex'
|
||||||
|
|
||||||
$('.picker-bg').spectrum
|
$('.picker-bg').spectrum
|
||||||
color: "##{backgroundColor}"
|
color: "##{backgroundColor}"
|
||||||
clickoutFiresChange: true
|
clickoutFiresChange: true
|
||||||
@@ -214,7 +230,24 @@ $(document).ready ->
|
|||||||
customLabel = getCustomLabel()
|
customLabel = getCustomLabel()
|
||||||
modeAwareRefreshPreview()
|
modeAwareRefreshPreview()
|
||||||
|
|
||||||
|
# Put passed parameter values into text boxes if needed.
|
||||||
|
|
||||||
|
passedCompoundName = getParameterByName 'compound'
|
||||||
|
if passedCompoundName != null
|
||||||
|
compoundTextBox.val(passedCompoundName)
|
||||||
|
smilesMode = false
|
||||||
|
|
||||||
|
passedSmiles = getParameterByName 'smiles'
|
||||||
|
if passedSmiles != null
|
||||||
|
smilesTextBox.val(passedSmiles)
|
||||||
|
smilesMode = true
|
||||||
|
|
||||||
|
passedLabel = getParameterByName 'label'
|
||||||
|
if passedLabel != null
|
||||||
|
customLabelTextBox.val(passedLabel)
|
||||||
|
|
||||||
# Grab initial values from text boxes.
|
# Grab initial values from text boxes.
|
||||||
|
|
||||||
currentCompoundName = compoundTextBox.val()
|
currentCompoundName = compoundTextBox.val()
|
||||||
currentCompoundSmiles = smilesTextBox.val()
|
currentCompoundSmiles = smilesTextBox.val()
|
||||||
customLabel = customLabelTextBox.val()
|
customLabel = customLabelTextBox.val()
|
||||||
|
|||||||
Reference in New Issue
Block a user