Ver Mensaje Individual
  #6 (permalink)  
Antiguo 19/02/2012, 09:35
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 2 meses
Puntos: 20
Respuesta: Problema usar .js en contenido cargado con ajax

He modifico los 3 sitios donde había un evento click pero sigue sin funcionar

Código Javascript:
Ver original
  1. (function($){
  2.     $.fn.replaceSelects = function(options) {
  3.         var defaults = {
  4.             cssClass: 'optionbox',
  5.             zIndex: 2,
  6.             hideOnBodyClick: true,
  7.             replaceForIphone: false,
  8.             onElementSelect: function (element) {
  9.                 return true;
  10.             },
  11.             hideListEffect: function (element) {
  12.                 $(element).hide('fast');
  13.             },
  14.             toggleListEffect: function (element) {
  15.                 $(element).toggle('fast');
  16.                 return true;
  17.             }
  18.         };
  19.         var options = jQuery.extend(defaults, options);
  20.         var is_select_opened = null;
  21.        
  22.         return this.each(function() {
  23.             if (!options.replaceForIphone && (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) )  {
  24.                 return false;
  25.             }
  26.             var opts = new Array;
  27.             var selected = new Object();
  28.             var width = $(this).width();
  29.             if (parseInt($(this).css('width'))>0) {
  30.                 width = parseInt($(this).css('width'));
  31.             }
  32.             var hasFloat = $(this).css('float');
  33.             width += 40;
  34.             $(this).children().each(function() {
  35.                 var o = new Object();
  36.                 o.value = $(this).attr('value');
  37.                 o.html = $(this).html();
  38.                 o.selected = $(this).attr('selected');
  39.                 o.disabled = $(this).attr('disabled');
  40.                 if (o.selected) {
  41.                     selected = o;
  42.                 }
  43.                 opts.push(o);
  44.             });
  45.             $(this).hide(); //hide me
  46.             html = ''; _title = '';
  47.             for (x in opts) {
  48.                 html += '<a href="#'+escape(opts[x].html)+'" class="option'+(opts[x].selected?'-selected':'')+(opts[x].disabled?'-disabled':'')+'" rel="'+opts[x].value+'">'+opts[x].html+'</a>';
  49.             }
  50.             if (!$(this).parent().hasClass('select-container')) {
  51.                 $(this).wrap('<div class="select-replacement '+options.cssClass+'" '+(hasFloat?'style="float:'+hasFloat+';"':'')+'><div class="select-container" style="display:none"></div><div class="selected" style="width:'+width+'px"><div class="selected-inner">'+selected.html+'</div></div><div class="options" style="display:none;width:'+width+'px">'+html+'</div></div>');
  52.             }
  53.             $('.select-replacement .selected').unbind('click');
  54.             //$('.select-replacement .selected').click(function() {
  55.             $('.select-replacement .selected').live('click',function(){
  56.                 if (options.toggleListEffect($(this).parent().children('.options')[0])) {
  57.                     options.zIndex++;
  58.                     $(this).parent().css('z-index',options.zIndex);
  59.                     $(this).parent().children('.options').css('z-index',options.zIndex);
  60.                     if ($.fn.replaceSelects.is_select_opened && $.fn.replaceSelects.is_select_opened.parent().children('.selected')[0]!=this) {
  61.                         options.hideListEffect($.fn.replaceSelects.is_select_opened[0]);
  62.                     }
  63.                     $.fn.replaceSelects.is_select_opened = $(this).parent().children('.options');
  64.                 }
  65.             });
  66.             $('.select-replacement .options .option, .select-replacement .options .option-selected, .select-replacement .options .option-disabled, .select-replacement .options .option-selected-disabled').unbind('click');
  67.             //$('.select-replacement .options .option, .select-replacement .options .option-selected, .select-replacement .options .option-disabled, .select-replacement .options .option-selected-disabled').click(function() {
  68.             $('.select-replacement .options .option, .select-replacement .options .option-selected, .select-replacement .options .option-disabled, .select-replacement .options .option-selected-disabled').live('click',function(){
  69.                 if (options.onElementSelect(this)) {
  70.                     if (!$(this).is('.option-disabled') && !$(this).is('.option-selected-disabled')) {
  71.                         var optionbox = $(this).parent().parent();
  72.                         var select = optionbox.children('.select-container').children('select');
  73.                         optionbox.children('.selected').children('.selected-inner').html($(this).html());
  74.                         select.val($(this).attr('rel'));
  75.                         var f = select.attr('onchange');
  76.                         if (f) {
  77.                             f.call(select.val());
  78.                         }
  79.                         $(this).parent().children('.option, .option-selected').each(function() {
  80.                             $(this).removeClass('option-selected');
  81.                             $(this).addClass('option');
  82.                         });
  83.                         options.hideListEffect($(this).parent()[0]);
  84.                        
  85.                         $(this).addClass('option-selected');
  86.                         $(this).removeClass('option');
  87.                     }
  88.                 }
  89.                 return false;
  90.             });
  91.             if (options.hideOnBodyClick) {
  92.                 $(document).ready(function() {
  93.                     //$('body').click(function (event) {
  94.                     $('body').live('click',function(){
  95.                         if (!$(event.target).is('.select-replacement,.select-replacement *,.select-replacement .selected *')) {
  96.                             options.hideListEffect('.select-replacement .options');
  97.                         }
  98.                     });
  99.                 });
  100.             }
  101.         });
  102.     };
  103. })(jQuery);