Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Feb 29th, 2012  |  syntax: jQuery  |  size: 1.90 KB  |  hits: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $(document).ready(function(){
  2.                        
  3.                         $('#acordeon').accordion();    
  4.                                                
  5.                         $('#acordeon').find('ul').find('li').draggable({
  6.                                 helper : 'clone',
  7.                                 appendTo : 'body'              
  8.                                
  9.                         });
  10.                        
  11.                         $('#cart').find('ol').droppable({
  12.                                 activeClass : 'ui-state-default',
  13.                                 hoverClass  : 'ui-state-hover',
  14.                                 drop        : function(event,ui){
  15.                                                
  16.                                                 var draggable = ui.draggable;
  17.                                                 var html = agregarProducto(draggable); 
  18.                                                
  19.                                                
  20.                                                                                                
  21.                                 }
  22.                         });
  23.                        
  24.                         function agregarProducto(elemento){
  25.                                 var id     = $(elemento).attr('id');
  26.                                 var precio = $(elemento).children('span.precio').text();
  27.                                         precio = parseInt(precio);
  28.                                        
  29.                                 if($('#cart ol li'+id).length > 0){
  30.                                         var cantidad = $('#cart ol li'+ id + '.cantidad').text();
  31.                                                 cantidad = parseFloat(cantidad);
  32.                                                 cantidad++;
  33.                                                
  34.                                         var total = cantidad * precio; 
  35.                                        
  36.                                         $('#cart ol li'+ id + '.cantidad').text(cantidad);
  37.                                         $('#cart ol li'+ id + '.total').text(total.toFixed(2));
  38.                                 } else {
  39.                                  
  40.                                         var titulo = $(elemento).children('h3').html();
  41.                                         var cantidad = 1;
  42.                                         var total = precio * cantidad;
  43.                                        
  44.                                         var html = '<li class="'+id+'">'+
  45.                                         '<b>'+titulo+'</b>:' +
  46.                                         'RD$<span class="precio">'+precio.toFixed(2)+'<span> X'+
  47.                                         '<span class="cantidad">'+cantidad+'</span> ='+
  48.                                         'RD$<span class="total">'+total.toFixed(2)+'</span>'+'</li>';
  49.                                        
  50.                                   $('#cart ul').append(html);
  51.                                                                  
  52.                                   }
  53.                                        
  54.                                 totalGeneral();
  55.                                
  56.                         }      
  57.                                
  58.                                
  59.                         function totalGeneral(){
  60.                                 var total = 0;
  61.                                
  62.                                 $('#cart ol li').each(function(){
  63.                                         var subTotal = $(this).children('span.total').text();
  64.                                                 subTotal = parseFloat(subTotal);
  65.                                                
  66.                                         total += subTotal;     
  67.                                        
  68.                                 })
  69.                         }      
  70.                                
  71.                         $('.eliminar').live('click', function(){
  72.                                 $(this).parent('li').remove();
  73.                         });
  74.                        
  75.                         $('#totalgeneral').text('RD$'+total.toFixed(2));
  76.                        
  77.                 });