Color Palettes and Plugins

78 views
Skip to first unread message

Scott Simmons

unread,
Jun 29, 2011, 11:32:07 AM6/29/11
to tiddl...@googlegroups.com
Is it possible to reference colors in the ColorPalette within a plugin/macro?
 
At first, I thought I'd be able to set a JS variable from the value of a slice within the color palette, like so:
 
var myPluginColor1 = [[ColorPalette::PrimaryDark]];
 
... but all that does is set my variable equal to the literal string '[[ColorPalette::PrimaryDark]]'.  I tried adding quotes around the brackets, hoping it would parse the value of that tiddler slice, but that didn't work.
 
Is there a way to get the hex value from the Color Palette and associate it with a variable?
 
And on a related note:
 
Can you create shadow color palettes in a plugin, similar to the way you can create shadow stylesheets?
 
As far as I can tell, you can't pull in additional palettes by referencing them within the [[ColorPalette]] tiddler inside double brackets (i.e., [[MyExtraColorPalette]]) as you can additional style sheets.
 
 
Doing these things would certainly come in handy, as you could create plugins that used the pre-existing color schemes of TiddlyWikis rather than hard-coded colors.  (As it is, I've have to tweak a few plugins when I move them to TWs with dark backgrounds and light foregrounds.)

Eric Shulman

unread,
Jun 29, 2011, 2:53:03 PM6/29/11
to TiddlyWiki
> At first, I thought I'd be able to set a JS variable from the value of a
> slice within the color palette, like so:
>
> > var myPluginColor1 = [[ColorPalette::PrimaryDark]];
>
> ... but all that does is set my variable equal to the literal string
> '[[ColorPalette::PrimaryDark]]'.  I tried adding quotes around the brackets,
> hoping it would parse the value of that tiddler slice, but that didn't work.
>
> Is there a way to get the hex value from the Color Palette and associate it
> with a variable?

var myPluginColor1 =
store.getTiddlerText("ColorPalette::PrimaryDark",defaultValue);

> And on a related note:
>
> *Can you create shadow color palettes in a plugin, similar to the way you
> can create shadow stylesheets?*
>
> As far as I can tell, you can't pull in additional palettes by referencing
> them within the [[ColorPalette]] tiddler inside double brackets (i.e.,
> [[MyExtraColorPalette]]) as you can additional style sheets.

The default ColorPalette simply defines standard core TW slices. When
used within CSS-bearing stylesheets, the TWCore automatically replaces
the slice references before passing the result to the browser for
handling. Note that the CSS can contain references to slices stored
in ANY tiddler, not just ColorPalette. Thus, a plugin can create its
own 'extra' color palette, and then reference those colors from a
custom stylesheet (e.g, by using [[MyColorPalette::slicename]]), or
directly by using store.getTiddlerText(...) within the plugin code.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
----------
Was this answer useful? If so, please help support TiddlyTools:

TiddlyTools direct contributions: (paypal)
http://www.TiddlyTools.com/#Donate
UnaMesa tax-deductible contributions:
http://about.unamesa.org/Participate (paypal)
TiddlyWiki consulting:
http://www.TiddlyTools.com/#ELSDesignStudios
http://www.TiddlyTools.com/#Contact

PMario

unread,
Jun 29, 2011, 6:38:42 PM6/29/11
to TiddlyWiki
There is a possibility to get all slices:

var slices = store.calcAllSlices("ColorPalette");

slices.PrimaryDark will have the color, if the slice is defined.

In your code you have to check if the slices elements are there.
-m
Reply all
Reply to author
Forward
0 new messages