For anyone with specific knowledge of it, this all relates to the WordPress "Theme Customizer", though that's not necessary to answer this.
Basically, I have a page (in PHP) which contains a left-side "pane" of settings which apply to the contents of an iframe, which is the right portion of the screen.
Conceptually, I'm looking to use jQuery draggable to make the CSS background-position
of the main background image adjustable via the draggable function. I need to apply draggable()
on the customize.php
page, enqueue the script there, and then manipulate the DOM inside the iframe. It needs to be done at the container/parent level because there is a setting at that level which will update the X and Y coordinates and save them in the settings stored there.
I think what I need might be impossible, but I'm wondering if it's possible with javascript to do both of the following:
- Get the content of the iframe
- Manipulate the DOM inside the iframe, adjust the background image via
draggable()
and storebackground-position
coordinates as a data-attribute and then save them to the appropriate setting input field.
In my experience, manipulating the DOM inside an iframe from the "parent" / container level is difficult and I'm wondering if there's something I don't know, it's definitely impossible, or there is some workaround? (Note that the originating domain is the same, so there would not be any cross-domain iframe issues)
Here is a reduced code of my test implementation for parent iframe communication. i added some samples how it could be used. But i have to note that it is out of my labs section, and i currently don't have had the time to check if it is fully cross browser compatible. but if it is not there will only be some minor change that are have to be done. (EDIT tested in current chrome, ff and IE 6-9)
I hope this will help you with you problem. But again i cannot guarantee right now that it will work perfectly (but i'm pretty sure).
code of the parent
code of the iframe