spectrum
spectrum copied to clipboard
Fix clickoutFiresChange if you click on an iframe
bind event into a iframe.
Handling the click in iframes can be tricky business because of the same origin policy and the fact that the frames can live (and load) independently from the spectrum instance. We would want to make sure that we weren't throwing exceptions when trying to bind to a document from a different origin, and to clean up the events on any frames from which they were added.
So I'd like if we could set up a more in depth test for this before landing a change. I've set up two fiddles for testing:
Outer frame: http://jsfiddle.net/bgrins/fSd8B/ Inner frame: http://jsfiddle.net/bgrins/QfcSG/
This demonstrates one way that it could be solved from the inner frame (assuming you control the code there as well). Basically, just adding a listener on the inner document and triggering the click.spectrum event on the outer body is a workaround.
If we could come up with something in the plugin that handles this automatically without throwing errors on non same-origin pages, dealing with unloaded frames, cleaning up the handlers when spectrum is destroyed, etc I would be for it - but I'm not sure how easy it will be. We may look at jQuery UI for inspiration on some of this to see if they've worked around frames on their handlers.
Perfect. That's work. Maybe that "trigger" can help other people working with iframes of the same origin policy
Actually you won't be able to trigger on the parent frame without same origin. Just like you can't reach into the frame and access its document (which is what the PR change does).
I just saw iframeFix in jQuery UI: http://api.jqueryui.com/draggable/#option-iframeFix. This puts transparent overlays over all of the iframes in a document: https://github.com/jquery/jquery-ui/blob/7017805745873e61b32769354a13dc697cdf3ae0/ui/draggable.js#L122-L130. Then they are removed here: https://github.com/jquery/jquery-ui/blob/7017805745873e61b32769354a13dc697cdf3ae0/ui/draggable.js#L283-L285. This is how I would suggest we tackle this problem in spectrum.
If you can update the PR to match this code to add the overlays on show and remove them on hide (behind an iframeFix option) I'd be happy to merge.