X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.4.x%2Fjavascripts%2Fcommon.js;h=c757ff2ec3e3b85b70095a22959997920aae7986;hb=67cb7059b2dab2d5d1c72214e7cfa026b0ec6b75;hp=13120a328453cc2f19c2dab531db11e69b46dcef;hpb=080ecdb578eb49a116464aefc6b86bd5b6f6da38;p=pettanr%2FclientJs.git diff --git a/0.4.x/javascripts/common.js b/0.4.x/javascripts/common.js index 13120a3..c757ff2 100644 --- a/0.4.x/javascripts/common.js +++ b/0.4.x/javascripts/common.js @@ -1,16 +1,16 @@ /* * pettanR common.js - * version 0.4.12 + * version 0.4.37 * * author: itozyun */ /* - * http://pettanr.sourceforge.jp/test/type.html + * http://pettanr.sourceforge.jp/test/type.html */ var Type = { isObject : function(v) { - return typeof v === 'object'; + return v !== null && typeof v === 'object'; }, isFunction : function(v) { return typeof v === 'function'; @@ -27,31 +27,38 @@ isNumber : function(v) { return typeof v === 'number'; }, - isHTMLElement : ( 'HTMLElement' in window ? - function(v){ - return v instanceof HTMLElement - } : - function(v) { - if( Type.isObject(v) === false ){ - return false; + isFinite : function(v){ + return Type.isNumber(v) === true && isFinite(v); + }, + isHTMLElement : function(v){ + if( 'HTMLElement' in window ){ + Type.isHTMLElement = function(v){ + return v instanceof HTMLElement; } - var r; - if(v && v.nodeType === 1){ - try{ - r = v.cloneNode(false); - } catch(n) { + } else { + Type.isHTMLElement = function(v) { + if( Type.isObject(v) === false ){ return false; } - if(r === v) return false; - try{ - r.nodeType = 9; - return r.nodeType === 1; - } catch(n) {} - return true; + var r; + if(v && v.nodeType === 1){ + try{ + r = v.cloneNode(false); + } catch(n) { + return false; + } + if(r === v) return false; + try{ + r.nodeType = 9; + return r.nodeType === 1; + } catch(n) {} + return true; + } + return false; } - return false; } - ), + return Type.isHTMLElement(v); + }, /* isElementCollection : function(v) { return (Object.prototype.toString.call(v) === "[object HTMLCollection]"); @@ -68,7 +75,7 @@ var pettanr = ( function(){ var FUNCTION_ARRAY = [], - URL = document.location.href.split( '#')[ 0], + URL = document.location.href.split( '#')[ 0 ], IS_LOCAL = URL.indexOf( 'file:') === 0, URL_PARAMS = ( function(){ var search = document.location.search, @@ -83,7 +90,7 @@ var pettanr = ( function(){ if( elm.length === 2){ v = decodeURIComponent( elm[ 1]); if( '' + parseFloat( v) === v) v = parseFloat( v); - if( '' + parseInt( v) === '0' + v) v = parseInt( v); + if( '' + parseInt( v, 10 ) === '0' + v) v = parseInt( v, 10 ); if( v === 'true') v = true; if( v === 'false') v = false; if( v === 'null') v = null; @@ -98,20 +105,20 @@ var pettanr = ( function(){ } return {}; })(), - IS_DEBUG = typeof URL_PARAMS.debug === 'boolean' ? URL_PARAMS.debug : IS_LOCAL === true, + IS_DEBUG = Type.isBoolean( URL_PARAMS.debug ) ? URL_PARAMS.debug : IS_LOCAL === true, jqWindow , jqDocument , jqBody; return { - version: '0.4.11', + version: '0.4.36', init: function(){ - jqWindow = $( window); - jqDocument = $( document); - jqBody = $( document.body); + jqWindow = $( window ); + jqDocument = $( document ); + jqBody = $( document.body ); var l = FUNCTION_ARRAY.length, _fn; for( var i=0; i array + // liveNode > array for( i=0, l=_children.length; i document.createElement( 'img') - */ - function loadImage( images, abspath, onLoad, onError, delay, timeout) { - images = images || document.images; - var img, - i = 0, l = images.length, - tick = 0; - for(; i < l; ++i) { - img = images[i]; - if ( img.src === abspath && img.complete) { - var size = pettanr.util.getImageSize( img); - onLoad( abspath, size.width, size.height); - return; - } - } - img = document.createElement( 'img'); //var img = new Image(); ではieでimgのsizeが取れない、、、removeChildも失敗し、imgSizeGetterにimgが残る - img.finish = false; - img.onabort = img.onerror = function() { - if (img.finish) { return; } - img.finish = true; - onError(abspath); - img.onload = img.onabort = img.onerror = ""; - }; - img.onload = function() { - img.finish = true; - if (window.opera && !img.complete) { - onError(abspath); - img.onload = img.onabort = img.onerror = ""; - return; - } - var size = pettanr.util.getImageSize( img); - onLoad( abspath, size.width, size.height); - img.onload = img.onabort = img.onerror = ""; - //img = void 0; - }; - img.src = abspath; - if (!img.finish && timeout) { - setTimeout(function() { - if (img.finish) { return; } - if (img.complete) { - img.finish = true; - if (img.width) { return; } - onError(abspath); - img.onload = img.onabort = img.onerror = ""; - return; - } - if ((tick += delay) > timeout) { - img.finish = true; - onError(abspath); - img.onload = img.onabort = img.onerror = ""; - return; - } - setTimeout(arguments.callee, delay); - }, 0); - } - } + return size; }, getAbsolutePath: function( path) { var e = document.createElement("div"); @@ -504,7 +403,7 @@ pettanr.util = ( function(){ return ret; }, getChildIndex: function( _parent, _child){ - var _children = _parent.getElementsByTagName( _child.tagName), + var _children = _parent.getElementsByTagName( _child.tagName ), l = _children.length; for(var i=0; i= 8) data.RenderingVersion = ua.ieRenderingVersion; - data.browserType = ua.STANDALONE === true ? 'Standalone' : 'bundle'; - if( ua.ieVersion < 9) { - data.vml = ua.VML; - } else { - data.svg = ua.SVG; - } - } - data.RenderingMode = ua.isStanderdMode === true ? 'Standerd' : 'Quirks'; - - for( var key in data){ - elmDt = document.createElement( 'dt'); - elmDt.innerHTML = key; - elmDd = document.createElement( 'dd'); - elmDd.innerHTML = '' + data[ key]; - if( !data[ key]) elmDd.style.color = 'red'; - elmDl.appendChild( elmDt); - elmDl.appendChild( elmDd); - } - } else { - var _debug = document.getElementById( 'debug'); - if( _debug){ - pettanr.util.removeAllChildren( _debug); - _debug.parentNode.removeChild( _debug); - } + var LoginUserNavi = { + show: function(){ + var i = pettanr.util.getChildIndex( this.parentNode, this ); + i !== -1 && bootApplication( i ); + return false; + }, + hide: function(){} } - } - /* global-navi */ - var navi = document.getElementById('global-navi'), - origin = document.createElement('a'), - items = ( function(){ - var ret = ['Home', 'Comic list', 'Picture', 'Setting']; - pettanr.DEBUG === true && ret.push( 'debug'); - return ret; - })(), - l = items.length, - item; - origin.href = '#'; - for(var i=0; i _w || this.MIN_HEIGHT > _h ){ + if( Type.isHTMLElement( this.rootElement ) === true ){ + // 小さすぎる!、と表示 + }; + return; + }; + this.onPaneResize( _w, _h ); + }; + this.MIN_WIDTH = 240; + this.MIN_HEIGHT = 240; + } + + var AbstractApplication = function(){ + var instance; + this.displayName = 'app name'; + this.ID = 'app id'; + this.rootElement = null; + this.parentElement = null; + this.nextSibling = null; + this.getUID = function(){ + return pettanr.util.getIndex( APPLICATION_LIST, instance ); + } + this.open = function( _w, _h /*, _option */ ){ + instance = this; + if( this.MIN_WIDTH > _w || this.MIN_HEIGHT > _h ){ + if( Type.isHTMLElement( this.rootElement ) === true ){ + // 小さすぎる!、と表示 + } + } + if( arguments.length > 2){ + // argumentsRellay( this.onOpen, arguments ); + this.onOpen.apply( this, arguments ); } else { - _viewID = HOME_ID; + this.onOpen( _w, _h ); } - - if( document.getElementById( _viewID)){ - return _viewID; + }; + this.close = function(){ + if( this.onClose() === false ){ + return false; } - return HOME_ID; - })( pettanr.URL_PARAMS.view); - - pettanr.DEBUG === true && VIEW_ID_ARRAY.push( 'debug'); + }; + this.onOpen = function( _w, _h /*, _option */ ){ + // overrride + }; + this.onClose = function(){ + // overrride + return true; + }; // false の場合、close の拒否 + this.addMouseEventListener = function( _element, _eventType, _handler ){ + MouseEventManager.add( instance, _element, _eventType, _handler ); + }; + } + AbstractApplication.prototype = new AbstractBasicPane(); - show(); + var ApplicationReference = function( application ){ + this.inOverlay = false; + this.getUID = function(){ + return pettanr.util.getIndex( APPLICATION_LIST, application ); + } + this.boot = function( /* _option */ ){ + if( arguments.length > 0 ){ + bootApplication( application, pettanr.util.copyArray( arguments ) ); + } else { + bootApplication( application ); + } + } + this.bootInOverlay = function( /* _option */ ){ + this.inOverlay = true; + pettanr.overlay.show( application, pettanr.util.copyArray( arguments ) ); + } + this.shutdown = function(){ + if( this.inOverlay === true ){ + pettanr.overlay.hide(); + this.inOverlay = false; + } else { + bootApplication( 0 ); + } + } + this.addToLancher = function(){ + if( pettanr.util.getIndex( LUNCHER_APPLICATION_LIST, application ) !== -1 ) return; + LUNCHER_APPLICATION_LIST.push( application ); - function onWindowResize(){ - var _fn, - l = funcArray.length, - w = jqWindow.width(), - h = jqWindow.height(); - //for( var i=0; i 0 ){ + var _arg = []; + for( i=0; i= 0 ? v : -1; }, + pow = Math.pow, + round = Math.round, + floor = Math.floor, + TARGET = TAIL_WIDTH * TAIL_WIDTH, + isFinit = Type.isFinite, + ACCURACY = 1, // 有効少数桁 + cround = function ( v, r ){ + r = r || ACCURACY; + return round( v * pow( 10.0, r )) / pow( 10.0, r ); + }, + DEG_TO_RAD = Math.PI / 180; + + var XBROWSER_BALLOON_CLASS = function( w, h, a ){ + var balloonElm = vectorEnabled === true ? ELM_BALLOON_ORIGIN.cloneNode( true ) : document.createElement( 'img' ), // pettanr.imageに変更 + path = balloonElm.getElementsByTagName( 'path' )[ 0 ], + shape = balloonElm.getElementsByTagName( 'shape' )[ 0 ], + instance = this, l = ','; - draw( a, w, h); - - function draw( _a, _w, _h){ - a = _a !== undefined ? _a : a; - w = _w !== undefined ? _w -PADDING_TOP *2 : w; - h = _h !== undefined ? _h -PADDING_LEFT *2 : h; - - if( vectorEnabled === false){ - balloonElm.setAttribute( 'src', balloonUrlBuilder( a)); - return; - } - - var rx = w /2, - ry = h /2, - tailRad = a * DEG_TO_RAD, - tailX = rx +( rx +TAIL_HEIGHT) * cos( tailRad), - tailY = ry +( ry +TAIL_HEIGHT) * sin( tailRad), + function draw( _a ){ + var rx = w / 2, + ry = h / 2, + tailRad = _a * DEG_TO_RAD, + tailX = rx + ( rx + TAIL_HEIGHT ) * sin( tailRad ), + tailY = ry - ( ry + TAIL_HEIGHT ) * cos( tailRad ), startX, startY, endX, endY; /* * tailの太さをTAIL_WIDTHに一致させるため、角度を絞りつつ計算 @@ -1594,106 +1865,118 @@ pettanr.balloon = ( function() { tailDeg = 0, d; for( var i = 45; i > 0.01; i /= 2){ - d = ( tailDeg +i) /2; - startRad = ( a +d) * DEG_TO_RAD; - endRad = ( a -d) * DEG_TO_RAD; + d = ( tailDeg + i ) /2; + startRad = ( _a + d ) * DEG_TO_RAD; + endRad = ( _a - d ) * DEG_TO_RAD; - _startX = rx +cos( startRad) *rx; - _startY = ry +sin( startRad) *ry; - _endX = rx +cos( endRad) *rx; - _endY = ry +sin( endRad) *ry; //円弧上のY位置=円中心Y+sin(角度×PI÷180)×円半径 + _startX = rx + sin( startRad ) * rx; + _startY = ry - cos( startRad ) * ry; + _endX = rx + sin( endRad ) * rx; + _endY = ry - cos( endRad ) * ry; //円弧上のY位置=円中心Y+sin(角度×PI÷180)×円半径 - if( pow( ( _startX -_endX), 2) + pow( ( _startY -_endY), 2) < TARGET){ + if( pow( ( _startX - _endX ), 2 ) + pow( ( _startY - _endY ), 2 ) < TARGET ){ tailDeg += i; - startX = _startX; - startY = _startY; - endX = _endX; - endY = _endY; + startX = _startX; + startY = _startY; + endX = _endX; + endY = _endY; } } /* * */ - if( IS_VML === true){ + if( IS_VML === true ){ var _tailX = tailX *10, _tailY = tailY *10, - __startX = startX *10, - __startY = startY *10, - __endX = endX *10, - __endY = endY *10, __w = w *10, __h = h *10; - shape.style.width = w +'px'; - shape.style.height = h +'px'; - shape.coordsize = [ __w, __h].join( l); + shape.style.width = w + 'px'; + shape.style.height = h + 'px'; + shape.coordsize = [ __w, __h ].join( l ); shape.path = [ ' ar ', 0, l, 0, l, __w, l, __h, l, - round( __endX), l, round( __endY), l, - round( __startX), l, round( __startY), - ' l ', round( _tailX), l, round( _tailY), + round( endX * 10 ), l, round( endY * 10 ), l, + round( startX * 10 ), l, round( startY * 10 ), + ' l ', round( _tailX ), l, round( _tailY ), ' x e' ].join( ''); - balloonElm.style.marginTop = _tailY < 0 ? floor( ( 60 +_tailY) /10) : 10; - balloonElm.style.marginLeft = _tailX < 0 ? floor( ( 60 +_tailX) /10) : 10; + balloonElm.style.marginTop = _tailY < 0 ? floor( ( 60 + _tailY) / 10 ) : 10; + balloonElm.style.marginLeft = _tailX < 0 ? floor( ( 60 + _tailX) / 10 ) : 10; } else { - balloonElm.setAttribute( 'width', w +PADDING_LEFT *2); - balloonElm.setAttribute( 'height', h +PADDING_TOP *2); + balloonElm.setAttribute( 'width', w + PADDING_LEFT *2 ); + balloonElm.setAttribute( 'height', h + PADDING_TOP *2 ); path.setAttribute( 'd', [ - 'M', cround( tailX + PADDING_LEFT), l, cround( tailY +PADDING_TOP), - 'L', cround( startX +PADDING_LEFT), l, cround( startY +PADDING_TOP), + 'M', cround( tailX + PADDING_LEFT ), l, cround( tailY + PADDING_TOP ), + 'L', cround( startX + PADDING_LEFT ), l, cround( startY + PADDING_TOP ), 'A', rx, l, ry, '0 1 1', // flag - cround( endX +PADDING_LEFT), l, cround( endY +PADDING_TOP), + cround( endX + PADDING_LEFT ), l, cround( endY + PADDING_TOP ), 'z' ].join( ' ')); } - function cround( v, r){ - r = r || ACCURACY; - return round( v *pow( 10.0, r)) /pow( 10.0, r); - } } - function balloonUrlBuilder( _a){ - var d = 360 /NUM_BALLOON_IMAGE; - _a += 90 +d /2; - return [ 'system_pictures\/_w', _a < 360 -d /2 ? floor( _a /d) : 0, '.gif'].join( ''); - } - return { - elm: balloonElm, - resize: draw, - angle: function( _a){ - _a !== undefined && _a !== a && - vectorEnabled === false ? balloonUrlBuilder( _a) : draw( _a); - return a; - }, - type: function( _type){ - //draw( _a); - }, - getURL: function(){ - return balloonUrlBuilder( a); - }, - destroy: function(){ - balloonElm.parentNode && balloonElm.parentNode.removeChild( balloonElm); - balloonElm = null; - delete this.destroy; + this.elm = balloonElm; + this.resize = function ( _a, _w, _h ){ + w = isFinit( _w ) === true ? _w - PADDING_TOP * 2 : w; + h = isFinit( _h ) === true ? _h - PADDING_LEFT * 2 : h; + // ie6 でリサイズが反応しない対策 + if( vectorEnabled === false && pettanr.ua.isIE === true && pettanr.ua.ieVersion < 7 ){ + var parent = balloonElm.parentNode; + parent.removeChild( balloonElm ); + parent.insertBefore( balloonElm, parent.firstChild ); + } + instance.angle( _a ); + }; + this.angle = function( _a ){ + if( isFinit( _a ) === true ){ + a = _a; + if( vectorEnabled === false ){ + balloonElm.src = pettanr.balloon.getBalloonUrl( w, h, _a ); + } else { + draw( _a ); + } } + return a; + } + this.type = function( _type ){ + //draw( _a); } + this.destroy = function(){ + delete instance.destroy; + balloonElm.parentNode && balloonElm.parentNode.removeChild( balloonElm ); + balloonElm = path = shape = instance = null; + } + + instance.resize( a, w, h ); }; IS_VML === false && vectorEnabled === true && ( function(){ - var detect = XBROWSER_BALLOON_CLASS.apply( {}, [ 100, 100, 0]), - size = pettanr.util.getElementSize( detect.elm); + var detect = new XBROWSER_BALLOON_CLASS( 100, 100, 0 ), + size = pettanr.util.getElementSize( detect.elm ); vectorEnabled = size.width !== 0 && size.height !== 0; detect.destroy(); detect = size = null; })(); return { - createBalloon: function( _w, _h, _a){ - return XBROWSER_BALLOON_CLASS.apply( {}, [ _w, _h, _a]); + createBalloon: function( _w, _h, _a ){ + return new XBROWSER_BALLOON_CLASS( _w, _h, _a ); + }, + isBalloonInstance: function( _ballon ){ + + }, + getBalloonUrl: function( _w, _h, _a ){ + var d = 360 / NUM_BALLOON_IMAGE; + _a = _a + d / 2; + return [ + pettanr.CONST.SYSTEM_PICTURE_PATH, '_w', + _a < 360 - d / 2 ? floor( _a / d ) : 0, + _w <= 400 || _h <= 400 ? '_b1' : '', + '.gif' ].join( '' ); }, TYPE_NONE: 0, TYPE_SPEACH_BALLOON: 1, @@ -1727,185 +2010,280 @@ pettanr.balloon = ( function() { * -moz-transform:scale( -1, -1); */ pettanr.image = ( function(){ - var REG_PNG = /\.png?/i, - IS_CSS3 = 0, - IS_VML = 1, - IS_ACTIVEX = 2, - IS_CANVAS = 3, - IS_FLASH = 4, - IS_SILVERLIGHT = 5, - IS_SERVER = 6, + + var FetchImageControl = ( function(){ + var TASK_LIST = []; + + /* + * FetchClass original is + * + * LICENSE: MIT? + * URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631 + * AUTHOR: uupaa.js@gmail.com + * + */ + + var FetchClass = function( abspath, onLoadCallback, onErrorCallback, delay, timeout ){ + var img, + size, + tick = 0, + timer = null, + finish = false; + /* + if( pettanr.ua.isIE === false && pettanr.ua.ieVersion < 8 ){ + var images = document.images, + i=0, l= images.length; + for( i=0; i timeout ){ + finish = true; + timer = window.setTimeout( asyncCallback, 10 ); + return; + } + timer = window.setTimeout( detect, delay ); + } + + function asyncCallback(){ + size ? onLoadCallback( abspath, size.width, size.height ) : onErrorCallback( abspath ); + destroy(); + } + function destroy(){ + finish = true; + img.src = img.onload = img.onabort = img.onerror = ''; + img = void 0; + size = onLoadCallback = onErrorCallback = timer = null; + } + this.stop = function(){ + timer !== null && window.clearTimeout( timer ); + destroy(); + } + } + + return { + load: function( URLorELM, onLoad, onError, delay, opt_timeout ){ + var src, fetch; + if( Type.isString( URLorELM ) === true ){ + src = URLorELM; + } else + if( Type.isHTMLElement( URLorELM ) === true && URLorELM.tagName.toLowerCase() === 'img' ){ + src = URLorELM.src; + } else { + return; + } + + fetch = new FetchClass( + pettanr.util.getAbsolutePath( src ), + onLoad, onError, + Type.isFinite( delay ) === true ? delay : 250, + Type.isFinite( opt_timeout ) === true ? opt_timeout : undefined + ); + // TASK_LIST.push( fetch ); + + return fetch; + } + } + })(); + + var REG_PNG = /\.png?/i, + IS_CSS3 = 0, + IS_VML = 1, + IS_ACTIVEX = 2, + IS_CANVAS = 3, + IS_FLASH = 4, + IS_SILVERLIGHT = 5, + IS_SERVER = 6, IS_ACTIVEX_SERVER = 7, BACKEND = ( function(){ - if( pettanr.DEBUG === true && pettanr.URL_PARAMS.rimg){ + if( pettanr.DEBUG === true && pettanr.URL_PARAMS.rimg ){ var rimg = pettanr.URL_PARAMS.rimg.toLowerCase(); - if( rimg === 'css3') return IS_CSS3; - if( rimg === 'activex') return IS_ACTIVEX; - if( rimg === 'vml') return IS_VML; - } - if( pettanr.ua.isIE === false || pettanr.ua.ieVersion >= 9) return IS_CSS3; // 不十分! - if( pettanr.ua.VML === true) return IS_VML; - if( pettanr.ua.ACTIVEX === true) return IS_ACTIVEX; - if( pettanr.FLASH === true) return IS_FLASH; - if( pettanr.SILVERLIGHT === true) return IS_SILVERLIGHT; + if( rimg === 'css3' ) return IS_CSS3; + if( rimg === 'activex' ) return IS_ACTIVEX; + if( rimg === 'vml' ) return IS_VML; + } + if( pettanr.ua.isIE === false || pettanr.ua.ieVersion >= 9 ) return IS_CSS3; // 不十分! + if( pettanr.ua.VML === true ) return IS_VML; + if( pettanr.ua.ACTIVEX === true ) return IS_ACTIVEX; + if( pettanr.FLASH === true ) return IS_FLASH; + if( pettanr.SILVERLIGHT === true ) return IS_SILVERLIGHT; return IS_SERVER; })(), BACKEND_WHEN_PNG = ( function(){ - if( pettanr.ua.isIE === false || pettanr.ua.ieVersion > 6) return BACKEND; - if( pettanr.ua.VML === true) return IS_VML; - if( pettanr.FLASH === true) return IS_FLASH; - if( pettanr.SILVERLIGHT === true) return IS_SILVERLIGHT; - if( pettanr.ua.ACTIVEX === true) return IS_ACTIVEX_SERVER; + if( pettanr.ua.isIE === false || pettanr.ua.ieVersion > 6 ) return BACKEND; + if( pettanr.ua.VML === true ) return IS_VML; + if( pettanr.FLASH === true ) return IS_FLASH; + if( pettanr.SILVERLIGHT === true ) return IS_SILVERLIGHT; + if( pettanr.ua.ACTIVEX === true ) return IS_ACTIVEX_SERVER; return IS_SERVER; })(), + CLASS_NAME = 'reversible-image-container', + CLASS_NAME_LOADING = CLASS_NAME + ' loading', + CLASS_NAME_ERROR = CLASS_NAME +' error', + RETRY_DELAY = 5000, + NUM_RETRY = 3, ReversibleImageClass, ReversibleImageClassWithPingfix; - var XBackendReversibleImageClass = ( function(){ - var CLASS_NAME = 'reversible-image-container', - CLASS_NAME_LOADING = CLASS_NAME + ' loading', - CLASS_NAME_ERROR = CLASS_NAME +' error', - RETRY_DELAY = 5000; - NUM_RETRY = 3; - - var css3Image = function( url, w, h, onLoadCallback){ - var elmWrap = document.createElement( 'div'), - elmImg, - loaded = false, - retryTimer = null; - elmWrap.className = CLASS_NAME_LOADING; - pettanr.util.loadImage( url, onLoad, onError, 100, 10000); - function onLoad( _url, _actualW, _actualH){ - if( elmWrap === null) return; - elmImg = new Image; - /* - * createElement 直後に append しないと、ie(ActiveX)で img が正しく表示されない. - */ - elmWrap.appendChild( elmImg); - elmImg.setAttribute( 'src', url); - elmWrap.className = CLASS_NAME; - onLoadCallback && onLoadCallback( _url, _actualW, _actualH); - onLoadCallback = null; - loaded = true; - resize( w, h); - } - function onError( _url){ - if( elmWrap === null) return; - elmWrap.className = CLASS_NAME_ERROR; - retryTimer = setTimeout( function(){ - elmWrap.className = CLASS_NAME_LOADING; - pettanr.util.loadImage( url, onLoad, onError, 100, 10000); - }, RETRY_DELAY); - } - function resize( _w, _h){ - w = _w !== undefined ? _w : w; - h = _h !== undefined ? _h : h; - if( loaded === false) return; - elmImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : ''; - } - return { - elm : elmWrap, - resize: resize, - destroy: function(){ - loaded === true && elmWrap.removeChild( elmImg); - retryTimer !== null && clearTimeout( retryTimer); - elmWrap = vmlImg = onLoadCallback = retryTimer = null; - elmWrap = elmImg = onLoadCallback = null; - delete this.destroy; - } - } + var css3Image = function( url, w, h, onLoadCallback ){ + var elmWrap = document.createElement( 'div' ), + elmImg = null, + retryTimer = null, + fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ), + instance = this; + elmWrap.className = CLASS_NAME_LOADING; + + function onLoad( _url, _actualW, _actualH ){ + if( elmWrap === null ) return; + elmImg = new Image; // new Image でないと ie6,7 でクラッシュするかも、、、? + /* + * createElement 直後に append しないと、ie(ActiveX)で img が正しく表示されない. + */ + elmWrap.appendChild( elmImg ); + elmImg.setAttribute( 'src', url ); + elmWrap.className = CLASS_NAME; + onLoadCallback && onLoadCallback( _url, _actualW, _actualH ); + onLoadCallback = fetch = null; + instance.resize( w, h ); } - var activexImage = css3Image; - var vmlImage = function( url, w, h, onLoadCallback){ - var elmWrap = document.createElement( 'div'), - vmlImg, - loaded = false, - retryTimer = null; + function onError( _url ){ + if( elmWrap === null ) return; + elmWrap.className = CLASS_NAME_ERROR; + retryTimer = window.setTimeout( retry, RETRY_DELAY ); + fetch = null; + } + function retry(){ elmWrap.className = CLASS_NAME_LOADING; - pettanr.util.loadImage( url, onLoad, onError, 100, 10000); - function onLoad( _url, _actualW, _actualH){ - if( elmWrap === null) return; - elmWrap.className = CLASS_NAME; - vmlImg = document.createElement( 'v:image'); - vmlImg.src = url; - loaded = true; - resize( w, h); - onLoadCallback && onLoadCallback( _url, _actualW, _actualH); - onLoadCallback = null; - } - function onError( _url){ - if( elmWrap === null) return; - elmWrap.className = CLASS_NAME_ERROR; - retryTimer = setTimeout( function(){ - elmWrap.className = CLASS_NAME_LOADING; - pettanr.util.loadImage( url, onLoad, onError, 100, 10000); - }, RETRY_DELAY); - } - function resize( _w, _h){ - w = _w !== undefined ? _w : w; - h = _h !== undefined ? _h : h; - if( loaded !== true) return; - vmlImg.style.width = w < 0 ? -w : w +'px'; - vmlImg.style.height = h < 0 ? -h : h +'px'; - //if( flipH !== _flipH || flipV !== _flipV){ - vmlImg.parentNode === elmWrap && elmWrap.removeChild( vmlImg); - //} - vmlImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : ''; - elmWrap.appendChild( vmlImg); - } - return { - elm : elmWrap, - resize: resize, - destroy: function(){ - loaded === true && elmWrap.removeChild( vmlImg); - retryTimer !== null && clearTimeout( retryTimer); - elmWrap = vmlImg = onLoadCallback = retryTimer = null; - delete this.destroy; - } - } + fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ); } - var serverImage = function( url, w, h, onLoadCallback){ + + this.elm = elmWrap; + this.resize = function( _w, _h ){ + w = _w !== undefined ? _w : w; + h = _h !== undefined ? _h : h; + if( elmImg === null ) return; + elmImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : ''; + } + this.destroy = function(){ + delete instance.destroy; + elmImg !== null && elmWrap.removeChild( elmImg ); + retryTimer !== null && window.clearTimeout( retryTimer ); + fetch !== null && fetch.stop(); + elmWrap = elmImg = onLoadCallback = retryTimer = fetch = instance = null; } + } - return function( url, w, h, onLoadCallback){ - var flipH = w < 0, - flipV = h < 0, - onLoadCallbackAsync = onLoadCallback,// ? function(){ setTimeout( onLoadCallback, 0);} : undefined,// 一度読み込んだ画像は即座にonLoadになるため遅延 - xBackendImage = ( function( urlIsXDomain){ - if( BACKEND === IS_CSS3) return css3Image.apply( {}, [ url, w, h, onLoadCallbackAsync]); - if( BACKEND === IS_VML) return vmlImage.apply( {}, [ url, w, h, onLoadCallbackAsync]); - if( BACKEND === IS_ACTIVEX) return activexImage.apply( {}, [ url, w, h, onLoadCallbackAsync]); - return serverImage.apply( {}, [ url, w, h, onLoadCallbackAsync]); - })(); - return { - elm: xBackendImage.elm, - w: function( _w){ - _w !== undefined && xBackendImage.resize( _w, h); - return w; - }, - h: function( _h){ - _h !== undefined && xBackendImage.resize( w, _h); - return h; - }, - resize: xBackendImage.resize, - destroy: function(){ - xBackendImage.destroy && xBackendImage.destroy(); - xBackendImage = onLoadCallback = onLoadCallbackAsync = null; - delete this.destroy; - } - } - } - })(); + var activexImage = css3Image; + + var vmlImage = function( url, w, h, onLoadCallback ){ + var elmWrap = document.createElement( 'div' ), + vmlImg = null, + retryTimer = null, + fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ), + instance = this; + elmWrap.className = CLASS_NAME_LOADING; + function onLoad( _url, _actualW, _actualH ){ + if( elmWrap === null ) return; + elmWrap.className = CLASS_NAME; + vmlImg = document.createElement( 'v:image' ); + vmlImg.src = url; + onLoadCallback && onLoadCallback( _url, _actualW, _actualH ); + onLoadCallback = fetch = null; + instance.resize( w, h ); + } + function onError( _url ){ + if( elmWrap === null ) return; + elmWrap.className = CLASS_NAME_ERROR; + retryTimer = window.setTimeout( retry, RETRY_DELAY ); + fetch = null; + } + function retry(){ + elmWrap.className = CLASS_NAME_LOADING; + fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ); + } + + this.elm = elmWrap; + this.resize = function( _w, _h ){ + w = _w !== undefined ? _w : w; + h = _h !== undefined ? _h : h; + if( vmlImg === null ) return; + vmlImg.style.width = ( w < 0 ? -w : w ) + 'px'; + vmlImg.style.height = ( h < 0 ? -h : h ) + 'px'; + //if( flipH !== _flipH || flipV !== _flipV){ + vmlImg.parentNode === elmWrap && elmWrap.removeChild( vmlImg ); + //} + vmlImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : ''; + elmWrap.appendChild( vmlImg ); + } + this.destroy = function(){ + instance.destroy; + + vmlImg !== null && elmWrap.removeChild( vmlImg ); + retryTimer !== null && window.clearTimeout( retryTimer ); + fetch !== null && fetch.stop(); + elmWrap = vmlImg = onLoadCallback = retryTimer = fetch = instance = null; + } + } + + var serverImage = css3Image; // function( url, w, h, onLoadCallback ){} + + if( BACKEND === IS_CSS3 ) ReversibleImageClass = css3Image; + if( BACKEND === IS_VML ) ReversibleImageClass = vmlImage; + if( BACKEND === IS_ACTIVEX ) ReversibleImageClass = activexImage; + if( BACKEND === IS_SERVER ) ReversibleImageClass = activexImage; + + css3Image = vmlImage = activexImage = activexImage = null; + return { createReversibleImage: function( url, w, h, onLoadCallback){ - return XBackendReversibleImageClass.apply( {}, [ url, w, h, onLoadCallback]); + return new ReversibleImageClass( url, w, h, onLoadCallback ); } } })(); /* - * bind : 製本 + * bind : 製本 */ pettanr.bind = ( function(){ var BIND_WORKER_ARRAY = [], @@ -1915,6 +2293,9 @@ pettanr.bind = ( function(){ var ret = document.createElement( 'div'); ret.style.cssText = 'width: auto;height: 0;padding: 0;margin: 0;display: block;visibility: hidden;float: none;position: static;'; return ret; + })(), + ELM_TITLE_ORIGN = ( function(){ + })(); /* @@ -1941,7 +2322,7 @@ pettanr.bind = ( function(){ var size = getInnerSize(); if (_size.w !== size.w || _size.h !== size.h) { // resized _size = size; // update - onResizeFunction( _size); + onResizeFunction( _size ); } setTimeout( unlock, 0); // delay unlock } @@ -1954,151 +2335,175 @@ pettanr.bind = ( function(){ } - var ElementBuilder = ( function(){ - var ELM_TITLE_ORIGN = ( function(){ - - })(), - ELM_TEXT_ORIGN = ( function(){ - var _table = document.createElement( 'table'), - _tr = document.createElement( 'tr'); - _table.appendChild( _tr); - _tr.appendChild( document.createElement( 'td')); - _table.cellspacing = '0'; - return _table; - })(); + var ElementBuilderClass = function( elmTarget, noClassnameMode ){ + var RIMG_ARRAY = [], + BALLOON_ARRAY = []; function buildComicElement(){ } - function buildPanelElement( elmTarget, json, noClassnameMode){ - var _elmPanel = document.createElement( 'div'), + function buildPanelElement( json, zoom ){ + var _elmPanel = document.createElement( 'div' ), _style = { - "border-width": typeof json.border === 'number' ? json.border + 'px' : 0, + 'border-width': typeof json.border === 'number' ? json.border + 'px' : 0, width: json.width + 'px', height: json.height + 'px' }, _cssText = [], _comicElements = json.panel_elements || [], - _comicElement, _elmImgWrap, _rImg, _rPic, _balloon, _elmBalloonWrap, _elmText; - if( noClassnameMode === true){ + _comicElement, _elmImg, _rImg, _rPic, + _balloon, _elmBalloonWrap, _elmText, _text, _speechesAttributes, _key; + if( noClassnameMode === true ){ } else { _elmPanel.className = NAMESPACE_CLASSNAME + 'panel'; } - for( var _key in _style){ - _cssText.push( _key + ':' + _style[ _key]); + for( var _key in _style ){ + _cssText.push( _key + ':' + _style[ _key ] ); } _elmPanel.style.cssText = _cssText.join( ';'); - elmTarget.appendChild( _elmPanel); + elmTarget.appendChild( _elmPanel ); - for( var i=0, l=_comicElements.length; i 0 ){ + RIMG_ARRAY.shift().destroy(); + } + while( BALLOON_ARRAY.length > 0 ){ + BALLOON_ARRAY.shift().destroy(); + } + pettanr.util.removeAllChildren( elmTarget ); + } + + this.build = function( json, zoom ){ + clean(); + + // json is Comic ? Panel ? + var panels = json.panels; + if( Type.isArray( panels ) === true ){ + // comic + for( var i=0, l=panels.length; i