leaverou / html5-progress-polyfill Goto Github PK
View Code? Open in Web Editor NEWPolyfill for the HTML5 <progress> element
Home Page: http://lea.verou.me/polyfills/progress/
License: Other
Polyfill for the HTML5 <progress> element
Home Page: http://lea.verou.me/polyfills/progress/
License: Other
You should match only HTML elements, as you currently match non-HTML <progress>
elements and don't match HTML <progress>
elements in an XML context. Here's a helper function that should make it easy:
function match_HTML_element(elt, name) {
if (elt.nodeType === elt.ELEMENT_NODE) {
return false;
}
var elt_name = elt.localName;
if (!elt.ownerDocument.xmlVersion) {
elt_name = elt_name.toLowerCase();
}
return elt.namespaceURI === "http://www.w3.org/1999/xhtml" && elt_name === name;
}
You'd want to replace node.nodeName === 'PROGRESS'
with match_HTML_element(node, "progress")
and label.nodeName !== 'LABEL'
with !match_HTML_element(label, "label")
in your code.
I have a page using KnockoutJS. This polyfill breaks because of the implementation of isInited()
. I'm assuming KO is cloning the element somehow that's not compatible with your polyfill.
The current implementation looks like this:
isInited: function(progress) {
return progress.getAttribute('role') === 'progressbar';
}
I changed it to look like this and it fixed it:
isInited: function(progress) {
return 'position' in progress;
}
I'd submit a pull request but I'm not certain this is the best solution.
A minor omission from the "how to use" documentation on the web site: it seems that for IE8 to work correctly, it needs the document.createElement("progress")
line in the section otherwise IE8 doesn't apply the CSS.
In your // Fallback to regular properties if getters/setters are not supported
section, it's quite clear without running it that it won't work as intended. You want etters.get.call(o)
.
A small bug appears when a border is applied to the progress bar. If the value of the progress bar is set to zero, the progress bar increases in width slightly, until the value is changed to a non-zero value. You can see what I mean here:
http://www.useragentman.com/tmp/progressPolyfill/test1.html
In order to fix this issue, I changed line 161 in your script from:
if(progress.position !== -1) {
progress.style.paddingRight = progress.offsetWidth *
(1-progress.position) + 'px';
}
to this:
if(progress.position !== -1) {
progress.style.paddingRight = progress.clientWidth *
(1-progress.position) + 'px';
}
(Note the change from offsetWidth to clientWidth). When this is applied, the jump in width doesn't happen anymore, as seen here:
http://www.useragentman.com/tmp/progressPolyfill/test1-fixed.html
Not a big deal and could be integrated very easily!
Can you confirm this works on iOS?
I tried setting progressElement.value = 50;
though it doesn't seem to do anything on iOS 5.1.
Thanks!
The link in the description is broken.
Polyfill for the HTML5 <progress> element http://leaverou.me/polyfills/progress/
should be
Polyfill for the HTML5 <progress> element http://lea.verou.me/polyfills/progress/
(added a dot between "lea" and "verou")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.