Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Element.dataset #45

Open
termi opened this issue Feb 3, 2012 · 5 comments
Open

Implement Element.dataset #45

termi opened this issue Feb 3, 2012 · 5 comments

Comments

@termi
Copy link
Collaborator

termi commented Feb 3, 2012

I began to collect information on the possible IE8 shim.
A workaround can be found here http://eligrey.com/blog/post/html-5-dataset-support

@Raynos
Copy link
Owner

Raynos commented Feb 3, 2012

The problem with dataset is this.

el.dataset.foo = "bar";
assert(el.getAttribute("data-foo") === "bar");

This basically means we need to hook getAttribute, setAttribute and hasAttribute up so that it reads from the dataset.

@termi
Copy link
Collaborator Author

termi commented Feb 3, 2012

And what about for(var i in element.dataset){ } and Array.from(element.dataset)?

el.dataset.foo = "bar";

means that we need getter/setter, witch IE8 supported only for DOM Element :(

I mean we need more stronger solution.

@Raynos
Copy link
Owner

Raynos commented Feb 3, 2012

You don't need getter/setters on .foo you need an ES6 proxy

In theory this should work.

  • dataset when got is pre populated with all the data- attributes
  • You can set/get on the dataset and it will store it internally somewhere.
  • Calls to getAttributes/setAttribute/attributes etc will reflect our internal dataset.
  • We may want to periodically put all the changed attributes of the internal dataset on the actual DOM node through the real APIs

@Raynos
Copy link
Owner

Raynos commented Feb 3, 2012

Note things like this will never work. (not without proxies)

var e = document.createElement("div");
e.dataset.foo = "bar";
console.log(e.outerHTML);

@brettz9
Copy link

brettz9 commented Dec 13, 2012

Doesn't address the issues mentioned here, but I have updated the original from Eli Grey with some improvements (including some changes taking advantage of his subsequent Xccessors shim): https://gist.github.com/4093766#file_html5_dataset.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants