|
|
Thread Tools | Display Modes |
|
#1
|
|
|
David Underhill
|
When a user clicks on a thumbnail in my gallery, the #mainImage src attribute is updated. Is there some way I can register a JavaScript event listener so that I receive a callback when this happens?
If not, I could have a function check #mainImage.src every 100ms and check to see if it had changed. This wouldn't be so bad, but I was hoping I wouldn't have to resort to polling it. Is there a better way? |
|
|
|
|
#2
|
|
|
Scripting dude-volunteer
|
If you put this javascript in your bottom javascript:
Code:
onPhotoShow.subscribe(MyNewPhotoLoaded);
function MyNewPhotoLoaded()
{
// put your code here
}
__________________
--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 |
|
|
|
|
#3
|
|
|
David Underhill
|
Wonderful! Is there someplace where this and other events are documented? I imagine there might be other things like this that would be worth discovering :).
|
|
|
|
|
#4
|
|
|
Scripting dude-volunteer
|
Not that I know of.
__________________
--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 |
|
|
|
|
#5
|
|
|
David Underhill
|
Haha, that's too bad. Well, I'm especially glad for your help and quick replies then
Is there a way to get the new image's SmugMug Key and ID without parsing #mainImage.src? It wouldn't be hard to parse but if the work's already done I'll take advantage of it. Also, is there a similar event I can subscribe to in order to be notified of when the list of thumbnails change? And to get a list of which thumbnails are currently showing? I could just look at the children of #thumbnail to get a list of image IDs, but if there's a easier way ... |
|
|
|
|
#6
|
||
|
Scripting dude-volunteer
|
Quote:
The following global JS variables are available in the Smugmug view web page, but may not be available in other pages so be careful with your script. AlbumID AlbumKey ImageID ImageKey In the Smugmug view, you can get lots more info about the various photos in the page with access to the photoInfo array: photoInfo[ImageID] For example, the filename can be retrieved with: photoInfo[ImageID].fileName
__________________
--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 |
|
|
|
||
|
#7
|
|
|
David Underhill
|
Wow, thanks for all this great info John - this should keep me busy for a little while now!
|
|
|
|
|
#8
|
||
|
David Underhill
|
Quote:
Is there a way to get a callback as soon as ImageID is set? That's all the information I need, and perhaps there's some way I could get a callback faster in this case. |
|
|
|
||
|
#9
|
||
|
Scripting dude-volunteer
|
Quote:
__________________
--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 |
|
|
|
||
|
#10
|
|
|
David Underhill
|
Fortunately there is a way to get the callback faster. Unfortunately, the only way to do it is via polling.
I use setInterval() to periodically call a function which checks to see if ImageID is changed. When ImageID changes, I manually issue the callback registered with onPhotoShow. I find that this results in a MUCH snappier response time that is quite tolerable for the user. Numbers (for fun)
|
|
|
|
|
#11
|
||
|
Scripting dude-volunteer
|
Quote:
__________________
--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 |
|
|
|
||
|
#12
|
|
|
David Underhill
|
Here's the code:
Code:
/**
* poll to find out about any change to ImageID ASAP - the onPhotoShow
* callback is usually WAY too slow to wait for (~600ms!).
*/
var pastImageID = null;
setInterval(function() {
if(pastImageID !== ImageID) {
if(photoInfo[ImageID] !== undefined) {
newPhotoLoaded(); // sets pastImageID to ImageID
}
}
}, 100);
I'd be interested to hear about what you observe when trying it out. |
|
|
|
| Tell The World! | |
| Tags | |
| callback , image changed , javascript | |
| Similar Threads | Thread Starter | Forum | Replies | Last Post | ![]() |
| Image Tank Review- Wolverine PicPac 250GB | Justiceiro | Accessories | 10 | Oct-15-2009 12:35 PM | |
| Audubon Swamp Garden in Magnolia Gardens | Dixie | Wildlife | 25 | Apr-10-2007 09:54 PM | |
| JavaScript Help Anyone? (Pop-up Image Size) | jethro | SmugMug Customization | 4 | Nov-16-2006 12:15 AM | |
| Thread Tools | |
| Display Modes | |
|
|