Note to {JT} about javascript customization
jfriend
Registered Users Posts: 8,097 Major grins
This is a note to {JT}. We need a new event (kind of like onPhotoshow.subscribe) that signifies that as far as Smugmug is concerned, the page is fully done and everything they are going to add to the page has been added.
Problem Statement: How do you trigger your own javascript event when Smugmug is done adding things to the page?
With the recent addition to Smugmug pages of more and more dynamically created objects that are created at YE.onDOMReady time, it has suddenly become quite difficult to reliably do certain kinds of javascript customization because there's no reliable way to trigger an event when Smugmug is done building the page. It used to be that at YE.onDOMReady time, anything Smugmug was putting in the page was there because it came from the page load. But now some things are added dynamically to the page at YE.onDOMReady time (slideshow button, share button, buy button, cart button, etc...). Since there is no guaranteed execution order of YE.onDOMReady calls, it's very difficult to find a way to trigger execution of your own javascript function when Smugmug is done with the page.
If you only care about modifying one javascript object, you can use YE.onContentReady for that one object. But, if you want to run some javascript that operates on multiple objects and some of those are dynamically craeted things, there is no easy way to do it.
An example: A user wants a javascript function that will move the slideshow button and place it on the same row as the buy button. Both of those buttons are dynamically created things. How do I trigger a javascript function at the earliest possible moment that both of these objects and their containers are fully formed?
One Solution: While there are probably many ways to solve this dilemna, one way would be by creating a new page-level event that Smugmug triggers when all their own dynamically created objects are done (perhaps similar to the way onPhotoShow.subscribe() works). Then, we could just register an interest in the event that tells us that Smugmug is done adding things to the page and we'd know the page was ours to safely modify now.
Problem Statement: How do you trigger your own javascript event when Smugmug is done adding things to the page?
With the recent addition to Smugmug pages of more and more dynamically created objects that are created at YE.onDOMReady time, it has suddenly become quite difficult to reliably do certain kinds of javascript customization because there's no reliable way to trigger an event when Smugmug is done building the page. It used to be that at YE.onDOMReady time, anything Smugmug was putting in the page was there because it came from the page load. But now some things are added dynamically to the page at YE.onDOMReady time (slideshow button, share button, buy button, cart button, etc...). Since there is no guaranteed execution order of YE.onDOMReady calls, it's very difficult to find a way to trigger execution of your own javascript function when Smugmug is done with the page.
If you only care about modifying one javascript object, you can use YE.onContentReady for that one object. But, if you want to run some javascript that operates on multiple objects and some of those are dynamically craeted things, there is no easy way to do it.
An example: A user wants a javascript function that will move the slideshow button and place it on the same row as the buy button. Both of those buttons are dynamically created things. How do I trigger a javascript function at the earliest possible moment that both of these objects and their containers are fully formed?
One Solution: While there are probably many ways to solve this dilemna, one way would be by creating a new page-level event that Smugmug triggers when all their own dynamically created objects are done (perhaps similar to the way onPhotoShow.subscribe() works). Then, we could just register an interest in the event that tells us that Smugmug is done adding things to the page and we'd know the page was ours to safely modify now.
--John
Homepage • Popular
JFriend's javascript customizations • Secrets for getting fast answers on Dgrin
Always include a link to your site when posting a question
Homepage • Popular
JFriend's javascript customizations • Secrets for getting fast answers on Dgrin
Always include a link to your site when posting a question
0
Comments
John,
I believe that this case should be simple enough to handle with two cascaded YE.onContentReady events.
Cheers,
David
SmugMug API Developer
My Photos
It would be really useful to have an event when Smumug is done adding things to the page.
Homepage • Popular
JFriend's javascript customizations • Secrets for getting fast answers on Dgrin
Always include a link to your site when posting a question
I'm not sure what you mean by "truly never done". I''m just interested in when all the static elements that are added via javascript have been added to the page (slideshow button, buy button, cart button, etc...). I'm just look for something similar to onPhotoShow.subscribe(), but in this case it would be onPageBuilt.subscribe() of something like that.
Homepage • Popular
JFriend's javascript customizations • Secrets for getting fast answers on Dgrin
Always include a link to your site when posting a question
John,
This could be achieved with some additional logic pretty easily...
Cheers,
David
SmugMug API Developer
My Photos
Is window load guaranteed to be after all calls to onDOMReady?
Homepage • Popular
JFriend's javascript customizations • Secrets for getting fast answers on Dgrin
Always include a link to your site when posting a question
i'm pretty certain you should be fine, since window.load isn't called until all images etc have been loaded.
SmugMug API Developer
My Photos
If YUI would guarantee that onDOMReady calls were called in the order they registered, my onDOMReady call in the footer javascript could work too, but I can't find anything written about onDOMReady calling order. I could look at their code to see how it works, but if it's not documented, then it could change.
Homepage • Popular
JFriend's javascript customizations • Secrets for getting fast answers on Dgrin
Always include a link to your site when posting a question
Homepage • Popular
JFriend's javascript customizations • Secrets for getting fast answers on Dgrin
Always include a link to your site when posting a question
How you interpret that is up to you.