;(function ( $, window, document, undefined ) { // Create the defaults once var pluginName = 'ploguine', defaults = { width: "100%", height: "800px", folder: "", imgArray: "", basepath: "/", autoplay: true, delay: 3000, fadeOnLoad: 2000, crossfadeDelay: 1000, random: true, imgSizing: "" }; var currentPosition = 0; // plugin constructor function Plugin( element, options ) { var base = this; base.element = element; //dom element base.$element = $(element); //jquery element this.myindex = "1"; base.options = $.extend( {}, defaults, options) ; base._defaults = defaults; base._name = pluginName; base.nextSlide = function(){ if (base.options.crossfadeDelay > base.options.delay) { //this.options.crossfadeDelay = this.options.delay-50; //leave a gap } var trans1 = '-webkit-transition', myCSSObj = { opacity : 0 }; var trans2 = '-moz-transition', myCSSObj = { opacity : 0 }; var trans3 = '-o-transition', myCSSObj = { opacity : 0 }; var trans4 = '-ms-transition', myCSSObj = { opacity : 0 }; var trans5 = 'transition', myCSSObj = { opacity : 0 }; myCSSObj[trans1] = 'opacity '+ base.options.crossfadeDelay +'ms ease-in-out'; myCSSObj[trans2] = 'opacity '+ base.options.crossfadeDelay +'ms ease-in-out'; myCSSObj[trans3] = 'opacity '+ base.options.crossfadeDelay +'ms ease-in-out'; myCSSObj[trans4] = 'opacity '+ base.options.crossfadeDelay +'ms ease-in-out'; myCSSObj[trans5] = 'opacity '+ base.options.crossfadeDelay +'ms ease-in-out'; //fadeout the front div base._divtorotate = $(element).children().last(); base._divtorotate.animate({ na: 100 }, { //this is a hack we animate a non existing property step: function(now,fx) { $(this).css(myCSSObj); // $(element).children().first().css(myCSSObj_reverse); }, complete: function() { base._divtorotate.removeClass("active"); base._divtorotate.prependTo($(element)); base._divtorotate.css('opacity', 1); $(element).children().last().addClass("active"); currentPosition = $(element).children().last().data("index"); }, duration:base.options.crossfadeDelay },'linear'); } base.init(); } Plugin.prototype.init = function () { //try to find the specified folder var base = this; $.ajax({ url: "/js/jquery.laburbainslideshow.php", type: "POST", data: { folder: base.options.folder, random: base.options.random, basepath: base.options.basepath } }).done(function( result ) { console.log(result); base.options.imgArray = eval(result); base.$element.css({width:base.options.width, display:'none'}); for (var i = 0; i < base.options.imgArray.length; i++) { base.$element.append("
"); } //fadein if (base.options.fadeOnLoad > 0) { base.$element.fadeIn(base.options.fadeOnLoad); }else{ base.$element.show(); } //if the img array is bigger than 1 start timer if (base.options.imgArray.length > 1) { setInterval($.proxy(base.nextSlide, base), base.options.delay); //setInterval(console.log("nextcalled"), this.options.delay); } }); }; $.fn[pluginName] = function ( options ) { return this.each(function () { if (!$.data(this, 'plugin_' + pluginName)) { $.data(this, 'plugin_' + pluginName, new Plugin( this, options )); } }); } $.fn.getActive = function(){ return currentPosition; }; })( jQuery, window, document );