OSDN Git Service

add comic2html_0.1.html
[pettanr/clientJs.git] / 0.4.x / test / type.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
2 <html xmlns:v="urn:schemas-microsoft-com:vml"><!-- InstanceBegin template="/Templates/base.dwt" codeOutsideHTMLIsLocked="false" -->\r
3 <head>\r
4         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">\r
5         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">\r
6         <meta http-equiv="Content-Language" content="ja">\r
7         <meta http-equiv="Content-Script-Type" content="text/javascript">\r
8         <meta http-equiv="Content-Style-Type" content="text/css">\r
9         <meta http-equiv="imagetoolbar" content="no">\r
10         <link rel="stylesheet" type="text/css" href="../stylesheets/common.css">\r
11         <!-- InstanceBeginEditable name="doctitle" -->\r
12         <title>[js]type | pettanR</title>\r
13         <!-- InstanceEndEditable -->\r
14         <!-- InstanceBeginEditable name="head" -->\r
15         <style>\r
16                 dt { font-weight:bold;}\r
17                 .type-is-String { color:red;}\r
18                 .type-is-Number { color:#f6f;}\r
19                 .type-is-Function { color:green;}\r
20                 .type-is-Array, .type-is-Object {\r
21                         color:blue;\r
22                 }\r
23                 .type-is-Boolean, .type-is-null, .type-is-undefined {\r
24                         color:#666;\r
25                 }\r
26                 .type-is-HTMLElement {\r
27                         color:orange;\r
28                 }\r
29         </style>\r
30         <!-- InstanceEndEditable -->\r
31 </head>\r
32 \r
33 <body>\r
34     <div id="general-content">\r
35         <div id="outer-wrapper">\r
36             \r
37             <div id="header">\r
38                 <div class="base-content-width" style="position:relative;">\r
39                     <h1><a href="../index.html">pettanR</a></h1>\r
40                 <!-- global navi -->\r
41                     <div id="global-navi">\r
42                         <noscript id="noscript-alert">You need to have JavaScript enabled.</noscript>\r
43                     </div>\r
44                 </div>\r
45             </div>\r
46             \r
47             <div id="inner-wrapper" class="base-content-width">\r
48                                 <!-- InstanceBeginEditable name="main_content" -->\r
49 \r
50                                 <div id="main">\r
51                                         <div id="breadcrumb"><a href="index.html">テスト インデックス</a> &gt; javascript のための型判定</div>\r
52                                         <h2>javascript のための型判定</h2>\r
53                                         <p>以下の表は js によっ書き出されています.Array 型 と  HTMLElement 型 の判定が面倒です.また、NodeList 型が返るか?はブラウザ毎の実装差があるようです.</p>\r
54                                         <dl id="output" class="dl-table clearfix"></dl>\r
55                                         <h3>参考記事</h3>\r
56                                         <p>以下の記事を参考にしました.</p>\r
57                                         <p>\r
58                                                 <a href="http://d.hatena.ne.jp/cheesepie/20091122/1258897939" target="_blank">JavaScriptで型判定いろいろ - Cheese Pie</a>\r
59                                                 このページの型チェック用コードのベースにした記事です.\r
60                                         </p>\r
61                                         <p>\r
62                                                 <a href="http://zombiebook.seesaa.net/article/118457190.html" target="_blank">Javascript:element の判定とそれに関わる諸事: Script雑感</a>\r
63                                                 isElement の判定の参考にしました.ie5  や ns6 といった古いブラウザでもチェックされていてすばらしいです. \r
64                                         </p>\r
65                                         <h3>メモ</h3>\r
66                                         <p>2012-03-18 file.read() のための DeepCopy を書きたくて、型判定方法について調べる.</p>\r
67                                 </div>\r
68                                 <!-- InstanceEndEditable -->\r
69             </div>\r
70         </div>\r
71     </div>\r
72     \r
73     <div id="footer-content"><!-- #BeginLibraryItem "/Library/footer.lbi" -->\r
74 \r
75         <div id="footer">\r
76             <div id="footer-item-container" class="base-content-width clearfix">\r
77                 <div class="footer-item-wrapper">\r
78                     <div class="footer-item">\r
79                         <h2>ぺったんR にようこそ</h2>\r
80                         <ul>\r
81                             <li>サンプル</li>\r
82                             <li>ぺったんRの特徴</li>\r
83                             <li>沿革</li>\r
84                         </ul>\r
85                         <h2>Test</h2>\r
86                         <ul>\r
87                             <li><a href="index.html">Test Index</a></li>\r
88                         </ul>\r
89                     </div>\r
90                 </div>\r
91                 <div class="footer-item-wrapper">\r
92                     <div class="footer-item">\r
93                         <h2>ドキュメント</h2>\r
94                         <ul>\r
95                             <li><a href="http://sourceforge.jp/projects/pettanr/wiki/ForAuthors" rel="me" target="_blank">作家向けドキュメント</a></li>\r
96                             <li>絵師向けドキュメント</li>                                                     \r
97                             <li><a href="http://sourceforge.jp/projects/pettanr/wiki/ForDevelopers" rel="me" target="_blank">開発者向けドキュメント</a></li>\r
98                             <li><a href="http://sourceforge.jp/projects/pettanr/wiki/ForWebmasters" rel="me" target="_blank">編集長向けドキュメント</a></li>\r
99                         </ul>\r
100                     </div>\r
101                 </div>\r
102                 <div class="footer-item-wrapper">\r
103                     <div class="footer-item">\r
104                         <h2>プロトタイプ</h2>\r
105                         <ul>\r
106                             <li><a href="http://pettanr.heroku.com/" rel="me" target="_blank">pettanr.heroku.com</a></li>\r
107                             <li><a href="../work.html" rel="console">ユーザーコンソール</a></li>\r
108                         </ul>\r
109                         <h2>Ajax contents</h2>\r
110                         <ul>\r
111                             <li><a href="../help/jp.xml">help | jp</a></li>\r
112                         </ul>\r
113                     </div>\r
114                 </div>\r
115                 <div class="footer-item-wrapper" style="width:170px;">\r
116                     <div class="footer-item" style="padding-right:0;">\r
117                         <h2>ぺったんRチーム</h2>\r
118                         <ul>\r
119                             <li>わたしたちについて</li>\r
120                             <li>ミッション</li>\r
121                             <li><a href="../diary/itozyun.xml">itozyun's diary</a></li>\r
122                             <li>個人情報保護方針</li>\r
123                             <li>作品の取り扱い</li>\r
124                             <li>お問い合わせ</li>\r
125                         </ul>\r
126                     </div>\r
127                 </div>\r
128             </div>\r
129             <div id="copyright">Copyright (c) 2011-2012 pettanR team, some rights reserved.</div>\r
130         </div><!-- #EndLibraryItem --></div>\r
131         <script type="text/javascript" src="../javascripts/common.js"></script>\r
132 <!-- InstanceBeginEditable name="script" -->\r
133                 <script type="text/javascript">\r
134 /**\r
135  * Decision type of variable.\r
136  * @class Type\r
137  * @static\r
138  */\r
139         var Type = {\r
140                 isObject : function(v) {\r
141                         return typeof v === 'object';\r
142                 },\r
143                 isFunction : function(v) {\r
144                         return typeof v === 'function';\r
145                 },\r
146                 isArray : function(v) {\r
147                         return Object.prototype.toString.call(v) === "[object Array]";\r
148                 },\r
149                 isBoolean : function(v) {\r
150                         return typeof v === 'boolean';\r
151                 },\r
152                 isString : function(v) {\r
153                         return typeof v === 'string';\r
154                 },\r
155                 isNumber : function(v) {\r
156                         return typeof v === 'number';\r
157                 },\r
158                 isHTMLElement : ( 'HTMLElement' in window ?\r
159                         function(v){\r
160                                 return v instanceof HTMLElement\r
161                         } :\r
162                         function(v) {\r
163                                 if( Type.isObject(v) === false ){\r
164                                         return false;\r
165                                 }\r
166                                 var r;\r
167                                 if(v && v.nodeType === 1){\r
168                                         try{\r
169                                                 r = v.cloneNode(false);\r
170                                         } catch(n) {\r
171                                                 return false;\r
172                                         }\r
173                                         if(r === v) return false;\r
174                                         try{\r
175                                                 r.nodeType = 9;\r
176                                                 return r.nodeType === 1;\r
177                                         } catch(n) {}\r
178                                         return true;\r
179                                 }\r
180                                 return false;\r
181                         }\r
182                 ),\r
183                 isElementCollection : function(v) {\r
184                         return (Object.prototype.toString.call(v) === "[object HTMLCollection]");\r
185                 },\r
186                 isNull : function(v) {\r
187                         return v === null;\r
188                 },\r
189                 isUndefined : function(v) {\r
190                         return typeof v === 'undefined';\r
191                 },\r
192                 /**\r
193                  * @method getType\r
194                  * @param {Any} v The variable\r
195                  * @return {String} type of the variable\r
196                  */\r
197                 getType : function(v) {\r
198                         if(Type.isNull(v)) {\r
199                                 return "null";\r
200                         }\r
201                         if(Type.isUndefined(v)) {\r
202                                 return "undefined";\r
203                         }\r
204                         if(Type.isHTMLElement(v)) {\r
205                                 return "HTMLElement";\r
206                         }\r
207                         return Object.prototype.toString.call(v).split(" ")[1].replace("]", "");\r
208                 }\r
209         };\r
210 \r
211         var output = document.getElementById( 'output'),\r
212                 testNameArray = [ '"abc"', 'true', '100', '[]', '{}', 'function(){}', 'undefined', 'null', 'document.getElementById( "output")', 'document.getElementById("notExist")', 'document.getElementsByTagName("div")', 'document.body.childNodes', 'document.createTextNode( "hello" )'],\r
213                 testValueArray = [ "abc", true, 100, [], {}, function(){}, undefined, null, output, document.getElementById("notExist"), document.getElementsByTagName("div"), document.body.childNodes, document.createTextNode( "hello" )],\r
214                 dt, dd, type;\r
215         for(var i=0, l=testValueArray.length; i<l; ++i){\r
216                 dt = document.createElement( 'dt');\r
217                 dd = document.createElement( 'dd');\r
218                 output.appendChild( dt );\r
219                 output.appendChild( dd );\r
220                 type = Type.getType(testValueArray[i]);\r
221                 dt.appendChild( document.createTextNode( type ));\r
222                 dt.className = 'type-is-' + type;\r
223                 dd.appendChild( document.createTextNode( testNameArray[i]));\r
224         }\r
225                 </script>\r
226 \r
227 <!-- InstanceEndEditable -->\r
228 </body>\r
229 <!-- InstanceEnd --></html>\r