demo

by Edgar Martinez

HTML

<div id='elbarto'>
cpntenodpo
</div>
<br/>
<div id='elbarto2'>
jijijij
</div>

JavaScript

(function ($) {
 var idDemo=0;
 
 var methods={
  update:function(){
	
			$(this).css( "background", "green" );
	},
  init:function(opt){
	
			return this.each(function(){

						$(this).css( "color", "white" );
						$(this).css( "background", "red" );
						$(this).css( "padding", "5px" );
			});

	}
 
 };
    $.fn.demo = function() {
	
  
	
	 var cantidad_argumentos=arguments.length;
	 
	 if(cantidad_argumentos==0){//Sin argumentos
	 
	 	    
		   idDemo=idDemo;
			 	console.log(idDemo);
			 idDemo++;
			 
      return methods.init.apply(this);
   }else{
	      
		 if(cantidad_argumentos==1){//Configuraciones
			 switch(typeof arguments[0]){

				 case "object"://Iniciando con configuracions personalizadas
					 return methods.init.call(this,arguments[0]);
				 case "string"://Iniciando

					 if(arguments[0]=="update"){
						 return methods.update.call(this);
					 }

					 break;

				 default:
					 $.error("Error al crear el hidden button");
			 }
		 }
		 
   }
 }
 
}( jQuery ));

$("#elbarto").demo();

$("#elbarto2").demo();

			
			$(window).resize(function () {
				$("#elbarto2").demo("update");
			});