views:

75

answers:

2

I came across a jQuery lightbox plug-in called PrettyPhoto. Seems very interesting. At the bottom of documentation I noticed a section about Public API, which I paste in its entirety below:

Version 2.5 introduced an easy to use API. You can now open prettyPhoto from anywere. The public API functions are the following:

$.prettyPhoto.open('images/fullscreen/image.jpg','Title','Description');
$.prettyPhoto.changePage('next');
$.prettyPhoto.changePage('previous');
$.prettyPhoto.close();

You can also open galleries using the API, just pass arrays to the open function.

images = ['images/fullscreen/image1.jpg','images/fullscreen/image2.jpg','images/fullscreen/image3.jpg'];
titles = ['Title 1','Title 2','Title 3'];
descriptions = ['Description 1','Description 2','Description 3']
$.prettyPhoto.open(images,titles,descriptions);

You can now open prettyPhoto from Flash or launch is from anywhere, anytime!

Great! I want to try it, but I have never dealt with APIs and have no idea how and where to plug the API code provided.

Can I create some sort of widget that will allow people placing it on other sites and open pictures there from my site? I'm lost. Google search did not yield any demos of its implementations.

Any nudge in the write direction will be highly appreciated.

+4  A: 

This is Javascript, so you need to write some Javascript code that interacts with the PrettyPhoto object. Usually PrettyPhoto works semi-automagically, you just initialize it with a number of options and it'll find links on the current page and act only when the user clicks on these links. Using the API you can get it to display images or move between images on your command though (i.e. you can write Javascript code that commands PrettyPhoto). "API" here just means "a bunch of public functions you can call." It should work as shown in the example, verbatim.

deceze
Wow, it is a bit out of my league but I think I need to move towards embracing this technology eventually.
santa
@santa Just FYI, you're already using APIs all the time in PHP. Every function you call in PHP is technically an API call, if you've ever downloaded and used some 3rd party library it had APIs you used. Javascript is not any different, it's just not PHP and you're probably just not used to it.
deceze
+1  A: 

API stands for Application programming interface.

Every application that supports an API has it's own custom implementation. On your specific case PrettyPhoto made an API than can be used calling those very same functions you pasted on your code.

Frankie