GithubHelp home page GithubHelp logo

Comments (17)

jonrohan avatar jonrohan commented on May 5, 2024

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.

jonrohan avatar jonrohan commented on May 5, 2024

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.

tjdhome avatar tjdhome commented on May 5, 2024

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.

JamesMGreene avatar JamesMGreene commented on May 5, 2024

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.

jonrohan avatar jonrohan commented on May 5, 2024

Actually #60 just merged, which may solve this problem? Since you can use a non-string context now. @tjdhome

from zeroclipboard.

JamesMGreene avatar JamesMGreene commented on May 5, 2024

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.

jonrohan avatar jonrohan commented on May 5, 2024

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.

jonrohan avatar jonrohan commented on May 5, 2024

@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.

jonrohan avatar jonrohan commented on May 5, 2024

I guess document.getElementById would work

from zeroclipboard.

jonrohan avatar jonrohan commented on May 5, 2024

I'm gonna create a PR to move the discussion there. closing this issue

from zeroclipboard.

JamesMGreene avatar JamesMGreene commented on May 5, 2024

Also see my comment on #60. :-\

from zeroclipboard.

tjdhome avatar tjdhome commented on May 5, 2024

One [last?] thought- accept either a list of elements/selector-expression or a function which returns a list of dom elements.

from zeroclipboard.

domchristie avatar domchristie commented on May 5, 2024

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.

JamesMGreene avatar JamesMGreene commented on May 5, 2024

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.

JamesMGreene avatar JamesMGreene commented on May 5, 2024

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.

jonrohan avatar jonrohan commented on May 5, 2024

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.

JamesMGreene avatar JamesMGreene commented on May 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.