-
Book Overview & Buying
-
Table Of Contents
Instant Galleria How-to
By :
Here we will learn how we can use and extend the flickr plugin to display a flickr gallery with Galleria.
We're going to use the myfirstgallery.html file and modify the example again, though it's fine to use whatever gallery implementation is available if preferred.
Create a basic gallery with Galleria's flickr plugin using the following JavaScript code inside our head tag:
<script src="http://code.jquery.com/jquery.min.js"></script> <script src="../galleria-1.2.8.min.js"></script> <script src="../plugins/flickr/galleria.flickr.min.js"> </script> <script type="text/javascript"> $(document).ready(function(){ Galleria.loadTheme( '../themes/classic/galleria.classic.min.js'); Galleria.run('#galleria', { flickr: 'search:beach' }); }); </script>
Here, we're just including the JavaScript plugin and calling the Galleria.run function with the flickr option to search for photos with beach in their title. By default, the flickr gallery only retrieves the first 30 Flickr photos.
For a more complex flickr gallery that continually retrieves more images from Flickr, we can use Flickr in a more dynamic way, along with Galleria, to continuously add images to the gallery as the user approaches the end of the gallery using the following code:
<script type="text/javascript">
$(document).ready(function(){
Galleria.loadTheme(
'../themes/classic/galleria.classic.min.js');
var flickr = new Galleria.Flickr(),
page = 1;
flickr.search('beach', function(data) {
Galleria.run('#galleria', { dataSource: data });
});
Galleria.ready(function(options) {
var galleria = this;
galleria.bind('loadfinish', function(e) {
/* after an image is loaded, check to see how
close we are to loading more images */
if((e.index + 5) > galleria.getDataLength()){
/* start loading more images */
page += 1;
flickr._find({ text: 'beach', page: page},
function(data) {
// add the image data to the gallery
galleria.push(data);
});
}
});
});
});
</script>Here we're utilizing some of Galleria's API to continually add images as we approach the end of the gallery. The loadfinish event is called after each image is loaded. The flickr._find method allows us to search Flickr with a page parameter so that we can grab the next set of results. Finally, the galleria.push method lets us add the image data to the Galleria instance.
The benefit of doing it this way as opposed to loading all the images immediately is that the web page will load much faster, as it only retrieves the images as necessary.
The flickr plugin uses the flickr RESTful API to retrieve images that are used with the Galleria API to dynamically add images to the gallery.
There are additional flickr plugin options that can be used; however, they need to be specified in their own flickrOptions object:
Galleria.run('#galleria', {
flickr: 'search:beach',
flickrOptions: {
max: 50
}
});The following list is a complete listing of flickr plugin options:
max: This option provides the maximum number of images that will be retrieved from Flickr. Its default value is set to 30.
imageSize: This option provides the size of the image. Options include small, thumb, medium, big, original. Its default value is set to medium.
sort: This option provides the sort order for the images. Potential values include field followed by "asc" or "desc". Allowed fields are date-posted, date-taken, and interestingness. Its default value is set to interestingness-desc.
description: This option is a Boolean to specify whether the description should also be retrieved from Flickr. Its default value is set to false.
There is also a flickr plugin API that allows for more advanced behavior such as sorting, batching, group searches, and retrieving tags and set. Detailed documentation on what's available can be found at http://galleria.io/docs/plugins/flickr/.
Additionally, Flickr provides a very robust RESTful API that the plugin utilizes. An overview on all the available methods can be found at http://www.flickr.com/services/api/.
The flickr._find method we used utilizes the flickr.photos.search rest method. For a more detailed description of available parameters to that method, visit http://www.flickr.com/services/api/flickr.photos.search.html.
Change the font size
Change margin width
Change background colour