Comments (6)
I wonder if we would be better served by providing a custom callback with the paletteTemplate
function, or even just an event like onPaletteDrawn
that passes that element in. Then you could do whatever you wanted as far as display logic in the palette. In this case, you could keep that map of names to colors in your program then write out the needed attributes. Would this cover what you are looking to do?
from spectrum.
That would work, but in my use case I'm using the following settings combination:
showPaletteOnly: true,
flat: true,
palette: extensivePaletteArrayWithFiftyPlusValues,
With a large palette, depending on how you implement this there could be many callbacks being fired. (Are you thinking one callback per palette array element, or one callback for the entire palette??)
Without knowing the internals of Spectrum all that well, I have to believe it would be more efficient to process a list of attributes once (along with the necessary hex values) during setup. A callback approach means I also have to leave a large chunk of "intestines" vital for Spectrum's operation outside of its "body", so to speak.
That said, obviously I'm being selfish and want Spectrum to do it for me, but I can't deny that your approach would solve my (relatively minor) problem.
from spectrum.
As for performance, that callback is happening anyway (internally in the plugin), and it is no big deal (since it is just dealing with string concatenation at the moment). I was suggesting that we could allow it to be overridden with a custom templating function in case you wanted to do something extra.
It would be more efficient to process the list of attributes as you suggested, but the only issue I have with implementing it directly is that I think if we were more flexible it would help more people. I see the need to customize the palette beyond the defaults, but I think everyone may have different goals (possibly wanting to change more than just the title - for instance, I could imagine wanting to make a certain swatch or row of swatches smaller than others or something).
Here is the current template function used internally in the plugin: https://github.com/bgrins/spectrum/blob/master/spectrum.js#L102. It is called once for each palette row. Obviously it would be nice for users to not have to reimplement that whole function (but that would be the easiest way to allow you to get custom behavior) - I'm trying to think of a different way to organize it. Possibly I can create a DOM element of the swatch and pass it into your custom callback, in which you could modify it however you wanted. That may not be good for performance as you mentioned, but it probably wouldn't be that bad.
from spectrum.
While this is an old thread, I'm facing the same issue as OP. Would like to add title attributes to name the colors. The link seems to point to HTML. What would your current recommendation be?
from spectrum.
@cmrockwell incidentally we were just discussing what sounds like the same request today in #407. I think the first option in #407 (comment) should work
from spectrum.
Yep, that works! Thanks much for the response
from spectrum.
Related Issues (20)
- spectrum("set", for transparent color?
- jQuery 3.4.1 -> 3.5.0 breaks palette layout HOT 1
- Selecting white sets value to #000000
- Container does not appears with 2.0.0 version HOT 1
- showButtons doesn't work HOT 3
- Colors stack in the palette HOT 1
- function rgbaToHex swap alha chanel
- Clicking outside of spectrum to fire on mousedown instead of click/mouseup?
- inssue with spectrum and the last jquery version 3.5
- Download link blocked over HTTPS in Chrome
- Spectrum Options not working HOT 1
- A problem with including var and conditional functions in the function HOT 2
- Elements are not accessable via Keyboard. NVDA Screen reader does not read it properly
- Problem after upgrading to JQuery 3.5.1 HOT 2
- Is there option to make Palette visible vertically instead of horizontally HOT 1
- Selection Palette bug HOT 1
- sp-container not destroyed when clicking on .sp-choose HOT 1
- Reset / Clear method HOT 1
- Upgrade to latest jQuery 3.6.0 with migrate 3.4.0 throws some deprecation-infos
- Color picker does not move 'sp-dragger' to reflect the color choice from the palette when a color is selected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spectrum.