/* 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.2 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){if(typeof options.pause_rate=='undefined'){var pause_rate=5000}else{var pause_rate=options.pause_rate}if(typeof options.fade_rate=='undefined'){var fade_rate=1000}else{var fade_rate=options.fade_rate}if(typeof options.loading_text=='undefined'){var loading_text='Loading...'}else{var loading_text=options.loading_text}if(typeof options.media_type=='undefined'){var media_type='content'}else{var media_type=options.media_type}if(typeof options.container=='undefined'){var container="#anyfeed_slideshow_main"}else{var container=options.container}if(typeof options.xml_url=='undefined'){var xml_url="temp.xml"}else{var xml_url=options.xml_url}if(typeof options.c_width=='undefined'){var c_width="100%"}else{var c_width=options.c_width}if(typeof options.c_height=='undefined'){var c_height="200px"}else{var c_height=options.c_height}if(typeof options.navigation=='undefined'){var navigation=true}else{var navigation=options.navigation}if(typeof options.title_bar=='undefined'){var title_bar=true}else{var title_bar=options.title_bar}if(typeof options.bgcolor=='undefined'){var bgcolor='transparent'}else{var bgcolor=options.bgcolor}if(typeof options.debug=='undefined'){var debug=false}else{var debug=options.debug}var total=0;var loaded=0;var slideshow_handle;var loading_handle;var slide_i=-1;var started=false;this.start=start;this.init=init;this.next=next;this.prev=prev;this.loading_start=loading_start;this.loading_stop=loading_stop;this.test=test;function init(){jQuery(container).css({width:c_width,height:c_height});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){jQuery(xml).find('item').each(function(){var title=jQuery(this).find('title').text();var link=jQuery(this).find('link').text();jQuery(this).find('media\\:'+media_type).each(function(){var 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;loading_stop(pause_rate+fade_rate);start()}};i1.src=url;if(title_bar){var titlebar='
'+title+'
'}else{var titlebar=''}jQuery(container).html(jQuery(container).html()+'
'+titlebar+'
');counter=counter+1;if(debug)console.log("Added.")}})})}else{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);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;var 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;loading_stop(pause_rate+fade_rate);start()}};i1.src=url;if(title_bar){var titlebar='
'+title+'
'}else{var titlebar=''}jQuery(container).html(jQuery(container).html()+'
'+titlebar+'
');counter=counter+1;if(debug)console.log("Added.")}});if(tmpcounter==0){if(debug)console.log("Attempting to find XML Content:encoded...");var fish=jQuery(this).find('content\\:encoded').text();if(fish){var 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;loading_stop(pause_rate+fade_rate);start()}};i1.src=url;if(title_bar){var titlebar='
'+title+'
'}else{var titlebar=''}jQuery(container).html(jQuery(container).html()+'
'+titlebar+'
');counter=counter+1;if(debug)console.log("Added.")}}}if(tmpcounter==0){if(debug)console.log("Attempting to find images in description text...");var fish=jQuery(this).find('description').text();var re=new RegExp("/(=counter){total=counter-1;loading_stop(pause_rate+fade_rate);start()}};i1.src=url;if(title_bar){var titlebar='
'+title+'
'}else{var 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.")}}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)}start()});if(debug)console.groupEnd();if(debug)console.group("Loading Images...")},error:function(){if(debug){jQuery(container).html("Failed to retreive XML file.")}}})}function start(){if(debug)console.groupEnd();if(total==0){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)}function next(){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)}function prev(){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)}function loading_start(){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)}function loading_stop(when){setTimeout(function(){clearTimeout(loading_handle);jQuery('#anyfeed_slideshow_loading').stop(true).fadeOut();started=true},when)}function test(){alert(started)}}