Jump to content

Using A jQuery Plugin


cpugeek
 Share

Recommended Posts

Hello, it's been a while since I've posted in this forum, but I'm doing what I can to get a pre-existing jQuery plugin to work, and I'm currently pulling out all of my hair. The plugin itself works, I'm just unsure how to implement it. After including it, what html would I use to create the slider? A live version of the script can be viewed here: http://wptitans.com/majestics/

// JavaScript DocumentjQuery(function($){ $.fn.featureslider = function(options){ /* ================================================================================================ *//* ======================================== Plugin Options ======================================== *//* ================================================================================================ */var defaults = {				time:4000,	   width:600,	   height:400,	   effect:'none',	   autoplay:false,	   listControls:true,	   callback:function(){   }	  	  	 };  var options = $.extend(defaults, options);/* ================================================================================================ *//* ==================================== Variables & Precaching ==================================== *//* ================================================================================================ */ return this.each(function()  {  var root = $(this).addClass('mainslider');   var parent = root.parent();  var li = root.find("li");	 var images = li.find("img");  var pos,random_no,timer,image_timer,counter,arr,wait,index,block,w,h,src,parent,im,override=false,in_animation = false,controls,canvas,html5_flag=false,imageData,canvas,context,root_parent;	 var current = li.eq(1).toggleClass('active'),prev = li.first().addClass("reset");  var bool = true,first_bool = true;  root.css({   width: options.width,   height: options.height   });  li.first().find("div.description").css("display","block");  li.first().fadeIn('slow');    current.hide();   if(options.listControls==true)	 appendControls();  /* ================================================================================================ *//* ======================================== Switcher Module ======================================= *//* ================================================================================================ */    function switcher()   {	 if(current.prev().length>0)	   prev = current.prev();	 else	   prev = li.last();		 prev.removeClass("reset");	 current.toggleClass("active reset");		 if(current.next().length>0)		 // setting the next slide	   current = current.next();	 else	   current = li.first();		current.hide();	current.addClass("active");	options.callback();  	 } /* ================================================================================================ *//* ================================= Effects Switching & Ending =================================== *//* ================================================================================================ */ function endeffect(image){		if(options.listControls==true)	  {	  controls.removeClass("control_active");	  controls.eq(current.index()).addClass("control_active");	  }    clearInterval(timer);  setTimeout(function(){			  in_animation = false;	  if(override==false) // Return if manually triggered	  image_timer = setTimeout(function() {  current.find("div.description").fadeOut('fast');	switcher(); effects();  },(options.time-800));	 },1000);		};function effects(){   if(li.is(":animated"))return;    if(bool==true)  {   li.first().find("div.description").hide();   bool=false;	first_bool = false;  }    switch(0)   {     case 0:	current.find("div.description").fadeIn('normal');   current.fadeIn("slow",function(){  	endeffect($(this));		});break;    }}/* ================================================================================================ *//* ======================================== Control Options ======================================= *//* ================================================================================================ */    function appendControls()  {  var str = "<ul class='controls'>";  for(var i=0;i<li.length;i++)  str = str + "<li>"+(i+1)+"</li>";  str = str+"</ul>";    root.after(str);     controls = parent.find(".controls li");  controls.first().addClass("control_active");  controls.parent().css("left",  980/2 + 20 +  controls.parent().width()/2  )   controls.bind({  click:function(){ setImage($(this).index());  },  mouseover:function(){ $(this).toggleClass("control_hover"); },  mouseout:function(){ $(this).toggleClass("control_hover"); }	});     }/* ================================================================================================ *//* ======================================== Image Settings ======================================== *//* ================================================================================================ */ 	  function setImage(index){ 	  if(first_bool==true)	 {	if(in_animation==true||current.index()-1==index)  return;  }  else   if(in_animation==true||current.index()==index)  return;   li.removeClass("reset active");  current.find("div.description").hide();  clearTimeout(image_timer); // Manual Override...   if(first_bool==true)  li.first().addClass("reset");   current.addClass("reset");  prev = current;  current = li.eq(index).addClass("active");   override = true;  effects(); }      if(options.autoplay==true)	image_timer = setTimeout(function() {   effects();  },options.time);  // Starting the Slideshow    }); };  });

Edited by cpugeek
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...