I don't believe $.fn.data is symmetric with respect to get and set. This will update an in memory cache of "data-*" values only, leaving the corresponding DOM attribute untouched.
I think jq's data methods allow you to store any type of object. So in the example above, '60' would be stored as a Number and not a String. When you extract it, you would get the Number and this helps if you want to do any math on the value.
Since you can't really set element attributes to non-string values, trying to sync the 'data' values with element attributes raises all sorts of unwanted problems.
Guessing, but it's probably because $.fn.data is meant as a storage mechanism, not a DOM manipulation mechanism. Changing the DOM attribute would make it just that tiny bit more expensive and you can already use $.fn.attr to do the same thing.
Yeah now this rings a bell I did have a go at using it like this before but the DOM didn't update as mentioned so I reverted to using it how I wrote above.
Yeah that's the angle I was going for with this so it's just super simple to add it wherever you want it without having to worry about layouts etc. or borking your elements.
Using :after means you don't even need to factor it as an element into your existing design, you just place it on top.
I appreciate bumping this link in a few places but I have some questions regarding it.
If all you do is put a js file in and a theme file, how do you have control over what element, the progress bar is on without having to write css to do so and how do you say which requests to monitor and which ones to not? It seems like having full control isn't quite there.
You could simply add an AJAX prefilter that has an update function within it before making AJAX calls and that wouldn't be many lines of code at all and means one less dependency.
I would have to say if your element is using both of it's pseudo elements, this may not be the one for you or you may have to introduce another element to use progre(c)ss.
My main scenario would be using it on a container element which in my use cases rarely is using it's pseudo elements already but I can see how this would be an issue.
Yes, I'd be more than happy to provide a SASS version, I'll look into that, hopefully this evening as it shouldn't be too long to make one at all.
Do you feel the documentation gets across what can be done with it clear enough?
For instance, This doesn't need a js dependency but you could easily mock progress using a keyframe animation on a particular progre(c)ss etc. I am going to try and make some clearer docs and try add some feature attributes, or classes.
I just want it to be clear to people that you can add it to existing elements I think without changing design.
Thanks again for the feedback and I'll get a SASS file in as soon as I can.
I would definitely emphasize that it's pure CSS, because it wasn't obvious to me when I looked. Instead of
custom css progress bars with minimal effort!
you could write:
Pure CSS progress bars with minimal effort!
(Yeah, the lack of capitalization looks a bit shoddy to me.)
Aside from that, it looks great. That said, I think a JavaScript helper to complement it would be great; I am using NProgress in several apps, and I like the fact that I can just start and stop it, and it will just do its thing.
"A nanoscopic progress bar. Featuring realistic trickle animations to convince your users that something is happening!"
You could do the same with progre(c)ss. And do it purely with CSS. Essentially that is what I am doing with the proge(c)ss bars on the page, I am using a keyframe animation and just setting different times on it.
Also, the main point of this is just to make a super simple CSS implementation that requires little JS to work.
Because on the js side you are still having to call a start function and a done function and whatever else you need which is the same as being able to do this with just CSS and then just doing a one liner in js that sets the attribute or adds a class.
Also with progre(c)ss you are only needing one file and people can quite easily change the attribute without having to load in a js file.