/* Plugin Name: Anyfeed Slideshow Plugin URI: http://tixen.net/anyfeed-slideshow/ Description: A quick and easy jQuery based slideshow widget, fed from absolutely any XML/RSS/ATOM feed that contains images! Version: 1.0.5 Author: Soleil Golden Author URI: http://tixen.net/ License: GPL 2.0 Copyright 2010, Soleil Golden (email : soleil@tixen.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ function anyfeed_slideshow(options) { /*--------------------------- Global Variables -------------------------*/ var pause_rate=5000,fade_rate=1000,loading_text='Loading...',media_type='content'; var container="#anyfeed_slideshow_main",xml_url="temp.xml",c_width="100%"; var c_height="200px",navigation=true,title_bar=true,bgcolor='transparent',debug=false; var total=0,loaded=0,slideshow_handle,loading_handle,slide_i=(-1),started=false; var titlebar,fish,url,re; for (var key in options) { if(eval(key+'!== undefined')) { eval(key+' = options.'+key+';'); } } /*----------------------------------------------------------------------*/ this.init = function() { // Set width and height jQuery(container).css({width: c_width, height: c_height}); anyfeed.loading_start(); if(debug) { console.group("Parsing XML"); } jQuery.ajax({ type: "GET", url: xml_url, dataType: "xml", timeout: 5000, success: function(xml) { if(navigation) { jQuery(container).html(jQuery(container).html()+'
'); } var counter = 0; var media; jQuery(xml).find('rss').each(function(){ if(jQuery(this).attr('xmlns:media')){media = true;} else{media = false;} }); if(media){ // Media feed (Flikr, Yahoo, etc) jQuery(xml).find('item').each(function(){ var title = jQuery(this).find('title').text(); var link = jQuery(this).find('link').text(); if(debug) { console.log("Trying to parse media feed."); } jQuery(this).find('[nodeName=media:'+media_type+']').each(function(){if(debug) { console.log("Successful- pulling image."); } url = jQuery(this).attr('url'); if(debug) { console.log(url); } if(url === null || url === "" || url === undefined) { if(debug) { console.log("Skipped."); } } else{ var i1 = new Image(); i1.onload = function() { loaded = loaded + 1; if(loaded >= counter){ total = counter -1; anyfeed.loading_stop(pause_rate + fade_rate); anyfeed.start(); } }; i1.src = url; if(title_bar){ titlebar='
'+title+'
';} else{ titlebar = ''; } jQuery(container).html(jQuery(container).html()+'
'+titlebar+'
'); counter = counter + 1; if(debug) { console.log("Added."); } } }); }); } else { // Regular RSS Feed (prep) if(debug) { console.log("Trying to parse RSS feed."); } jQuery(xml).find('item').each(function(){ var tmpcounter = 0; var title = jQuery(this).find('title').text(); var link = jQuery(this).find('link').text(); if(debug) { console.group("Title: " + title); } // Regular RSS Feed if(debug) { console.log("Attempting to find image attachments"); } jQuery(this).find('enclosure').each(function(){ if(debug) { console.info("Feed with image attachments"); } tmpcounter += 1; url = jQuery(this).attr('url'); if(debug) { console.log(url); } if(url === null || url === "" || url === undefined) { if(debug) { console.log("Skipped."); } } else{ var i1 = new Image(); i1.onload = function() { if(debug) { console.info("Loading... %a / %b", counter, loaded + 1); } loaded = loaded + 1; if(loaded >= counter){ total = counter -1; anyfeed.loading_stop(pause_rate + fade_rate); anyfeed.start(); } }; i1.src = url; if(title_bar){ titlebar='
'+title+'
';} else{ titlebar = ''; } jQuery(container).html(jQuery(container).html()+'
'+titlebar+'
'); counter = counter + 1; if(debug) { console.log("Added."); } } }); // Feed without image attachments if(tmpcounter === 0) { if(debug) { console.log("Attempting to find XML Content:encoded..."); } fish = jQuery(this).find('[nodeName=content:encoded]').text(); if(fish) { url = jQuery(fish).find('img').attr('src'); if(url === null || url === "" || url === undefined) { if(debug) { console.log("Skipped."); } } else{ if(debug) { console.info("Feed without image attachments"); } if(debug) { console.log("URL: " + url); } tmpcounter += 1; var i1 = new Image(); i1.onload = function() { if(debug) { console.info("Loading... %a / %b", counter, loaded + 1); } loaded = loaded + 1; if(loaded >= counter){ total = counter -1; anyfeed.loading_stop(pause_rate + fade_rate); anyfeed.start(); } }; i1.src = url; if(title_bar){ titlebar='
'+title+'
';} else{ titlebar = ''; } jQuery(container).html(jQuery(container).html()+'
'+titlebar+'
'); counter = counter + 1; if(debug) { console.log("Added."); } } } // end check fish for content } // End feed without image attachments // Feed without Content, only descriptions if(tmpcounter === 0) { if(debug) { console.log("Attempting to find images in description text..."); } fish = jQuery(this).find('description').text(); re = new RegExp("/(= counter){ total = counter -1; anyfeed.loading_stop(pause_rate + fade_rate); anyfeed.start(); } }; i1.src = url; if(title_bar){ titlebar='
'+title+'
';} else{ titlebar = ''; } jQuery(container).html(jQuery(container).html()+'
'+titlebar+'
'); if(debug) { console.log("%a Added.", counter); } counter = counter + 1; } else { if(debug) { console.log("skipped."); } } } else { if(debug) { console.log("Nothing here! Skipping."); } } } // End feed without content if(debug) { console.groupEnd(); } }); } if(counter === 0) {return false;} jQuery(container).hover( function() { if(started){ jQuery("div.anyfeed_titlebar").fadeIn(fade_rate / 5); if(total > 0)jQuery("div.anyfeed_navigation").fadeIn(fade_rate / 5); setTimeout(function() {jQuery("div.anyfeed_titlebar").css({display: "block"});},fade_rate / 3); if(total > 0)setTimeout(function() {jQuery("div.anyfeed_navigation").css({display: "block"});},fade_rate / 3); } clearTimeout(slideshow_handle); }, function () { if(started){ jQuery("div.anyfeed_titlebar").fadeOut(fade_rate / 2); if(total > 0) jQuery("div.anyfeed_navigation").fadeOut(fade_rate / 2); setTimeout(function() {jQuery("div.anyfeed_titlebar").css({display: "none"});},fade_rate / 2); } anyfeed.start(); } ); if(debug) { console.groupEnd(); } if(debug) { console.group("Loading Images..."); } }, error: function() { if(debug){jQuery(container).html("Failed to retreive XML file."); } } }); } this.start = function() { if(debug) { console.groupEnd(); } if(total === 0){ anyfeed.loading_stop(1); jQuery("#anyfeed_photo_0").fadeIn(fade_rate); return false; } slideshow_handle = setInterval(function() { if(slide_i >= total){ var fadethis="#anyfeed_photo_"+(total); slide_i = 0; } else { var fadethis = "#anyfeed_photo_"+(slide_i); slide_i = slide_i + 1; } setTimeout(function(){ jQuery(fadethis).fadeOut(fade_rate); }, fade_rate / 2); jQuery("#anyfeed_photo_"+slide_i).fadeIn(fade_rate); }, pause_rate + fade_rate); } this.next = function(){ if(slide_i >= total){ var fadethis="#anyfeed_photo_"+(total); slide_i = 0; } else { var fadethis="#anyfeed_photo_"+(slide_i); slide_i = slide_i + 1; } setTimeout(function(){ jQuery(fadethis).fadeOut(fade_rate / 3); }, fade_rate / 6); jQuery("#anyfeed_photo_"+slide_i).fadeIn(fade_rate / 3); } this.prev = function(){ if(slide_i <= 0){ var fadethis="#anyfeed_photo_0"; slide_i = total; }else { var fadethis="#anyfeed_photo_"+slide_i; slide_i = slide_i - 1; } setTimeout(function(){ jQuery(fadethis).fadeOut(fade_rate / 3); }, fade_rate / 6); jQuery("#anyfeed_photo_"+slide_i).fadeIn(fade_rate / 3); } this.loading_start = function() { jQuery(container).html('
'+loading_text+'
'); jQuery('#anyfeed_slideshow_loading').css({opacity: 0.1}); loading_handle = setInterval(function() { jQuery("#anyfeed_slideshow_loading").animate( { opacity: 0.5 }, 1400, function() { jQuery("#anyfeed_slideshow_loading").animate( { opacity: 0.1 }, 1400); }); }, 3000); // End setInterval } // End loading_start this.loading_stop = function(when) { setTimeout(function(){ clearTimeout(loading_handle); jQuery('#anyfeed_slideshow_loading').stop(true).fadeOut(); started=true; }, when); } // End loading_stop this.test = function() { alert(started); } } // End Class function