/[suikacvs]/www/test/charset/singlebyte/table.html
Suika

Diff of /www/test/charset/singlebyte/table.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Fri Jun 6 14:04:45 2008 UTC revision 1.2 by wakaba, Sat Jun 7 06:27:08 2008 UTC
# Line 1  Line 1 
1  <!DOCTYPE HTML>  <!DOCTYPE HTML>
2    <head>
3    <style>
4    .match {
5      background-color: green;
6      color: white;
7    }
8    .not-match {
9      background-color: red;
10      color: white;
11    }
12    </style>
13  <body>  <body>
14    
15  <table>  <table>
16  <thead>  <thead><tr><th>Original Byte<th>Result String
 <tr><th>Original Byte<th>Result String  
17  <tbody>  <tbody>
18  </table>  </table>
19    
20  <iframe style=display:none></iframe>  <iframe style=display:none src=dummy></iframe>
21    
22  <script>  <script>
23    var charset = (location.search || '?').substring (1);    var query = (location.search || '?').substring (1).split (/;/);
24      var charset = decodeURIComponent (query[0] || '');
25      var plain = query[1] == 'plain';
26    var iframe = document.getElementsByTagName ('iframe')[0];    var iframe = document.getElementsByTagName ('iframe')[0];
27    var tbody = document.getElementsByTagName ('tbody')[0];    var tbody = document.getElementsByTagName ('tbody')[0];
28    var nextByte = 0x00;    var nextByte = -1;
29      var lastTimer;
30      var results = [];
31      var timeoutError = true;
32    
33      var mappingTables = {};
34      var mappingTableNames = ['ie7vista', 'safari31vista', 'opera92vista', 'fx2vista'];
35      var theadtr = document.getElementsByTagName ('thead')[0].firstChild;
36      for (var i = 0; i < mappingTableNames.length; i++) {
37        readMappingTable (charset, mappingTableNames[i]);
38        theadtr.appendChild (document.createElement ('th'))
39            .appendChild (document.createTextNode (mappingTableNames[i]));
40      }
41    
42    doNext ();    doNext ();
43    
44      function readMappingTable (charset, uaid) {
45        var c = charset.replace (/[^A-Za-z0-9_-]/g, '_');
46        var fileName = 'result/' + c + '-' + uaid + '.txt';
47        var xhr = new XMLHttpRequest ();
48        xhr.open ('GET', fileName, false);
49        xhr.send (null);
50        if (xhr.status < 400) {
51          mappingTables[uaid] = xhr.responseText.split ('\n');
52        }
53      } // readMappingTable
54        
55    function doNext () {    function doNext () {
56      if (nextByte <= 0xFF) {      clearTimeout (lastTimer);
57        timeoutError = false
58    
59        if (nextByte == -1) {
60          if (document.all && !window.opera) {
61            iframe.onreadystatechange = function () {
62              if (this.readyState == 'complete') {
63                doNext ();
64              }
65            };
66          } else {
67            iframe.onload = doNext;
68          }
69          nextByte++;
70          iframe.src = 'about:blank';
71        } else if (nextByte <= 0xFF) {
72        if (document.all && !window.opera) {        if (document.all && !window.opera) {
73          iframe.onreadystatechange = function () {          iframe.onreadystatechange = function () {
74            if (this.readyState == 'complete') {            if (this.readyState == 'complete') {
# Line 28  Line 78 
78        } else {        } else {
79          iframe.onload = addTableRow;          iframe.onload = addTableRow;
80        }        }
81          lastTimer = setTimeout (function () {
82            timeoutError = true;
83            iframe.onload = null;
84            iframe.onreadystatechange = null;
85            addTableRow ();
86          }, 5000);
87        iframe.src = 'charset.cgi/' + encodeURIComponent (charset)        iframe.src = 'charset.cgi/' + encodeURIComponent (charset)
88            + '?' + nextByte++;            + '?' + nextByte++ + (plain ? ';plain' : '');
89      } else {      } else {
90        iframe.onload = null;        iframe.onload = null;
91        iframe.onreadystatechange = null;        iframe.onreadystatechange = null;
92          doLast ();
93      }      }
94    } // doNext    } // doNext
95    
# Line 40  Line 97 
97      var tr = document.createElement ('tr');      var tr = document.createElement ('tr');
98    
99      tr.appendChild (document.createElement ('th'))      tr.appendChild (document.createElement ('th'))
100          .appendChild (document.createTextNode ('0x' + (nextByte - 1).toString (16).toUpperCase ()));          .appendChild (document.createTextNode (getByteCode (nextByte - 1)));
101    
102      var td = tr.appendChild (document.createElement ('td'));      var td = tr.appendChild (document.createElement ('td'));
103      var docbody = iframe.contentWindow.document.body;      var docbody = iframe.contentWindow.document.body;
104      var value = docbody.firstChild ? docbody.firstChild.data : '';      var value = timeoutError ? '' : docbody.firstChild ? docbody.firstChild.firstChild ? docbody.firstChild.firstChild.data : docbody.firstChild.data || '' : '';
105      for (var i = 0; i < value.length; i++) {      for (var i = 0; i < value.length; i++) {
106        td.appendChild (document.createTextNode ('U+' + value.charCodeAt (i).toString (16).toUpperCase () + ' '));        td.appendChild (document.createTextNode (getCharCode (value.charCodeAt (i)) + ' '));
107        }
108        results[nextByte - 1] = td.innerText || td.textContent;
109    
110        for (var i = 0; i < mappingTableNames.length; i++) {
111          var tableid = mappingTableNames[i];
112          var cell = tr.appendChild (document.createElement ('td'));
113          var cellValue = '';
114          if (mappingTables[tableid]) {
115            cellValue = mappingTables[tableid][nextByte - 1];
116            cell.appendChild (document.createTextNode (cellValue));
117            if (cellValue != results[nextByte - 1]) {
118              cell.className = 'not-match';
119            } else {
120              cell.className = 'match';
121            }
122          } else {
123            cell.className = 'no-data';
124          }
125      }      }
126    
127      tbody.appendChild (tr);      tbody.appendChild (tr);
128    
129      doNext ();      doNext ();
130    } // addTableRow    } // addTableRow
131    
132      function doLast () {
133        var ta = document.createElement ('textarea');
134        ta.value = results.join ('\n');
135        document.body.appendChild (ta);
136      } // doLast
137    
138      function getByteCode (c) {
139        var r = c.toString (16).toUpperCase ();
140        if (r.length < 2) {
141          r = '0' + r;
142        }
143        return '0x' + r;
144      } // getByteCode
145    
146      function getCharCode (c) {
147        var r = c.toString (16).toUpperCase ();
148        if (r.length < 2) {
149          r = '000' + r;
150        } else if (r.length < 3) {
151          r = '00' + r;
152        } else if (r.length < 4) {
153          r= '0' + r;
154        }
155        return 'U+' + r;
156      } // getCharCode
157    
158  </script>  </script>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24