Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/01/2011, 17:06
Avatar de _cronos2
_cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 10 meses
Puntos: 310
Respuesta: Función se vuelve undefined de repente

Jajaja, este es el código:
Código Javascript:
Ver original
  1. String.prototype.low=function(){ return this.toLowerCase(); };
  2. var extSS = function(){};
  3. extSS.prototype = {
  4.  isIE : document.all,
  5.  instrucciones : {
  6.   'reglas' : this.isIE ? 'rules' : 'cssRules',
  7.   'add' : (this.isIE ? 'add' : 'insert') + 'Rule',
  8.   'remove' : (this.isIE ? 'remove' : 'delete') + 'Rule'
  9.  },
  10.  hojas : document.styleSheets,
  11.  getSS : function(id){
  12.   var cosa;
  13.   switch(typeof id){
  14.    case 'number' :
  15.     return this.hojas[id] ? this.hojas[id] : false;
  16.    break;
  17.    case 'string' :
  18.     for(var url = /(file|http):\/\/(\/*).+\//, i=0; cosa = this.hojas[i]; i++){
  19.      if(cosa.href == id || cosa.href.replace(url) == id || cosa.href.replace(url, '').replace(/\.css$/, '') == id)
  20.       return cosa;
  21.     }
  22.    break;
  23.   }
  24.   return false;
  25.  },
  26.  find : function(select, propi){
  27.   var estilo;
  28.   for(i=0; SS = this.hojas[i]; i++){  
  29.    estilo = SS[this.instrucciones['reglas']];
  30.    for(j=0; regla = estilo[j]; j++){
  31.     if(regla.selectorText.low() == select.low() && regla.style[propi])
  32.      return regla.style[propi];
  33.    }
  34.   }
  35.   return false;
  36.  },
  37.  set : function(select, propi, val){
  38.   var estilo;
  39.   for(i=0; SS = this.hojas[i]; i++){  
  40.    estilo = SS[this.instrucciones['reglas']];
  41.    for(j=0; regla = estilo[j]; j++){
  42.     if(regla.selectorText.low() == select.low() && regla.style[propi])
  43.      regla.style[propi] = val;
  44.    }
  45.   }
  46.   return false;
  47.  },
  48.  add : function(hoja, select, propi, val){
  49.   var SS = this.getSS(hoja);
  50.   try{
  51.    SS.insertRule(select + '{' + propi + ':' + val + '}', SS[this.instrucciones['reglas']].length);
  52.   }catch(e){ // IE
  53.    SS.addRule(select, propi + ':' + val);
  54.   }
  55.  },
  56.  remove : function(hoja, select){
  57.   var estilo;
  58.   switch(typeof hoja){
  59.    case 'number' :
  60.     estilo = this.hojas[hoja][this.instrucciones['reglas']];
  61.     for(i=0; regla = estilo[i]; i++){
  62.      if(regla.selectorText.low() == select.low())
  63.       this.getSS(hoja)[this.instrucciones['remove']](j);
  64.     }
  65.    break;  
  66.    case 'string' :
  67.     if(hoja=='all'){
  68.      for(i=0; SS = this.hojas[i]; i++){
  69.       estilo = SS[this.instrucciones['reglas']];
  70.       for(j=0; regla = estilo[j]; j++){
  71.        if(regla.selectorText.low() == select.low())
  72.         SS[this.instrucciones['remove']](j);
  73.       }
  74.      }
  75.     }else{
  76.      var SS = this.getSS(hoja), estilo = SS[this.instrucciones['reglas']];
  77.      for(i = 0; regla = estilo[i]; i++){
  78.       if(regla.selectorText.low() == select.low())
  79.        SS[this.instrucciones['remove']](i)
  80.      }
  81.     }
  82.    break;
  83.   }
  84.  }
  85. };
  86. var SS = new extSS();
Los códigos son los de @JavierB, pero yo los junté en un sólo objeto.
Saludos (:
__________________
" 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

Última edición por _cronos2; 13/01/2011 a las 17:11