OSDN Git Service

Version 0.6.121, iScroll5 is working on iPhone touch 1G, update X.Audio.
[pettanr/clientJs.git] / 0.4.x / javascripts / common.js
1 /*\r
2  * pettanR common.js\r
3  *   version 0.4.37\r
4  * \r
5  * author: itozyun\r
6  */\r
7 \r
8 /*\r
9  * http://pettanr.sourceforge.jp/test/type.html\r
10  */\r
11         var Type = {\r
12                 isObject : function(v) {\r
13                         return v !== null && typeof v === 'object';\r
14                 },\r
15                 isFunction : function(v) {\r
16                         return typeof v === 'function';\r
17                 },\r
18                 isArray : function(v) {\r
19                         return Object.prototype.toString.call(v) === "[object Array]";\r
20                 },\r
21                 isBoolean : function(v) {\r
22                         return typeof v === 'boolean';\r
23                 },\r
24                 isString : function(v) {\r
25                         return typeof v === 'string';\r
26                 },\r
27                 isNumber : function(v) {\r
28                         return typeof v === 'number';\r
29                 },\r
30                 isFinite : function(v){\r
31                         return Type.isNumber(v) === true && isFinite(v);\r
32                 },\r
33                 isHTMLElement : function(v){\r
34                         if( 'HTMLElement' in window ){\r
35                                 Type.isHTMLElement = function(v){\r
36                                         return v instanceof HTMLElement;\r
37                                 }\r
38                         } else {\r
39                                 Type.isHTMLElement = function(v) {\r
40                                         if( Type.isObject(v) === false ){\r
41                                                 return false;\r
42                                         }\r
43                                         var r;\r
44                                         if(v && v.nodeType === 1){\r
45                                                 try{\r
46                                                         r = v.cloneNode(false);\r
47                                                 } catch(n) {\r
48                                                         return false;\r
49                                                 }\r
50                                                 if(r === v) return false;\r
51                                                 try{\r
52                                                         r.nodeType = 9;\r
53                                                         return r.nodeType === 1;\r
54                                                 } catch(n) {}\r
55                                                 return true;\r
56                                         }\r
57                                         return false;\r
58                                 }\r
59                         }\r
60                         return Type.isHTMLElement(v);\r
61                 },\r
62                 /*\r
63                 isElementCollection : function(v) {\r
64                         return (Object.prototype.toString.call(v) === "[object HTMLCollection]");\r
65                 },\r
66                 */\r
67                 isNull : function(v) {\r
68                         return v === null;\r
69                 },\r
70                 isUndefined : function(v) {\r
71                         return typeof v === 'undefined';\r
72                 }\r
73         };\r
74 \r
75 \r
76 var pettanr = ( function(){\r
77         var     FUNCTION_ARRAY = [],\r
78                 URL = document.location.href.split( '#')[ 0 ],\r
79                 IS_LOCAL = URL.indexOf( 'file:') === 0,\r
80                 URL_PARAMS = ( function(){\r
81                         var search = document.location.search,\r
82                                 l = search.length;\r
83                     if( 1 < l){\r
84                         var     query = search.substring( 1),\r
85                                         params = query.split( '&'),\r
86                                         ret = {}, elm, name, v;\r
87                         while( params.length > 0){\r
88                             elm = params.shift().split( '=');\r
89                                         name = decodeURIComponent( elm[ 0]);\r
90                                         if( elm.length === 2){\r
91                                                 v = decodeURIComponent( elm[ 1]);\r
92                                                 if( '' + parseFloat( v) === v) v = parseFloat( v);\r
93                                                 if( '' + parseInt( v, 10 ) === '0' + v) v = parseInt( v, 10 );\r
94                                                 if( v === 'true') v = true;\r
95                                                 if( v === 'false') v = false;\r
96                                                 if( v === 'null') v = null;\r
97                                                 if( v === 'undefined') v = undefined;\r
98                                     ret[ name] = v;\r
99                                         } else\r
100                                         if( elm.length === 1){\r
101                                                 ret[ name] = true;\r
102                                         }\r
103                         }\r
104                         return ret;\r
105                     }\r
106                     return {};\r
107                 })(),\r
108                 IS_DEBUG = Type.isBoolean( URL_PARAMS.debug ) ? URL_PARAMS.debug : IS_LOCAL === true,\r
109                 jqWindow , jqDocument , jqBody;\r
110         return {\r
111                 version: '0.4.36',\r
112                 init: function(){\r
113                         jqWindow   = $( window );\r
114                         jqDocument = $( document );\r
115                         jqBody     = $( document.body );\r
116                         \r
117                         var l = FUNCTION_ARRAY.length,\r
118                                 _fn;\r
119                         for( var i=0; i<l; i++){\r
120                                 _fn = FUNCTION_ARRAY[ i];\r
121                                 _fn.init && _fn.init( _fn === pettanr.view ? FUNCTION_ARRAY : undefined );\r
122                         }\r
123                         \r
124                         delete pettanr.init;\r
125                 },\r
126                 fn: function( _fn){\r
127                         FUNCTION_ARRAY.push( _fn);\r
128                         pettanr.init === undefined && _fn.init && _fn.init();\r
129                 },\r
130                 jqWindow: function(){\r
131                         return jqWindow;\r
132                 },\r
133                 jqDocument: function(){\r
134                         return jqDocument;\r
135                 },\r
136                 jqBody: function(){\r
137                         return jqBody;\r
138                 },\r
139                 URL_PARAMS: URL_PARAMS,\r
140                 ROOT_PATH: ( function(){\r
141                         // script と html の ドメインが一致\r
142                         var _h1 = document.getElementsByTagName( 'h1')[ 0],\r
143                                 _a = _h1.getElementsByTagName( 'a')[ 0],\r
144                                 _root = _a.href.split( '\/'),\r
145                                 _current = document.location.href.split( '\/'),\r
146                                 ret = '.\/';\r
147                         for( var i=0, l=_current.length - _root.length; i<l; ++i){\r
148                                 ret = '.' + ret;\r
149                         }\r
150                         return ret;\r
151                         // script と html の ドメインが不一致\r
152                 })(),\r
153                 LOCAL: IS_LOCAL,\r
154                 DEBUG: IS_DEBUG,\r
155                 LINE_FEED_CODE_TEXTAREA: ( function(){\r
156                         var text = document.createElement('textarea');\r
157                         text.value = '\n';\r
158                         return text.value;\r
159                 })(),\r
160                 LINE_FEED_CODE_PRE: ( function(){\r
161                         var pre = document.createElement('pre');\r
162                         pre.appendChild( document.createTextNode('\n'));\r
163                         return pre.firstChild.data;\r
164                 })()\r
165         }\r
166 })();\r
167 \r
168 /*\r
169  * pettanr.util\r
170  * \r
171  *   extend( baseInstance, extend)\r
172  *   cleanCommnetNode()\r
173  *   cleanElement()\r
174  *   getElementSize( _elm)\r
175  *   getImageSize()\r
176  *   getAbsolutePath()\r
177  *   getGrobalObjectName()\r
178  * \r
179  */\r
180 pettanr.util = ( function(){\r
181         var ELM_SIZE_GETTER = ( function(){\r
182                         var ret = document.createElement( 'DIV'),\r
183                                 style = ret.style;\r
184                         ret.id = 'elmSizeGetter';\r
185                         style.position = 'absolute';\r
186                         style.left = '0px';\r
187                         style.top = '-9999px';\r
188                         style.visibility = 'hidden';\r
189                         document.body.appendChild( ret);\r
190                         return ret;\r
191                 })(),\r
192                 IMG_SIZE_GETTER = ( function(){\r
193                         var ret = ELM_SIZE_GETTER.cloneNode( true);\r
194                         ret.id = 'imgSizeGetter';\r
195                         document.body.appendChild( ret);\r
196                         return ret;\r
197                 })(),\r
198                 CLEAN_TARGET_ELEMENT = 'script,style,object,applet,embed,iframe,frame,base,bgsound,frameset,listing'.split( ',');\r
199         \r
200         /* clean comment node */\r
201         cleanCommnetNode();\r
202         \r
203         /* clean noscript */\r
204         var nodeNoscript = document.getElementsByTagName( 'noscript'),\r
205                 noscript;\r
206         for(var i=0; i<nodeNoscript.length; ++i){\r
207                 noscript = nodeNoscript[i];\r
208                 noscript.parentNode && noscript.parentNode.removeChild( noscript);\r
209         }\r
210         nodeNoscript = noscript = null;\r
211         \r
212         function cleanCommnetNode( _targetElm){\r
213                 search( _targetElm || document.body );\r
214                 \r
215                 function search( _elm){\r
216                         if( !_elm) return;\r
217                         if( _elm.nodeType === 8){\r
218                                 _elm.parentNode.removeChild( _elm);\r
219                                 return;\r
220                         }\r
221                         var i, l, _children = _elm.childNodes, _array = [];\r
222                         if( _children && typeof _children.length === 'number'){\r
223                                 // liveNode > array\r
224                                 for( i=0, l=_children.length; i<l; ++i){\r
225                                         _array.push( _children[ i ] );\r
226                                 }\r
227                                 while( _array.length !== 0 ){\r
228                                         search( _array.shift());\r
229                                 }\r
230                         }\r
231                 }\r
232         }\r
233         return {\r
234                 extend: function( baseInstance, extend ){\r
235                         for( var key in extend ){\r
236                                 if( Type.isUndefined( baseInstance[ key ] ) === true ){\r
237                                         baseInstance[ key ] = extend[ key ];\r
238                                 } else\r
239                                 if( typeof baseInstance[ key ] === typeof extend[ key ] ){\r
240                                         baseInstance[ key ] = extend[ key ];\r
241                                 } else {\r
242                                         alert( 'extend error' );\r
243                                 }\r
244                         }\r
245                         return baseInstance;\r
246                 },      \r
247                 cleanCommnetNode: cleanCommnetNode,\r
248                 cleanElement: function( _targetElm){\r
249                         var _nodes, _elm, _array, j, m;\r
250                         for( var i=0, l=CLEAN_TARGET_ELEMENT.length; i<l; ++i){\r
251                                 _nodes = _targetElm.getElementsByTagName( CLEAN_TARGET_ELEMENT[ i]);\r
252                                 _array = [];\r
253                                 for( j=0, m = _nodes.length; j<m; ++j){\r
254                                         _array.push( _nodes[ j]);\r
255                                 }\r
256                                 for( j=0, m = _array.length; j<m; ++j){\r
257                                         _elm = _nodes[ j];\r
258                                         _elm.parentNode && _elm.parentNode.removeChild( _elm);\r
259                                 }\r
260                         }\r
261                         cleanCommnetNode( _targetElm);\r
262                         if( pettanr.ua.isIE === false) return;\r
263                         _nodes = _targetElm.all || _targetElm.getElementsByName( '*');\r
264                         for( i=0, l = _nodes.length; i<l; ++i){\r
265                                 _elm = _nodes[ i];\r
266                                 _elm.style.filter = '';\r
267                                 _elm.style.behavior = '';\r
268                         }\r
269                 },\r
270                 getElementSize: function( _elm ){\r
271                         if( Type.isHTMLElement( _elm ) === false ){\r
272                                 return {\r
273                                         width:  0,\r
274                                         height: 0\r
275                                 };\r
276                         };\r
277                         var     parentElm   = _elm.parentNode,\r
278                                 prevElm     = _elm.previousSibling,\r
279                                 nextElm     = _elm.nextSibling,\r
280                                 displayNone = _elm.style.display === 'none';\r
281                         if( displayNone === true ) _elm.style.display = '';\r
282                         ELM_SIZE_GETTER.appendChild( _elm );\r
283                         var ret = {\r
284                                 width:          _elm.offsetWidth,\r
285                                 height:         _elm.offsetHeight\r
286                         }\r
287                         if( displayNone === true ) _elm.style.display = 'none';\r
288                         if( nextElm ){\r
289                                 parentElm.insertBefore( _elm, nextElm );\r
290                         } else          \r
291                         if( prevElm && prevElm.nextSibling ){\r
292                                 parentElm.insertBefore( _elm, prevElm.nextSibling );\r
293                         } else {\r
294                                 parentElm && parentElm.appendChild( _elm );\r
295                         }                       \r
296                         return ret;\r
297                 },\r
298                 getImageSize: function( img){\r
299                         var     parentElm = img.parentNode,\r
300                                 prevElm = img.previousSibling,\r
301                                 nextElm = img.nextSibling,\r
302                                 displayNone = img.style.display === 'none';\r
303                         if( displayNone === true) img.style.display = '';\r
304                         IMG_SIZE_GETTER.appendChild( img);\r
305                         \r
306                         var size = getActualDimension( img);\r
307                         \r
308                         IMG_SIZE_GETTER.removeChild( img);\r
309                         if( displayNone === true) img.style.display = 'none';\r
310                         if( nextElm){\r
311                                 parentElm.insertBefore( img, nextElm);\r
312                         } else          \r
313                         if( prevElm && prevElm.nextSibling){\r
314                                 parentElm.insertBefore( img, prevElm.nextSibling);\r
315                         } else {\r
316                                 parentElm && parentElm.appendChild( img);\r
317                         }\r
318                         \r
319                 /* LICENSE: MIT\r
320                  * AUTHOR: uupaa.js@gmail.com\r
321                  */\r
322                         function getActualDimension(image) {\r
323                                 var run, mem, w, h, key = "actual";\r
324                         \r
325                         // for Firefox, Safari, Google Chrome\r
326                                 if ("naturalWidth" in image) {\r
327                                         return {\r
328                                                 width:  image.naturalWidth,\r
329                                                 height: image.naturalHeight\r
330                                         };\r
331                                 }\r
332                         \r
333                                 if ("src" in image) { // HTMLImageElement\r
334                                         if (image[key] && image[key].src === image.src) {\r
335                                                 return image[key];\r
336                                         }\r
337                                         if (document.uniqueID) { // for IE\r
338                                                 run = image.runtimeStyle;\r
339                                                 mem = { w: run.width, h: run.height }; // keep runtimeStyle\r
340                                                 run.width  = "auto"; // override\r
341                                                 run.height = "auto";\r
342                                                 w = image.width;\r
343                                                 h = image.height;\r
344                                                 run.width  = mem.w; // restore\r
345                                                 run.height = mem.h;\r
346                                         } else { // for Opera and Other\r
347                                                 mem = { w: image.width, h: image.height }; // keep current style\r
348                                                 image.removeAttribute("width");\r
349                                                 image.removeAttribute("height");\r
350                                                 w = image.width;\r
351                                                 h = image.height;\r
352                                                 image.width  = mem.w; // restore\r
353                                                 image.height = mem.h;\r
354                                         }\r
355                                         return image[key] = { width: w, height: h, src: image.src }; // bond\r
356                                 }\r
357                                 // HTMLCanvasElement\r
358                                 return { width: image.width, height: image.height };\r
359                         }\r
360                         \r
361                         return size;\r
362                 },\r
363                 getAbsolutePath: function( path) {\r
364                         var e = document.createElement("div");\r
365                         e.innerHTML = '<a href=\"' + path + '\" />';\r
366                         return e.firstChild.href;\r
367                 },\r
368                 getAbsolutePosition: function( _elm){\r
369                         // Find the destination's position\r
370                         var     destx = _elm.offsetLeft,\r
371                                 desty = _elm.offsetTop,\r
372                                 thisNode = _elm,\r
373                                 body = document.body;\r
374                         while (thisNode.offsetParent && thisNode.offsetParent !== body){\r
375                                 thisNode = thisNode.offsetParent;\r
376                                 destx += thisNode.offsetLeft;\r
377                                 desty += thisNode.offsetTop;\r
378                         }\r
379                         return {\r
380                                 x:      destx,\r
381                                 y:      desty\r
382                         }\r
383                 },\r
384                 pullHtmlAsTemplete: function( IDorELM){\r
385                         if( typeof IDorELM === 'string'){\r
386                                 IDorELM = document.getElementById( IDorELM);\r
387                         }\r
388                         if( !IDorELM) return;\r
389                         IDorELM.parentNode && IDorELM.parentNode.removeChild( IDorELM);\r
390                         if( IDorELM.id && IDorELM.id.indexOf( 'templete-') === 0){\r
391                                 IDorELM.removeAttribute( 'id');\r
392                         }\r
393                         return IDorELM;\r
394                 },\r
395                 getElementsByClassName: function( _elm, _className, opt_tagName){\r
396                         var _all = !opt_tagName || opt_tagName === '*',\r
397                                 _nodes = _all === true ? ( _elm.all || _elm.getElementsByTagName( '*')) : _elm.getElementsByTagName( opt_tagName),\r
398                                 _node, _classes, ret = [];\r
399                         for( var i=0, l = _nodes.length; i<l; ++i){\r
400                                 _node = _nodes[ i];\r
401                                 _node.nodeType === 1 && this.hasClassName( _node, _className) === true && ret.push( _node);\r
402                         }\r
403                         return ret;\r
404                 },\r
405                 getChildIndex: function( _parent, _child){\r
406                         var _children = _parent.getElementsByTagName( _child.tagName ),\r
407                                 l = _children.length;\r
408                         for(var i=0; i<l; ++i){\r
409                                 if( _children[ i] === _child) return i;\r
410                         }\r
411                         return -1;\r
412                 },\r
413                 hasClassName: function( _elm, _className){\r
414                         var _classes = ( _elm.className || '').split( ' ');\r
415                         for( var i=0, l=_classes.length; i<l; ++i){\r
416                                 if( _classes[ i] === _className) return true;\r
417                         }\r
418                         return false;\r
419                 },\r
420                 removeAllChildren: function ( _elm){\r
421                         while( _elm.firstChild){\r
422                                 remove( _elm.firstChild);\r
423                         }\r
424                         function remove( _node){\r
425                                 while( _node.firstChild){\r
426                                         remove( _node.firstChild);\r
427                                 }\r
428                                 _node.parentNode && _node.parentNode.removeChild( _node);\r
429                         }\r
430                 },\r
431                 getIndex: function( _array, _element){\r
432                         if( Array.prototype.indexof ){\r
433                                 pettanr.util.getIndex = function( _array, _element){\r
434                                         return _array.indexof( _element);\r
435                                 }\r
436                         } else {\r
437                                 pettanr.util.getIndex = function( _array, _element){\r
438                                         for( var i=0, l = _array.length; i<l; ++i){\r
439                                                 if( _array[ i] === _element) return i;\r
440                                         }\r
441                                         return -1;                                      \r
442                                 }\r
443                         }\r
444                         return pettanr.util.getIndex( _array, _element);\r
445                 },\r
446                 copyArray: function( _array ){\r
447                         var ret = new Array( l );\r
448                         for(var i=0, l = _array.length; i<l; ++i){\r
449                                 ret[ i ] = _array[ i ];\r
450                         }\r
451                         return ret;\r
452                 },\r
453                 /*\r
454                  * \r
455                  */\r
456                 createGlobalFunction: function( _func) {\r
457                         var randomKey = null;\r
458                         while( true) {\r
459                                 randomKey = '_glovalFunction_' + ( '' + Math.random()).replace( /\./,'');\r
460                                 if( eval( 'typeof '+randomKey) === 'undefined') {\r
461                                         break;\r
462                                 }\r
463                         }\r
464                         window[ randomKey] = _func;\r
465                         return randomKey;\r
466                 },\r
467                 createGlobalFunc: function( func){\r
468                         var randomKey = null;\r
469                         while(true) {\r
470                                 randomKey = 'hogeGlovalFunc_'+(''+Math.random()).replace(/\./,'');\r
471                                 if(eval('typeof '+randomKey) == 'undefined') {\r
472                                         break;\r
473                                 }\r
474                         }\r
475                         eval(randomKey+'='+((typeof func=='string') ? func : func.toString()));\r
476                         return randomKey;\r
477                 },\r
478                 createGlobalVar: function( obj){\r
479                         var randomKey = null;\r
480                         while(true) {\r
481                                 randomKey = 'hogeGlovalVar_'+(''+Math.random()).replace(/\./,'');\r
482                                 if(eval('typeof '+randomKey+'') == 'undefined') {\r
483                                         break;\r
484                                 }\r
485                         }\r
486                         var globalObj = eval(randomKey+'={}');\r
487                         globalObj.value = obj;\r
488                         return randomKey;\r
489                 },\r
490                 createGlobalUniqueName: function(){\r
491                         var randomKey = null;\r
492                         while(true) {\r
493                                 randomKey = '_uniqueName'+(''+Math.random()).replace(/\./,'');\r
494                                 if( typeof window[randomKey] === 'undefined'){\r
495                                         break;\r
496                                 }\r
497                         }\r
498                         return randomKey;\r
499                 },\r
500                 createIframe: function( id, callback){\r
501                         var ua = pettanr.ua;\r
502             var el = document.createElement( ua.isIE ? '<iframe name="' + id + '" frameborder="0" scrolling="no">' : 'iframe');\r
503 \r
504             if( ua.isIE){\r
505                                 el.onreadystatechange = detect;\r
506             } else {\r
507                 // iron(chrome) の場合、append の前に onload を指定しないと onload が呼ばれない\r
508                 el.onload = onLoad;\r
509                 //setTimeout( asynkCallback, 0 );\r
510                         }\r
511 \r
512                         document.body.appendChild( el);\r
513             el.id = el.name = id;\r
514             el.setAttribute( 'name', id);\r
515             el.style.cssText = 'width:1px;height:1px;visibility:hidden;position:absolute;top:1px;left:1px;';\r
516                         // http://d.hatena.ne.jp/onozaty/20070830/p1\r
517                         // [JavaScript]IE6ではJavaScriptで動的に作成したiframeに対してsubmitできない(IE7は未確認) ->解決\r
518                         el.contentWindow.name = id;                                     \r
519             \r
520             window[id] = el;\r
521 \r
522             function detect(){\r
523                 if ( this.readyState === "complete") {\r
524                     this.onreadystatechange = new Function();\r
525                     this.onreadystatechange = null;\r
526                     setTimeout( asynkCallback, 0 );\r
527                 }\r
528             }\r
529                         function onLoad(){\r
530                                 el.onload = null;\r
531                                 setTimeout( asynkCallback, 0 );\r
532                         }\r
533                         function asynkCallback(){\r
534                                 callback( el );\r
535                         }\r
536                 }\r
537         }\r
538 })();\r
539 \r
540 /*\r
541  * pettanr.ua\r
542  * \r
543  *   detect userAgent\r
544  *   detect plug in\r
545  */\r
546 pettanr.ua = ( function(){\r
547         var ua = (function(){\r
548                         var acme = {};\r
549                         \r
550                         var n = navigator;\r
551                         var dua = n.userAgent;\r
552                         var dav = n.appVersion;\r
553                         var tv = parseFloat(dav);\r
554                         acme.isOpera = (dua.indexOf("Opera") >= 0) ? tv: undefined;\r
555                         acme.isKhtml = (dav.indexOf("Konqueror") >= 0) ? tv : undefined;\r
556                         acme.isWebKit = parseFloat(dua.split("WebKit/")[1]) || undefined;\r
557                         acme.isChrome = parseFloat(dua.split("Chrome/")[1]) || undefined;\r
558                         var index = Math.max(dav.indexOf("WebKit"), dav.indexOf("Safari"), 0);\r
559                         if(index && !acme.isChrome){\r
560                                 acme.isSafari = parseFloat(dav.split("Version/")[1]);\r
561                                 if(!acme.isSafari || parseFloat(dav.substr(index + 7)) <= 419.3){\r
562                                         acme.isSafari = 2;\r
563                                 }\r
564                         }\r
565                         if(document.all && !acme.isOpera){\r
566                                 acme.isIE = parseFloat(dav.split("MSIE ")[1]) || undefined;\r
567                         }\r
568                         \r
569                         return acme;\r
570                 })(),\r
571                 isIE = navigator.userAgent.toLowerCase().indexOf( 'msie') !== -1,\r
572                 ieVersion = isIE === true ? parseInt( navigator.appVersion.toLowerCase().replace( /.*msie[ ]/, '').match( /^[0-9]+/)) : 0,\r
573                 ieRenderingVersion = ieVersion === 8 ? document.documentMode : ieVersion,\r
574                 isStanderdMode = document.compatMode === 'CSS1Compat',\r
575                 ActiveX = ( function(){\r
576                         if( isIE === false || ieVersion > 8) return false;\r
577                         var     b = document.body,\r
578                                 c = b.className || '',\r
579                                 x,\r
580                                 ret = pettanr.URL_PARAMS.ActiveX,\r
581                                 ns = 'pettanr-ActiveX-',\r
582                                 enabled = 'enabled',\r
583                                 disabled = 'disabled';\r
584                         if( ret !== true && ret !== false){\r
585                                 if( pettanr.util.hasClassName( b, ns + enabled) === true) return true;\r
586                                 if( pettanr.util.hasClassName( b, ns + disabled) === true) return false;\r
587                                 x = document.createElement('div');\r
588                                 b.appendChild(x);\r
589                                 x.style.cssText = 'width:1px;height:1px;line-height:1px;filter:progid:DXImageTransform.Microsoft.Shadow()';\r
590                                 ret = x.offsetHeight > 1;\r
591                                 b.removeChild(x);\r
592                         }\r
593                         b.className += [ c !== '' ? ' ' : c, ns, ret === true ? enabled : disabled ].join( '');\r
594                         return ret;\r
595                 })(),\r
596                 VML = ( function(){\r
597                         if( ActiveX === false || isIE === false || ieVersion > 8) return false;\r
598                         var globalObjectName = pettanr.util.createGlobalUniqueName(),\r
599                                 script,\r
600                                 id = 'detectVML';\r
601                         document.write( [ '<!--[if gte vml 1]><script id="', id, '">window', '.', globalObjectName, '=1;<\/script><![endif]-->'].join( ''));\r
602                         if( window[globalObjectName] === 1){\r
603                                 script = document.getElementById( id);\r
604                                 script.parentNode.removeChild( script);\r
605                                 window[globalObjectName] = null;\r
606                                 return true;\r
607                         }\r
608                         return false;\r
609                 })(),\r
610                 isStandAloneMode = ( function(){\r
611                         if( isIE === false) return false;\r
612                         if( VML === true) return false;\r
613                         var globalObjectName = pettanr.util.createGlobalUniqueName(),\r
614                                 script,\r
615                                 id = 'detectStandAlone';\r
616                         document.write( [ '<!--[if IE ', Math.floor( ieVersion), ']><script id="', id, '">window', '.', globalObjectName, '=1;<\/script><![endif]-->'].join( ''));\r
617                         if( window[globalObjectName] === 1){\r
618                                 script = document.getElementById( id);\r
619                                 script.parentNode.removeChild( script);\r
620                                 window[globalObjectName] = null;\r
621                                 return false;\r
622                         }\r
623                         return true;\r
624                 })();\r
625         return {\r
626                 IE:                                     ua.isIE,\r
627                 GECKO:                          0,\r
628                 OPERA:                          ua.isOpera,\r
629                 KHTML:                          ua.isKhtml,\r
630                 WEBKIT:                         ua.isWebKit,\r
631                 CHROME:                         ua.isChrome,\r
632                 isIE:                           isIE,\r
633                 ieVersion:                      ieVersion,\r
634                 ieRenderingVersion:     ieRenderingVersion,\r
635                 isStanderdMode:         isStanderdMode,\r
636                 VENDER_PREFIX: ( function() {\r
637                         var ua = navigator.userAgent.toLowerCase();\r
638                         if ( ua.indexOf('opera') !== -1) {\r
639                                 return 'O';\r
640                         } else if ( ua.indexOf('msie') !== -1) {\r
641                                 return 'ms';\r
642                         } else if ( ua.indexOf('webkit') !== -1) {\r
643                                 return 'webkit';\r
644                         } else if ( navigator.product === 'Gecko') {\r
645                                 return 'Moz';\r
646                         }\r
647                         return '';\r
648                 })(),\r
649                 ACTIVEX: ActiveX,\r
650                 VML: VML,\r
651                 STANDALONE: isStandAloneMode,\r
652                 startVML: function(){\r
653                         delete this.startVML;\r
654                         if( pettanr.ua.VML !== true) return false;\r
655                         if (!document.namespaces["v"]) {\r
656                         document.namespaces.add("v", "urn:schemas-microsoft-com:vml", "#default#VML");\r
657                     }\r
658                     document.createStyleSheet().cssText = "v\:shape,v\:image{behavior:url(#default#VML);display:block;};";\r
659                 }\r
660         }\r
661 })();\r
662 \r
663 \r
664 pettanr.CONST = ( function(){\r
665         var SERVER_SUPPORT    = !( 'has_server_support' in window && has_server_support === false ),\r
666                 PETTANR_ROOT_PATH = ( function(){\r
667                         if( SERVER_SUPPORT === false ){\r
668                                 var h1 = document.getElementsByTagName( 'h1' )[ 0 ];\r
669                                 if( h1 ){\r
670                                         var a = h1.getElementsByTagName( 'a' )[ 0 ];\r
671                                         return a ? a.href : '';\r
672                                 }\r
673                                 return '';\r
674                         }\r
675                         var loc = document.location;\r
676                         return [ loc.protocol, '\/\/', loc.host, '\/' ].join( '' );\r
677                 })(),\r
678                 RELATIVE = ( function(){\r
679                         var ret  = '',\r
680                                 loc  = document.location,\r
681                                 path = [ loc.protocol, '\/', loc.host, '\/', loc.pathname.split( '\\' ).join( '\/' ) ].join( '' ),\r
682                                 l    = path.split( '\/' ).length - PETTANR_ROOT_PATH.split( '\/' ).length;\r
683                         for( var i=0; i<l; ++i ){\r
684                                 ret += '..\/';\r
685                         }\r
686                         return ret;\r
687                 })();\r
688                 \r
689         return {\r
690                 PETTANR_ROOT_PATH:                      PETTANR_ROOT_PATH,\r
691                 URL_ORIGINAL_PICTURES_JSON: ( SERVER_SUPPORT === false ? 'json\/' : PETTANR_ROOT_PATH ) + 'original_pictures.json',\r
692                 URL_RESOURCE_PICTURES_JSON: ( SERVER_SUPPORT === false ? 'json\/' : PETTANR_ROOT_PATH ) + 'resource_pictures.json',\r
693                 URL_COMICS_JSON:                        ( SERVER_SUPPORT === false ? 'json\/' : PETTANR_ROOT_PATH ) + 'comics.json',\r
694                 URL_PANELS_JSON:                        ( SERVER_SUPPORT === false ? 'json\/' : PETTANR_ROOT_PATH ) + 'panels.json',\r
695                 NS_PETTANR_COMIC:                       'pettanr-comic',\r
696                 RESOURCE_PICTURE_PATH:          ( SERVER_SUPPORT === false ? RELATIVE : PETTANR_ROOT_PATH ) + 'resource_pictures\/',\r
697                 SYSTEM_PICTURE_PATH:            ( SERVER_SUPPORT === false ? RELATIVE : PETTANR_ROOT_PATH ) + 'system_pictures\/',\r
698                 CREATE_COMIC_JS:                        SERVER_SUPPORT === false ? 'js\/create_new_comic.js' : PETTANR_ROOT_PATH + 'comics\/new.js',\r
699                 CREATE_PANEL_JS:                        SERVER_SUPPORT === false ? 'js\/create_new_panel.js' : PETTANR_ROOT_PATH + 'panels\/new.js',\r
700                 UPLOAD_PICTURE_JS:                      SERVER_SUPPORT === false ? 'js\/upload_picture.js' : PETTANR_ROOT_PATH + 'original_pictures\/new.js',\r
701                 REGISTER_ARTIST_JS:                     SERVER_SUPPORT === false ? 'js\/register_artist.js' : PETTANR_ROOT_PATH + 'artists\/new.js',\r
702                 JQUERY_URL:                                     SERVER_SUPPORT === false ? 'javascripts\/jquery-1.6.2.min.js' : PETTANR_ROOT_PATH + 'assets\/jquery-162_min.js',\r
703                 SERVER_SUPPORT:                         SERVER_SUPPORT\r
704         }\r
705 })();\r
706 \r
707 pettanr.view = ( function(){\r
708         /* create iframe overlay for user console */\r
709         var LoginUserNavi = {\r
710                         show: function(){\r
711                                 var i = pettanr.util.getChildIndex( this.parentNode, this );\r
712                                 i !== -1 && bootApplication( i );\r
713                                 return false;\r
714                         },\r
715                         hide: function(){}\r
716                 }\r
717 \r
718         /* debug info */\r
719         // ua version, lang, os, plugin ( vml, svg), standerdmode, balloon, rimg\r
720 \r
721 /*\r
722  * window resize event, overlay と currentなviewに流す\r
723  * view modeの保持\r
724  *       editor, overlay, comic-viewer, image-explorer\r
725  * fadeIn, faseOut\r
726  */\r
727 \r
728         var jqWindow,\r
729                 APPLICATION_LIST = [],\r
730                 LUNCHER_APPLICATION_LIST = [],\r
731                 currentApplication = null;\r
732         \r
733         var AbstractBasicPane = function(){\r
734                 this.onPaneResize = function( _w, _h ){}\r
735                 this.resize = function( _w, _h ){\r
736                         if( this.MIN_WIDTH > _w || this.MIN_HEIGHT > _h ){\r
737                                 if( Type.isHTMLElement( this.rootElement ) === true ){\r
738                                         // 小さすぎる!、と表示\r
739                                 };\r
740                                 return;\r
741                         };\r
742                         this.onPaneResize( _w, _h );\r
743                 };\r
744                 this.MIN_WIDTH = 240;\r
745                 this.MIN_HEIGHT = 240;\r
746         }\r
747         \r
748         var AbstractApplication = function(){\r
749                 var instance;\r
750                 this.displayName = 'app name';\r
751                 this.ID = 'app id';\r
752                 this.rootElement = null;\r
753                 this.parentElement = null;\r
754                 this.nextSibling = null;\r
755                 this.getUID = function(){\r
756                         return pettanr.util.getIndex( APPLICATION_LIST, instance );\r
757                 }\r
758                 this.open = function( _w, _h /*, _option */ ){\r
759                         instance = this;\r
760                         if( this.MIN_WIDTH > _w || this.MIN_HEIGHT > _h ){\r
761                                 if( Type.isHTMLElement( this.rootElement ) === true ){\r
762                                         // 小さすぎる!、と表示\r
763                                 }\r
764                         }\r
765                         if( arguments.length > 2){\r
766                                 // argumentsRellay( this.onOpen, arguments );\r
767                                 this.onOpen.apply( this, arguments );\r
768                         } else {\r
769                                 this.onOpen( _w, _h );\r
770                         }\r
771                 };\r
772                 this.close = function(){\r
773                         if( this.onClose() === false ){\r
774                                 return false;\r
775                         }\r
776                 };\r
777                 this.onOpen = function( _w, _h /*, _option */ ){\r
778                         // overrride\r
779                 };\r
780                 this.onClose = function(){\r
781                         // overrride\r
782                         return true;\r
783                 }; // false の場合、close の拒否 \r
784                 this.addMouseEventListener = function( _element, _eventType, _handler ){\r
785                          MouseEventManager.add( instance, _element, _eventType, _handler );\r
786                 };\r
787         }\r
788         AbstractApplication.prototype = new AbstractBasicPane();\r
789         \r
790         var ApplicationReference = function( application ){\r
791                 this.inOverlay = false;\r
792                 this.getUID = function(){\r
793                         return pettanr.util.getIndex( APPLICATION_LIST, application );\r
794                 }\r
795                 this.boot = function( /* _option */ ){\r
796                         if( arguments.length > 0 ){\r
797                                 bootApplication( application, pettanr.util.copyArray( arguments ) );\r
798                         } else {\r
799                                 bootApplication( application );\r
800                         }\r
801                 }\r
802                 this.bootInOverlay = function( /* _option */ ){\r
803                         this.inOverlay = true;\r
804                         pettanr.overlay.show( application, pettanr.util.copyArray( arguments ) );\r
805                 }\r
806                 this.shutdown = function(){\r
807                         if( this.inOverlay === true ){\r
808                                 pettanr.overlay.hide();\r
809                                 this.inOverlay = false;\r
810                         } else {\r
811                                 bootApplication( 0 );\r
812                         }\r
813                 }\r
814                 this.addToLancher = function(){\r
815                         if( pettanr.util.getIndex( LUNCHER_APPLICATION_LIST, application ) !== -1 ) return;\r
816                         LUNCHER_APPLICATION_LIST.push( application );\r
817         \r
818                         var navi = document.getElementById('global-navi'),\r
819                                 item = document.createElement('a');\r
820                         navi.appendChild( item );\r
821                         navi.style.width = ( ( item.offsetWidth || 80 ) * LUNCHER_APPLICATION_LIST.length ) + 'px';\r
822                         item.href = '#';\r
823                         item.appendChild( document.createTextNode( application.displayName ));\r
824                         item.onclick = LoginUserNavi.show;\r
825                 }\r
826         }\r
827 \r
828         function bootApplication( APPLICATIONorINDEX, _arguments ){\r
829                 var _application,\r
830                         i, j, l, \r
831                         nodesA = document.getElementById('global-navi').getElementsByTagName( 'a') || [],\r
832                         _index = -1;\r
833                 if( typeof APPLICATIONorINDEX === 'number' && APPLICATIONorINDEX < LUNCHER_APPLICATION_LIST.length){\r
834                         _application = LUNCHER_APPLICATION_LIST[ APPLICATIONorINDEX ];\r
835                 } else\r
836                 if( typeof APPLICATIONorINDEX === 'string' ){\r
837                         for( i=0, l=LUNCHER_APPLICATION_LIST.length; i<l; ++i ){\r
838                                 if( APPLICATIONorINDEX === APPLICATION_LIST[ i ].ID ){\r
839                                         _application = APPLICATION_LIST[ i ];\r
840                                         break;\r
841                                 }\r
842                         }\r
843                 } else\r
844                 if( pettanr.view.isApplicationInstance( APPLICATIONorINDEX ) === true ){\r
845                         _application = APPLICATIONorINDEX;\r
846                 } else\r
847                 if( !currentApplication ){\r
848                         _application = LUNCHER_APPLICATION_LIST[ 0 ];\r
849                 } else {\r
850                         return;\r
851                 }\r
852                 \r
853                 if( !_application ) return;\r
854                 \r
855                 for( i=0, l=LUNCHER_APPLICATION_LIST.length; i<l; ++i ){\r
856                         if( _application === LUNCHER_APPLICATION_LIST[ i ] ){\r
857                                 for( j=0, l=nodesA.length; j<l; ++j ){\r
858                                         nodesA[ j ].className = i === j ? 'current' : '';\r
859                                 }                                       \r
860                                 break;\r
861                         }\r
862                 }\r
863                 \r
864                 if( currentApplication === _application ) return;\r
865                 if( currentApplication ){\r
866                         currentApplication.close();\r
867                         currentApplication.rootElement && currentApplication.rootElement.parentNode &&\r
868                                 currentApplication.rootElement.parentNode.removeChild( currentApplication.rootElement );\r
869                 }\r
870                         \r
871                 currentApplication = _application;\r
872                 \r
873                 if( _application.nextSibling && _application.nextSibling.parentNode === _application.parentElement ){\r
874                         _application.parentElement.insertBefore( _application.rootElement, _application.nextSibling );\r
875                 } else\r
876                 if( _application.parentElement ){\r
877                         _application.parentElement.appendChild( _application.rootElement );\r
878                 } else {\r
879                         _application.rootElement && document.body.appendChild( _application.rootElement );\r
880                 }\r
881                         \r
882                 if( _arguments ){\r
883                         _arguments.unshift( jqWindow.width(), jqWindow.height() );\r
884                         _application.open.apply( _application, _arguments );\r
885                         // argumentsRellay( _application.open, _arguments );\r
886                 } else {\r
887                         _application.open( jqWindow.width(), jqWindow.height() );\r
888                 }\r
889                 pettanr.view.currentID = _application.ID;\r
890         }\r
891         \r
892         function argumentsRellay( _method, _arguments ){\r
893                 alert( typeof _method )\r
894                 l = _arguments.length;\r
895                 if( l > 0 ){\r
896                         var _arg = [];\r
897                         for( i=0; i<l; ++i ){\r
898                                 _arg.push( 'a[' + i + ']' );\r
899                         }\r
900                         window['_method'] = _method;\r
901                         //eval( '_method(' + _arg.join(',') + ')' );\r
902                         var f = new Function( 'a', '_method(' + _arg.join(',') + ')' );\r
903                         f( _arguments );\r
904                         window['_method'] = undefined;\r
905                 } else {\r
906                         _method();\r
907                 }               \r
908         }\r
909         \r
910         function onWindowResize(){\r
911                 var w = jqWindow.width(),\r
912                         h = jqWindow.height();\r
913                 currentApplication && currentApplication.resize( w, h );\r
914                 pettanr.overlay.onWindowResize( w, h );\r
915                 pettanr.form.onWindowResize( w, h );\r
916         }\r
917 \r
918         return {\r
919                 init: function( _funcArray ){\r
920                         jqWindow = pettanr.jqWindow();\r
921                         jqWindow.resize( onWindowResize );\r
922                         \r
923                         var _option = {}; // urlパラメータ\r
924                         \r
925                         onWindowResize();\r
926                         \r
927                         bootApplication( pettanr.URL_PARAMS.view || 0 );\r
928                         \r
929                         delete pettanr.view.init;\r
930                 },\r
931                 createBasicPane: function( _class, _options ){\r
932                         _class.prototype = new AbstractBasicPane();\r
933                         return new _class( _options );\r
934                 },\r
935                 _getAbstractApplication: function(){\r
936                         return new AbstractApplication();\r
937                 },\r
938                 registerApplication: function( _class, _options ){\r
939                         _class.prototype = new AbstractApplication();\r
940                         _application = new _class( _options );\r
941                         \r
942                         var elm = _application.rootElement;\r
943                         if( Type.isHTMLElement( elm ) === false ) return null;\r
944                          \r
945                         _application.parentElement = elm.parentNode;\r
946                         _application.nextSibling = elm.nextSibling;\r
947                         \r
948                         if( elm.parentNode ){\r
949                                 elm.parentNode.removeChild( elm );\r
950                         }\r
951                         APPLICATION_LIST.push( _application );\r
952                         return new ApplicationReference( _application );\r
953                 },\r
954                 isBasicPaneInstance: function( _basicPane ){\r
955                         return  _basicPane instanceof AbstractBasicPane;\r
956                 },\r
957                 isApplicationInstance: function( _application ){\r
958                         return _application instanceof AbstractApplication;\r
959                 },\r
960                 isApplicationReference: function( _reference ){\r
961                         return _reference instanceof ApplicationReference;\r
962                 },\r
963                 currentID:      null,\r
964                 EDITOR:         'editor',\r
965                 OVERLAY:        'overlay'\r
966         }\r
967 })();\r
968 \r
969 pettanr.overlay = ( function(){\r
970         var SHADOW_OPACITY = 0.5,\r
971                 ELM_CONTAINER  = document.getElementById( 'overlay-container' ),\r
972                 currentOverlay = null,\r
973                 bootParams     = null,\r
974                 visible        = false,\r
975                 jqConteiner, jqShadow, jqCloseButton,// jqBody, \r
976                 windowW, windowH;\r
977 \r
978         function asyncResize(){\r
979                 currentOverlay.resize( windowW, windowH );\r
980         }\r
981         function onCloseClick( e){\r
982                 pettanr.overlay.hide();\r
983                 e.preventDefault();\r
984                 return false;\r
985         }\r
986         function onFadeInComplete(){\r
987 \r
988         }\r
989         function onFadeOutComplete(){\r
990                 currentOverlay.close();\r
991                 currentOverlay.rootElement.style.display = 'none';\r
992                 currentOverlay.rootElement.style.visibility = 'hidden';\r
993                 currentOverlay = null;  \r
994         }\r
995         return {\r
996                 init: function(){\r
997                         //jqBody = pettanr.jqBody();\r
998                         jqConteiner   = $( '#overlay-container');\r
999                         jqShadow      = $( '#overlay-shadow');\r
1000                         jqCloseButton = $( '#overlay-close-button').click( onCloseClick );\r
1001                         \r
1002                         pettanr.key.addKeyDownEvent( pettanr.view.OVERLAY, 27, false, false, pettanr.overlay.hide ); // 27.esc\r
1003                         \r
1004                         delete pettanr.overlay.init;\r
1005                 },\r
1006                 show: function( _overlay, _bootParams ){\r
1007                         if( visible === true && currentOverlay === _overlay ) return;\r
1008                         if( pettanr.view.isApplicationInstance( _overlay ) === false ) return;\r
1009                         \r
1010                         document.body.style.overflow = 'hidden';\r
1011                         document.body.appendChild( ELM_CONTAINER ); // ie6-8 で必要、なんで、、、?\r
1012                         \r
1013                         this.visible = visible = true;\r
1014                         this.currentID = _overlay.ID;\r
1015                         currentOverlay = _overlay;\r
1016                         bootParams = _bootParams;\r
1017 \r
1018                         jqConteiner.stop().css( {\r
1019                                 filter:         '',\r
1020                                 opacity:        '',\r
1021                                 top:            document.documentElement.scrollTop || document.body.scrollTop\r
1022                         }).fadeIn( onFadeInComplete );\r
1023                         \r
1024                         currentOverlay.rootElement.style.display = '';\r
1025                         currentOverlay.rootElement.style.visibility = 'visible';\r
1026                         \r
1027                         ELM_CONTAINER.insertBefore( currentOverlay.rootElement, document.getElementById( 'overlay-close-button' ));\r
1028         \r
1029                         if( Type.isArray( bootParams ) === true ){\r
1030                                 bootParams.unshift( windowW, windowH )\r
1031                                 currentOverlay.open.apply( currentOverlay, bootParams );\r
1032                         } else {\r
1033                                 currentOverlay.open( windowW, windowH, bootParams );\r
1034                         }\r
1035                 },\r
1036                 hide: function(){\r
1037                         if( visible === false) return;\r
1038                         document.body.style.overflow = '';\r
1039                         \r
1040                         jqConteiner.stop().css( {\r
1041                                 filter:         '',\r
1042                                 opacity:        ''\r
1043                         }).fadeOut( onFadeOutComplete );\r
1044                         this.visible = visible = false;\r
1045                         this.currentID = null;\r
1046                 },\r
1047                 visible: visible,\r
1048                 currentID: null,\r
1049                 onWindowResize: function( _windowW, _windowH ){\r
1050                         windowW = _windowW;\r
1051                         windowH = _windowH;                     \r
1052                         \r
1053                         if( currentOverlay === null ) return;\r
1054                         \r
1055                         jqConteiner.css({\r
1056                                 height:         _windowH,\r
1057                                 top:            document.documentElement.scrollTop || document.body.scrollTop\r
1058                         });\r
1059                         jqShadow.css( { height: _windowH });\r
1060                         // 先にeditorのcanvasを確定する。\r
1061                         setTimeout( asyncResize, 0);\r
1062                 }\r
1063         }\r
1064 })();\r
1065 \r
1066 /* ----------------------------------------\r
1067  * KEY\r
1068  * \r
1069  *  - EDITABLE_TEXT_CONTROL\r
1070  * \r
1071  *    .SHIFT_DOWN_EVENT:        'shiftDown',\r
1072  *    .SHIFT_UP_EVENT:          'shiftUp',\r
1073  *    .CTRL_DOWN_EVENT:         'ctrlDown',\r
1074  *    .CTRL_UP_EVENT:           'ctrlUp',\r
1075  *    .SPACE_DOWN_EVENT:        'spaceDown',\r
1076  *    .SPACE_UP_EVENT:          'spaceUp',\r
1077  *    .init:                            function,\r
1078  *    .addKeyDownEvent:         function,\r
1079  *    .keyEventDispatcher:      function,\r
1080  * \r
1081  * ショートカットキーの監視とテキスト入力(input, textarea)、チェックボックスを管理する。\r
1082  * キー入力はdocumentで受けて、テキスト編集中(input, textarea)はそちらにキーイベント流す。\r
1083  * \r
1084  */\r
1085 pettanr.key = ( function(){\r
1086         var log,\r
1087                 jqWindow,\r
1088                 keyOperationChatcher,\r
1089                 KEYEVENT_ARRAY = [],\r
1090                 shiftEnabled = false,\r
1091                 ctrlEnabled = false;\r
1092         \r
1093         function keyHit( e){\r
1094                 log.html( [ e.keyCode, e.shiftKey, e.ctrlKey, e.altKey, e.type].join( ','));\r
1095                 //keyOperationChatcher.val( '');\r
1096                 var cancel = false,\r
1097                         type = e.type,\r
1098                         key = e.keyCode,\r
1099                         overlayEnabled = pettanr.overlay.visible === true,\r
1100                         currentViewID = overlayEnabled === true ? pettanr.overlay.currentID : pettanr.view.currentID;\r
1101                 if( type === 'keypress') type = 'keydown';\r
1102                 if( pettanr.form.keyEventRellay( e ) === false ){\r
1103                         var shift = e.shiftKey,\r
1104                                 ctrl = e.ctrlKey,\r
1105                                 l = KEYEVENT_ARRAY.length,\r
1106                                 d;\r
1107                         if( key === 16 || e.shiftKey === true){\r
1108                                 shiftEnabled = type !== 'keyup';\r
1109                         }\r
1110                         if( key === 17 || e.ctrlKey === true){\r
1111                                 ctrlEnabled = type !== 'keyup';\r
1112                         }\r
1113 \r
1114                         for( var i=0; i<l; i++){\r
1115                                 d = KEYEVENT_ARRAY[ i];\r
1116                                 if( (\r
1117                                                 d.viewID === currentViewID ||\r
1118                                                         ( overlayEnabled === true && d.viewID === pettanr.view.OVERLAY)\r
1119                                         ) &&\r
1120                                         d.keyCode === key &&\r
1121                                         ( d.shift === undefined || d.shift === shift) &&\r
1122                                         ( d.ctrl === undefined || d.ctrl === ctrl)\r
1123                                 ){\r
1124                                         Type.isFunction( d[ type ]) === true && new asyncCallback( d[ type ], e );\r
1125                                         cancel = true;\r
1126                                 }\r
1127                         }\r
1128                 }\r
1129                 if( cancel === true || key === 18 || key === 9 || key === 27 || e.altKey === true){ // 13.enter 18.esc 9.tab 27.esc   || ( key === 13 && overlayEnabled === false)\r
1130                         e.preventDefault();\r
1131                 e.keyCode      = 0;\r
1132                 e.cancelBubble = true;\r
1133                 e.returnValue  = false;\r
1134                         return false;\r
1135                 }\r
1136         }\r
1137         function asyncCallback( func, e ){\r
1138                 window.setTimeout( _callback, 0 );\r
1139                 function _callback(){\r
1140                         func( e );\r
1141                         func = e = null;\r
1142                 }\r
1143         }       \r
1144         \r
1145         var keyPress = pettanr.ua.isIE === true && pettanr.ua.ieRenderingVersion < 8 ? ( function( e){\r
1146                         var key = e.keyCode;\r
1147                         if( key === 13 || key === 27){\r
1148                                 keyHit( e);\r
1149                                 return false;\r
1150                         }\r
1151         }) : null;\r
1152         \r
1153         return {\r
1154                 init: function(){\r
1155                         log = $( '#key-event-log').html( 'ready');\r
1156 \r
1157                         jqWindow = pettanr.jqWindow().focus();\r
1158                         keyOperationChatcher = pettanr.jqDocument()\r
1159                                 .keydown( keyHit )\r
1160                                 .keyup( keyHit )\r
1161                                 .mouseenter( function(){\r
1162                                         jqWindow.focus();\r
1163                                 });\r
1164                         keyPress !== null && keyOperationChatcher.keypress( keyPress );\r
1165 \r
1166                         delete pettanr.key.init;\r
1167                 },\r
1168                 addKeyDownEvent: function( _viewID, _keyCode, _shift, _ctrl, _callbackFunction){\r
1169                         KEYEVENT_ARRAY.push( {\r
1170                                 viewID:                 _viewID,\r
1171                                 keyCode:                _keyCode,\r
1172                                 shift:                  _shift,\r
1173                                 ctrl:                   _ctrl,\r
1174                                 keydown:                _callbackFunction\r
1175                         });\r
1176                 },\r
1177                 addKeyUpdateEvent: function( _viewID, _keyCode, _shift, _ctrl, _callbackFunction){\r
1178                         KEYEVENT_ARRAY.push( {\r
1179                                 viewID:         _viewID,\r
1180                                 keyCode:        _keyCode,\r
1181                                 shift:          _shift,\r
1182                                 ctrl:           _ctrl,\r
1183                                 keydown:        _callbackFunction,\r
1184                                 keyup:          _callbackFunction\r
1185                         });\r
1186                 },\r
1187                 addCursorEvent: function( _viewID, _shift, _ctrl, _callbackFunction){\r
1188                         \r
1189                 },\r
1190                 keyEventDispatcher: function(){\r
1191                         return keyOperationChatcher;\r
1192                 },\r
1193                 shiftEnabled: function(){\r
1194                         return shiftEnabled;\r
1195                 },\r
1196                 ctrlEnabled: function(){\r
1197                         return ctrlEnabled;\r
1198                 }\r
1199         }\r
1200 })();\r
1201 \r
1202 /*\r
1203  * pettanr.form\r
1204  * \r
1205  * keyEventRellay\r
1206  *  form -> overlay -> view\r
1207  * \r
1208  */\r
1209 pettanr.form = ( function(){\r
1210         var     FORM_GROUP_TABLE = {},\r
1211                 currentID = null,\r
1212                 currentItem = null,\r
1213                 CLASSNAME_COMBOBOX_OPTION = 'combobox-option',\r
1214                 windowW, windowH,\r
1215                 ELM_A_ORIGIN = ( function(){\r
1216                         var ret = document.createElement( 'a');\r
1217                         ret.href = '#';\r
1218                         return ret;\r
1219                 })(),\r
1220                 ELM_INPUT_TEXT = ( function(){\r
1221                         var ret = document.createElement( 'input');\r
1222                         ret.type = 'text';\r
1223                         return ret;\r
1224                 })(),\r
1225                 ELM_COMBOBOX = ( function(){\r
1226                         var ret = document.createElement( 'a'),\r
1227                                 elmToggle = document.createElement( 'span' ),\r
1228                                 elmValue = document.createElement( 'span' );\r
1229                         ret.href = '#';\r
1230                         ret.appendChild( elmToggle );\r
1231                         ret.appendChild( elmValue );\r
1232                         elmToggle.className = 'combobox-toggle';\r
1233                         elmValue.className = 'combobox-value';\r
1234                         \r
1235                         elmToggle.appendChild( document.createTextNode( '▼' ));\r
1236                         elmValue.appendChild( document.createTextNode( 'null' ));\r
1237                         return ret;\r
1238                 })();\r
1239                 \r
1240         var InputTextClass = function( WRAPPER_ELM, ON_UPDATE_FUNCTION, GROUP_ID, validater ){\r
1241                 validater = Type.isFunction( validater ) === true ? validater : null;\r
1242                 \r
1243                 var elmValue = pettanr.util.getElementsByClassName( WRAPPER_ELM, 'editable-value' )[ 0],\r
1244                         value,\r
1245                         instance = this,\r
1246                         focus = false,\r
1247                         visible = true,\r
1248                         enabled = true,\r
1249                         elmA = ELM_A_ORIGIN.cloneNode( true );\r
1250                 \r
1251                 if( elmValue === undefined ){\r
1252                         alert( 'error!');\r
1253                 }\r
1254                 value = elmValue.innerHTML;\r
1255                 elmValue.innerHTML = '';\r
1256                 elmValue.className += ' editable-text';\r
1257                 try {\r
1258                         elmA.innerHTML = value;\r
1259                 } catch(e){\r
1260                         alert( value )\r
1261                 }\r
1262                 \r
1263                 elmValue.appendChild( elmA );\r
1264                 WRAPPER_ELM.onclick = onClick;\r
1265                 \r
1266                 function onClick(){\r
1267                         focus = true;\r
1268                         start( instance );\r
1269                         elmA.style.display = 'none';\r
1270                         elmValue.appendChild( ELM_INPUT_TEXT );\r
1271                         ELM_INPUT_TEXT.value = value;\r
1272                         ELM_INPUT_TEXT.focus();\r
1273                         ELM_INPUT_TEXT.select();\r
1274                         return false;\r
1275                 }\r
1276                 \r
1277                 this.value = function( _value ){\r
1278                         if( _value !== undefined){\r
1279                                 elmA.innerHTML = _value;\r
1280                                 value = _value;\r
1281                                 \r
1282                                 if( focus === true){\r
1283                                         ELM_INPUT_TEXT.value = value;\r
1284                                 }\r
1285                         }\r
1286                         currentItem === instance && instance.blur();\r
1287                         return value;\r
1288                 }\r
1289                 this.focus = function(){\r
1290                         onClick();\r
1291                 }\r
1292                 this.blur = function( keep ){\r
1293                         var _newValue = ELM_INPUT_TEXT.value,\r
1294                                 _validated = validater !== null ? '' + validater( _newValue ) : _newValue;\r
1295                         _newValue = keep !== 27 ? _validated : value; // 27:ESC\r
1296 \r
1297                         elmValue.removeChild( ELM_INPUT_TEXT );\r
1298                         \r
1299                         elmA.innerHTML = _newValue;\r
1300                         elmA.style.display = 'block';\r
1301                         \r
1302                         ON_UPDATE_FUNCTION && _newValue !== value && ON_UPDATE_FUNCTION( _newValue, value );\r
1303                         \r
1304                         value = _newValue;\r
1305                         focus = false;\r
1306                         \r
1307                         currentItem = null;\r
1308                 }\r
1309                 this.enabled = function(){\r
1310                         return enabled;\r
1311                 }\r
1312                 this.visible = function( _visible ){\r
1313                         if( _visible === true){\r
1314                                 WRAPPER_ELM.style.display = '';\r
1315                                 visible = true;\r
1316                         } else\r
1317                         if( _visible === false){\r
1318                                 WRAPPER_ELM.style.display = 'none';\r
1319                                 visible = false;\r
1320                         }\r
1321                         return visible;\r
1322                 }\r
1323                 this.groupID = GROUP_ID;\r
1324         }\r
1325         \r
1326         var ButtonClass = function( WRAPPER_ELM, ON_CLICK_FUNCTION, GROUP_ID ){\r
1327                 var className = WRAPPER_ELM.className || '',\r
1328                         instance = this,\r
1329                         focus = false,\r
1330                         visible = true,\r
1331                         enabled = true;\r
1332                         \r
1333                 WRAPPER_ELM.onclick = onClick;\r
1334                 \r
1335                 function onClick(){\r
1336                         focus = true;\r
1337                         ON_CLICK_FUNCTION();\r
1338                         return false;\r
1339                 }\r
1340                 this.focus = function(){\r
1341                         focus = true;\r
1342                         WRAPPER_ELM.className = className + ' button-has-focus';\r
1343                         start( instance );\r
1344                 }\r
1345                 this.blur = function( keyCode ){\r
1346                         keyCode === 13 && ON_CLICK_FUNCTION();\r
1347                         WRAPPER_ELM.className = className;\r
1348                         focus = false;\r
1349                         finish( instance );\r
1350                 }\r
1351                 this.enabled = function(){\r
1352                         return enabled;\r
1353                 }\r
1354                 this.visible = function( _visible ){\r
1355                         if( _visible === true){\r
1356                                 WRAPPER_ELM.style.display = '';\r
1357                                 visible = true;\r
1358                         } else\r
1359                         if( _visible === false){\r
1360                                 WRAPPER_ELM.style.display = 'none';\r
1361                                 visible = false;\r
1362                         }\r
1363                         return visible;\r
1364                 }\r
1365                 this.groupID = GROUP_ID;\r
1366         }\r
1367 \r
1368         var FileInputClass = function( WRAPPER_ELM, ON_UPDATE_FUNCTION, GROUP_ID, validater, elmFileInput ){\r
1369                 validater = Type.isFunction( validater ) === true ? validater : null;\r
1370                 \r
1371                 var elmFilePath = pettanr.util.getElementsByClassName( WRAPPER_ELM, 'file-path')[ 0],\r
1372                         value,\r
1373                         index = GROUP_ID ? FORM_GROUP_TABLE[ GROUP_ID].length : -1,\r
1374                         instance,\r
1375                         focus = false,\r
1376                         visible = true,\r
1377                         enabled = true;\r
1378                 elmFileInput = WRAPPER_ELM.getElementsByTagName('input')[0] || elmFileInput || document.createElement( 'input');\r
1379                 elmFileInput.type = 'file';\r
1380                 elmFileInput.style.visivility = 'hidden';\r
1381 \r
1382                 WRAPPER_ELM.onclick = onClick;\r
1383                 elmFileInput.onchenge = onChange;\r
1384                 \r
1385                 function onClick( e){\r
1386                         focus = true;\r
1387                         start( instance );\r
1388                         elmFileInput.click();\r
1389                         return false;\r
1390                 }\r
1391                 \r
1392                 function onChange(){\r
1393                         elmFilePath.innerHTML = elmFileInput.value;\r
1394                 }\r
1395                 return {\r
1396                         init: function(){\r
1397                                 instance = this;\r
1398                                 delete this.init;\r
1399                         },\r
1400                         focus: function(){\r
1401                                 onClick();\r
1402                         },\r
1403                         blur: function( keep ){\r
1404                                 focus = false;\r
1405                         },\r
1406                         enabled: function(){\r
1407                                 return enabled;\r
1408                         },\r
1409                         visible: function( _visible){\r
1410                                 if( _visible === true){\r
1411                                         WRAPPER_ELM.style.display = '';\r
1412                                         visible = true;\r
1413                                 } else\r
1414                                 if( _visible === false){\r
1415                                         WRAPPER_ELM.style.display = 'none';\r
1416                                         visible = false;\r
1417                                 }\r
1418                                 return visible;\r
1419                         },\r
1420                         index : index,\r
1421                         groupID: GROUP_ID\r
1422                 }\r
1423         }\r
1424 \r
1425         var ComboBoxClass = function( WRAPPER_ELM, ON_UPDATE_FUNCTION, GROUP_ID ){\r
1426                 var elmBox = pettanr.util.getElementsByClassName( WRAPPER_ELM, 'combobox' )[ 0 ],\r
1427                         elmA = ELM_COMBOBOX.cloneNode( true ),\r
1428                         elmToggle = pettanr.util.getElementsByClassName( elmA, 'combobox-toggle' )[ 0 ],\r
1429                         elmValue = pettanr.util.getElementsByClassName( elmA, 'combobox-value' )[ 0 ].firstChild,\r
1430                         value, index = 0,\r
1431                         optionList = [],\r
1432                         instance = this,\r
1433                         oldBodyMouseupHandler,\r
1434                         focus = false,\r
1435                         visible = true,\r
1436                         enabled = true;\r
1437                         \r
1438                 elmBox.appendChild( elmA );\r
1439                 WRAPPER_ELM.onclick = onClick;\r
1440                 \r
1441                 function onClick(){\r
1442                         WRAPPER_ELM.onclick = null;\r
1443                         focus = true;\r
1444                         elmA.className = 'combobox-has-focus';\r
1445                         start( instance );\r
1446                         OptionControl.show( instance, optionList );\r
1447                         return false;\r
1448                 }\r
1449                 this.elm = elmBox;\r
1450                 this.focus = function(){\r
1451                         onClick();\r
1452                 }\r
1453                 this.blur = function( keyCode ){\r
1454                         OptionControl.hide( instance );\r
1455                         focus = false;\r
1456                         elmA.className = '';\r
1457                         finish( instance );\r
1458                         WRAPPER_ELM.onclick = onClick;\r
1459                 }\r
1460                 this.enabled = function(){\r
1461                         return enabled;\r
1462                 }\r
1463                 this.visible = function( _visible ){\r
1464                         if( _visible === true){\r
1465                                 WRAPPER_ELM.style.display = '';\r
1466                                 visible = true;\r
1467                         } else\r
1468                         if( _visible === false){\r
1469                                 WRAPPER_ELM.style.display = 'none';\r
1470                                 visible = false;\r
1471                         }\r
1472                         return visible;\r
1473                 }\r
1474                 this.value = function( _value ){\r
1475                         var i, j,\r
1476                                 l=optionList.length,\r
1477                                 _option;\r
1478                         if( Type.isString( _value ) === true && value !== _value ){\r
1479                                 for( i=0; i<l; ++i ){\r
1480                                         _option = optionList[ i ];\r
1481                                         if( _value === _option.value ){\r
1482                                                 value = _value;\r
1483                                                 index = i;\r
1484                                                 elmValue.data = _option.displayValue;\r
1485                                                 if( focus === true ){\r
1486                                                         OptionControl.update( instance, _value );\r
1487                                                 }\r
1488                                                 break;\r
1489                                         }\r
1490                                 }\r
1491                         }\r
1492                         return value;\r
1493                 }\r
1494                 this.selectIndex = function(){\r
1495                         return index;\r
1496                 }\r
1497                 this.createOption = function( displayValue, _value, isSelected ){\r
1498                         var exist = false,\r
1499                                 option = null, _option,\r
1500                                 _index;\r
1501                         _value = _value || displayValue;\r
1502                         for( var i = 0, l = optionList.length; i < l; ++i ){\r
1503                                 if( _value === optionList[ i ].value ){\r
1504                                         option = optionList[ i ];\r
1505                                         _index = i;\r
1506                                         break;\r
1507                                 }\r
1508                         }\r
1509                         if( option === null ){\r
1510                                 option = new OptionClass( instance, displayValue, _value );\r
1511                                 _index = optionList.length;\r
1512                                 optionList.push( option );\r
1513                         }\r
1514                         if( isSelected === true ){\r
1515                                 elmValue.data = option.displayValue;\r
1516                                 value = _value;\r
1517                                 index = _index;\r
1518                                 for( i = 0, l = optionList.length; i < l; ++i ){\r
1519                                         _option = optionList[ i ];\r
1520                                         _option.current( _option.value === _value );\r
1521                                 }\r
1522                         }\r
1523                         return option;\r
1524                 }\r
1525                 this.groupID = GROUP_ID;\r
1526         }\r
1527         \r
1528         var OptionControl = ( function(){\r
1529                 var ELM_OPTION_WRAPPER = ( function(){\r
1530                                 var ret = document.createElement( 'ul' );\r
1531                                 ret.className = 'option-container';\r
1532                                 return ret;\r
1533                         })();\r
1534                 var currentCombobox = null,\r
1535                         optionList,\r
1536                         elm,\r
1537                         value,\r
1538                         currentOption,\r
1539                         currentIndex;\r
1540                 \r
1541                 function updateCurrrentOption( _value, _updateCombobox ){\r
1542                         var _option;\r
1543                         for( var i=0, l=optionList.length; i<l; ++i ){\r
1544                                 _option = optionList[ i ]\r
1545                                 if( _value === _option.value ){\r
1546                                         currentOption && currentOption.current( false );\r
1547                                         _option.current( true );\r
1548                                         currentOption = _option;\r
1549                                         currentIndex = i;\r
1550                                         _updateCombobox === true && currentCombobox.value( _value );\r
1551                                 }\r
1552                         }\r
1553                 }\r
1554                 function bodyMouseupHandler(){\r
1555                         currentCombobox.blur();\r
1556                         OptionControl.hide( currentCombobox );\r
1557                 }\r
1558                 function updateWrapperPosition(){\r
1559                         var position = pettanr.util.getAbsolutePosition( elm );\r
1560                         \r
1561                         ELM_OPTION_WRAPPER.style.cssText = [\r
1562                                         'width:', elm.offsetWidth - 2, 'px;',\r
1563                                         'left:', position.x, 'px;',\r
1564                                         'top:', position.y + elm.offsetHeight, 'px;'\r
1565                                 ].join('');                     \r
1566                 }\r
1567                 return {\r
1568                         show: function( _combobox, _optionList ){\r
1569                                 if( currentItem !== _combobox || currentCombobox === _combobox ) return;\r
1570                                 currentCombobox && currentCombobox.blur();\r
1571                                 \r
1572                                 currentCombobox = _combobox;\r
1573                                 optionList = _optionList;\r
1574                                 elm = _combobox.elm;\r
1575                                 \r
1576                                 updateCurrrentOption( _combobox.value(), false );\r
1577                                 \r
1578                                 for( var i=0, l=optionList.length; i<l; ++i ){\r
1579                                         ELM_OPTION_WRAPPER.appendChild( optionList[ i ].elm );\r
1580                                 }\r
1581                                 \r
1582                                 document.body.appendChild( ELM_OPTION_WRAPPER );\r
1583                                 oldBodyMouseupHandler = document.body.onmouseup;\r
1584                                 document.body.onmouseup = bodyMouseupHandler;\r
1585                                 \r
1586                                 updateWrapperPosition();\r
1587                         },\r
1588                         hide: function( _combobox ){\r
1589                                 if( currentCombobox !== _combobox ) return;\r
1590 \r
1591                                 ELM_OPTION_WRAPPER.parentNode && ELM_OPTION_WRAPPER.parentNode.removeChild( ELM_OPTION_WRAPPER );\r
1592                                 while( ELM_OPTION_WRAPPER.firstChild ){\r
1593                                         ELM_OPTION_WRAPPER.removeChild( ELM_OPTION_WRAPPER.firstChild );\r
1594                                 }\r
1595                                 currentCombobox = null;\r
1596                                 currentOption = null;\r
1597                                 currentIndex = 0;\r
1598                                 \r
1599                                 document.body.onmouseup = oldBodyMouseupHandler;\r
1600                         },\r
1601                         change: function( down ){\r
1602                                 var l = optionList.length,\r
1603                                         way = down === true ? 1 : -1;\r
1604                                         i = currentIndex + way\r
1605                                 if( currentCombobox === false || l < 2 ) return;\r
1606                                 i = i < 0 ?\r
1607                                                 l - 1 :\r
1608                                                 i < l ? i : 0;\r
1609                                 updateCurrrentOption( optionList[ i ].value, false );\r
1610                         },\r
1611                         update: function( _combobox, _value ){\r
1612                                 if( currentCombobox !== _combobox || currentItem !== _combobox ) return;\r
1613                                 if( currentOption.value === _value ) return;\r
1614                                 updateCurrrentOption( _value, true );\r
1615                         },\r
1616                         decide: function(){\r
1617                                 currentCombobox.value( currentOption.value );\r
1618                                 currentCombobox.blur();\r
1619                                 OptionControl.hide( currentCombobox );\r
1620                         },\r
1621                         onWindowResize: function( _w, _h ){\r
1622                                 setTimeout( updateWrapperPosition, 0 );\r
1623                         }\r
1624                 }\r
1625         })();\r
1626         \r
1627                 var OptionClass = function( combobox, displayValue, value ){\r
1628                         var elm = document.createElement( 'li' ),\r
1629                                 a = document.createElement( 'a' ),\r
1630                                 isCurrent = undefined;\r
1631                         elm.appendChild( a );\r
1632                         a.appendChild( document.createTextNode( displayValue ));\r
1633                         elm.className = CLASSNAME_COMBOBOX_OPTION;\r
1634                         a.href = '#';\r
1635                         \r
1636                         a.onmousedown = onClick; // onclick では 選択ボックス 隠すように body に設定した onmouseup が先に動いてしまう!\r
1637                         function onClick(){\r
1638                                 OptionControl.update( combobox, value );\r
1639                                 OptionControl.hide( combobox );\r
1640                                 combobox.blur();\r
1641                                 return false;\r
1642                         }\r
1643                         this.elm = elm;\r
1644                         this.displayValue = displayValue;\r
1645                         this.value = value = value || displayValue;\r
1646                         this.current = function( _isCurrent ){\r
1647                                 if( Type.isBoolean( _isCurrent ) === true && isCurrent !== _isCurrent ){\r
1648                                         elm.className = CLASSNAME_COMBOBOX_OPTION + ( _isCurrent === true ? ' current-option' : '' );\r
1649                                         isCurrent = _isCurrent;\r
1650                                 }\r
1651                                 return !!isCurrent;\r
1652                         }\r
1653                 }\r
1654         \r
1655 \r
1656         function start( _currentItem ){\r
1657                 currentItem !== _currentItem && currentItem && currentItem.blur();\r
1658                 currentItem = _currentItem;\r
1659         }\r
1660         function finish( _currentItem ){\r
1661                 currentItem = currentItem === _currentItem ? null : currentItem;\r
1662         }\r
1663 \r
1664         function tabShift( _groupID, _index, _way ){\r
1665                 // currentApplication の確認\r
1666                 //if( _applicationID === ( pettanr.overlay.visible === true ? pettanr.overlay.currentID : pettanr.view.currentID )){\r
1667                 //      return;\r
1668                 //};\r
1669                 var GROUP_ARRAY = FORM_GROUP_TABLE[ _groupID ] || [],\r
1670                         l = GROUP_ARRAY.length,\r
1671                         i = _index + _way,\r
1672                         _item;\r
1673                 if( l < 2 ) return;\r
1674                 while( i !== _index ){\r
1675                         i = i < 0 ?\r
1676                                 l - 1 :\r
1677                                 i < l ? i : 0; // 0 < i < l\r
1678                         _item = GROUP_ARRAY[ i ];\r
1679                         if( _item.enabled() === true && _item.visible() === true ){\r
1680                                 setTimeout( _item.focus, 0 );\r
1681                                 return;\r
1682                         }\r
1683                         i += _way;\r
1684                 }\r
1685         }\r
1686 \r
1687         return {\r
1688                 init: function(){},\r
1689                 focus: function(){\r
1690                         return currentItem !== null; \r
1691                 },\r
1692                 keyEventRellay: function( e ){\r
1693                         if( e.type === 'keyup' ) return false;\r
1694                         if( currentItem === null ) return false;\r
1695                         \r
1696                         var keyCode = e.keyCode;\r
1697                         var _groupID = currentItem.groupID,\r
1698                                 _index = pettanr.util.getIndex( FORM_GROUP_TABLE[ _groupID ], currentItem );\r
1699                         if( currentItem instanceof ComboBoxClass ) {\r
1700                                 if( 37 <= keyCode && keyCode <= 40 ){ // ↑38 ←37 →39 ↓40\r
1701                                         OptionControl.change( keyCode === 40 );\r
1702                                         return true;\r
1703                                 } else\r
1704                                 keyCode === 13 && OptionControl.decide();\r
1705                         }\r
1706                         if( keyCode === 13 || keyCode === 27 || keyCode === 9 || keyCode === 18 || e.altKey === true ){ // 13.return 27.esc 9.tab 18.alt\r
1707                                 currentItem && currentItem.blur( keyCode );\r
1708                                 keyCode === 9 && _groupID && tabShift( _groupID, _index, e.shiftKey === true ? -1 : 1 );\r
1709                                 keyCode === 13 && _groupID && tabShift( _groupID, _index, 1 );\r
1710                         }\r
1711                         return true;\r
1712                 },\r
1713                 createUIGroup: function( _applicationReferance ){\r
1714                         \r
1715                 },\r
1716                 createInputText: function( _elm, _onUpdate, _groupID, _validater ){\r
1717                         if( typeof _groupID === 'string' && !FORM_GROUP_TABLE[ _groupID]){\r
1718                                 FORM_GROUP_TABLE[ _groupID] = [];\r
1719                         }\r
1720                         var ret = new InputTextClass( _elm, _onUpdate, _groupID, _validater );\r
1721                         _groupID && FORM_GROUP_TABLE[ _groupID ].push( ret );\r
1722                         return ret;\r
1723                 },\r
1724                 createButton: function( _elm, _onClick, _groupID ){\r
1725                         if( typeof _groupID === 'string' && !FORM_GROUP_TABLE[ _groupID]){\r
1726                                 FORM_GROUP_TABLE[ _groupID ] = [];\r
1727                         }\r
1728                         var ret = new ButtonClass( _elm, _onClick, _groupID );\r
1729                         _groupID && FORM_GROUP_TABLE[ _groupID ].push( ret );\r
1730                         return ret;\r
1731                 },\r
1732                 createFileInput: function( _elm, _onUpdate, _groupID, _validater, _elmFileInput ){\r
1733                         if( typeof _groupID === 'string' && !FORM_GROUP_TABLE[ _groupID]){\r
1734                                 FORM_GROUP_TABLE[ _groupID] = [];\r
1735                         }\r
1736                         var ret = FileInputClass( _elm, _onUpdate, _groupID, _validater, _elmFileInput );\r
1737                         _groupID && FORM_GROUP_TABLE[ _groupID].push( ret);\r
1738                         return ret;\r
1739                 },\r
1740                 createCombobox: function( _elm, _onUpdate, _groupID, _optionList ){\r
1741                         if( typeof _groupID === 'string' && !FORM_GROUP_TABLE[ _groupID]){\r
1742                                 FORM_GROUP_TABLE[ _groupID ] = [];\r
1743                         }\r
1744                         var ret = new ComboBoxClass( _elm, _onUpdate, _groupID );\r
1745                         _groupID && FORM_GROUP_TABLE[ _groupID ].push( ret );\r
1746                         return ret;\r
1747                 },\r
1748                 createCheckBox: function(){\r
1749                         \r
1750                 },\r
1751                 createRadio: function(){\r
1752                         \r
1753                 },\r
1754                 createSlider: function(){\r
1755                         \r
1756                 },\r
1757                 onWindowResize: function( w, h ){\r
1758                         windowW = w;\r
1759                         windowH = h;\r
1760                         currentItem instanceof ComboBoxClass && OptionControl.onWindowResize( w, h );\r
1761                 }\r
1762         }\r
1763 })();\r
1764 \r
1765 \r
1766 /* ----------------------------------------\r
1767  * Vector Support\r
1768  * \r
1769  *              __________\r
1770  *             /          \\r
1771  *            /            \\r
1772  *            |,startX,Y    |\r
1773  * tailX,Y - <              |\r
1774  *            |'endX,Y      |\r
1775  *            \            /\r
1776  *                 \__________/\r
1777  * \r
1778  * SVG\r
1779  * -----------------------\r
1780  * ie9, other modern browser\r
1781  * \r
1782  * XML\r
1783  * -----------------------\r
1784  * ie5.5-8\r
1785  * \r
1786  * 内部の角度計算は radian で統一したい。\r
1787  * 当初 vectorEnabled = true で一度書いてみる。\r
1788  * 駄目なら、代替のイメージのsrcの用意もここで担当。\r
1789  * 閲覧と編集両方で使う。\r
1790  * \r
1791  */\r
1792 pettanr.balloon = ( function() {\r
1793         var MIN_BALLOON_WIDTH  = 30,\r
1794                 MIN_BALLOON_HEIGHT = 30,\r
1795                 NUM_BALLOON_IMAGE  = 24,\r
1796                 TAIL_WIDTH         = 6,\r
1797                 TAIL_HEIGHT        = 10,\r
1798                 STROKE_WIDTH       = 1.2,\r
1799                 PADDING_TOP        = TAIL_HEIGHT,\r
1800                 PADDING_LEFT       = TAIL_HEIGHT,\r
1801                 IS_VML             = pettanr.ua.isIE === true && pettanr.ua.ieVersion < 9,\r
1802                 ELM_BALLOON_ORIGIN = ( function(){\r
1803                         var ret;\r
1804                         try {\r
1805                                 if( IS_VML === true){\r
1806                                         ret = document.createElement( 'DIV');\r
1807                                         var shape = document.createElement( 'v:shape');\r
1808                                         shape.coordorigin = "0,0";\r
1809                                         shape.strokecolor = "black";\r
1810                                         shape.strokeweight = STROKE_WIDTH;\r
1811                                         shape.fillcolor = "white";\r
1812                                         ret.appendChild( shape);\r
1813                                 } else {\r
1814                                         var kSVGNS = 'http://www.w3.org/2000/svg';\r
1815                                         ret = document.createElementNS( kSVGNS, 'svg');\r
1816                                         var path = document.createElementNS( kSVGNS, 'path');\r
1817                                         path.setAttribute( 'fill', "white");\r
1818                                         path.setAttribute( 'stroke', "black");\r
1819                                         path.setAttribute( 'strokeWidth', STROKE_WIDTH);\r
1820                                         ret.appendChild( path);\r
1821                                 }\r
1822                                 return ret;     \r
1823                         } catch( e){\r
1824                                 return null;\r
1825                         }\r
1826                 })(),\r
1827                 vectorEnabled = ELM_BALLOON_ORIGIN !== null &&\r
1828                                                 pettanr.URL_PARAMS.vector !== false &&\r
1829                                                 !( IS_VML === true && pettanr.ua.VML === false );\r
1830 \r
1831         var cos        = Math.cos,\r
1832                 sin        = Math.sin,\r
1833                 abs        = function(v){ return v >= 0 ? v : -1; },\r
1834                 pow        = Math.pow,\r
1835                 round      = Math.round,\r
1836                 floor      = Math.floor,\r
1837                 TARGET     = TAIL_WIDTH * TAIL_WIDTH,\r
1838                 isFinit    = Type.isFinite,\r
1839                 ACCURACY   = 1, // 有効少数桁      \r
1840                 cround     = function ( v, r ){\r
1841                                                 r = r || ACCURACY;\r
1842                                                 return round( v * pow( 10.0, r )) / pow( 10.0, r );\r
1843                                         },\r
1844                 DEG_TO_RAD = Math.PI / 180;\r
1845 \r
1846         var XBROWSER_BALLOON_CLASS = function( w, h, a ){\r
1847                 var balloonElm = vectorEnabled === true ? ELM_BALLOON_ORIGIN.cloneNode( true ) : document.createElement( 'img' ), // pettanr.imageに変更\r
1848                         path = balloonElm.getElementsByTagName( 'path' )[ 0 ],\r
1849                         shape = balloonElm.getElementsByTagName( 'shape' )[ 0 ],\r
1850                         instance = this,\r
1851                         l = ',';\r
1852                 \r
1853                 function draw( _a ){\r
1854                         var rx      = w / 2,\r
1855                                 ry      = h / 2,\r
1856                                 tailRad = _a * DEG_TO_RAD,\r
1857                                 tailX   = rx + ( rx + TAIL_HEIGHT ) * sin( tailRad ),\r
1858                                 tailY   = ry - ( ry + TAIL_HEIGHT ) * cos( tailRad ),\r
1859                                 startX, startY, endX, endY;\r
1860                 /*\r
1861                  * tailの太さをTAIL_WIDTHに一致させるため、角度を絞りつつ計算\r
1862                  */\r
1863                         var startRad, endRad,\r
1864                                 _startX, _startY, _endX, _endY,\r
1865                                 tailDeg = 0, d;\r
1866                         \r
1867                         for( var i = 45; i > 0.01; i /= 2){\r
1868                                 d = ( tailDeg + i ) /2;\r
1869                                 startRad = ( _a + d ) * DEG_TO_RAD;\r
1870                                 endRad   = ( _a - d ) * DEG_TO_RAD;\r
1871                                 \r
1872                                 _startX  = rx + sin( startRad ) * rx;\r
1873                                 _startY  = ry - cos( startRad ) * ry;\r
1874                                 _endX    = rx + sin( endRad ) * rx;\r
1875                                 _endY    = ry - cos( endRad ) * ry;     //円弧上のY位置=円中心Y+sin(角度×PI÷180)×円半径\r
1876                                         \r
1877                                 if( pow( ( _startX - _endX ), 2 ) + pow( ( _startY - _endY ), 2 ) < TARGET ){\r
1878                                         tailDeg += i;\r
1879                                         startX  = _startX;\r
1880                                         startY  = _startY;\r
1881                                         endX    = _endX;\r
1882                                         endY    = _endY;\r
1883                                 }\r
1884                         }\r
1885 \r
1886                 /*\r
1887                  * \r
1888                  */                     \r
1889                         if( IS_VML === true ){\r
1890                                 var _tailX = tailX *10,\r
1891                                         _tailY = tailY *10,\r
1892                                         __w = w *10,\r
1893                                         __h = h *10;\r
1894                                 \r
1895                                 shape.style.width = w + 'px';\r
1896                                 shape.style.height = h + 'px';\r
1897                                 shape.coordsize = [ __w, __h ].join( l );\r
1898                                 shape.path = [\r
1899                                         ' ar ', 0, l, 0, l, __w, l, __h, l,\r
1900                                         round( endX * 10 ), l, round( endY * 10 ), l,\r
1901                                         round( startX * 10 ), l, round( startY * 10 ),\r
1902                                         ' l ', round( _tailX ), l, round( _tailY ),\r
1903                                         ' x e'\r
1904                                 ].join( '');\r
1905 \r
1906                                 balloonElm.style.marginTop =  _tailY < 0 ? floor( ( 60 + _tailY) / 10 ) : 10;\r
1907                                 balloonElm.style.marginLeft = _tailX < 0 ? floor( ( 60 + _tailX) / 10 ) : 10;\r
1908                         } else {\r
1909                                 balloonElm.setAttribute( 'width', w + PADDING_LEFT *2 );\r
1910                                 balloonElm.setAttribute( 'height', h + PADDING_TOP *2 );\r
1911                                 path.setAttribute( 'd', [\r
1912                                         'M', cround( tailX + PADDING_LEFT ), l, cround( tailY + PADDING_TOP ),\r
1913                                         'L', cround( startX + PADDING_LEFT ), l, cround( startY + PADDING_TOP ),\r
1914                                         'A', rx, l, ry,\r
1915                                         '0 1 1',                        // flag\r
1916                                         cround( endX + PADDING_LEFT ), l, cround( endY + PADDING_TOP ),\r
1917                                         'z'\r
1918                                 ].join( ' '));\r
1919                         }\r
1920                 }\r
1921                 \r
1922                 this.elm = balloonElm;\r
1923                 this.resize = function ( _a, _w, _h ){\r
1924                         w  = isFinit( _w ) === true ? _w - PADDING_TOP * 2 : w;\r
1925                         h  = isFinit( _h ) === true ? _h - PADDING_LEFT * 2 : h;\r
1926                         // ie6 でリサイズが反応しない対策\r
1927                         if( vectorEnabled === false && pettanr.ua.isIE === true && pettanr.ua.ieVersion < 7 ){\r
1928                                 var parent = balloonElm.parentNode;\r
1929                                 parent.removeChild( balloonElm );\r
1930                                 parent.insertBefore( balloonElm, parent.firstChild );\r
1931                         }\r
1932                         instance.angle( _a );\r
1933                 };\r
1934                 this.angle = function( _a ){\r
1935                         if( isFinit( _a ) === true ){\r
1936                                 a = _a;\r
1937                                 if( vectorEnabled === false ){\r
1938                                         balloonElm.src = pettanr.balloon.getBalloonUrl( w, h, _a );\r
1939                                 } else {\r
1940                                         draw( _a );\r
1941                                 }\r
1942                         }\r
1943                         return a;\r
1944                 }\r
1945                 this.type = function( _type ){\r
1946                         //draw( _a);\r
1947                 }\r
1948                 this.destroy = function(){\r
1949                         delete instance.destroy;\r
1950                         balloonElm.parentNode && balloonElm.parentNode.removeChild( balloonElm );\r
1951                         balloonElm = path = shape = instance = null;\r
1952                 }\r
1953                 \r
1954                 instance.resize( a, w, h );\r
1955         };\r
1956         \r
1957         IS_VML === false && vectorEnabled === true && ( function(){\r
1958                 var detect = new XBROWSER_BALLOON_CLASS( 100, 100, 0 ),\r
1959                         size = pettanr.util.getElementSize( detect.elm );\r
1960                 vectorEnabled = size.width !== 0 && size.height !== 0;\r
1961                 detect.destroy();\r
1962                 detect = size = null;\r
1963         })();\r
1964 \r
1965         return {\r
1966             createBalloon: function( _w, _h, _a ){\r
1967                 return new XBROWSER_BALLOON_CLASS( _w, _h, _a );\r
1968             },\r
1969             isBalloonInstance: function( _ballon ){\r
1970                 \r
1971             },\r
1972             getBalloonUrl: function( _w, _h, _a ){\r
1973                         var d = 360 / NUM_BALLOON_IMAGE;\r
1974                         _a = _a + d / 2;\r
1975                         return [\r
1976                                 pettanr.CONST.SYSTEM_PICTURE_PATH, '_w',\r
1977                                 _a < 360 - d / 2 ? floor( _a / d ) : 0,\r
1978                                 _w <= 400 || _h <= 400 ? '_b1' : '',\r
1979                                 '.gif' ].join( '' );\r
1980             },\r
1981                 TYPE_NONE:                              0,\r
1982                 TYPE_SPEACH_BALLOON:    1,\r
1983                 TYPE_THINKING:                  2,\r
1984                 TYPE_BOM:                               3,\r
1985                 TYPE_BLACK_BOX:                 4,\r
1986                 TYPE_BLUE_BOX:                  5\r
1987         }\r
1988 })();\r
1989 \r
1990 /* ----------------------------------------\r
1991  *  pettanr.image\r
1992  *  \r
1993  *   xBackendな画像反転、画像描画機能。\r
1994  *   \r
1995  *   画像の反転\r
1996  *     - css3\r
1997  *     - ActiveX (ie)\r
1998  *     - VML (ie)\r
1999  *     - canvas ??\r
2000  *     - flash(lite)\r
2001  *     - silverlight\r
2002  *     - pettan server\r
2003  *   \r
2004  *   png画像の表示(アルファpngをサポートしないie6以下のため)\r
2005  *     - ActiveX\r
2006  *     - VML\r
2007  *     - flash(lite)\r
2008  *     - silverlight\r
2009  *     \r
2010  *     -moz-transform:scale( -1, -1);\r
2011  */\r
2012 pettanr.image = ( function(){\r
2013         \r
2014         var FetchImageControl = ( function(){\r
2015                 var TASK_LIST = [];\r
2016 \r
2017                 /* \r
2018                  * FetchClass original is\r
2019                  * \r
2020                  * LICENSE: MIT?\r
2021                  *  URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631\r
2022                  *  AUTHOR: uupaa.js@gmail.com\r
2023                  * \r
2024                  */\r
2025 \r
2026                 var FetchClass = function( abspath, onLoadCallback, onErrorCallback, delay, timeout ){\r
2027                         var img,\r
2028                                 size,\r
2029                                 tick = 0,\r
2030                                 timer = null,\r
2031                                 finish = false;\r
2032                                 /*\r
2033                         if( pettanr.ua.isIE === false && pettanr.ua.ieVersion < 8 ){\r
2034                                 var images = document.images,\r
2035                                         i=0, l= images.length;\r
2036                                 for( i=0; i<l; ++i ){\r
2037                                         img = images[ i ];\r
2038                                         if( img.src === abspath && img.complete ){\r
2039                                                 finish = true;\r
2040                                                 size = pettanr.util.getImageSize( img );\r
2041                                                 timer = window.setTimeout( asyncCallback, 0 );\r
2042                                                 break;\r
2043                                         }\r
2044                                 }\r
2045                                 images = null;\r
2046                         }*/\r
2047                         //if( finish === false ){\r
2048                                 img = document.createElement( 'img' ); //var img = new Image(); ではieでimgのsizeが取れない、、、removeChildも失敗し、imgSizeGetterにimgが残る\r
2049                                 img.onabort = img.onerror = onError;\r
2050                                 img.onload = onLoad;\r
2051                                 img.src = abspath;\r
2052                                 finish === false && timeout && detect();\r
2053                         //}\r
2054                         \r
2055                         function onError(){\r
2056                                 if( finish === true ) return;\r
2057                                 finish = true;\r
2058                                 timer = window.setTimeout( asyncCallback, 10 );\r
2059                         }                       \r
2060                         function onLoad(){\r
2061                                 // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、\r
2062                                 // if( timer ) return; // これがあると safari3.2 で駄目、、、\r
2063                                 finish = true;\r
2064                                 timer !== null && window.clearTimeout( timer );\r
2065                                 if( window.opera && !img.complete ){\r
2066                                         timer = window.setTimeout( asyncCallback, 10 );\r
2067                                         return;\r
2068                                 }\r
2069                                 size = pettanr.util.getImageSize( img );\r
2070                                 timer = window.setTimeout( asyncCallback, 10 );\r
2071                         }\r
2072                         function detect(){\r
2073                                 if( finish === true ) return;\r
2074                                 if( img.complete ){\r
2075                                         finish = true;\r
2076                                         if( img.width ) return;\r
2077                                         timer = window.setTimeout( asyncCallback, 10 );\r
2078                                         return;\r
2079                                 }\r
2080                                 if( ( tick += delay ) > timeout ){\r
2081                                         finish = true;\r
2082                                         timer = window.setTimeout( asyncCallback, 10 );\r
2083                                         return;\r
2084                                 }\r
2085                                 timer = window.setTimeout( detect, delay );\r
2086                         }\r
2087                         \r
2088                         function asyncCallback(){\r
2089                                 size ? onLoadCallback( abspath, size.width, size.height ) : onErrorCallback( abspath );\r
2090                                 destroy();\r
2091                         }\r
2092                         function destroy(){\r
2093                                 finish  = true;\r
2094                                 img.src = img.onload = img.onabort = img.onerror = '';\r
2095                                 img     = void 0;\r
2096                                 size    = onLoadCallback = onErrorCallback = timer = null;\r
2097                         }\r
2098                         this.stop = function(){\r
2099                                 timer !== null && window.clearTimeout( timer );\r
2100                                 destroy();                      \r
2101                         }\r
2102                 }\r
2103                 \r
2104                 return {\r
2105                         load: function( URLorELM, onLoad, onError, delay, opt_timeout ){\r
2106                                 var src, fetch;\r
2107                                 if( Type.isString( URLorELM ) === true ){\r
2108                                         src = URLorELM;\r
2109                                 } else\r
2110                                 if( Type.isHTMLElement( URLorELM ) === true && URLorELM.tagName.toLowerCase() === 'img' ){\r
2111                                         src = URLorELM.src;\r
2112                                 } else {\r
2113                                         return;\r
2114                                 }\r
2115                                 \r
2116                                 fetch = new FetchClass(\r
2117                                         pettanr.util.getAbsolutePath( src ),\r
2118                                         onLoad, onError,\r
2119                                         Type.isFinite( delay ) === true ? delay : 250,\r
2120                                         Type.isFinite( opt_timeout ) === true ? opt_timeout : undefined\r
2121                                 );\r
2122                                 // TASK_LIST.push( fetch );\r
2123                                 \r
2124                                 return fetch;\r
2125                         }\r
2126                 }\r
2127         })();\r
2128         \r
2129         var REG_PNG           = /\.png?/i,\r
2130                 IS_CSS3           = 0,\r
2131                 IS_VML            = 1,\r
2132                 IS_ACTIVEX        = 2,\r
2133                 IS_CANVAS         = 3,\r
2134                 IS_FLASH          = 4,\r
2135                 IS_SILVERLIGHT    = 5,\r
2136                 IS_SERVER         = 6,\r
2137                 IS_ACTIVEX_SERVER = 7,\r
2138                 BACKEND = ( function(){\r
2139                         if( pettanr.DEBUG === true && pettanr.URL_PARAMS.rimg ){\r
2140                                 var rimg = pettanr.URL_PARAMS.rimg.toLowerCase();\r
2141                                 if( rimg === 'css3' ) return IS_CSS3;\r
2142                                 if( rimg === 'activex' ) return IS_ACTIVEX;\r
2143                                 if( rimg === 'vml' ) return IS_VML;\r
2144                         }\r
2145                         if( pettanr.ua.isIE === false || pettanr.ua.ieVersion >= 9 ) return IS_CSS3; // 不十分!\r
2146                         if( pettanr.ua.VML === true ) return IS_VML;\r
2147                         if( pettanr.ua.ACTIVEX === true ) return IS_ACTIVEX;\r
2148                         if( pettanr.FLASH === true ) return IS_FLASH;\r
2149                         if( pettanr.SILVERLIGHT === true ) return IS_SILVERLIGHT;\r
2150                         return IS_SERVER;\r
2151                 })(),\r
2152                 BACKEND_WHEN_PNG = ( function(){\r
2153                         if( pettanr.ua.isIE === false || pettanr.ua.ieVersion > 6 ) return BACKEND;\r
2154                         if( pettanr.ua.VML === true ) return IS_VML;\r
2155                         if( pettanr.FLASH === true ) return IS_FLASH;\r
2156                         if( pettanr.SILVERLIGHT === true ) return IS_SILVERLIGHT;\r
2157                         if( pettanr.ua.ACTIVEX === true ) return IS_ACTIVEX_SERVER;\r
2158                         return IS_SERVER;\r
2159                 })(),\r
2160                 CLASS_NAME         = 'reversible-image-container',\r
2161                 CLASS_NAME_LOADING = CLASS_NAME + ' loading',\r
2162                 CLASS_NAME_ERROR   = CLASS_NAME +' error',\r
2163                 RETRY_DELAY        = 5000,\r
2164                 NUM_RETRY          = 3,\r
2165                 ReversibleImageClass,\r
2166                 ReversibleImageClassWithPingfix;\r
2167         \r
2168         var css3Image = function( url, w, h, onLoadCallback ){\r
2169                 var elmWrap    = document.createElement( 'div' ),\r
2170                         elmImg     = null,\r
2171                         retryTimer = null,\r
2172                         fetch      = FetchImageControl.load( url, onLoad, onError, 100, 10000 ),\r
2173                         instance   = this;\r
2174                 elmWrap.className = CLASS_NAME_LOADING;\r
2175 \r
2176                 function onLoad( _url, _actualW, _actualH ){\r
2177                         if( elmWrap === null ) return;\r
2178                         elmImg = new Image; // new Image でないと ie6,7 でクラッシュするかも、、、?\r
2179                         /*\r
2180                          * createElement 直後に append しないと、ie(ActiveX)で img が正しく表示されない.\r
2181                          */\r
2182                         elmWrap.appendChild( elmImg );\r
2183                         elmImg.setAttribute( 'src', url );\r
2184                         elmWrap.className = CLASS_NAME;\r
2185                         onLoadCallback && onLoadCallback( _url, _actualW, _actualH );\r
2186                         onLoadCallback = fetch = null;\r
2187                         instance.resize( w, h );\r
2188                 }\r
2189                 function onError( _url ){\r
2190                         if( elmWrap === null ) return;\r
2191                         elmWrap.className = CLASS_NAME_ERROR;\r
2192                         retryTimer = window.setTimeout( retry, RETRY_DELAY );\r
2193                         fetch = null;\r
2194                 }\r
2195                 function retry(){\r
2196                         elmWrap.className = CLASS_NAME_LOADING;\r
2197                         fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 );\r
2198                 }\r
2199 \r
2200                 this.elm = elmWrap;\r
2201                 this.resize = function( _w, _h ){\r
2202                         w = _w !== undefined ? _w : w;\r
2203                         h = _h !== undefined ? _h : h;\r
2204                         if( elmImg === null ) return;\r
2205                         elmImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : '';\r
2206                 }\r
2207                 this.destroy = function(){\r
2208                         delete instance.destroy;\r
2209                         \r
2210                         elmImg !== null && elmWrap.removeChild( elmImg );\r
2211                         retryTimer !== null && window.clearTimeout( retryTimer );\r
2212                         fetch !== null && fetch.stop();\r
2213                         elmWrap = elmImg = onLoadCallback = retryTimer = fetch = instance = null;\r
2214                 }\r
2215         }\r
2216                 \r
2217         var activexImage = css3Image;\r
2218         \r
2219         var vmlImage = function( url, w, h, onLoadCallback ){\r
2220                 var elmWrap = document.createElement( 'div' ),\r
2221                         vmlImg = null,\r
2222                         retryTimer = null,\r
2223                         fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ),\r
2224                         instance = this;\r
2225                 elmWrap.className = CLASS_NAME_LOADING;\r
2226                 function onLoad( _url, _actualW, _actualH ){\r
2227                         if( elmWrap === null ) return;\r
2228                         elmWrap.className = CLASS_NAME;\r
2229                         vmlImg = document.createElement( 'v:image' );\r
2230                         vmlImg.src = url;\r
2231                         onLoadCallback && onLoadCallback( _url, _actualW, _actualH );\r
2232                         onLoadCallback = fetch = null;\r
2233                         instance.resize( w, h );\r
2234                 }\r
2235                 function onError( _url ){\r
2236                         if( elmWrap === null ) return;\r
2237                         elmWrap.className = CLASS_NAME_ERROR;\r
2238                         retryTimer = window.setTimeout( retry, RETRY_DELAY );\r
2239                         fetch = null;\r
2240                 }\r
2241                 function retry(){\r
2242                         elmWrap.className = CLASS_NAME_LOADING;\r
2243                         fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 );\r
2244                 }\r
2245                 \r
2246                 this.elm = elmWrap;\r
2247                 this.resize = function( _w, _h ){\r
2248                         w = _w !== undefined ? _w : w;\r
2249                         h = _h !== undefined ? _h : h;\r
2250                         if( vmlImg === null ) return;\r
2251                         vmlImg.style.width  = ( w < 0 ? -w : w ) + 'px';\r
2252                         vmlImg.style.height = ( h < 0 ? -h : h ) + 'px';\r
2253                         //if( flipH !== _flipH || flipV !== _flipV){\r
2254                                 vmlImg.parentNode === elmWrap && elmWrap.removeChild( vmlImg );\r
2255                         //}\r
2256                                 vmlImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : '';\r
2257                                 elmWrap.appendChild( vmlImg );\r
2258                 }\r
2259                 this.destroy = function(){\r
2260                         instance.destroy;\r
2261                         \r
2262                         vmlImg !== null && elmWrap.removeChild( vmlImg );\r
2263                         retryTimer !== null && window.clearTimeout( retryTimer );\r
2264                         fetch !== null && fetch.stop();\r
2265                         elmWrap = vmlImg = onLoadCallback = retryTimer = fetch = instance = null;\r
2266                 }\r
2267         }\r
2268         \r
2269         var serverImage = css3Image; // function( url, w, h, onLoadCallback ){}\r
2270         \r
2271         if( BACKEND === IS_CSS3 )    ReversibleImageClass = css3Image;\r
2272         if( BACKEND === IS_VML )     ReversibleImageClass = vmlImage;\r
2273         if( BACKEND === IS_ACTIVEX ) ReversibleImageClass = activexImage;\r
2274         if( BACKEND === IS_SERVER )  ReversibleImageClass = activexImage;\r
2275         \r
2276         css3Image = vmlImage = activexImage = activexImage = null;\r
2277         \r
2278         return {\r
2279                 createReversibleImage: function( url, w, h, onLoadCallback){\r
2280                         return new ReversibleImageClass( url, w, h, onLoadCallback );\r
2281                 }\r
2282         }\r
2283 })();\r
2284 \r
2285 /*\r
2286  * bind : 製本\r
2287  */\r
2288 pettanr.bind = ( function(){\r
2289         var BIND_WORKER_ARRAY = [],\r
2290                 NAMESPACE_CLASSNAME = pettanr.CONST.NS_PETTANR_COMIC + '-',\r
2291                 RESOURCE_PICTURE_PATH = pettanr.CONST.RESOURCE_PICTURE_PATH,\r
2292                 ELM_DETECT_WIDTH = ( function(){\r
2293                         var ret = document.createElement( 'div');\r
2294                         ret.style.cssText = 'width: auto;height: 0;padding: 0;margin: 0;display: block;visibility: hidden;float: none;position: static;';\r
2295                         return ret;\r
2296                 })(),\r
2297                 ELM_TITLE_ORIGN = ( function(){\r
2298                         \r
2299                 })();\r
2300 \r
2301         /*\r
2302          * original\r
2303          *   http://d.hatena.ne.jp/uupaa/20090720/1248097177\r
2304          */\r
2305         var ResizeAgentClass = function( onResizeFunction, opt_elmCheck){\r
2306                 var     _globalLock = 0,\r
2307                         _size = { w: 0, h: 0 };\r
2308                         _ie = !!document.all,\r
2309                         _quirks = (document.compatMode || "") !== "CSS1Compat",\r
2310                         _ieroot = _quirks ? "body" : "documentElement";\r
2311                         _root = opt_elmCheck ? opt_elmCheck : ( _ie ? document[_ieroot] : window);\r
2312 \r
2313                 function getInnerSize() {\r
2314                         return {\r
2315                                 w: _root.innerWidth  || _root.clientWidth,\r
2316                                 h: _root.innerHeight || _root.clientHeight\r
2317                         };\r
2318                 }\r
2319 \r
2320                 function loop() {\r
2321                         if (!_globalLock++) {\r
2322                                 var size = getInnerSize();\r
2323                                 if (_size.w !== size.w || _size.h !== size.h) { // resized\r
2324                                         _size = size; // update\r
2325                                         onResizeFunction( _size );\r
2326                                 }\r
2327                                 setTimeout( unlock, 0); // delay unlock\r
2328                         }\r
2329                         setTimeout(loop, 500);\r
2330                 }\r
2331                 function unlock(){\r
2332                         _globalLock = 0;\r
2333                 }\r
2334                 loop();\r
2335         }\r
2336         \r
2337         \r
2338         var ElementBuilderClass = function( elmTarget, noClassnameMode ){\r
2339                 var RIMG_ARRAY     = [],\r
2340                         BALLOON_ARRAY  = [];\r
2341                 \r
2342                 function buildComicElement(){\r
2343                         \r
2344                 }\r
2345                 \r
2346                 function buildPanelElement( json, zoom ){\r
2347                         var _elmPanel = document.createElement( 'div' ),\r
2348                                 _style = {\r
2349                                                 'border-width':         typeof json.border === 'number' ? json.border + 'px' : 0,\r
2350                                                 width:                          json.width + 'px',\r
2351                                                 height:                         json.height + 'px'\r
2352                                 },\r
2353                                 _cssText = [],\r
2354                                 _comicElements = json.panel_elements || [],\r
2355                                 _comicElement, _elmImg, _rImg, _rPic,\r
2356                                 _balloon, _elmBalloonWrap, _elmText, _text, _speechesAttributes, _key;\r
2357                         if( noClassnameMode === true ){\r
2358                                 \r
2359                         } else {\r
2360                                 _elmPanel.className = NAMESPACE_CLASSNAME + 'panel';\r
2361                         }\r
2362                         for( var _key in _style ){\r
2363                                 _cssText.push( _key + ':' + _style[ _key ] );\r
2364                         }\r
2365                         _elmPanel.style.cssText = _cssText.join( ';');\r
2366                         elmTarget.appendChild( _elmPanel );\r
2367                         \r
2368                         for( var i=0, l=_comicElements.length; i<l; ++i ){\r
2369                                 _comicElement = _comicElements[ i ];\r
2370                                 _rPic = _comicElement.resource_picture;\r
2371                                 if( _rPic ){\r
2372                                         _rImg = pettanr.image.createReversibleImage(\r
2373                                                         [ RESOURCE_PICTURE_PATH, _rPic.id, '.', _rPic.ext ].join( ''),\r
2374                                                         _comicElement.width, _comicElement.height\r
2375                                                 );\r
2376                                         _elmImg = _rImg.elm;\r
2377                                         _elmPanel.appendChild( _elmImg );\r
2378                                         _elmImg.className = NAMESPACE_CLASSNAME + 'image';\r
2379                                         _elmImg.style.cssText = [\r
2380                                                 'left:',   _comicElement.x, 'px;',\r
2381                                                 'top:',    _comicElement.y, 'px;',\r
2382                                                 'z-index:',_comicElement.z, ';'\r
2383                                         ].join( '');                                    \r
2384                                         if( _elmImg.tagName === 'img' ){\r
2385                                                 _elmImg.width        = Math.abs( _comicElement.width );\r
2386                                                 _elmImg.height       = Math.abs( _comicElement.height );\r
2387                                         } else {\r
2388                                                 _elmImg.style.width  = Math.abs( _comicElement.width ) + 'px';\r
2389                                                 _elmImg.style.height = Math.abs( _comicElement.height ) + 'px';\r
2390                                         }\r
2391                                         \r
2392                                         RIMG_ARRAY.push( _rImg );\r
2393                                 } else {\r
2394                                         _elmBalloonWrap = document.createElement( 'div' );\r
2395                                         _elmPanel.appendChild( _elmBalloonWrap );\r
2396                                         _elmBalloonWrap.className = NAMESPACE_CLASSNAME + 'balloon';\r
2397                                         _elmBalloonWrap.style.cssText = [\r
2398                                                 'width:',   _comicElement.width, 'px;',\r
2399                                                 'height:',  _comicElement.height, 'px;',\r
2400                                                 'left:',    _comicElement.x, 'px;',\r
2401                                                 'top:',     _comicElement.y, 'px;',\r
2402                                                 'z-index:', _comicElement.z, ';'\r
2403                                         ].join( '');\r
2404 \r
2405                                         _balloon = pettanr.balloon.createBalloon( _comicElement.width, _comicElement.height, _comicElement.tail );\r
2406                                         _elmBalloonWrap.appendChild( _balloon.elm );\r
2407                                         \r
2408                                         _elmText = document.createElement( 'p' );\r
2409                                         _elmBalloonWrap.appendChild( _elmText );\r
2410                                         \r
2411                                         _elmText.appendChild( document.createElement( 'span' ) );\r
2412                                         \r
2413                                         _text = '';\r
2414                                         _speechesAttributes = _comicElement.speeches_attributes;\r
2415                                         if( _speechesAttributes ){\r
2416                                                 for( _key in _speechesAttributes ){\r
2417                                                         _text += _speechesAttributes[ _key ] && _speechesAttributes[ _key ].content ? _speechesAttributes[ _key ].content : '';\r
2418                                                 }\r
2419                                         }\r
2420                                         _elmText.firstChild.appendChild( document.createTextNode( _text ));\r
2421                                         BALLOON_ARRAY.push( _balloon );\r
2422                                 }\r
2423                         }\r
2424                 }\r
2425                 \r
2426                 function clean(){\r
2427                         // clean elmTarget\r
2428                         while( RIMG_ARRAY.length > 0 ){\r
2429                                 RIMG_ARRAY.shift().destroy();\r
2430                         }\r
2431                         while( BALLOON_ARRAY.length > 0 ){\r
2432                                 BALLOON_ARRAY.shift().destroy();\r
2433                         }\r
2434                         pettanr.util.removeAllChildren( elmTarget );            \r
2435                 }\r
2436                 \r
2437                 this.build = function( json, zoom ){\r
2438                         clean();\r
2439                         \r
2440                         // json is Comic ? Panel ?\r
2441                         var panels = json.panels;\r
2442                         if( Type.isArray( panels ) === true ){\r
2443                                 // comic\r
2444                                 for( var i=0, l=panels.length; i<l; ++i ){\r
2445                                         buildPanelElement( panels[ i ], zoom );\r
2446                                 }\r
2447                         } else\r
2448                         if( json.panel_elements ){\r
2449                                 // panel\r
2450                                 buildPanelElement( json, zoom );\r
2451                         } else {\r
2452                                 // invalid json\r
2453                         }\r
2454                 }\r
2455                 this.zoom = function(){\r
2456                         \r
2457                 }\r
2458                 this.destroy = function(){\r
2459                         clean();\r
2460                 }\r
2461         };\r
2462         \r
2463         var BindWorkerClass = function( elmTarget, json, zoomSelfEnabled, noClassnameMode ){\r
2464                 var builder    = new ElementBuilderClass( elmTarget, noClassnameMode );\r
2465                 var elmDetectW = ELM_DETECT_WIDTH.cloneNode( false );\r
2466                 var resizer    = null;\r
2467                 \r
2468                 if( zoomSelfEnabled === true){\r
2469                         elmTarget.parentNode.insertBefore( elmDetectW, elmTarget );\r
2470                         resizer = new ResizeAgentClass( onResize, elmDetectW );\r
2471                 }\r
2472                 function onResize(){\r
2473                         \r
2474                 }\r
2475                 json && typeof json === 'object' && builder.build( json );\r
2476                 \r
2477                 this.init = function(){\r
2478                                 \r
2479                 }\r
2480                 this.zoom = function(){\r
2481                         builder.zoom();\r
2482                 }\r
2483                 this.json = function( _json ){\r
2484                         json = _json;\r
2485                         builder.build( _json );\r
2486                 }\r
2487                 this.targetElement = function(){\r
2488                                 \r
2489                 }\r
2490                 this.layout = function(){\r
2491                                 \r
2492                 }\r
2493                 this.destroy = function(){\r
2494                         builder.destroy();\r
2495                         elmTarget = json = builder = null;\r
2496                 }\r
2497         }\r
2498         \r
2499         return {\r
2500                 createBindWorker: function( elmTarget, opt_COMICJSONorPANELJSON, opt_zoomSelfEnabled, opt_noClassnameMode ){\r
2501                         var ret = new BindWorkerClass( elmTarget, opt_COMICJSONorPANELJSON, !!opt_zoomSelfEnabled, !!opt_noClassnameMode);\r
2502                         BIND_WORKER_ARRAY.push( ret );\r
2503                         return ret;\r
2504                 },\r
2505                 isBindWorkerInstance: function( _bindWorker ){\r
2506                         return _bindWorker instanceof BindWorkerClass;\r
2507                 }\r
2508         }\r
2509 })();\r
2510 \r
2511 var VisualEffect = ( function(){\r
2512         \r
2513         var ANIMATION_TICKET_ARRAY = [],\r
2514                 fpms = 50,\r
2515                 TIMER = null,\r
2516                 FILTER = 'filter',\r
2517                 OPACITY = 'opacity',\r
2518                 REG_ALPHA = /alpha\([^)]*\)/i,\r
2519                 CORON = ':',\r
2520                 EMPTY = '',\r
2521                 SEMICORON = ';';\r
2522         \r
2523         function startAnimation( _elm, _cssObject, _onComplete, _onEnterFrame, _numFrames){\r
2524                 var _ticket;\r
2525                 for( var i=0, l=ANIMATION_TICKET_ARRAY.length; i<l; ++i){\r
2526                         _ticket = ANIMATION_TICKET_ARRAY[ i];\r
2527                         if( _ticket.elm === _elm) {\r
2528                                 _ticket.destroy();\r
2529                                 break;\r
2530                         }\r
2531                 }\r
2532                 //  coputedStyle と _cssObject を比較して , 一致及び非数は削除しつつ コピー\r
2533                 //  filter opacity の追加 REG_ALPHA.test( _value ) ? _value.replace( REG_ALPHA, opacity ) : _value + " " + opacity\r
2534                 /*\r
2535                  * cssObject をまわす\r
2536                  * 非数は削除\r
2537                  * cssText と一致も削除\r
2538                  * coputedStyle と一致も削除\r
2539                  * updateTraget ととして記録\r
2540                  * 初期値を cssObject としてセット\r
2541                  * cssTest にセット zoom もセット\r
2542                  */\r
2543                 \r
2544                 //\r
2545                 /*\r
2546                         var style = elem.style,\r
2547                                 currentStyle = elem.currentStyle,\r
2548                                 opacity = jQuery.isNumeric( value ) ? "alpha(opacity=" + value * 100 + ")" : "",\r
2549                                 filter = currentStyle && currentStyle.filter || style.filter || "";\r
2550 \r
2551                         // IE has trouble with opacity if it does not have layout\r
2552                         // Force it by setting the zoom level\r
2553                         style.zoom = 1;\r
2554                  */\r
2555                 \r
2556                 var _currentParameters = [],\r
2557                         _offsetParameters = [],\r
2558                         _endParameters = [],\r
2559                         _targetAttributes = [];\r
2560                 \r
2561                 ANIMATION_TICKET_ARRAY.push( new AnimationTaskClass(\r
2562                         _elm,\r
2563                         _currentParameters, _offsetParameters, _endParameters, _targetAttributes,\r
2564                         typeof _onComplete === 'function' ? _onComplete : null,\r
2565                         typeof _onEnterFrame === 'function' ? _onEnterFrame : null,\r
2566                         _numFrames\r
2567                 ));\r
2568                 \r
2569                 if( TIMER === null){\r
2570                         TIMER = window.setInterval( onEnterFrame, fpms);\r
2571                 }\r
2572         }\r
2573         function onEnterFrame(){\r
2574                 var _ticket,\r
2575                         i = 0;\r
2576                 while( i<ANIMATION_TICKET_ARRAY.length){\r
2577                         _ticket = ANIMATION_TICKET_ARRAY[ i];\r
2578                         if( _ticket.onEnterFrame() === true){\r
2579                                 _ticket.destroy();\r
2580                                 ANIMATION_TICKET_ARRAY.splice( i, 1);\r
2581                         } else {\r
2582                                 ++i;\r
2583                         }\r
2584                 }\r
2585                 if( ANIMATION_TICKET_ARRAY.length === 0){\r
2586                         window.clearInterval( TIMER);\r
2587                         TIMER = null;\r
2588                 }\r
2589         }\r
2590         function updateCss( _elm, _updateParameters, _targetAttributes, _numAttributes){\r
2591                 if( _numAttributes > 1){\r
2592                         var _cssTexts = _elm.style.cssText.split( ';'), _css,\r
2593                                 _separate,\r
2594                                 _cssObject = {}, _target, _value, _number, _px,\r
2595                                 j;\r
2596                         for(var i=0, l=_cssTexts.length; i<l; ++i){\r
2597                                 _css = _cssTexts[ i];\r
2598                                 _separate = _css.indexOf( ':');\r
2599                                 if( _separate >= 3){\r
2600                                         _target = _css.substr( 0, _separate +1);\r
2601                                         _value = _css.substr( _separate +1);\r
2602                                         /*\r
2603                                          * ie filter\r
2604                                          */\r
2605                                         if( _target === FILTER){\r
2606                                                 for( j=0; j<_numAttributes; ++j){\r
2607                                                         if( _targetAttributes[ j] === OPACITY){\r
2608                                                                 _cssTexts[ i] = [\r
2609                                                                                 _target, ':',\r
2610                                                                                 _value.replace( REG_ALPHA, "alpha(opacity=" + _updateParameters[ j] * 100 + ")")\r
2611                                                                         ].join( '');\r
2612                                                                 break;\r
2613                                                         }\r
2614                                                 }\r
2615                                         /*\r
2616                                          * other\r
2617                                          */\r
2618                                         } else {\r
2619                                                 _number = '' + parseFloat( _value);\r
2620                                                 _px = _value.indexOf( _number);\r
2621                                                 _px = _px > 0 ? _value.substr( _px + _number.length) : '';\r
2622                                                 for( j=0; j<_numAttributes; ++j){\r
2623                                                         if( _targetAttributes[ j] === _target){\r
2624                                                                 _cssTexts[ i] = [ _target, ':', _updateParameters[ j], _px].join( '');\r
2625                                                                 break;\r
2626                                                         }\r
2627                                                 }                                               \r
2628                                         }\r
2629                                 }\r
2630                         }\r
2631                         _elm.style.cssText = _cssTexts.join( ';');\r
2632                         return; \r
2633                 }\r
2634                 /*\r
2635                  * 一度に update する Attributes が少ない場合、cssText は使用しない.\r
2636                  */\r
2637         }\r
2638         \r
2639         var AnimationTaskClass = function( ELM, currentParameters, offsetParameters, endParameters, targetAttributes, onComplete, onEnterFrame, numFrames){\r
2640                 var l = targetAttributes.length;\r
2641                 return {\r
2642                         elm:    ELM,\r
2643                         onEnterFrame: function(){\r
2644                                 var _updateCss = {}, i;\r
2645                                 if( numFrames === 1){\r
2646                                         for( i=0; i<l; ++i){\r
2647                                                 _updateCss[ targetAttributes[ i]] = endParameters[ i];\r
2648                                                 ++i;\r
2649                                         }\r
2650                                         updateCss( ELM, currentParameters, targetAttributes, l);\r
2651                                         onComplete !== null && onComplete();\r
2652                                 } else {\r
2653                                         for( i=0; i<l; ++i){\r
2654                                                 _updateCss[ targetAttributes[ i]] = currentParameters[ i] = Math.floor( currentParameters[ i] + offsetParameters[ i]);\r
2655                                                 ++i;\r
2656                                         }\r
2657                                         updateCss( ELM, currentParameters, targetAttributes, l);\r
2658                                         onEnterFrame !== null && onEnterFrame( _updateCss);\r
2659                                 }\r
2660                                 --numFrames;\r
2661                                 return numFrames === 0;\r
2662                         },\r
2663                         destroy: function(){\r
2664                                 ELM = onComplete = onEnterFrame = null;\r
2665                         }\r
2666                 }\r
2667         }\r
2668         \r
2669         var VisualEffectClass = function( ELM){\r
2670                 var isHtmlElement;\r
2671                 \r
2672                 function registerAnime( _cssObject, _onComplete, _onEnterFrame, _time){\r
2673                         var _numFrames = Math.floor( _time / fpms);\r
2674                         startAnimation( ELM, _cssObject, _onComplete, _onEnterFrame, _numFrames);\r
2675                 }\r
2676                 function startFadeIn(){\r
2677                         \r
2678                 }\r
2679                 function startFadeOut(){\r
2680                         \r
2681                 }\r
2682                 function update( _x, _y, _w, _h){\r
2683                         var _cssText = ELM.style.cssText;\r
2684                         \r
2685                 }\r
2686                 \r
2687                 this.anime = registerAnime;\r
2688                 this.fadeIn = startFadeIn;\r
2689                 this.fadeOut = startFadeOut;\r
2690                 this.update = update;\r
2691         }\r
2692         \r
2693         return {\r
2694                 createVisualEffect: function( _elm){\r
2695                         return new VisualEffectClass( _elm);\r
2696                 },\r
2697                 isInstanceOfVisualEffect: function( _instance){\r
2698                         return _instance instanceof VisualEffectClass;\r
2699                 }\r
2700         }\r
2701 })();\r
2702 \r
2703 \r
2704 \r
2705 /*\r
2706  *  Google Analytics\r
2707  */\r
2708 \r
2709 if( pettanr.LOCAL === false){\r
2710         var _gaq = _gaq || [];\r
2711         _gaq.push(['_setAccount', 'UA-28023955-1']);\r
2712         _gaq.push(['_trackPageview']);\r
2713         \r
2714         (function() {\r
2715                 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\r
2716                 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\r
2717                 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\r
2718         })();   \r
2719 }