I have a suggestion for the prettyPhoto developers:
I implemented deeplinking on a prettyphoto gallery by using the "changepicturecallback".
function change_picture() {
location.hash = setPosition;
}
The setPosition carries the current opened photo (an integer index). By using it on the location.hash, I could get urls like:
http://mysite.com.br/mygallery/#4
I added sharing links in the gallery so the user can share the url through orkut, twitter, facebook or email.
To let it be possible, prettyPhoto must be opened through API in a pic searching it by his setPosition. This way, accessing the url above, I can fall directly on the 5th pic of my gallery. I done it with the following code:
$(document).ready(function() {
if(location.hash) {
var index = location.hash.slice(1);
var pics = $('.gallery-list .item div a[rel*=lightbox]');
var urls = pics.map(function() { return $(this).attr('href') });
var titles = pics.map(function() { return $(this).attr('title') });
$.prettyPhoto.open(urls, null, titles, index);
}
});
The problem is that the "open' method does not expect the 4th parameter (index). So, I changed the prettyPhoto code:
$.prettyPhoto.open = function() {
if(typeof settings == "undefined"){ // Means it's an API call, need to manually get the settings and set the variables
settings = pp_settings;
_buildOverlay(this); // Build the overlay {this} being the caller
pp_images = $.makeArray(arguments[0]);
pp_titles = (arguments[1]) ? $.makeArray(arguments[1]) : $.makeArray("");
pp_descriptions = (arguments[2]) ? $.makeArray(arguments[2]) : $.makeArray("");
isSet = (pp_images.length > 1) ? true : false;
setPosition = (arguments[3]) ? parseInt(arguments[3]) : 0; // XXX make it possible to specify the pic index
}
...
Take a look on the last line of the if statement. The 4th argument defines the initial photo and, if it is not set, start from zero (the first one).
What about add this funcionallity to prettyPhoto? May I send a patch?