Changeset 29
- Timestamp:
- 12/14/07 12:48:20 (11 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
collected/trunk/html-test-cases/getting-tabindex-in-ie.html
r28 r29 5 5 6 6 <head> 7 <title>Using JavaScript to get the tabindex value 8 of an element in Internet Explorer</title> 7 <title>Getting the tabindex value of an element with JavaScript</title> 9 8 <script type="text/javascript"> 10 9 function Logger(id){ 11 10 this._id = id; 12 this._elemId = undefined;13 this._elemMessage = "";14 11 } 15 Logger.prototype._getElem = function(){16 return document.getElementById(this._elemId);17 };18 12 Logger.prototype._makeTd = function(text){ 19 13 var td = document.createElement("td"); … … 21 15 return td; 22 16 }; 23 Logger.prototype.begin = function(elemId, elemMessage){ 24 this._elemId = elemId; 25 this._elemMessage = elemMessage; 26 }; 27 Logger.prototype.log = function(mechanism, value){ 17 Logger.prototype.log = function(desc, mechanism, value){ 28 18 var table = document.getElementById(this._id); 29 19 var tbody = table.getElementsByTagName("tbody")[0]; 30 20 var tr = document.createElement("tr"); 31 tr.appendChild(this._makeTd( this._elemMessage));21 tr.appendChild(this._makeTd(desc)); 32 22 tr.appendChild(this._makeTd(mechanism)); 33 tr.appendChild(this._makeTd(value)); 23 if(value === null){ 24 tr.appendChild(this._makeTd("null")); 25 }else{ 26 tr.appendChild(this._makeTd(value)); 27 } 34 28 tbody.appendChild(tr); 35 29 }; 36 Logger.prototype.logGetAttribute = function(attr, iFlags){ 37 if(arguments.length == 2){ 38 this.log('getAttribute("' + attr + '", ' + iFlags + ")", 39 this._getElem().getAttribute(attr, iFlags)); 30 Logger.prototype.logGetAttribute = function(id, desc, attr, iFlags){ 31 var elem = document.getElementById(id); 32 if(arguments.length == 4){ 33 this.log(desc, 'elem.getAttribute("' + attr + '", ' + iFlags + ")", 34 elem.getAttribute(attr, iFlags)); 40 35 }else{ 41 this.log( 'getAttribute("' + attr + '")',42 this._getElem().getAttribute(attr));36 this.log(desc, 'elem.getAttribute("' + attr + '")', 37 elem.getAttribute(attr)); 43 38 } 44 39 }; 45 Logger.prototype.logTabindexProperty = function(){ 46 this.log("tabindex", this._getElem().tabindex); 40 Logger.prototype.logTabindexProperty = function(id, desc){ 41 var elem = document.getElementById(id); 42 this.log(desc, "elem.tabindex", elem.tabindex); 47 43 }; 48 Logger.prototype.logTabIndexProperty = function(){ 49 this.log("tabIndex", this._getElem().tabIndex); 44 Logger.prototype.logTabIndexProperty = function(id, desc){ 45 var elem = document.getElementById(id); 46 this.log(desc, "elem.tabIndex", elem.tabIndex); 50 47 }; 51 Logger.prototype.logAttributes = function( attr){52 node = this._getElem().attributes[attr];48 Logger.prototype.logAttributes = function(id, desc, attr){ 49 var node = document.getElementById(id).attributes[attr]; 53 50 if(node){ 54 this.log('attributes["' + attr + '"].nodeValue', node.nodeValue); 51 this.log(desc, 'elem.attributes["' + attr + '"].nodeValue', 52 node.nodeValue); 55 53 }else{ 56 this.log( 'attributes["' + attr + '"]', node);54 this.log(desc, 'elem.attributes["' + attr + '"]', node); 57 55 } 58 56 }; 59 Logger.prototype.logTabindex = function(){ 60 this.logGetAttribute("tabindex"); 61 this.logGetAttribute("tabindex", 0); 62 this.logGetAttribute("tabindex", 1); 63 this.logGetAttribute("tabindex", 2); 64 this.logGetAttribute("tabIndex"); 65 this.logGetAttribute("tabIndex", 0); 66 this.logGetAttribute("tabIndex", 1); 67 this.logGetAttribute("tabIndex", 2); 68 this.logTabindexProperty(); 69 this.logTabIndexProperty(); 70 this.logAttributes("tabindex"); 71 this.logAttributes("tabIndex"); 57 Logger.prototype.logTabindex = function(id, desc){ 58 this.logGetAttribute(id, desc, "tabindex"); 59 if(isIE()){ 60 this.logGetAttribute(id, desc, "tabindex", 0); 61 this.logGetAttribute(id, desc, "tabindex", 1); 62 this.logGetAttribute(id, desc, "tabindex", 2); 63 } 64 this.logGetAttribute(id, desc, "tabIndex"); 65 if(isIE()){ 66 this.logGetAttribute(id, desc, "tabIndex", 0); 67 this.logGetAttribute(id, desc, "tabIndex", 1); 68 this.logGetAttribute(id, desc, "tabIndex", 2); 69 } 70 this.logTabindexProperty(id, desc); 71 this.logTabIndexProperty(id, desc); 72 this.logAttributes(id, desc, "tabindex"); 73 this.logAttributes(id, desc, "tabIndex"); 72 74 }; 73 function logTabindexes(){ 75 function isIE(){ 76 return navigator.userAgent.indexOf("MSIE") != -1; 77 } 78 function removeTabindex(id){ 79 var elem = document.getElementById(id); 80 if(isIE){ 81 elem.removeAttribute("tabIndex"); 82 }else{ 83 elem.removeAttribute("tabindex"); 84 } 85 } 86 function run(){ 87 var userAgentTextNode = document.createTextNode(navigator.userAgent); 88 document.getElementById("userAgent").appendChild(userAgentTextNode); 89 removeTabindex("div-tabindex-removed"); 90 removeTabindex("input-tabindex-removed"); 74 91 logger = new Logger("log"); 75 logger.begin("div-no-tabindex", "div with no tabindex"); 76 logger.logTabindex(); 77 logger.begin("div-tabindex-1", 'div with tabindex="1"'); 78 logger.logTabindex(); 92 logger.logTabindex("div-no-tabindex", "div with no tabindex"); 93 logger.logTabindex("div-tabindex-1", 'div with tabindex="1"'); 94 logger.logTabindex("div-tabindex-removed", "div with tabindex removed"); 95 logger.logTabindex("input-no-tabindex", "input with no tabindex"); 96 logger.logTabindex("input-tabindex-1", 'input with tabindex="1"'); 97 logger.logTabindex("input-tabindex-removed", "input with tabindex removed"); 79 98 } 80 99 </script> 81 100 </head> 82 101 83 <body onload="logTabindexes()"> 84 <div id="div-no-tabindex"></div> 85 <div id="div-tabindex-1" tabindex="1"></div> 102 <body onload="run()"> 103 <h2>User agent</h2> 104 <div id="userAgent"></div> 105 <h2>Results</h2> 86 106 <table id="log"> 87 107 <thead> … … 90 110 <tbody></tbody> 91 111 </table> 112 <hr> 113 <div id="div-no-tabindex"></div> 114 <div id="div-tabindex-1" tabindex="1"></div> 115 <div id="div-tabindex-removed" tabindex="1"></div> 116 <input id="input-no-tabindex"> 117 <input id="input-tabindex-1" tabindex="1"> 118 <input id="input-tabindex-removed" tabindex="1"> 92 119 </body> 93 120
