X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=public%2Fassets%2Fcommon.js;fp=public%2Fassets%2Fcommon.js;h=a604d02d4dd870b4ac38e086121339bfa8e1062c;hp=41b7c9118ef9fd32afb0178bc23295a155fcb26e;hb=b5b537bb72484a06c3d227b8d7a2efe74fd6a2ba;hpb=2e0fa61cdcc5832ec3c65f1afd57235a065f53c3 diff --git a/public/assets/common.js b/public/assets/common.js index 41b7c911..a604d02d 100644 --- a/public/assets/common.js +++ b/public/assets/common.js @@ -1,6 +1,6 @@ /* * pettanR common.js - * version 0.4.30 + * version 0.4.34 * * author: itozyun */ @@ -108,7 +108,7 @@ var pettanr = ( function(){ IS_DEBUG = Type.isBoolean( URL_PARAMS.debug ) ? URL_PARAMS.debug : IS_LOCAL === true, jqWindow , jqDocument , jqBody; return { - version: '0.4.28', + version: '0.4.33', init: function(){ jqWindow = $( window ); jqDocument = $( document ); @@ -675,7 +675,17 @@ pettanr.CONST = ( function(){ var loc = document.location; return [ loc.protocol, '\/\/', loc.host, '\/' ].join( '' ); })(), - DEPTH = document.location.pathname.split( '\/' ).length; + RELATIVE = ( function(){ + var ret = '', + loc = document.location, + path = [ loc.protocol, '\/', loc.host, '\/', loc.pathname.split( '\\' ).join( '\/' ) ].join( '' ), + l = path.split( '\/' ).length - PETTANR_ROOT_PATH.split( '\/' ).length; + for( var 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 ){ @@ -1828,24 +1846,12 @@ pettanr.balloon = ( function() { instance = this, l = ','; - draw( a, w, h ); - - function draw( _a, _w, _h ){ - a = _a !== undefined ? _a : a; - _a = a;// - 90; - 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, + function draw( _a ){ + 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 ), + tailX = rx + ( rx + TAIL_HEIGHT ) * sin( tailRad ), + tailY = ry - ( ry + TAIL_HEIGHT ) * cos( tailRad ), startX, startY, endX, endY; /* * tailの太さをTAIL_WIDTHに一致させるため、角度を絞りつつ計算 @@ -1857,19 +1863,19 @@ pettanr.balloon = ( function() { 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; + 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; } } @@ -1879,10 +1885,6 @@ pettanr.balloon = ( function() { 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; @@ -1891,8 +1893,8 @@ pettanr.balloon = ( function() { 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 ), + round( endX * 10 ), l, round( endY * 10 ), l, + round( startX * 10 ), l, round( startY * 10 ), ' l ', round( _tailX ), l, round( _tailY ), ' x e' ].join( ''); @@ -1911,35 +1913,41 @@ pettanr.balloon = ( function() { '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 = ( _a >= _a ? _a : _a + 360 ) + d / 2; - return [ 'system_pictures\/_w', _a < 360 - d / 2 ? floor( _a / d ) : 0, '.gif' ].join( '' ); - } this.elm = balloonElm; - this.resize = draw; + 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 ){ - _a !== undefined && _a !== a && - vectorEnabled === false ? balloonUrlBuilder( _a ) : draw( _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.getURL = function(){ - return balloonUrlBuilder( 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(){ @@ -1951,9 +1959,21 @@ pettanr.balloon = ( function() { })(); return { - createBalloon: function( _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, TYPE_THINKING: 2, @@ -2102,14 +2122,14 @@ 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 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 ){ @@ -2133,21 +2153,20 @@ pettanr.image = ( function(){ if( pettanr.ua.ACTIVEX === true ) return IS_ACTIVEX_SERVER; return IS_SERVER; })(), - CLASS_NAME = 'reversible-image-container', + CLASS_NAME = 'reversible-image-container', CLASS_NAME_LOADING = CLASS_NAME + ' loading', - CLASS_NAME_ERROR = CLASS_NAME +' error', - RETRY_DELAY = 5000, - NUM_RETRY = 3, + CLASS_NAME_ERROR = CLASS_NAME +' error', + RETRY_DELAY = 5000, + NUM_RETRY = 3, ReversibleImageClass, ReversibleImageClassWithPingfix; var css3Image = function( url, w, h, onLoadCallback ){ - var elmWrap = document.createElement( 'div' ), - elmImg, - loaded = false, + var elmWrap = document.createElement( 'div' ), + elmImg = null, retryTimer = null, - fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ), - instance = this; + fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ), + instance = this; elmWrap.className = CLASS_NAME_LOADING; function onLoad( _url, _actualW, _actualH ){ @@ -2161,7 +2180,6 @@ pettanr.image = ( function(){ elmWrap.className = CLASS_NAME; onLoadCallback && onLoadCallback( _url, _actualW, _actualH ); onLoadCallback = fetch = null; - loaded = true; instance.resize( w, h ); } function onError( _url ){ @@ -2179,13 +2197,13 @@ pettanr.image = ( function(){ this.resize = function( _w, _h ){ w = _w !== undefined ? _w : w; h = _h !== undefined ? _h : h; - if( loaded === false ) return; + 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; - loaded === true && elmWrap.removeChild( elmImg ); + elmImg !== null && elmWrap.removeChild( elmImg ); retryTimer !== null && window.clearTimeout( retryTimer ); fetch !== null && fetch.stop(); elmWrap = elmImg = onLoadCallback = retryTimer = fetch = instance = null; @@ -2196,24 +2214,22 @@ pettanr.image = ( function(){ var vmlImage = function( url, w, h, onLoadCallback ){ var elmWrap = document.createElement( 'div' ), - vmlImg, - loaded = false, + vmlImg = null, retryTimer = null, fetch = FetchImageControl.load( url, onLoad, onError, 100, 10000 ), instance = this; elmWrap.className = CLASS_NAME_LOADING; - function onLoad( _url, _actualW, _actualH){ + 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; - loaded = true; instance.resize( w, h ); } function onError( _url ){ - if( elmWrap === null) return; + if( elmWrap === null ) return; elmWrap.className = CLASS_NAME_ERROR; retryTimer = window.setTimeout( retry, RETRY_DELAY ); fetch = null; @@ -2227,9 +2243,9 @@ pettanr.image = ( function(){ this.resize = function( _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( 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 ); //} @@ -2239,21 +2255,19 @@ pettanr.image = ( function(){ this.destroy = function(){ instance.destroy; - loaded === true && elmWrap.removeChild( vmlImg ); + vmlImg !== null && elmWrap.removeChild( vmlImg ); retryTimer !== null && window.clearTimeout( retryTimer ); fetch !== null && fetch.stop(); elmWrap = vmlImg = onLoadCallback = retryTimer = fetch = instance = null; } } - var serverImage = function( url, w, h, onLoadCallback ){ - - } + var serverImage = css3Image; // function( url, w, h, onLoadCallback ){} - if( BACKEND === IS_CSS3 ) ReversibleImageClass = css3Image; - if( BACKEND === IS_VML ) ReversibleImageClass = vmlImage; + if( BACKEND === IS_CSS3 ) ReversibleImageClass = css3Image; + if( BACKEND === IS_VML ) ReversibleImageClass = vmlImage; if( BACKEND === IS_ACTIVEX ) ReversibleImageClass = activexImage; - if( BACKEND === IS_SERVER ) ReversibleImageClass = activexImage; + if( BACKEND === IS_SERVER ) ReversibleImageClass = activexImage; css3Image = vmlImage = activexImage = activexImage = null;