/[suikacvs]/webroot/www/js/enum/props.en.html
Suika

Contents of /webroot/www/js/enum/props.en.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download) (as text)
Sun Jan 11 04:50:27 2009 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +9 -4 lines
File MIME type: text/html
Added more properties; Added license note

1 wakaba 1.1 <!DOCTYPE HTML>
2 wakaba 1.2 <title>JavaScript object properties</title>
3 wakaba 1.1 <link rel=stylesheet href="/www/style/html/xhtml">
4 wakaba 1.2 <link rel=license href="http://suika.fam.cx/c/pd" title="Public Domain. (This document and |prop-list| file.)">
5 wakaba 1.1
6     <style>
7     [name=result_ta] {
8     height: 40em;
9     }
10     </style>
11    
12     <body onload="
13     var xhr = new XMLHttpRequest ();
14     xhr.open ('GET', 'prop-list.txt?' + Math.random (), false);
15     xhr.send (null);
16     document.getElementsByName ('known_props_ta')[0].value = xhr.responseText;
17     ">
18    
19 wakaba 1.2 <h1>JavaScript object properties</h1>
20 wakaba 1.1
21     <form>
22 wakaba 1.2 <p><label>Code to be <code>eval</code>ed:<br>
23     <textarea name=code_ta></textarea></label>
24 wakaba 1.1
25     <p><label>List of known properties:<br>
26     <textarea name=known_props_ta>
27 wakaba 1.2 </textarea></label><br>
28     (<a href=prop-list>source</a>; ask <a
29     href="/~wakaba/who?">Wakaba</a> to add more properties)
30 wakaba 1.1
31     <p><button type=submit>Start</button>
32    
33     <h2>Result</h2>
34    
35     <p><textarea name=result_ta>
36     </textarea>
37    
38     </form>
39    
40     <script>
41     document.forms[0].onsubmit = function (event) {
42     if (window.event) window.event.returnValue = false;
43     if (event && event.preventDefault) event.preventDefault ();
44    
45     var objCode = this.code_ta.value;
46     var obj = eval (objCode);
47    
48     if (typeof (obj) === "undefined" || obj === null) {
49     obj = {};
50     objCode = '{}';
51     }
52    
53     var knownProps = this.known_props_ta.value.split (/[\r\n]+/);
54    
55     var newKnownProps = [];
56     var newKnownPropNames = {};
57    
58     var props = {};
59     var noProps = {};
60    
61     for (var i = 0; i < knownProps.length; i++) {
62     var propName = knownProps[i];
63     if (propName == '') continue;
64     if (propName.match (/^\s/)) continue;
65 wakaba 1.2 if (propName.match (/\S\s+\S/)) continue;
66 wakaba 1.1 propName = propName.replace (/\s+$/, '');
67    
68     try {
69     if (typeof (obj[propName]) !== 'undefined') {
70     if (!newKnownPropNames["name=" + propName]) newKnownProps.push (propName);
71     newKnownPropNames["name=" + propName] = true;
72     props["name="+propName] = {dontEnum: true};
73     } else {
74     if (!newKnownPropNames["name=" + propName]) newKnownProps.push (propName);
75     newKnownPropNames["name=" + propName] = true;
76     noProps["name="+propName] = {};
77     }
78     } catch (e) {
79     if (!newKnownPropNames["name=" + propName]) newKnownProps.push (propName);
80     newKnownPropNames["name=" + propName] = true;
81     props["name="+propName] = {error: '' + e};
82     }
83     }
84    
85     for (var propName in obj) {
86     if (!props["name="+propName]) {
87     props["name="+propName] = {notInList: true};
88     newKnownProps.push (propName);
89     }
90     props["name="+propName].dontEnum = false;
91     }
92    
93     var n = function (s) {
94     s = s || '';
95     s = s.toLowerCase ()
96     .replace (/_/g, '');
97     return s;
98     };
99    
100     var sort = function (l) {
101     var m;
102     try {
103     m = l.sort (function (a, b) {
104     a = n (a); b = n (b);
105     return a < b ? -1 : a > b ? 1 : 0;
106     });
107     } catch (e) { } // IE sometimes fails. Why?
108     return m || l;
109     };
110    
111     var propNames = [];
112     for (var propName in props) {
113     propNames.push (propName);
114     }
115     propNames = sort (propNames);
116    
117     var noPropNames = [];
118     for (var propName in noProps) {
119     noPropNames.push (propName);
120     }
121     noPropNames = sort (noPropNames);
122    
123     var result = 'UA: ' + navigator.userAgent + "\n";
124     result += 'Object: ' + objCode + "\n";
125     result += "\n";
126     result += 'Properties:\n';
127     for (var i = 0; i < propNames.length; i++) {
128     result += propNames[i].replace (/^name=/, '');
129     if (props[propNames[i]].dontEnum) result += '\tDontEnum';
130     if (props[propNames[i]].notInList) result += '\t_not_in_list_';
131     if (props[propNames[i]].error) result += '\t_error(' + props[propNames[i]].error + ')_';
132     result += '\n';
133     }
134     result += "\n";
135     result += "Not found:\n"
136     for (var i = 0; i < noPropNames.length; i++) {
137     result += noPropNames[i].replace (/^name=/, '') + '\n';
138     }
139     this.result_ta.value = result;
140    
141     this.known_props_ta.value = sort (newKnownProps).join ("\n");
142    
143     return false;
144     };
145     </script>

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24