Comments (17)
We do have a class query selector built in, so you are not required to use ids
any of these will work
ZeroClipboard.Client(".clipboard-buttons")
ZeroClipboard.Client("button")
ZeroClipboard.Client("button:first-child")
from zeroclipboard.
I don't know if I want to start down the path of adding specific lines for libraries, but what would be great, that this point brings up, is the ability to pass in dom elements. @JamesMGreene what do you think?
from zeroclipboard.
Right, but the problem is that the widgets often start with some context which is NOT expressible as a string. The selectors which you handle all assume that they can be fully expressed via a selector string.
Since jquery selector results can usually be treated as an array, a simple test for an extra property (.jquery) seemed fairly innocuous- especially for the benefit gained. I suppose a test fore '.length' would be fine too and more general. But, passing in dom elements would be fine too.
from zeroclipboard.
I was a bit worried about requests like this and #60 when we went the query/selector route. Honestly, I feel like we'd be better off for maintenance if we only accepts element arrays (and maybe a single element) and let people manage their own selectors ahead of time.
from zeroclipboard.
Actually #60 just merged, which may solve this problem? Since you can use a non-string context now. @tjdhome
from zeroclipboard.
This would also avoid:
- Additional feature requests to offer full Sizzle selector support without Sizzle.
- Selector "bugs" being filed when users try advanced Sizzle queries without Sizzle (i.e. because Sizzle supports more advanced queries (and contexts) than
querySelectorAll
does). - Excessive type checking and logic branch overhead.
- Forcing users to requery for result sets they already have retrieved via jQuery, etc.
from zeroclipboard.
I could see the benefit of dropping the selector part. It's pretty common that people have libraries already installed. So it would end up being like this.
ZeroClipboard.Client(already_queried_elements);
from zeroclipboard.
@JamesMGreene we would need to come up with another solution for this https://github.com/jonrohan/ZeroClipboard/blob/master/src/javascript/ZeroClipboard/client.js#L39
from zeroclipboard.
I guess document.getElementById would work
from zeroclipboard.
I'm gonna create a PR to move the discussion there. closing this issue
from zeroclipboard.
Also see my comment on #60. :-\
from zeroclipboard.
One [last?] thought- accept either a list of elements/selector-expression or a function which returns a list of dom elements.
from zeroclipboard.
For me, it's a choice between:
a) making jQuery a dependency, and therefore supporting the various ways of querying elements, or …
b) just support element arrays (or single elements), leaving the task of selecting elements up to the user
When I was going through the API docs, and saw that I could use CSS selectors, I almost assumed it would behave like jQuery selectors (which is why I submitted #60).
from zeroclipboard.
What @domchristie just described is exactly what I'm talking about: someone starts reading docs, sees CSS selectors, assumes they can use the full-blown Sizzle selector engine that they all know and love, try an advanced Sizzle selector, then file a bug when it doesn't work as expected.
I'm thinking it would be best to pull in the reigns early on and switch to just accepting only an Element array... otherwise prepare for a trip down the rabbit hole. 👎
from zeroclipboard.
In other words: we're shipping an awesome library for clipboard injection, not DOM querying or manipulation. Let's keep those concerns separate so we can focus on enhancing our own library rather than importing half of Sizzle. 👍
from zeroclipboard.
I'm thinking it would be best to pull in the reigns early on and switch to just accepting only an Element array... otherwise prepare for a trip down the rabbit hole.
Agreed, I've started a branch so we can see what it might look like. Should we throw an error or return null if users still try and submit a query string?
from zeroclipboard.
Seems like throwing a TypeError
would be warranted in that situation, for both the Client
constructor and the glue
and unglue
methods.
from zeroclipboard.
Related Issues (20)
- Copy a table using zeroclipboard
- ZeroClipboard never initialises HOT 1
- Why the button on github repo page doesn't need a flash object HOT 2
- Seeking new maintainers/collaborators HOT 8
- zeroclipboard alternative HOT 1
- it not work in mac chrome HOT 2
- how to use in vue2.0? HOT 1
- the content contains "<script" , the copy doesn't work
- Not working upon Recent upgrade of chrome in windows, but IE works HOT 7
- Problem with using this in something other than a button
- why the position absolute are not working. help HOT 1
- not working in chrome HOT 2
- Unable to keep format as it is while copying HOT 1
- How can get the selector to set to other method
- Xss problem HOT 6
- init zeroclipboard throw flash-disabled error HOT 1
- Encoding problems in IE11
- Copy the table and paste the data into MS-Excel
- Demo page not work but github copy clone url does? HOT 1
- `<button>` independent, support run as callback please!
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 zeroclipboard.