Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/01/2011, 08:00
Avatar de _cronos2
_cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 11 meses
Puntos: 310
Respuesta: Problema con objeto en IE

Es de una librería que estoy intentando montarme XD El código es muy largo pero dejo lo importante:
Código Javascript:
Ver original
  1. var JSPlus = (function(){
  2.  var privado = {
  3.   // [...]
  4.   opacity : function(){
  5.    var isIE = document.all, estilos = isIE ? ['filter', 100] : ['opacity', 1], valor = isIE ? ['alpha(opacity=', ')'] : ['', ''];
  6.    if(arguments.length){
  7.     this.style[estilos[0]] = valor[0] + (arguments[0] * estilos[1]) + valor[1];
  8.    }else{
  9.     if(this.style[estilos[0]]){
  10.      return this.style[estilos[0]].match(/\d+(\.\d+)?/)[0]/estilos[1];
  11.     }else{
  12.      if(SS.find(this.tagName, estilos[0])){
  13.       return SS.find(this.tagName, estilos[0]).match(/\d+(\.\d+)?/)[0]/estilos[1];
  14.      }else{
  15.       if(SS.find('#'+this.id, estilos[0]))
  16.        return SS.find('#'+this.id, estilos[0]).match(/\d+(\.\d+)?/)[0]/estilos[1];
  17.       else{
  18.        for(var i=0, partir=this.className.split(' '); clase=partir[i]; i++){
  19.         if(SS.find('.'+clase, estilos[0]))
  20.          return SS.find('.'+clase, estilos[0]).match(/\d+(\.\d+)?/)[0]/estilos[1];
  21.        }
  22.       }
  23.      }
  24.     }
  25.     return 1;
  26.    }
  27.    return P(this);
  28.   },
  29.   // [...]
  30.  };
  31.  return {
  32.   extender : function(elem, obj){
  33.    if(elem.extendido && elem != privado) return elem;
  34.    for(var i in obj){
  35.     elem[i] = obj[i];
  36.    }
  37.    return elem;
  38.   },
  39.   get : function(obj){
  40.    switch(typeof obj){
  41.     case 'object':
  42.      return JSPlus.extender(obj, privado);
  43.     break;
  44.     case 'string':
  45.      return JSPlus.extender(document.querySelector(obj), privado);
  46.     break;
  47.    }
  48.    return null;
  49.   }
  50.  };
  51. })();
  52. var P = JSPlus.get;
Entonces si por ejemplo tengo un código así:
Código Javascript:
Ver original
  1. P('#img').opacity(0.3);
Funciona en FF y Chrome, pero en IE me dice que se esperaba un objeto (en la línea de this.style[estilos[0]] = valor[0] + (arguments[0] * estilos[1]) + valor[1]; )
Saludos (:
PD: Gracias a @Panino por la idea del mixin, jamás se me hubiera ocurrido XD
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red