X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.4.x%2Fjavascripts%2Fcommon.js;h=c757ff2ec3e3b85b70095a22959997920aae7986;hb=dc5a75639232882249108b4f708916e9690e42b3;hp=663641dbd5222db8eecd682cc7bfcdf732c8e670;hpb=5592df19c3498d587690a19022f1351cae368a4d;p=pettanr%2FclientJs.git diff --git a/0.4.x/javascripts/common.js b/0.4.x/javascripts/common.js index 663641d..c757ff2 100644 --- a/0.4.x/javascripts/common.js +++ b/0.4.x/javascripts/common.js @@ -1,13 +1,81 @@ /* * pettanR common.js - * version 0.4.2 + * version 0.4.37 * * author: itozyun */ +/* + * http://pettanr.sourceforge.jp/test/type.html + */ + var Type = { + isObject : function(v) { + return v !== null && typeof v === 'object'; + }, + isFunction : function(v) { + return typeof v === 'function'; + }, + isArray : function(v) { + return Object.prototype.toString.call(v) === "[object Array]"; + }, + isBoolean : function(v) { + return typeof v === 'boolean'; + }, + isString : function(v) { + return typeof v === 'string'; + }, + isNumber : function(v) { + return typeof v === 'number'; + }, + 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; + } + } else { + Type.isHTMLElement = function(v) { + if( Type.isObject(v) === false ){ + return false; + } + 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 Type.isHTMLElement(v); + }, + /* + isElementCollection : function(v) { + return (Object.prototype.toString.call(v) === "[object HTMLCollection]"); + }, + */ + isNull : function(v) { + return v === null; + }, + isUndefined : function(v) { + return typeof v === 'undefined'; + } + }; + + 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, @@ -15,19 +83,19 @@ var pettanr = ( function(){ if( 1 < l){ var query = search.substring( 1), params = query.split( '&'), - ret = {}, elm, name; + ret = {}, elm, name, v; while( params.length > 0){ elm = params.shift().split( '='); name = decodeURIComponent( elm[ 0]); if( elm.length === 2){ - ret[ name] = ( function( v){ - if( '' + parseFloat( v) === v) return parseFloat( v); - if( v === 'true') return true; - if( v === 'false') return false; - if( v === 'null') return null; - if( v === 'undefined') return undefined; - return v; - })( decodeURIComponent( elm[ 1])); + v = decodeURIComponent( elm[ 1]); + if( '' + parseFloat( v) === v) v = parseFloat( 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; + if( v === 'undefined') v = undefined; + ret[ name] = v; } else if( elm.length === 1){ ret[ name] = true; @@ -37,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.2', + 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 + 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"); @@ -432,7 +388,7 @@ pettanr.util = ( function(){ if( !IDorELM) return; IDorELM.parentNode && IDorELM.parentNode.removeChild( IDorELM); if( IDorELM.id && IDorELM.id.indexOf( 'templete-') === 0){ - IDorELM.id = ''; + IDorELM.removeAttribute( 'id'); } return IDorELM; }, @@ -442,20 +398,20 @@ pettanr.util = ( function(){ _node, _classes, ret = []; for( var i=0, l = _nodes.length; i' : 'iframe'); + + if( ua.isIE){ + el.onreadystatechange = detect; + } else { + // iron(chrome) の場合、append の前に onload を指定しないと onload が呼ばれない + el.onload = onLoad; + //setTimeout( asynkCallback, 0 ); + } + + document.body.appendChild( el); + el.id = el.name = id; + el.setAttribute( 'name', id); + el.style.cssText = 'width:1px;height:1px;visibility:hidden;position:absolute;top:1px;left:1px;'; + // http://d.hatena.ne.jp/onozaty/20070830/p1 + // [JavaScript]IE6ではJavaScriptで動的に作成したiframeに対してsubmitできない(IE7は未確認) ->解決 + el.contentWindow.name = id; + + window[id] = el; + + function detect(){ + if ( this.readyState === "complete") { + this.onreadystatechange = new Function(); + this.onreadystatechange = null; + setTimeout( asynkCallback, 0 ); + } + } + function onLoad(){ + el.onload = null; + setTimeout( asynkCallback, 0 ); + } + function asynkCallback(){ + callback( el ); + } } } })(); @@ -557,33 +572,54 @@ pettanr.ua = ( function(){ ieVersion = isIE === true ? parseInt( navigator.appVersion.toLowerCase().replace( /.*msie[ ]/, '').match( /^[0-9]+/)) : 0, ieRenderingVersion = ieVersion === 8 ? document.documentMode : ieVersion, isStanderdMode = document.compatMode === 'CSS1Compat', - VML = ( function(){ + ActiveX = ( function(){ if( isIE === false || ieVersion > 8) return false; + var b = document.body, + c = b.className || '', + x, + ret = pettanr.URL_PARAMS.ActiveX, + ns = 'pettanr-ActiveX-', + enabled = 'enabled', + disabled = 'disabled'; + if( ret !== true && ret !== false){ + if( pettanr.util.hasClassName( b, ns + enabled) === true) return true; + if( pettanr.util.hasClassName( b, ns + disabled) === true) return false; + x = document.createElement('div'); + b.appendChild(x); + x.style.cssText = 'width:1px;height:1px;line-height:1px;filter:progid:DXImageTransform.Microsoft.Shadow()'; + ret = x.offsetHeight > 1; + b.removeChild(x); + } + b.className += [ c !== '' ? ' ' : c, ns, ret === true ? enabled : disabled ].join( ''); + return ret; + })(), + VML = ( function(){ + if( ActiveX === false || isIE === false || ieVersion > 8) return false; var globalObjectName = pettanr.util.createGlobalUniqueName(), - script; - document.write( [ ''].join( '')); + script, + id = 'detectVML'; + document.write( [ ''].join( '')); if( window[globalObjectName] === 1){ - script = document.getElementById( 'detectVML'); + script = document.getElementById( id); script.parentNode.removeChild( script); - window[globalObjectName] = script = null; + window[globalObjectName] = null; return true; } - //pettanr.util.cleanCommnetNode(); return false; })(), isStandAloneMode = ( function(){ if( isIE === false) return false; if( VML === true) return false; var globalObjectName = pettanr.util.createGlobalUniqueName(), - script; - document.write( [ ''].join( '')); + script, + id = 'detectStandAlone'; + document.write( [ ''].join( '')); if( window[globalObjectName] === 1){ - script = document.getElementById( 'detectStandAlone'); + script = document.getElementById( id); script.parentNode.removeChild( script); - window[globalObjectName] = script = null; + window[globalObjectName] = null; return false; } - //pettanr.util.cleanCommnetNode(); return true; })(); return { @@ -610,24 +646,7 @@ pettanr.ua = ( function(){ } return ''; })(), - ACTIVEX: ( function(){ - if( isIE === false || ieVersion > 8) return false; - var b = document.body, - c = b.className || '', - x, - ret = pettanr.URL_PARAMS.ActiveX; - if( ret === undefined){ - if( pettanr.util.hasClassName( b, 'pettanr-ActiveX-enabled') === true) return true; - if( pettanr.util.hasClassName( b, 'pettanr-ActiveX-disabled') === true) return false; - x = document.createElement('div'); - b.appendChild(x); - x.style.cssText = 'width:1px;height:1px;filter:progid:DXImageTransform.Microsoft.Shadow()'; - ret = x.offsetHeight > 1; - b.removeChild(x); - } - b.className += [ c !== '' ? ' ' : c, 'pettanr-ActiveX-', ret === true ? 'enabled' : 'disabled'].join( ''); - return ret; - })(), + ACTIVEX: ActiveX, VML: VML, STANDALONE: isStandAloneMode, startVML: function(){ @@ -643,231 +662,59 @@ pettanr.ua = ( function(){ pettanr.CONST = ( function(){ - var isLocal = pettanr.LOCAL === true || pettanr.URL_PARAMS.exjson === false, - RETTANR_ROOOT_PATH = 'http:\/\/pettanr.heroku.com\/'; + var SERVER_SUPPORT = !( 'has_server_support' in window && has_server_support === false ), + PETTANR_ROOT_PATH = ( function(){ + if( SERVER_SUPPORT === false ){ + var h1 = document.getElementsByTagName( 'h1' )[ 0 ]; + if( h1 ){ + var a = h1.getElementsByTagName( 'a' )[ 0 ]; + return a ? a.href : ''; + } + return ''; + } + var loc = document.location; + return [ loc.protocol, '\/\/', loc.host, '\/' ].join( '' ); + })(), + 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' : 'iframe'); - el.id = el.name = id; - el.setAttribute( 'name', id); - - el.style.position = 'absolute'; - el.style.left = el.style.top = '0px'; - el.style.width = el.style.height ='100%'; - //el.style.overflow = 'hidden'; - el.hspace = el.vspace = el.marginheight = el.marginwidth = 0; - - _body.appendChild(el); - window[id] = el; - iframe = el; - - if (!ua.isIE) { - var idoc;//WebKit > 521 corresponds with Safari 3, which started with 522 WebKit version. - if (ua.isWebKit > 521) { - idoc = el.contentWindow.document; - } else if (ua.isSafari) { - idoc = el.document; - } else { // if(d.isMozilla){ - idoc = el.contentWindow; - } - - if ( !idoc) { - try { - el.src = src; - el.contentWindow.location.replace = src; - } catch (e){} - try { - //el.contentWindow.location = src; - } catch (e){} - try { - el.location = src; // for Safari 2.0.3 ?? - } catch (e){} - - } else if( ua.isOpera){ - el.src = src; // for Opera - el.contentWindow.location.replace = src; // for Opera - } else { - //el.src = src; // for firefox - idoc.location.replace(src); - } - } - - delete LoginUserNavi.init; - }, - show: function(){ - if(visible === true) return; - if (_root) { - _root.style.overflow = 'hidden'; - } - _body.style.overflow = 'hidden'; - - var index = ( function( a){ - var node = a.parentNode.getElementsByTagName( 'a'), - l = node.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 LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext].join( '') : null, - reversibleImage = null, - actualW, actualH, - onEnterFlag = false; - JQ_ICON_WRAP.children( 'div').eq( 0).html( data.filesize + 'bytes'); - jqContainer.append( JQ_ICON_WRAP.css( { left: INDEX * itemW})); - - function onLoad( url, _imgW, _imgH){ - if( reversibleImage === null) { - alert( url); - return; - } - actualW = _imgW || 64; - actualH = _imgH || 64; - JQ_ICON_WRAP.children( 'div').eq( 1).html( actualW +'x' +actualH); - var zoom = 128 /( actualW > actualH ? actualW : actualH), - _h = Math.floor( actualH *zoom), - _w = Math.floor( actualW *zoom); - reversibleImage.elm.style.width = _w +'px'; - reversibleImage.elm.style.height = _h +'px'; - reversibleImage.elm.style.margin = Math.floor( itemH /2 -_h /2)+'px 0 0'; - reversibleImage.resize( _w, _h); - JQ_ICON_WRAP.click( onClick); - } - - function onClick( e){ - pettanr.overlay.hide(); - if (onUpdateFunction) { - if( LOW_SRC === null){ - onUpdateFunction( SRC, actualW, actualH); - } else { - onCloseUpdate( onUpdateFunction); // close()で値が消えるので、クロージャに保持 - } - } - close(); - } - - function onCloseUpdate( onUpdate){ - pettanr.util.loadImage( SRC, - function( _abspath, imgW, imgH){ - onUpdate( SRC, imgW, imgH); - onUpdate = null; - }, - function( _abspath){ - onUpdate( SRC, data.width || 64, data.height || 64); - onUpdate = null; - } - ); - } - - return { - onEnter: function(){ - if( onEnterFlag === true) return; - reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onLoad); - JQ_ICON_WRAP.children( 'img').replaceWith( reversibleImage.elm); - onEnterFlag = true; - }, - destroy: function(){ - reversibleImage && reversibleImage.destroy(); - JQ_ICON_WRAP.remove(); - reversibleImage = JQ_ICON_WRAP = null; - delete this.destroy; - } - } - } - - function close(){ - jqContainer.stop().animate( { - height: 0, - top: Math.floor( windowH /2) - }, function(){ - jqWrap.hide() - }); - while( ICON_ARRAY.length > 0){ - ICON_ARRAY.shift().destroy(); - } - onEnterInterval !== null && window.clearTimeout( onEnterInterval); - onUpdateFunction = onEnterInterval = null; - } - function onEnterShowImage(){ - var l = ICON_ARRAY.length, - _start = -wrapX /itemW -1, - _end = _start + winW /itemW +1; - for( var i=0; i 0 ? 0 : wrapX < winW -containerW ? winW -containerW : wrapX; - jqContainer.css( { left: wrapX}); - - onEnterInterval !== null && window.clearTimeout( onEnterInterval); - onEnterInterval = window.setTimeout( onEnterShowImage, 500); - } - //e.stopPropagation(); - return false; - } - return { - init: function(){ - this.jqWrap = jqWrap = $( '#image-gruop-wrapper').hide(); - jqContainer = $( '#image-icon-container').mousewheel( onMouseWheel); - containerH = pettanr.util.getElementSize( jqContainer.get( 0)).height; - jqItemOrigin = $( $( '#imageGruopItemTemplete').remove().html()); - var itemSize = pettanr.util.getElementSize( jqItemOrigin.get( 0)); - itemW = itemSize.width; - itemH = itemSize.height; - jqName = $( '#gruop-name-display'); - jqButton = $( '#image-gruop-button').click( onCloseClick); - buttonW = pettanr.util.getElementSize( jqButton.get( 0)).width; - - delete IMAGE_GROUP_EXPROLER.init; - }, - jqWrap: null, - show: function( _folder, _onUpdateFunction){ - this.init !== undefined && this.init(); - - folder = _folder; - onUpdateFunction = _onUpdateFunction; - pettanr.overlay.show( this); - - var l = _folder.getChildFileLength(); - for( var i=0; i containerW ? winW : containerW, - h = windowH > containerH ? containerH : windowH; - - jqWrap.show(); - jqContainer.css( { - width: w, - height: 0, - left: 0, - top: Math.floor( windowH /2) - }).stop().animate( { - height: h, - top: Math.floor( windowH /2 -h /2) - }); - - jqButton.css( { - left: Math.floor( winW /2 -buttonW /2), - top: Math.floor( windowH /2 +containerH /2 +10) - }); - - onEnterShowImage(); - }, - onWindowResize: function( _windowW, _windowH){ - var w = _windowW > containerW ? _windowW : containerW, - h = _windowH > containerH ? containerH : _windowH, - offsetW = Math.floor( _windowW /2 -winW /2); - winW = _windowW; - if( offsetW <= 0){ // smaller - jqContainer.css( { - left: offsetW, - width: w - }).animate( { - left: 0, - top: Math.floor( _windowH /2 -h /2) - }); - } else { - jqContainer.css( { // bigger - left: 0, - width: w, - borderLeftWidth: offsetW - }).animate( { - top: Math.floor( _windowH /2 -h /2), - borderLeftWidth: 0 - }); - } - jqButton.css( { - left: Math.floor( _windowW /2 -buttonW /2), - top: Math.floor( _windowH /2 +containerH /2 +10) - }); - onEnterShowImage(); - }, - onClose: close, - ID: 'imageGroupExproler' - } - })(); - /* - * - */ - - function close(){ - currentOverlay && currentOverlay.onClose && currentOverlay.onClose(); - pettanr.overlay.hide(); } - function asyncResize(){ - currentOverlay.onWindowResize( windowW, windowH); - } - function onCloseClick( e){ - close(); - e.preventDefault(); - return false; + function onFadeOutComplete(){ + currentOverlay.close(); + currentOverlay.rootElement.style.display = 'none'; + currentOverlay.rootElement.style.visibility = 'hidden'; + currentOverlay = null; } return { init: function(){ //jqBody = pettanr.jqBody(); - jqConteiner = $( '#overlay-container'); - jqShadow = $( '#overlay-shadow'); - jqCloseButton = $( '#overlay-close-button').click( onCloseClick); + jqConteiner = $( '#overlay-container'); + jqShadow = $( '#overlay-shadow'); + jqCloseButton = $( '#overlay-close-button').click( onCloseClick ); - pettanr.key.addKeyDownEvent( pettanr.view.OVERLAY, 27, false, false, close); // 27.esc + pettanr.key.addKeyDownEvent( pettanr.view.OVERLAY, 27, false, false, pettanr.overlay.hide ); // 27.esc delete pettanr.overlay.init; }, - show: function( _currentOverlay){ - if( visible === true && currentOverlay === _currentOverlay) return; + show: function( _overlay, _bootParams ){ + if( visible === true && currentOverlay === _overlay ) return; + if( pettanr.view.isApplicationInstance( _overlay ) === false ) return; + + document.body.style.overflow = 'hidden'; + document.body.appendChild( ELM_CONTAINER ); // ie6-8 で必要、なんで、、、? + + this.visible = visible = true; + this.currentID = _overlay.ID; + currentOverlay = _overlay; + bootParams = _bootParams; + jqConteiner.stop().css( { filter: '', - opacity: '' - }).fadeIn(); - this.visible = visible = true; - currentOverlay = _currentOverlay; - this.currentID = _currentOverlay.ID; - jqCloseButton.toggle( !!_currentOverlay.onClose); + opacity: '', + top: document.documentElement.scrollTop || document.body.scrollTop + }).fadeIn( onFadeInComplete ); + + currentOverlay.rootElement.style.display = ''; + currentOverlay.rootElement.style.visibility = 'visible'; + + ELM_CONTAINER.insertBefore( currentOverlay.rootElement, document.getElementById( 'overlay-close-button' )); + + if( Type.isArray( bootParams ) === true ){ + bootParams.unshift( windowW, windowH ) + currentOverlay.open.apply( currentOverlay, bootParams ); + } else { + currentOverlay.open( windowW, windowH, bootParams ); + } }, hide: function(){ - currentOverlay = null; if( visible === false) return; + document.body.style.overflow = ''; + jqConteiner.stop().css( { filter: '', opacity: '' - }).fadeOut(); + }).fadeOut( onFadeOutComplete ); this.visible = visible = false; this.currentID = null; }, visible: visible, currentID: null, - onWindowResize: function( _windowW, _windowH){ - jqConteiner.css( { height: _windowH}); - jqShadow.css( { height: _windowH}); + onWindowResize: function( _windowW, _windowH ){ windowW = _windowW; - windowH = _windowH; + windowH = _windowH; + + if( currentOverlay === null ) return; + + jqConteiner.css({ + height: _windowH, + top: document.documentElement.scrollTop || document.body.scrollTop + }); + jqShadow.css( { height: _windowH }); // 先にeditorのcanvasを確定する。 - currentOverlay && currentOverlay.onWindowResize && setTimeout( asyncResize, 0); + setTimeout( asyncResize, 0); } } })(); @@ -1295,21 +1094,21 @@ pettanr.key = ( function(){ log.html( [ e.keyCode, e.shiftKey, e.ctrlKey, e.altKey, e.type].join( ',')); //keyOperationChatcher.val( ''); var cancel = false, - callback = e.type, + type = e.type, key = e.keyCode, overlayEnabled = pettanr.overlay.visible === true, currentViewID = overlayEnabled === true ? pettanr.overlay.currentID : pettanr.view.currentID; - if( callback === 'keypress') callback = 'keydown'; - if( pettanr.form.keyEventRellay( e) === false){ + if( type === 'keypress') type = 'keydown'; + if( pettanr.form.keyEventRellay( e ) === false ){ var shift = e.shiftKey, ctrl = e.ctrlKey, l = KEYEVENT_ARRAY.length, d; if( key === 16 || e.shiftKey === true){ - shiftEnabled = callback !== 'keyup'; + shiftEnabled = type !== 'keyup'; } if( key === 17 || e.ctrlKey === true){ - ctrlEnabled = callback !== 'keyup'; + ctrlEnabled = type !== 'keyup'; } 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 ){ + 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に一致させるため、角度を絞りつつ計算 @@ -1681,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, @@ -1814,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 ); + } + + 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'))) : ''; } - var serverImage = function( url, w, h, onLoadCallback){ + 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 = [], @@ -2002,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(){ + })(); /* @@ -2028,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 } @@ -2041,155 +2335,370 @@ 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 1){ + var _cssTexts = _elm.style.cssText.split( ';'), _css, + _separate, + _cssObject = {}, _target, _value, _number, _px, + j; + for(var i=0, l=_cssTexts.length; i= 3){ + _target = _css.substr( 0, _separate +1); + _value = _css.substr( _separate +1); + /* + * ie filter + */ + if( _target === FILTER){ + for( j=0; j<_numAttributes; ++j){ + if( _targetAttributes[ j] === OPACITY){ + _cssTexts[ i] = [ + _target, ':', + _value.replace( REG_ALPHA, "alpha(opacity=" + _updateParameters[ j] * 100 + ")") + ].join( ''); + break; + } + } + /* + * other + */ + } else { + _number = '' + parseFloat( _value); + _px = _value.indexOf( _number); + _px = _px > 0 ? _value.substr( _px + _number.length) : ''; + for( j=0; j<_numAttributes; ++j){ + if( _targetAttributes[ j] === _target){ + _cssTexts[ i] = [ _target, ':', _updateParameters[ j], _px].join( ''); + break; + } + } + } + } + } + _elm.style.cssText = _cssTexts.join( ';'); + return; + } + /* + * 一度に update する Attributes が少ない場合、cssText は使用しない. + */ + } + + var AnimationTaskClass = function( ELM, currentParameters, offsetParameters, endParameters, targetAttributes, onComplete, onEnterFrame, numFrames){ + var l = targetAttributes.length; + return { + elm: ELM, + onEnterFrame: function(){ + var _updateCss = {}, i; + if( numFrames === 1){ + for( i=0; i