OSDN Git Service

Version 0.6.97, rename X.Dom.Image -> X.Util.Image.
[pettanr/clientJs.git] / 0.3.0 / common.js
1 /*\r
2  * pettanR common.js\r
3  *   version 0.1.0\r
4  * \r
5  * author: itozyun\r
6  */\r
7 \r
8 ( function(){\r
9         var noscripts = document.getElementsByTagName('NOSCRIPT'),\r
10                 noscript;\r
11         for(var i=0; i<noscripts.length; ++i){\r
12                 noscript = noscripts[i];\r
13                 noscript.parentNode && noscript.parentNode.removeChild( noscript);\r
14         }\r
15         \r
16         var location = document.location.pathname,\r
17                 isWorkPage = location.indexOf( '\/work.html') !== -1,\r
18                 deep =  location.indexOf( '\/diary\/') !== -1 ||\r
19                                 location.indexOf( '\/text\/') !== -1 ||\r
20                                 location.indexOf( '\/help\/') !== -1 ||\r
21                                 location.indexOf( '\/sitemap\/') !== -1 ||\r
22                                 location.indexOf( '\/wiki\/') !== -1;\r
23 \r
24         var LoginUserConsole = isWorkPage === false ?\r
25                 ( function(){\r
26                         var _body = document.body,\r
27                                 _root = document.getElementsByTagName( 'HTML')[ 0],\r
28                                 filter,\r
29                                 iframe, visible = false;\r
30                         return {\r
31                                 init: function(){\r
32                                         filter = document.createElement( 'DIV');\r
33                                         filter.style.position = 'absolute';\r
34                                         filter.style.left = filter.style.top = '0px';\r
35                                         filter.style.width = filter.style.height ='100%';\r
36                                         filter.style.backgroundColor = '#fff';\r
37         \r
38                                         var id = 'work',\r
39                                                 src = deep === true ? '../work.html' : 'work.html';\r
40                                         \r
41                                         var el = document.createElement(ua.isIE ? '<iframe name="' + id + '" src="' + src + '">' : 'iframe');\r
42                                         el.id = el.name = id;\r
43                                         el.setAttribute( 'name', id);\r
44                                         \r
45                                         el.style.position = 'absolute';\r
46                                         el.style.left = el.style.top = '0px';\r
47                                         el.style.width = el.style.height ='100%';\r
48                                         el.style.overflow = 'hidden';\r
49                                         el.hspace = el.vspace = el.marginheight = el.marginwidth = 0;\r
50                                         \r
51                                         _body.appendChild(el);\r
52                                         window[id] = el;\r
53                                         iframe = el;\r
54                                         \r
55                                         if (!ua.isIE) {\r
56                                                 var idoc;//WebKit > 521 corresponds with Safari 3, which started with 522 WebKit version.\r
57                                                 if (ua.isWebKit > 521) {\r
58                                                         idoc = el.contentWindow.document;\r
59                                                 } else if (ua.isSafari) {\r
60                                                         idoc = el.document;\r
61                                                 } else { //  if(d.isMozilla){\r
62                                                         idoc = el.contentWindow;\r
63                                                 }\r
64                                                 \r
65                                                 if ( !idoc) {\r
66                                                         try {\r
67                                                                 el.src = src;\r
68                                                                 el.contentWindow.location.replace = src;                                                        \r
69                                                         } catch (e){}\r
70                                                         try {\r
71                                                                 //el.contentWindow.location = src;                                                      \r
72                                                         } catch (e){}\r
73                                                         try {\r
74                                                                 el.location = src; // for Safari 2.0.3 ??\r
75                                                         } catch (e){}\r
76                                                         \r
77                                                 } else if( ua.isOpera){\r
78                                                         el.src = src; // for Opera\r
79                                                         el.contentWindow.location.replace = src; // for Opera\r
80                                                 } else {\r
81                                                         //el.src = src; // for firefox\r
82                                                         idoc.location.replace(src);\r
83                                                 }\r
84                                         }\r
85                                         \r
86                                         delete LoginUserConsole.init;\r
87                                 },\r
88                                 show: function(){\r
89                                         if(visible === true) return;\r
90                                         if (_root) {\r
91                                                 _root.style.overflow = 'hidden';\r
92                                         }\r
93                                         _body.style.overflow = 'hidden';\r
94                                         \r
95                                         LoginUserConsole.init && LoginUserConsole.init();\r
96                                         \r
97                                         iframe.parentNode !== _body && _body.appendChild(iframe);\r
98                                         \r
99                                         _body.insertBefore(filter, iframe);                             \r
100                                         \r
101                                         visible = true;\r
102                                 },\r
103                                 hide: function(){\r
104                                         if(visible === false) return;\r
105                                         \r
106                                         _body.removeChild(filter);\r
107                                         _body.style.overflow = '';\r
108                                         if (_root) {\r
109                                                 _root.style.overflow = '';\r
110                                         }\r
111                                         _body.removeChild(iframe);\r
112                                         \r
113                                         visible = false;\r
114                                 }\r
115                         }\r
116                 })() :\r
117                 ( function(){\r
118                         return {\r
119                                 show: function(){\r
120                                         h2c.view.show( h2c.editor);\r
121                                 },\r
122                                 hide: function(){}\r
123                         }\r
124                 })();\r
125 \r
126         var ua = (function(){\r
127                         var acme = {};\r
128                         \r
129                         var n = navigator;\r
130                         var dua = n.userAgent;\r
131                         var dav = n.appVersion;\r
132                         var tv = parseFloat(dav);\r
133                         acme.isOpera = (dua.indexOf("Opera") >= 0) ? tv: undefined;\r
134                         acme.isKhtml = (dav.indexOf("Konqueror") >= 0) ? tv : undefined;\r
135                         acme.isWebKit = parseFloat(dua.split("WebKit/")[1]) || undefined;\r
136                         acme.isChrome = parseFloat(dua.split("Chrome/")[1]) || undefined;\r
137                         var index = Math.max(dav.indexOf("WebKit"), dav.indexOf("Safari"), 0);\r
138                         if(index && !acme.isChrome){\r
139                                 acme.isSafari = parseFloat(dav.split("Version/")[1]);\r
140                                 if(!acme.isSafari || parseFloat(dav.substr(index + 7)) <= 419.3){\r
141                                         acme.isSafari = 2;\r
142                                 }\r
143                         }\r
144                         if(document.all && !acme.isOpera){\r
145                                 acme.isIE = parseFloat(dav.split("MSIE ")[1]) || undefined;\r
146                         }\r
147                         \r
148                         return acme;\r
149                 })();\r
150         \r
151         var navi = document.getElementById('global-navi'),\r
152                 origin = document.createElement('A'),\r
153                 items = ['Home', 'Comic list', 'Picture', 'Setting'],\r
154                 l = items.length,\r
155                 item;\r
156         for(var i=0; i<l; ++i){\r
157                 item = origin.cloneNode(true);\r
158                 item.innerHTML = items[i];\r
159                 item.href = '#';\r
160                 item.onclick = LoginUserConsole.show;\r
161                 navi.appendChild(item);\r
162         }\r
163 })();\r
164 \r
165 var _gaq = _gaq || [];\r
166 _gaq.push(['_setAccount', 'UA-28023955-1']);\r
167 _gaq.push(['_trackPageview']);\r
168 \r
169 (function() {\r
170         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\r
171         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\r
172         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\r
173 })();