(function ($) {
$.fn.jqFlick = function (options) {
// Default options:
options = $.extend({
width: 100,
height: 67,
maxFetch: 9,
captions: false,
autoAdvance: false,
advancePeriod: 5000,
apiKey: ''
}, options);
// Template for building Flickr's image URLs:
var flickrSRC = '../farm%7bfarm%7d.static.flickr.com/%7bSERVER%7d/%7bID%7d_%7bSECRET%7d.jpg',
flickrSlider = this;
flickrSlider.trigger('jqFlickRemove');
// Fetching the images using Flickr's API:
$.getJSON('flickrphotoscfcc.aspx?jsoncallback=?', function (r) {
if (!r || !r.photos.photo || !r.photos.photo.length) {
throw "There is no such photoset!";
}
var currentPos = 1,
cnt = r.photos.photo.length;
var ul = $('
', {
css: {
height: options.height
}
});
var li = $('- ').appendTo(ul);
// Looping through the photo results:
$.each(r.photos.photo, function (index, value) {
if (index < options.maxFetch) {
data = this;
// Creating a new IMG element
if ((index % 3) == 2) {
$('
', { css: { marginRight: '0px'} }).attr("src", data.url_m).appendTo(li);
}
else {
$('
').attr("src", data.url_m).appendTo(li);
}
}
});
flickrSlider.addClass('flickrSliderHolder')
.width(options.width)
.height(options.height + 25)
.append(ul);
flickrSlider.trigger('slide', [1]);
});
// This custom event removes all event listeners,
// and empties the slider holder:
flickrSlider.bind('jqFlickRemove', function () {
if ($.fn.jqFlick.timeOut) {
clearTimeout($.fn.jqFlick.timeOut);
}
flickrSlider.empty().unbind('jqFlickRemove slide');
});
return flickrSlider;
};
// Helper function for replacing "{KEYWORD}" with
// the respectful values of an object:
function templateReplace(template, data) {
return template.replace(/{([^}]+)}/g, function (match, group) {
return data[group.toLowerCase()];
});
}
})(jQuery);