-
Notifications
You must be signed in to change notification settings - Fork 142
Refactor SVG events #954
Comments
SVG Event researchThe pages we havehttps://developer.mozilla.org/en-US/docs/Web/Events/beginEvent These three fire relatively obviously — when a SMIL animation (e.g. https://developer.mozilla.org/en-US/docs/Web/Events/SVGAbort
https://developer.mozilla.org/en-US/docs/Web/Events/SVGError
https://developer.mozilla.org/en-US/docs/Web/Events/SVGLoad
Note: "load" fires on SVG as expected in Chrome, but Firefox still supports the older "SVGLoad" https://developer.mozilla.org/en-US/docs/Web/Events/SVGResize
https://developer.mozilla.org/en-US/docs/Web/Events/SVGScroll
https://developer.mozilla.org/en-US/docs/Web/Events/SVGUnload
https://developer.mozilla.org/en-US/docs/Web/Events/SVGZoom
Removed SVG events From jwatt's mail: "As per https://svgwg.org/svg2-draft/single-page.html#changes-interact SVGZoom Specifically: "Replaced SVGLoad, SVGAbort, SVGError and SVGUnload with load, abort, error and unload respectively. Also from jwatt mail: "If you're listening for the correct event name, on the correct elements, for the From https://svgwg.org/svg2-draft/single-page.html#attindex-RegularAttributes: onbegin, onend, and onrepeat can be specified on onload, onerror can be specified on: a, animate, animateMotion, animateTransform, audio, canvas, circle, defs, desc, ellipse, foreignObject, g, iframe, image, line, linearGradient, marker, metadata, mpath, path, pattern, polygon, polyline, radialGradient, rect, script, set, stop, style, svg, switch, symbol, text, textPath, title, tspan, unknown, use, video, view onabort, onunload, onresize, and onscroll can be specified on only onzoom doesn't exist; SVGZoom is removed from spec. See https://svgwg.org/svg2-draft/single-page.html#interact-LoadEvent for more descriptions of how the events work. Work to do:
onscroll - Does exist in Firefox/Chrome, but I'm really not sure how you'd get the actual SVG to show scrollbars.
onabort - Does exist in Firefox/Chrome, fired when a document is stopped from loading completely. This is pretty hard to trigger, so probably just show a trivial example on this page. Also create abort_event page on SVGElement. onunload - onunload doesn't exist on embedded SVG elements in Fx or Chrome. Not sure where this exists, to be honest. onresize - Does exist in Firefox, on external SVG documents, e.g. referenced inside an element by e.currentTarget.contentWindow. In Chrome they only exist on the actual element. Create two quick pages for onresize and resize_event, to explain this? I can get it to fire, by resizing the element that embeds the SVG. Note: Doesn't fire when you load the svg in an element then resize it. In this case by default the SVG is stretched to fill the Summary: onbegin, onend, and onrepeat - move to hang off of SVGAnimationElement. Delete SVGZoom onload, onerror, onscroll, onabort, onresize - create pages for these on SVGElement onunload - doesn't seem to exist. HRM, THESE ONES ARE NIGHTMARES. MIGHT JUST REDIRECT TO THE STANDARD PAGES, AND CREATE AN EVENT SECTION ON SVGELEMENT THAT EXPLAINS THE IDIOSYNCRACIES. Or something. |
OK, so the animation events are done. See here for the events: https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimationElement#Events See here for the associated BCD: mdn/browser-compat-data#3767 |
Deleted the SVGZoom page. |
All the others have been moved to underneath the SVGElement interface page: https://developer.mozilla.org/en-US/docs/Web/API/SVGElement#Events See also here for BCD: mdn/browser-compat-data#3771 @irenesmith , you're on the list to review this one. Sorry. This is really horrible ;-) |
@chrisdavidmills It's easier to review than to write by a whole lot. The events were added to either SVGAnimationElement or SVGElement. I reviewed the pull request but it had already been merged. Oh well. |
Thanks @irenesmith . Yeah, I didn't really think they needed "See also" sections. If you think there are links that could be added, I'm happy to add them. |
All done — now just need to wait until BCD is available, and then refresh pages. |
Pages refreshed; BCD now visible on pages. @wbamberg, this can be moved to done, imo. Do you want give it a final check, as project lead? |
Thanks Chris! The The live example (e.g. https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimationElement/beginEvent_event#Examples) has a few problems. First I don't think it's ideal to use console.log to show output, because the user has to read all the example to see that they have to open the console, then open the console and pick through it. It's much better to display the output in the example (as we do for example in https://developer.mozilla.org/en-US/docs/Web/API/FileReader/progress_event#Examples). Second, if I do open the console, I just see an error:
and the script the example is using looks very weird (to see this code you could for example click "open in CodePen"): let svgElem = document.querySelector('svg');
let animateElem = document.querySelector('animateMotion');
animateElem.addEventListener('beginEvent', () => {
console.log('beginEvent fired');
})
animateElem.addEventListener('endEvent', () => {
console.log('endEvent fired');
})
animateElem.addEventListener('repeatEvent', (e) => {
console.log('repeatEvent fired');
if(e.detail) {
console.log('Repeat number: ' + e.detail);
}
})animateElem.onbegin = () => {
console.log('beginEvent fired');
}) (see the last three lines). What's happening I think is that the snippet showing the Finally I think it's problematic for an example to run on page load, then to finish running after a bit. Because suppose I open the page and read it a bit, then eventually get to the live example after it's finished (this is a very very likely scenario). Now the example is finished and there's no way to run it again, so it's unusable. So I think it is better for the example to do nothing on page load, but offer a way for the user to start it. Again this is a thing we do in pages like https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/progress_event#Examples). |
@wbamberg ooops, yes, the URLs were wrong! I've fixed that now, in mdn/browser-compat-data#3896 Now on to the examples. |
@wbamberg OK, on to the live examples.
I am still not 100% convinced that the examples are perfect, but they are a lot better now. SVG is such a pain to manipulate with JS, compared to HTML. |
Thank you @chrisdavidmills , that's much better! |
cool. |
Closing this as it looks done, thanks @chrisdavidmills ! |
This is a work item for #685.
Pages:
The text was updated successfully, but these errors were encountered: