Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [PILLOLA]rendere setAttribute di Explorer conforme agli standard...

    ...utilizzando un commento condizionale
    codice:
    /*@cc_on
    Element = function () {};
    
    Element.prototype.getAttribute = function (attribute) {
    
        switch(attribute){
        case "class": attribute = "className";break;
        case "for": attribute = "htmlFor";break;
        case "style": return this.style.cssText;break;
        case "type":return(this.id)?document.getElementById(this.id).type:this.type;break;
        case "accesskey":return this.accessKey;break;
        case "maxlength":return this.maxLength;break;
        }
        return this[attribute];
    }
    
    Element.prototype.setAttribute = function (attribute, value) {
    var interface = new Element;
    switch(attribute){
      case "class": attribute = "className";break;
      case "for": attribute = "htmlFor";break;
      case "type": 
      var me=this.parentNode;
      if(!/id=/.test(this.outerHTML))
      	this.id=this.uniqueID;
      	
      this.outerHTML=this.outerHTML.replace(/type=[a-zA-Z]+/," ").replace(">"," type='"+value+"'>");
      var t=me.childNodes;
      var max=t.length;
      for(var i=0;i<max;i++)
    	  if(t[i].id==this.id){
    	  	t[i].getAttribute=interface.getAttribute;
    	  	t[i].setAttribute=interface.setAttribute;  
    	  }
      return;break;
      case "accesskey":this.accessKey=value;return;break; 
      case "style": this.style.cssText =value;return;break;
      case "maxlength":this.maxLength=value;return;break;
      }
        if(value.indexOf("on")!=0)
        	this[attribute] = function(){eval(value)};
        else
        	this[attribute] = value;
    }
    var __IEcreateElement = document.createElement;
    
    document.createElement = function (tagName) {
        
        var element = __IEcreateElement(tagName);
        
        element.getAttribute=interface.getAttribute;
        element.setAttribute=interface.setAttribute;
        
        return element;
    }
    var interface = new Element;
    onload=function(){
    	var list=document.all;
    	var max=list.length;
    	
    	while(--max)
    	{
    		list[max].getAttribute=interface.getAttribute;
    		list[max].setAttribute=interface.setAttribute;
    		
    	}
    	//HTML node
    	list[0].getAttribute=interface.getAttribute;
    	list[0].setAttribute=interface.setAttribute;
    }
    @*/
    breve spiegazione:
    codice:
    Element = function () {};
    creiamo un interfaccia Element da cui estenderemo tutti i nodi

    codice:
    Element.prototype.getAttribute = function (attribute) {
    
        switch(attribute){
        case "class": attribute = "className";break;
        case "for": attribute = "htmlFor";break;
        case "style": return this.style.cssText;break;
        case "type":return(this.id)?document.getElementById(this.id).type:this.type;break;
        case "accesskey":return this.accessKey;break;
        case "maxlength":return this.maxLength;break;
        }
        return this[attribute];
    }
    aggiungiamo la nuova getAttribute,
    con supporto per class,for,style,type,accesskey,maxlength
    codice:
    Element.prototype.setAttribute = function (attribute, value) {
    var interface = new Element;
    switch(attribute){
      case "class": attribute = "className";break;
      case "for": attribute = "htmlFor";break;
      case "type": 
      var me=this.parentNode;
      if(!/id=/.test(this.outerHTML))
      	this.id=this.uniqueID;
      	
      this.outerHTML=this.outerHTML.replace(/type=[a-zA-Z]+/," ").replace(">"," type='"+value+"'>");
      var t=me.childNodes;
      var max=t.length;
      for(var i=0;i<max;i++)
    	  if(t[i].id==this.id){
    	  	t[i].getAttribute=interface.getAttribute;
    	  	t[i].setAttribute=interface.setAttribute;  
    	  }
      return;break;
      case "accesskey":this.accessKey=value;return;break; 
      case "style": this.style.cssText =value;return;break;
      case "maxlength":this.maxLength=value;return;break;
      }
        if(value.indexOf("on")!=0)
        	this[attribute] = function(){eval(value)};
        else
        	this[attribute] = value;
    }
    aggiungiamo la nuova setAttribute,
    con supporto per class,for,style,type,accesskey,maxlength e per gli eventi onclick,ecc...
    codice:
    var __IEcreateElement = document.createElement;
    
    document.createElement = function (tagName) {
        
        var element = __IEcreateElement(tagName);
        
        element.getAttribute=interface.getAttribute;
        element.setAttribute=interface.setAttribute;
        
        return element;
    }
    estendiamo la createElement in maniera da supportare gli standard.
    ora tutti i nodi creati a runtime avranno un comportamento standard,
    manca pero' il supporto per i nodi presenti nell'HTML,aggiungiamoglielo.
    codice:
    var interface = new Element;
    onload=function(){
    	var list=document.all;
    	var max=list.length;
    	
    	while(--max)
    	{
    		list[max].getAttribute=interface.getAttribute;
    		list[max].setAttribute=interface.setAttribute;
    		
    	}
    	//HTML node
    	list[0].getAttribute=interface.getAttribute;
    	list[0].setAttribute=interface.setAttribute;
    }

    ora abbiamo il supporto completo w3c, o almeno piu attinente allo standard

    non funziona sui nodi creati con innerHTML/outerHTML, si puo estendere innerHTML cosi' come e' stato fatto ma non e' mia intenzione poiche innerHTML non e' standard

    c'e' un altro modo di fare l'ultimo step(aggiungere il supporto ai nodi già creati dall'HTML ),
    usare un file HTC come viene fatto QUI

  2. #2
    (testato unicamente su IE 6.0)
    da testare su IE 5

  3. #3
    ERRATA CORRIGE:
    codice:
    if(value.indexOf("on")!=0)
    diventa
    codice:
    if(value.indexOf("on")==0)

  4. #4
    interessante hack ora lo testo per benino e poi ti dico, era giusto la parte su cui si inchioda il mio CMS
    Domenico Biancardi from http://www.halmadaxx.com

  5. #5
    da sostituire anche
    codice:
    this.outerHTML=this.outerHTML.replace(/type=[a-zA-Z]+/," ").replace(">"," type='"+value+"'>");
    var t=me.childNodes;
      var max=t.length;
      for(var i=0;i<max;i++)
    	  if(t[i].id==this.id){
    	  	t[i].getAttribute=interface.getAttribute;
    	  	t[i].setAttribute=interface.setAttribute;  
    	  }
    con
    codice:
     if(me){
      this.outerHTML=this.outerHTML.replace(/type=[a-zA-Z]+/," ").replace(">"," type="+value+">");
      var t=me.childNodes;
      var max=t.length;
       for(var i=0;i<max;i++)
      	  if(t[i].id==this.id){
      	  	t[i].getAttribute=interface.getAttribute;
      	  	t[i].setAttribute=interface.setAttribute;    	  	
      	  }
      }else
      this.type=value;

    ps..ha ancora un problema con le input check...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.