From fbc8e8aa4dc1607d4b8812dd8e923bc22b50e723 Mon Sep 17 00:00:00 2001 From: itozyun Date: Thu, 3 May 2012 00:03:27 +0900 Subject: [PATCH] pettanR version0.4.28 --- 0.4.x/javascripts/common.js | 1687 +++++++++++------- 0.4.x/javascripts/system.js | 1256 +++++++++---- 0.4.x/javascripts/work.js | 3261 +++++++++++++++------------------- 0.4.x/js/create_new_comic.js | 2 +- 0.4.x/stylesheets/common.css | 36 +- 0.4.x/stylesheets/work.css | 415 +++-- 0.4.x/test/activex.html | 3 +- 0.4.x/test/comic-html-structure.html | 407 ++++- 0.4.x/test/dynamic-comic-html.html | 206 +++ 0.4.x/test/flip.svg | 2 +- 0.4.x/test/index.html | 17 +- 0.4.x/test/pettanr.xsl | 1 + 0.4.x/test/svg.html | 1 + 0.4.x/test/transform.html | 1 + 0.4.x/test/type.html | 1 + 0.4.x/test/vertical-center.html | 350 ++++ 0.4.x/work.html | 220 ++- 17 files changed, 4669 insertions(+), 3197 deletions(-) create mode 100644 0.4.x/test/dynamic-comic-html.html create mode 100644 0.4.x/test/vertical-center.html diff --git a/0.4.x/javascripts/common.js b/0.4.x/javascripts/common.js index 744cd38..41d9bb2 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.15 + * version 0.4.28 * * 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 && Type.isArray(v) === false && typeof v === 'object'; }, isFunction : function(v) { return typeof v === 'function'; @@ -105,10 +105,10 @@ 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.13', + version: '0.4.28', init: function(){ jqWindow = $( window); jqDocument = $( document); @@ -118,7 +118,7 @@ var pettanr = ( function(){ _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"); @@ -511,7 +404,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); - } - } } - /* 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; - })(), - item; - origin.href = '#'; - for(var i=0, l = items.length; i _w || this.MIN_HEIGHT > _h ){ @@ -970,51 +756,206 @@ pettanr.view = ( function(){ this.MIN_WIDTH = 240; this.MIN_HEIGHT = 240; } + var AbstractApplication = function(){ - this.prototype = new AbstractBasicPane(); + this.displayName = 'app name'; + this.ID = 'app id'; + this.rootElement = null; + this.parentElement = null; + this.nextSibling = null; + this.open = function( _w, _h /*, _option */ ){ + 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 { + this.onOpen( _w, _h ); + } + } + this.close = function(){ + if( this.onClose() === false ){ + return false; + } + } + this.onOpen = function( _w, _h /*, _option */ ){ + // overrride + }; + this.onClose = function(){ + // overrride + return true; + } // false の場合、close の拒否 + } + AbstractApplication.prototype = new AbstractBasicPane(); + + 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 ); + + var navi = document.getElementById('global-navi'), + item = document.createElement('a'); + navi.appendChild( item ); + navi.style.width = ( ( item.offsetWidth || 80 ) * LUNCHER_APPLICATION_LIST.length ) + 'px'; + item.href = '#'; + item.appendChild( document.createTextNode( application.displayName )); + item.onclick = LoginUserNavi.show; + } + } + + function bootApplication( APPLICATIONorINDEX, _arguments ){ + if( isWorkPage === false ) return; + + var _application, + i, j, l, + nodesA = document.getElementById('global-navi').getElementsByTagName( 'a') || [], + _index = -1; + if( typeof APPLICATIONorINDEX === 'number' && APPLICATIONorINDEX < LUNCHER_APPLICATION_LIST.length){ + _application = LUNCHER_APPLICATION_LIST[ APPLICATIONorINDEX ]; + } else + if( typeof APPLICATIONorINDEX === 'string' ){ + for( i=0, l=LUNCHER_APPLICATION_LIST.length; i 0 ){ + var _arg = []; + for( i=0; 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 +cos( startRad ) * rx; + _startY = ry +sin( startRad ) * ry; + _endX = rx +cos( endRad) * rx; + _endY = ry +sin( 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; @@ -1626,7 +1884,7 @@ pettanr.balloon = ( function() { /* * */ - if( IS_VML === true){ + if( IS_VML === true ){ var _tailX = tailX *10, _tailY = tailY *10, __startX = startX *10, @@ -1636,67 +1894,65 @@ pettanr.balloon = ( function() { __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 ), l, round( __endY ), l, + round( __startX ), l, round( __startY ), + ' 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); + 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( ''); + 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 = draw; + this.angle = function( _a ){ + _a !== undefined && _a !== a && + vectorEnabled === false ? balloonUrlBuilder( _a ) : 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; } }; 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; @@ -1704,7 +1960,7 @@ pettanr.balloon = ( function() { return { createBalloon: function( _w, _h, _a){ - return XBROWSER_BALLOON_CLASS.apply( {}, [ _w, _h, _a]); + return new XBROWSER_BALLOON_CLASS( _w, _h, _a ); }, TYPE_NONE: 0, TYPE_SPEACH_BALLOON: 1, @@ -1738,6 +1994,122 @@ pettanr.balloon = ( function() { * -moz-transform:scale( -1, -1); */ pettanr.image = ( function(){ + + 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, @@ -1748,175 +2120,160 @@ pettanr.image = ( function(){ 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; + var css3Image = function( url, w, h, onLoadCallback ){ + var elmWrap = document.createElement( 'div' ), + elmImg, + loaded = false, + 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; + loaded = true; + 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; - 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; - } - } + 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( loaded === false ) 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 ); + retryTimer !== null && window.clearTimeout( retryTimer ); + fetch !== null && fetch.stop(); + elmWrap = elmImg = onLoadCallback = retryTimer = fetch = instance = null; } - var activexImage = css3Image; - var vmlImage = function( url, w, h, onLoadCallback){ - var elmWrap = document.createElement( 'div'), - vmlImg, - loaded = false, - retryTimer = null; + } + + var activexImage = css3Image; + + var vmlImage = function( url, w, h, onLoadCallback ){ + var elmWrap = document.createElement( 'div' ), + vmlImg, + loaded = false, + 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; + loaded = true; + 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; - 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( 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 ); } - var serverImage = function( url, w, h, onLoadCallback){ + this.destroy = function(){ + instance.destroy; + loaded === true && 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 ){ - 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; - } - } - } - })(); + } + + 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 = [], @@ -2005,10 +2362,10 @@ pettanr.bind = ( function(){ for( var i=0, l=_comicElements.length; i tag:ペン次郎 > ペン次郎:笑う @@ -46,6 +32,8 @@ pettanr.file = ( function(){ var REQUEST_CONTROLER = ( function(){ var REQUEST_TICKET_RESISTER = [], + currentTicket = null, + currentData = null, DATA_TYPE_ARRAY = 'json,xml,html,text'.split( ','), DATA_IS_JSON = 0, DATA_IS_XML = 1, @@ -63,21 +51,34 @@ pettanr.file = ( function(){ }; function request(){ - if( REQUEST_TICKET_RESISTER.length === 0) return; - var _ticket = REQUEST_TICKET_RESISTER.shift(); + if( currentTicket !== null ) return; + currentTicket = REQUEST_TICKET_RESISTER.shift(); $.ajax({ - url: _ticket.url, - dataType: _ticket.type, - success: function( _data){ - _ticket.onLoad( _ticket.data, _data); - }, - error: function(){ - ++numError; - _ticket.onError( _ticket.data); - } + url: currentTicket.url, + dataType: currentTicket.type, + success: onSuccess, + error: onError }); } + function onSuccess( _data ){ + currentData = _data; + window.setTimeout( asyncSuccess, 0 ); + } + function asyncSuccess(){ + currentTicket.onLoad( currentTicket.data, currentData ); + currentTicket = currentData = null; + REQUEST_TICKET_RESISTER.length !== 0 && window.setTimeout( request, 0 ); + } + function onError(){ + ++numError; + window.setTimeout( asyncError, 0 ); + } + function asyncError(){ + currentTicket.onError( currentTicket.data ); + currentTicket = null; + REQUEST_TICKET_RESISTER.length !== 0 && window.setTimeout( request, 0 ); + } return { getNumTask: function(){ return REQUEST_TICKET_RESISTER.length; @@ -85,9 +86,9 @@ pettanr.file = ( function(){ getNumError: function(){ return numError; }, - getJson: function( _data, _url, _onLoad, _onError){ + getJson: function( _data, _url, _onLoad, _onError ){ REQUEST_TICKET_RESISTER.push( new RequestTicketClass( DATA_IS_JSON, _data, _url, _onLoad, _onError)); - request(); + currentTicket === null && request(); } } })(); @@ -101,6 +102,18 @@ pettanr.file = ( function(){ TREE_ARRAY.push( _tree); return _tree; }, + getFileUID: function( FILEDATAorFILE ){ + if( FILEDATAorFILE instanceof FileClass ){ + return FILEDATAorFILE.getUID(); + } + + var uid = pettanr.util.getIndex( FILEDATA_RESITER, FILEDATAorFILE ); + if( uid === -1){ + uid = FILEDATA_RESITER.length; + FILEDATA_RESITER.push( FILEDATAorFILE ); + } + return uid; + }, getFileDataAccess: function( UIDorFILEorFILEDATA){ var _uid, _data, _access; @@ -109,7 +122,7 @@ pettanr.file = ( function(){ } else if( UIDorFILEorFILEDATA instanceof FileClass){ _uid = UIDorFILEorFILEDATA.getUID(); - _data = FILEDATA_RESITER[ _uid] || null; + _data = FILEDATA_RESITER[ _uid ] || null; } else { _data = UIDorFILEorFILEDATA || null; } @@ -120,7 +133,7 @@ pettanr.file = ( function(){ if( _access.DATA === _data) return _access; } return null; - }, + }, getFileData: function( UIDorFILEorFILEDATA){ var _access = FILE_CONTROLER.getFileDataAccess( UIDorFILEorFILEDATA); return _access !== null ? _access.DATA : null; @@ -154,11 +167,11 @@ pettanr.file = ( function(){ replace: function( _uid, _file, _newIndex){ }, - addEventListener: function( FILEorNULL, _eventType, _callback){ + addEventListener: function( FILEorNULL, _eventType, _callback ){ var _uid = FILEorNULL instanceof FileClass ? FILEorNULL.getUID() : FILEorNULL; EVENT_LISTENER_REGISTER.push( new FileEventTicketClass( _uid, _eventType, _callback)); }, - removeEventListener: function( FILEorNULL, _eventType, _callback){ + removeEventListener: function( FILEorNULL, _eventType, _callback ){ var _uid = FILEorNULL instanceof FileClass ? FILEorNULL.getUID() : FILEorNULL, _ticket; for(var i=0, l = EVENT_LISTENER_REGISTER.length; i 0 ){ + _stack.shift(); + } + if( STACK_LIST.length !== 0 ){ + window.setTimeout( dispatch, 0 ); + } + } + return { + addEvent: function( _callback, _eventType, _targetFile, _key, _value ){ + if( STACK_LIST.length === 0 ){ + window.setTimeout( dispatch, 0 ); + } + STACK_LIST.push( [ _callback, _eventType, _targetFile, _key, _value ] ); + } + } + })(); + + var TreeClass = function( rootFileData ){ + var PARENT_FILE_RESITER = [], ACCESS = { - dispatchFileEvent: dispatchFileEvent, - destroy: onDestroy + dispatchFileEvent: dispatchFileEvent }, EVENT_LISTENER_ARRAY = [], rootFile, - rootFileData, currentFile, - currentFileData, instance; - TREE_ACCESS_ARRAY.push( ACCESS); - - function onDestroy(){ - - } + TREE_ACCESS_ARRAY.push( ACCESS ); - function dispatchFileEvent( e){ + function dispatchFileEvent( e ){ var _eventType = e.eventType, _targetFile = e.targetFile, _uid = _targetFile.getUID(), _ticket, _type, _callback; - for(var i=0, l = EVENT_LISTENER_REGISTER.length; i= currentFile.getChildFileLength()) return; - PARENT_FILE_RESITER.unshift( currentFile); - currentFile = currentFile.getChildFileByIndex( _index); + PARENT_FILE_RESITER.unshift( currentFile ); + currentFile = currentFile.getChildFileByIndex( _index ); currentFile.getSeqentialFiles(); return currentFile; }, up: function( _index){ var l = PARENT_FILE_RESITER.length; if( l === 0) return null; + + if( currentFile ){ + var _currentFile = currentFile; + currentFile = null; + _currentFile.destroy(); + } if( typeof _index === 'number'){ if( _index >= l) return null; - currentFile = this.getParentFileAt( _index); + currentFile = this.getParentFileAt( _index ); PARENT_FILE_RESITER.splice( 0, l -_index); } else { currentFile = PARENT_FILE_RESITER.shift(); @@ -275,7 +318,17 @@ pettanr.file = ( function(){ FILE_CONTROLER.removeEventListener( null, _eventType, _callback); }, destroy: function(){ - FILE_CONTROLER.destroyTree( UID); + FILE_CONTROLER.destroyTree( instance.getUID() ); + // removeEvent + var _currentFile = currentFile; + currentFile = rootFile = rootFileData = null; + // currentFile, rootFile を null にしないと .File.destroy() ができない. + _currentFile.destroy(); + while( PARENT_FILE_RESITER.length > 0 ){ + _currentFile = PARENT_FILE_RESITER.shift(); + _currentFile.destroy(); + } + instance = null; } } }; @@ -302,64 +355,31 @@ pettanr.file = ( function(){ * fileの変更、それに付随して追加されたイベントは、TreeClassで管理される。 * treeがdestryされると、fileのイベントリスナーも全て削除される。 * 他の tree も data の共通する currentFile に対してのみは、file の変更イベントを受け取って流す. + * + * parentData のほうがいい! */ - var FileClass = function( TREE, parentFile, data){ - var uid = pettanr.util.getIndex( FILEDATA_RESITER, data ), + var FileClass = function( tree, parentData, data ){ + var uid = FILE_CONTROLER.getFileUID( data ), instance = this; - if( uid === -1){ - uid = FILEDATA_RESITER.length; - FILEDATA_RESITER.push( data ); - } - FILEDATA_ACCESS.push( { + TREE: tree, + parentData: parentData, DATA: data, - updateParent: updateParent, dispatchFileEvent: dispatchEvent } ); - - function updateParent( _parent){ - parentFile = _parent; - } - function dispatchEvent( e){ - FILE_CONTROLER.fileEventRellay( instance, TREE, e); - } - /* grobal Methods */ - + tree = parentData = data = null; + + function dispatchEvent( e ){ + FILE_CONTROLER.fileEventRellay( uid, e ); + } this.getUID = function(){ return uid; } - /* - * ファイル構造は TRON のような ハイパーリンク方式 だが、文脈上の 親ファイルが存在する.その親ファイルを使う操作は.prototype に置く事ができない. - * 同様に TREE を使う操作も .prototype に置く事ができない. - */ - this.getChildFileByIndex = function( _index){ - var _children = FILE_CONTROLER.getChildren( instance ); - if( typeof _index !== 'number' || _index < 0 || typeof _children.length !== 'number' || _index >= _children.length) return null; - var _file = new FileClass( TREE, this, _children[ _index]); - // _file.init(); - return _file; - } - this.move = function( _newFolder, _newIndex, opt_callback){ - TREE.move( parentFile, UID, _newFolder, _newIndex, opt_callback); - } - this.replace = function( _newIndex, opt_callback){ - TREE.replace( parentFile, UID, _newIndex, opt_callback); - } - this.destroy = function(){ - var _access = FILE_CONTROLER.getFileDataAccess( instance ); - _index = getChildIndex( FILEDATA_ACCESS, _access ); - if( _index === -1 || _access === null) return; - FILEDATA_ACCESS.splice( _index, 1); - TREE = parentFile = data = null; - delete _access.DATA; - delete _access.updateParent; - delete _access.dispatchFileEvent; - } }; FileClass.prototype = { @@ -368,31 +388,39 @@ pettanr.file = ( function(){ }, getSeqentialFiles: function(){ var _driver = FILE_CONTROLER.getDriver( this ); - if( _driver !== null && typeof _driver.getSeqentialFiles === 'function'){ + if( _driver !== null && typeof _driver.getSeqentialFiles === 'function' ){ _driver.getSeqentialFiles( this ); } }, - addEventListener: function( _eventType, _callback){ - FILE_CONTROLER.addEventListener( this, _eventType, _callback); + addEventListener: function( _eventType, _callback ){ + FILE_CONTROLER.addEventListener( this, _eventType, _callback ); }, - removeEventListener: function( _eventType, _callback){ - FILE_CONTROLER.removeEventListener( this, _eventType, _callback); + removeEventListener: function( _eventType, _callback ){ + FILE_CONTROLER.removeEventListener( this, _eventType, _callback ); }, getChildFileLength: function(){ - var children = FILE_CONTROLER.getChildren( this); + var children = FILE_CONTROLER.getChildren( this ); return Type.isArray( children ) === true ? children.length : -1; }, - getChildFileIndex: function( _FILEorFILEDATA){ + getChildFileIndex: function( _FILEorFILEDATA ){ var children = FILE_CONTROLER.getChildren( this); - if( Type.isArray( children.length ) === false ) return -1; + if( Type.isArray( children ) === false ) return -1; var l = children.length, - _fileData = FILE_CONTROLER.getFileData( _FILEorFILEDATA); - if( _fileData === null) return -1; - for(var i=0; i= _children.length) return null; + var _file = new FileClass( _access.TREE, _access.DATA, _children[ _index ]); + // _file.init(); + return _file; + }, getName: function(){ var driver = FILE_CONTROLER.getDriver( this ); if( typeof driver.getName === 'function'){ @@ -423,33 +451,44 @@ pettanr.file = ( function(){ return FileDriverBase.getSummary( this); }, isWritable: function(){ - return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.WRITE); + return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.WRITE ); }, isSortable: function(){ - return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.SORT); + return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.SORT ); }, isCreatable: function(){ - return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.CREATE); + return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.CREATE ); }, isRenamable: function(){ - return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.RENAME); + return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.RENAME ); + }, + isDeletable: function(){ + return FILE_CONTROLER.getUpdateFlag( this, pettanr.file.FILE_UPDATE_POLICY.DELETE ); }, read: function(){ // simpleDeepCopy - return false; + var driver = FILE_CONTROLER.getDriver( this ); + if( typeof driver.read === 'function'){ + return driver.read( this ); + } + return FileDriverBase.read( this ); }, - write: function( _newName, _newData){ - return false; + write: function( _newData, _onUpdateFunction ){ + var driver = FILE_CONTROLER.getDriver( this ); + if( typeof driver.write === 'function'){ + return driver.write( this, _newData, _onUpdateFunction ); + } + return FileDriverBase.write( this, _newData, _onUpdateFunction ); }, - viwerApplicationList: function(){ + viewerApplicationList: function(){ var driver = FILE_CONTROLER.getDriver( this ); - if( typeof driver.viwerApplicationList === 'function'){ - return driver.viwerApplicationList( this ); + if( typeof driver.viewerApplicationList === 'function'){ + return driver.viewerApplicationList( this ); } - return FileDriverBase.viwerApplicationList( this ); + return FileDriverBase.viewerApplicationList( this ); }, editorApplicationList: function(){ - var driver = FILE_CONTROLER.editorApplicationList( this ); + var driver = FILE_CONTROLER.getDriver( this ); if( typeof driver.editorApplicationList === 'function'){ return driver.editorApplicationList( this ); } @@ -466,6 +505,54 @@ pettanr.file = ( function(){ }, onDelete: function(){ + }, + move: function( _newFolder, _newIndex, opt_callback ){ + var _access = FILE_CONTROLER.getFileDataAccess( this ); + _access.TREE.move( _access.parentData, this.getUID(), _newFolder, _newIndex, opt_callback ); + }, + replace: function( _newIndex, opt_callback ){ + var _access = FILE_CONTROLER.getFileDataAccess( this ); + _access.TREE.replace( _access.parentData, this.getUID(), _newIndex, opt_callback); + }, + /** + * サーチ + * 探しているファイルの属性と値を指定.一致する child の index を配列で返す. + */ + search: function( obj, rule ){ + var _children = FILE_CONTROLER.getChildren( this ), + _child, + ret = [], k, c; + for( var i=0, l=_children.length; i 0 ){ + ELM_VIEWER_BUTTON.style.display = ''; + } else { + ELM_VIEWER_BUTTON.style.display = 'none'; + }; + if( Type.isArray( editorList ) === true && editorList.length > 0 ){ + ELM_EDITOR_BUTTON.style.display = ''; + } else { + ELM_EDITOR_BUTTON.style.display = 'none'; + }; } function resize(){ - ELM_WRAPPER.style.top = (index * ICON_HEIGHT) +'px'; + // ELM_WRAPPER.style.top = (index * ICON_HEIGHT) +'px'; } function onCollect(){ - elmContainer.removeChild( ELM_WRAPPER); + elmContainer.removeChild( ELM_WRAPPER ); elmContainer = null; - FINDER_ICON_POOL.push( instansce); + FINDER_ICON_POOL.push( instansce ); } return { - init: function( _file, _elmContainer, _w, _index, _style, _callback){ + init: function( _file, _elmContainer, _w, _index, _style, _onDownCallback, _onEditorCallback, _onViewerCallback, _onActionCallback ){ instansce = this; if( elmContainer !== _elmContainer){ _elmContainer.appendChild( ELM_WRAPPER); elmContainer = _elmContainer; } if( file !== _file){ + file && file.destroy(); file = _file; + viewerList = file.viewerApplicationList(); + editorList = file.editorApplicationList(); draw(); } if( index !== _index){ index = _index; resize(); } - callback = _callback; + onDownCallback = _onDownCallback; + onEditorCallback = _onEditorCallback; + onViewerCallback = _onViewerCallback; + onActionCallback = _onActionCallback; }, elm: ELM_WRAPPER, index: function( _index){ @@ -736,12 +908,13 @@ pettanr.finder = ( function(){ return style; }, - onResize: function( w){ + onResize: function( w ){ }, destroy: function(){ - elmContainer.removeChild( ELM_WRAPPER); - file = elmContainer = null; + elmContainer.removeChild( ELM_WRAPPER ); + file && file.destroy(); + file = elmContainer = onDownCallback = onEditorCallback = onViewerCallback = onActionCallback = viewerList = editorList = null; FINDER_ICON_POOL.push( instansce); } } @@ -769,9 +942,9 @@ pettanr.finder = ( function(){ } return { - init: function( _file, _elmContainer, _index, _callback){ + init: function( _file, _elmContainer, _index, _callback ){ instansce = this; - if( elmContainer !== _elmContainer){ + if( elmContainer !== _elmContainer ){ _elmContainer.appendChild( ELM_WRAPPER); elmContainer = _elmContainer; } @@ -796,7 +969,7 @@ pettanr.finder = ( function(){ destroy: function(){ elmContainer.removeChild( ELM_WRAPPER); file = elmContainer = null; - BREAD_OBJECT_POOL.push( this); + BREAD_OBJECT_POOL.push( this ); } } } @@ -804,9 +977,9 @@ pettanr.finder = ( function(){ var FinderClass = function( ELM_CONTAINER, tree, header, footer ){ var ICON_ARRAY = [], BREAD_ARRAY = [], - elmContainer = ELM_ORIGIN_CONTAINER.cloneNode( true), - elmLocation = elmContainer.getElementsByTagName( 'ul')[0], - nodesDiv = elmContainer.getElementsByTagName( 'div'), + elmContainer = ELM_ORIGIN_CONTAINER.cloneNode( true ), + elmLocation = elmContainer.getElementsByTagName( 'ul' )[0], + nodesDiv = elmContainer.getElementsByTagName( 'div' ), elmSidebarButton = nodesDiv[1], elmStyleButton = nodesDiv[2], elmActionButton = nodesDiv[3], @@ -822,14 +995,16 @@ pettanr.finder = ( function(){ iconW = size.width, iconH = size.height, style = 0, - w, h, bodyH; + w, h, bodyH, + instance = this; - tree.addTreeEventListener( pettanr.file.TREE_EVENT.UPDATE, draw); + tree.addTreeEventListener( pettanr.file.TREE_EVENT.UPDATE, draw ); + ELM_CONTAINER.appendChild( elmContainer ); function draw( _w, _h ){ w = Type.isFinite( _w ) === true ? _w : w; h = Type.isFinite( _h ) === true ? _h : h; - bodyH = _h - headH; + bodyH = h - headH; var l = tree.hierarchy() +1, m = BREAD_ARRAY.length, _file, _bread; @@ -838,7 +1013,7 @@ pettanr.finder = ( function(){ if( i < m){ BREAD_ARRAY[ i].init( _file, elmLocation, i, onHeadClick); } else { - BREAD_ARRAY.push( getBreadcrumb( _file, elmLocation, i, onHeadClick)); + BREAD_ARRAY.push( getBreadcrumb( _file, elmLocation, i, onHeadClick )); } } while( l < BREAD_ARRAY.length){ @@ -850,9 +1025,9 @@ pettanr.finder = ( function(){ for( i=0; i 0){ _icon = FINDER_ICON_POOL.shift(); } else { _icon = new FinderIconClass(); } - _icon.init( _file, _elmContainer, w, index, style, callback); + _icon.init( _file, _elmContainer, w, index, style, onDown, onEditor, onViwer, onAction ); return _icon; } @@ -946,9 +1127,11 @@ pettanr.finder = ( function(){ init: function(){ }, - createFinder: function( _elmTarget, _tree, _header, _footer ){ + createFinder: function( _applicationReference, _elmTarget, _tree, _header, _footer ){ + if( pettanr.view.isApplicationReference( _applicationReference ) === false ) return; + var _finder = new FinderClass( _elmTarget, _tree, _header, _footer ); - FINDER_ARRAY.push( _finder); + FINDER_ARRAY.push( _finder ); return _finder; }, registerFinderHead: function(){ @@ -977,7 +1160,11 @@ pettanr.driver = ( function(){ var _data = FileAPI.getFileData( _file), _json = _data !== null ? _data.json : null; if( _json === true && _data.type === pettanr.driver.FILE_TYPE.COMIC ){ - _json = [ pettanr.CONST.PETTANR_ROOT_PATH, 'comics\/', _data.id, '.json\/play\/' ].join( '' ); + if( pettanr.LOCAL === true ){ + _json = [ 'json\/comics_', _data.id, '.json' ].join( '' ); + } else { + _json = [ pettanr.CONST.PETTANR_ROOT_PATH, 'comics\/', _data.id, '.json\/play\/' ].join( '' ); + } } if( typeof _json === 'string'){ FileAPI.getJson( _file, _json, onLoadJson, onErrorJson); @@ -999,10 +1186,10 @@ pettanr.driver = ( function(){ return _data.title; } else if( _type === pettanr.driver.FILE_TYPE.ARTIST ){ - return [ _data.id , ':', _data.name, '画伯' ].join( ''); + return [ _data.name, '画伯' ].join( ''); } else if( _type === pettanr.driver.FILE_TYPE.AUTHOR ){ - return [ _data.id , ':', _data.name, '先生' ].join( ''); + return [ _data.name, '先生' ].join( ''); } return _data.name; }, @@ -1042,34 +1229,62 @@ pettanr.driver = ( function(){ return 'cabinet file'; } if( _type === pettanr.driver.FILE_TYPE.COMIC){ - return 'comic file'; + return 'comic file, id:' + _data.id; } if( _type === pettanr.driver.FILE_TYPE.PANEL){ return [ _data.width, 'x', _data.height ].join( '' ); } if( _type === pettanr.driver.FILE_TYPE.AUTHOR){ - return 'author file'; + return 'author file, id:' + _data.id; } if( _type === pettanr.driver.FILE_TYPE.ARTIST){ - return [ 'Email:', _data.email || 'empty' , ', HP:', _data.homepage_url || 'empty' ].join( '' ); + return [ 'id:', _data.id, ' Email:', _data.email || 'empty' , ', HP:', _data.homepage_url || 'empty' ].join( '' ); } if( _type === pettanr.file.FILE_TYPE.FOLDER){ return 'pettanR folder'; } return 'pettanR unknown file'; }, - viwerApplicationList: function( _file ){ + write: function( _file, _newData, _onUpdateFunction ){ var _data = FileAPI.getFileData( _file ), _type = _data !== null ? _data.type : null; + if( _type === pettanr.driver.FILE_TYPE.COMIC ){ + } + if( _type === pettanr.driver.FILE_TYPE.PANEL ){ + } + if( _type === pettanr.driver.FILE_TYPE.PANEL_PICTURE ){ + + } + if( _type === pettanr.driver.FILE_TYPE.BALLOON ){ + } + if( _type === pettanr.driver.FILE_TYPE.PICTURE ){ + } + }, + viewerApplicationList: function( _file ){ + var _data = FileAPI.getFileData( _file ), + _type = _data !== null ? _data.type : null; + + if( _data === FILE_DATA_MY_PICTURES_ROOT ){ + return [ pettanr.premiumSatge ]; + } + if( _type === pettanr.driver.FILE_TYPE.ARTIST ){ + return [ pettanr.premiumSatge ]; + } return []; }, editorApplicationList: function( _file ){ var _data = FileAPI.getFileData( _file ), _type = _data !== null ? _data.type : null; + if( _type === pettanr.driver.FILE_TYPE.PANEL ){ + return [ pettanr.editor ]; + } + if( _type === pettanr.driver.FILE_TYPE.COMIC ){ + return [ pettanr.editor, pettanr.comicConsole ]; + } return []; } }, - FileAPI = pettanr.file.registerDriver( Driver), + FileAPI = pettanr.file.registerDriver( Driver ), FILE_DATA_SERVICE_ROOT = { name: 'PettanR root', type: pettanr.file.FILE_TYPE.FOLDER, @@ -1100,7 +1315,8 @@ pettanr.driver = ( function(){ name: 'My Comics', type: pettanr.file.FILE_TYPE.FOLDER, children: [], - driver: Driver + driver: Driver, + id: MyAuthorID }, FILE_DATA_LATEST_COMICS = { name: 'Latest Comics', @@ -1112,7 +1328,8 @@ pettanr.driver = ( function(){ type: pettanr.file.FILE_TYPE.FOLDER, children: [], driver: Driver, - json: pettanr.CONST.URL_ORIGINAL_PICTURES_JSON + json: pettanr.CONST.URL_ORIGINAL_PICTURES_JSON, + id: MyArtistID }, FILE_DATA_AUTHOR_ROOT = { name: 'Authors', @@ -1293,13 +1510,13 @@ pettanr.driver = ( function(){ _data.author = getResource( AUTHOR_ARRAY, _data.author_id ); // picture data をファイルに取り出し - if( Type.isArray( _data.panel_elements ) === true ){ - var _elements, - _elm, _rpic; + var _elements = _data.panel_elements, + _elm; + if( Type.isArray( _elements ) === true ){ for( i=0, l=_elements.length; 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); + } + + var wrap = document.getElementById('inner-wrapper'), + pageHeaderH = pettanr.util.getElementSize( document.getElementById( 'header' )).height, + instance = this; + + this.displayName = 'Debug'; + this.ID = 'debug'; + this.rootElement = document.getElementById( 'debug' ); + this.onOpen = function( _w, _h, _option ){ + wrap.style.display = ''; + wrap.style.height = ( _h - pageHeaderH ) + 'px'; + } + this.onClose = function(){ + wrap.style.display = 'none'; + } + this.onPaneResize = function( _w, _h ){ + instance.onOpen( _w, _h ); + } + }); + pettanr.debug.addToLancher(); + +} else { + var _debug = document.getElementById( 'debug'); + if( _debug){ + pettanr.util.removeAllChildren( _debug); + _debug.parentNode.removeChild( _debug); + _debug = null; + } +} + +/* ---------------------------------------- + * Image Group Exproler + * - overlay + */ +pettanr.premiumSatge = pettanr.view.registerApplication( function(){ + var ICON_ARRAY = [], + WHEEL_DELTA = 64, + ARTIST_TREE = pettanr.driver.createArtistTree(), + ARTIST_ROOT_FILE = ARTIST_TREE.getRootFile(), + instance = this, + winW, winH, + wrapX, + elmWrap = document.getElementById( 'image-group-wrapper' ), + elmContainer = document.getElementById( 'image-group-icon-container' ), + containerW, + containerH = pettanr.util.getElementSize( elmContainer ).height, + elmIconOrigin = ( function(){ + var ret = document.createElement( 'div' ), + data = document.createElement( 'div' ); + ret.appendChild( data ); + ret.className = 'image-group-item'; + data.className = 'image-group-item-title'; + return ret; + })(), + jqContainer, + size = pettanr.util.getElementSize( elmIconOrigin ), + itemW = size.width, + itemH = size.height, + elmName = document.getElementById( 'image-group-name' ), + elmButton = document.getElementById( 'image-group-button' ), + buttonW = pettanr.util.getElementSize( elmButton ).width, + //onUpdateFunction, + onUpdateFunction = null, + onUpdateData = null, + artistID = -1, + onEnterInterval = null; + + elmButton.onclick = clickOK; + + var BASE_PATH = pettanr.LOCAL === true ? 'resource_pictures\/' : pettanr.CONST.PETTANR_ROOT_PATH + 'resource_pictures\/', + THUMB_PATH = BASE_PATH, // + 'thumbnail/', + LIMIT_FILESIZE = 1024 * 10; // 10KB + + var ImageGroupIconClass = function( INDEX, data ){ + var elmIconWrap = elmIconOrigin.cloneNode( true ), + elmIconTitle = pettanr.util.getElementsByClassName( elmIconWrap, 'image-group-item-title' )[ 0 ], + SRC = [ BASE_PATH, data.id, '.', data.ext ].join( ''), + LOW_SRC = data.filesize && data.filesize > LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext ].join( '') : null, + reversibleImage = null, + timer = null, + onEnterFlag = false, + instance = this; + elmContainer.appendChild( elmIconWrap ); + elmIconWrap.style.left = ( INDEX * itemW ) + 'px'; + elmIconTitle.appendChild( document.createTextNode( data.filesize + 'bytes' ) ); + + function onImageLoad( url, _imgW, _imgH ){ + data.width = _imgW = _imgW || data.width || 64; + data.height = _imgH = _imgH || data.height || 64; + elmIconTitle.firstChild.data = _imgW + 'x' + _imgH; + var zoom = 128 /( _imgW > _imgH ? _imgW : _imgH ), + MATH_FLOOR = Math.floor, + h = MATH_FLOOR( _imgH * zoom ), + w = MATH_FLOOR( _imgW * zoom ); + reversibleImage.elm.style.cssText = [ + 'width:', w, 'px;', + 'height:', h, 'px;', + 'margin:', MATH_FLOOR( itemH / 2 - h / 2 ), 'px ', MATH_FLOOR( itemW / 2 - w / 2 ), 'px 0' + ].join(''); + reversibleImage.resize( w, h ); + elmIconWrap.onclick = onClick; + } + + function onClick(){ + onUpdateData = data; + pettanr.premiumSatge.shutdown(); + } + + function asyncDraw(){ + reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onImageLoad ); + elmIconWrap.appendChild( reversibleImage.elm ); + onEnterFlag = true; + timer = null; + } + + this.onEnter = function( delay ){ + timer = window.setTimeout( asyncDraw, delay ); + delete instance.onEnter; + } + this.destroy = function(){ + delete instance.destroy; + timer && window.clearTimeout( timer ); + reversibleImage && reversibleImage.destroy(); + pettanr.util.removeAllChildren( elmIconWrap ); + elmContainer.removeChild( elmIconWrap ); + elmIconWrap.onclick = ''; + reversibleImage = elmIconWrap = elmIconTitle = data = timer = null; + } + } + + function onEnterShowImage(){ + var l = ICON_ARRAY.length, + _start = -wrapX /itemW -1, + _end = _start + winW /itemW +1, + _icon; + for( var i=0, c = 0; i 0 ? 0 : wrapX < winW -containerW ? winW -containerW : wrapX; + jqContainer.css( { left: wrapX}); - }, - onClose: function(){ - finder.onClose(); - }, - onWindowResize: function( _w, _h){ - finder.resize( _w, _h - pageHeaderH); + onEnterInterval !== null && window.clearTimeout( onEnterInterval ); + onEnterInterval = window.setTimeout( onEnterShowImage, 500 ); } + //e.stopPropagation(); + return false; } -})(); + + function drawIcons(){ + while( ICON_ARRAY.length > 0 ){ + ICON_ARRAY.shift().destroy(); + } + + var _index = ARTIST_ROOT_FILE.search( { + id: artistID, + type: pettanr.driver.FILE_TYPE.ARTIST + })[ 0 ], + _artistFile = ARTIST_ROOT_FILE.getChildFileByIndex( _index ), + _file; + if( _artistFile !== null ){ + for(var i=0, l=_artistFile.getChildFileLength(); i 0 ){ + ICON_ARRAY.shift().destroy(); + } + onUpdateFunction !== null && onUpdateData !== null && onUpdateFunction( onUpdateData ); + onUpdateFunction = onUpdateData = null; + } + + /* grobal method */ + // this.rootElement = elmWrap; + this.displayName = 'premiumStage'; + this.ID = 'premiumStage'; + this.rootElement = elmWrap; + this.MIN_WIDTH = 320; + this.MIN_HEIGHT = 320; + this.init = function(){ + jqContainer = $( elmContainer ).mousewheel( onMouseWheel ); + + // よくない! 一時的な処理,,, + //var tree = pettanr.driver.createPictureTree(); + //tree.addTreeEventListener( pettanr.file.TREE_EVENT.UPDATE, drawIcons ); + + delete instance.init; + } + this.onOpen = function( _windowW, _windowH, _ARTISTIDorFILE, _onUpdateFunction ){ + instance.init && instance.init(); + + if( pettanr.driver.isPettanrFileInstance( _ARTISTIDorFILE ) === true ){ + var _data = pettanr.driver._getAPI().getFileData( _ARTISTIDorFILE ); + if( _ARTISTIDorFILE.getType() === pettanr.driver.FILE_TYPE.ARTIST || pettanr.driver._getMyPicturesData() === _data ){ + artistID = _data.id || -1; + } + } else + if( Type.isNumber( _ARTISTIDorFILE ) === true ){ + artistID = _ARTISTIDorFILE; + } + + onUpdateFunction = _onUpdateFunction || null; + onUpdateData = null; + + drawIcons(); + + wrapX = 0; + containerW = ICON_ARRAY.length * itemW; + + winW = _windowW; + winH = _windowH; + var w = winW > containerW ? winW : containerW, + h = _windowH > containerH ? containerH : _windowH, + MATH_FLOOR = Math.floor; + + jqContainer.css( { + width: w, + height: 0, + left: 0, + top: MATH_FLOOR( _windowH /2) + }).stop().animate( { + height: h, + top: MATH_FLOOR( _windowH /2 -h /2) + }, onEnterShowImage ); + + elmButton.style.cssText = [ + 'left:', MATH_FLOOR( winW /2 - buttonW /2), 'px;', + 'top:', MATH_FLOOR( _windowH /2 + containerH /2 +10), 'px' + ].join(''); + } + this.onPaneResize = function( _windowW, _windowH ){ + var w = _windowW > containerW ? _windowW : containerW, + h = _windowH > containerH ? containerH : _windowH, + MATH_FLOOR = Math.floor, + offsetW = MATH_FLOOR( _windowW /2 -winW /2); + + winW = _windowW; + winH = _windowH; + 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 + }); + } + elmButton.style.cssText = [ + 'left:', MATH_FLOOR( _windowW /2 -buttonW /2), 'px;', + 'top:', MATH_FLOOR( _windowH /2 +containerH /2 +10), 'px' + ].join(''); + onEnterShowImage(); + } + this.onClose = function(){ + jqContainer.stop().animate( { + height: 0, + top: Math.floor( winH /2 ) + }, onFadeout ); + onEnterInterval !== null && window.clearTimeout( onEnterInterval ); + onEnterInterval = null; + } +}); + + +/* ---------------------------------------- + * Text Editor + * - overlay + */ +pettanr.textEditor = pettanr.view.registerApplication( function(){ + var jqWrap, jqTextarea, jqButton, + textElement, onUpdateFunction, + ID = 'textEditor', + panelX, panelY, + instance = this; + //pettanr.key.addKeyDownEvent( ID, 69, false, false, clickOK); + + function clickOK(){ + textElement && textElement.text( jqTextarea.val() ); + window.setTimeout( asyncCallback, 0 ); + } + + function asyncCallback(){ + onUpdateFunction && onUpdateFunction( textElement ); + onUpdateFunction = textElement = null; + pettanr.textEditor.shutdown(); + } + + function keyCancel( e ){ + if( e.keyCode === 69 && e.shiftKey === false && e.ctrlKey === true){ + clickOK(); + e.preventDefault(); + e.keyCode = 0; + e.cancelBubble = true; + e.returnValue = false; + return false; + } + } + function textareaFitHeight(){ + var rows = 0; + while( jqTextarea.height() < textElement.h ){ + rows++; + jqTextarea.attr( 'rows', rows ); + } + rows > 1 && jqTextarea.attr( 'rows', --rows ); + } + + /* grobal method */ + // this.rootElement = elmWrap; + this.displayName = 'textEditor'; + this.ID = 'textEditor'; + this.rootElement = document.getElementById( 'speach-editor-wrapper' ); + this.MIN_WIDTH = 320; + this.MIN_HEIGHT = 320; + this.init = function(){ + jqWrap = $( '#speach-editor-wrapper' ).hide(); + jqTextarea = $( '#speach-editor' ).keydown( keyCancel ); + jqButton = $( '#speach-edit-complete-button').click( clickOK ); + delete instance.init; + } + this.onOpen = function( _w, _h, _panelX, _panelY, _textElement, _onUpdateFunction ){ + instance.init && instance.init(); + + panelX = _panelX; + panelY = _panelY; + textElement = _textElement; + onUpdateFunction = _onUpdateFunction || null; + + jqWrap.show(); + instance.onPaneResize( _w, _h ); + jqTextarea.val( _textElement.text() ).focus(); + + /* + * ie6,7は、textarea { width:100%}でも高さが変わらない。rowsを設定。 + */ + pettanr.ua.isIE === true && pettanr.ua.ieVersion <= 7 && setTimeout( textareaFitHeight, 0); + } + this.onPaneResize = function( _w, _h ){ + jqWrap.css( { + left: textElement.x + panelX, + top: textElement.y + panelY, + width: textElement.w, + height: textElement.h + }); + } + this.onClose = function(){ + jqWrap.hide(); + } +}); // i18n // login @@ -1462,10 +2096,6 @@ pettanr.fn( pettanr.key); pettanr.fn( pettanr.balloon); pettanr.fn( pettanr.editor); -pettanr.fn( pettanr.comicConsole); -pettanr.fn( pettanr.uploadConsole); -pettanr.fn( pettanr.panelConsole); -pettanr.fn( pettanr.artistConsole); pettanr.fn( pettanr.file); pettanr.fn( pettanr.finder); diff --git a/0.4.x/javascripts/work.js b/0.4.x/javascripts/work.js index 291ee01..8565e27 100644 --- a/0.4.x/javascripts/work.js +++ b/0.4.x/javascripts/work.js @@ -1,6 +1,6 @@ /* * pettanR work.js - * version 0.4.15 + * version 0.4.28 * * author: * itozyun @@ -37,8 +37,6 @@ * - MENU_BAR_CONTROL * - HISTORY_CONTROL * - SAVE_CONTROL - * - TEXT_EDITOR_CONTROL - * - IMAGE_GROUP_EXPROLER * - WINDOW_CONTROL * - WindowClass * - INFOMATION_WINDOW @@ -67,12 +65,12 @@ * * */ -pettanr.editor = ( function(){ +pettanr.editor = pettanr.view.registerApplication( function(){ - var COMIC_ELEMENT_TYPE_IMAGE = 0, - COMIC_ELEMENT_TYPE_TEXT = 1, + var PANEL_ELEMENT_TYPE_IMAGE = 0, + PANEL_ELEMENT_TYPE_TEXT = 1, MOUSE_LISTENER_ARRAY = [], - COMIC_ELEMENT_ARRAY = [], + PANEL_ELEMENT_ARRAY = [], ELM_MOUSE_EVENT_CHATCHER = document.getElementById( 'mouse-operation-catcher'), MIN_PANEL_HEIGHT = 20, MIN_ELEMENT_SIZE = 19, @@ -82,7 +80,11 @@ pettanr.editor = ( function(){ windowW, windowH, currentListener = null, currentCursor = '', + instance = this, option, + comicID = -1, + panelID = -1, + panelTimming = -1, log; /* ---------------------------------------- @@ -128,7 +130,7 @@ pettanr.editor = ( function(){ jqStage, jqBar; ELM_BAR.style.top = ( -barH) +'px'; - var MenubarSelectionClass = function( container, title, shortcut, visible, separateAfter){ + var MenubarSelectionClass = function( container, title, shortcut, visible, separateAfter ){ var ELM_WRAPPER = ELM_SELECTION_ORIGN.cloneNode( true), ELM_TITLE = ELM_WRAPPER.getElementsByTagName( 'span')[ 0], elmShortcut = ELM_WRAPPER.getElementsByTagName( 'kbd')[ 0]; @@ -182,8 +184,7 @@ pettanr.editor = ( function(){ ELM_BAR.appendChild( ELM_WRAPPER); function onClick( e){ - var that = this, - i = pettanr.util.getChildIndex( this.parentNode, this); + var i = pettanr.util.getChildIndex( this.parentNode, this); i !== -1 && this.className !== 'disabled' && SELECTION_CALLBACK_ARRAY[ i]( i); e.stopPropagation(); return false; @@ -358,16 +359,16 @@ pettanr.editor = ( function(){ var _argBack = _stack.argBack, _argForword = _stack.argForword, _value; - if( typeof _argBack.length === 'number'){ // isArray + if( Type.isArray( _argBack ) === true ){ // isArray while( _argBack.length > 0){ _value = _argBack.shift(); - _destroy === true && typeof _value.destroy === 'function' && _value.destroy(); + _destroy === true && Type.isFunction( _value.destroy ) === true && _value.destroy(); } } - if( typeof _argForword.length === 'number'){ + if( Type.isArray( _argForword ) === true ){ while( _argForword.length > 0){ _value = _argForword.shift(); - _destroy === true && typeof _value.destroy === 'function' && _value.destroy(); + _destroy === true && Type.isFunction( _value.destroy ) === true && _value.destroy(); } } } @@ -383,10 +384,10 @@ pettanr.editor = ( function(){ MENUBAR_BACK.visible( false); MENUBAR_FORWARD.visible( false); while( STACK_BACK.length > 0){ - destroyStack( STACK_BACK.shift(), true); + destroyStack( STACK_BACK.shift(), true ); } while( STACK_FORWARD.length > 0){ - destroyStack( STACK_FORWARD.shift(), true); + destroyStack( STACK_FORWARD.shift(), true ); } }, saveState: function( _function, _argBack, _argForword, _destroy) { @@ -402,65 +403,13 @@ pettanr.editor = ( function(){ var _stack; while( STACK_FORWARD.length > 0){ _stack = STACK_FORWARD.shift(); - destroyStack( _stack, _stack.destroy); + destroyStack( _stack, _stack.destroy ); } MENUBAR_FORWARD.visible( false); } } })(); - -/* ---------------------------------------- - * OUTPUT_CONSOLE - * - overlay - */ - var OUTPUT_CONSOLE = ( function(){ - var jqWrap, jqOutputArea, - ID = 'outputConsole'; - //pettanr.key.addKeyDownEvent( ID, 69, false, false, clickOK); - - function close(){ - jqWrap.hide(); - jqOutputArea.val(''); - } - function clickOK(){ - pettanr.overlay.hide(); - close(); - } - return { - init: function(){ - this.jqWrap = jqWrap = $( '#output-console-wrapper').hide(); - jqOutputArea = $( '#output-area'); - delete OUTPUT_CONSOLE.init; - }, - jqWrap: null, - show: function( _text){ - jqWrap.show(); - - - pettanr.overlay.show( this); - jqWrap.css( - { - left: Math.floor( ( windowW -jqWrap.width()) /2), - top: Math.floor( ( windowH -jqWrap.height()) /2) - } - ); - - jqOutputArea.val( _text).focus(); - }, - onWindowResize: function(){ - jqWrap.css( - { - left: Math.floor( ( windowW -jqWrap.width()) /2), - top: Math.floor( ( windowH -jqWrap.height()) /2) - } - ); - }, - onClose: close, - ID: 'textEditor' - } - })(); - /* ---------------------------------------- * SAVE_CONTROL * - controler @@ -474,24 +423,35 @@ pettanr.editor = ( function(){ updated = false; function quit(){ - // 本来は os.application.close(); - pettanr.view.show( 'entrance'); + pettanr.editor.shutdown(); } function outputAsHtml(){ - OUTPUT_CONSOLE.show( COMIC_ELEMENT_CONTROL.getAsHTML( true, false)); + pettanr.outputConsole.bootInOverlay( + pettanr.outputConsole.HTML, + comicID, panelID, panelTimming, + PANEL_CONTROL.w(), PANEL_CONTROL.h(), + 1, // border, BackgroundImage + PANEL_ELEMENT_ARRAY + ); } function outputAsJsonString(){ - OUTPUT_CONSOLE.show( COMIC_ELEMENT_CONTROL.getAsJsonString()); + pettanr.outputConsole.bootInOverlay( + pettanr.outputConsole.JSON, + comicID, panelID, panelTimming, + PANEL_CONTROL.w(), PANEL_CONTROL.h(), + 1, // border, BackgroundImage + PANEL_ELEMENT_ARRAY + ); } return { open: function(){}, close: function(){}, quit: quit, panelUpdated: function( _updated){ - if( _updated !== undefined && updated !== _updated){ - SAVE.visible( !!_updated); - SAVE_AND_QUIT.visible( !!_updated); + if( _updated !== undefined && updated !== _updated ){ + SAVE.visible( !!_updated ); + SAVE_AND_QUIT.visible( !!_updated ); updated = !!_updated; } return updated; @@ -503,469 +463,6 @@ pettanr.editor = ( function(){ })(); /* ---------------------------------------- - * Text Editor - * - overlay - */ - var TEXT_EDITOR_CONTROL = ( function(){ - var jqWrap, jqTextarea, jqButton, - textElement, onUpdateFunction, - ID = 'textEditor'; - //pettanr.key.addKeyDownEvent( ID, 69, false, false, clickOK); - - function close(){ - jqWrap.hide(); - textElement = onUpdateFunction = null; - } - function clickOK(){ - pettanr.overlay.hide(); - textElement && textElement.text( jqTextarea.val()); - onUpdateFunction && onUpdateFunction( textElement); - close(); - } - return { - init: function(){ - this.jqWrap = jqWrap = $( '#speach-editor-wrapper').hide(); - jqTextarea = $( '#speach-editor').keydown( function( e){ - if( e.keyCode === 69 && e.shiftKey === false && e.ctrlKey === true){ - clickOK(); - e.preventDefault(); - e.keyCode = 0; - e.cancelBubble = true; - e.returnValue = false; - return false; - } - }); - jqButton = $( '#speach-edit-complete-button').click( clickOK); - delete TEXT_EDITOR_CONTROL.init; - }, - jqWrap: null, - show: function( _textElement, _onUpdateFunction){ - textElement = _textElement; - onUpdateFunction = _onUpdateFunction || null; - pettanr.overlay.show( this); - var h = _textElement.h; - jqWrap.show().css( { - left: _textElement.x +PANEL_CONTROL.x(), - top: _textElement.y +PANEL_CONTROL.y(), - width: _textElement.w, - height: h - }); - jqTextarea.val( _textElement.text()).focus(); - - /* - * ie6,7は、textarea { width:100%}でも高さが変わらない。rowsを設定。 - */ - pettanr.ua.isIE === true && pettanr.ua.ieVersion <= 7 && setTimeout( function(){ - var rows = 0; - while( jqTextarea.height() < h){ - rows++; - jqTextarea.attr( 'rows', rows); - } - rows > 1 && jqTextarea.attr( 'rows', rows -1); - }, 0); - }, - onWindowResize: function(){ - textElement && this.show( textElement); - }, - onClose: close, - ID: ID - } - })(); - -/* ---------------------------------------- - * Image Group Exproler - * - overlay - */ - var IMAGE_GROUP_EXPROLER = ( function(){ - var ICON_ARRAY = [], - WHEEL_DELTA = 64, - containerW, containerH, wrapX, - jqWrap, jqContainer, jqItemOrigin, - itemW, itemH, - jqName, jqButton, buttonW, - //onUpdateFunction, - _g_onUpdateFunction, - winW, - onEnterInterval = null; - - var BASE_PATH = pettanr.LOCAL === false ? 'http://pettan.heroku.com/resource_pictures/' : 'resource_pictures/', - THUMB_PATH = BASE_PATH, // + 'thumbnail/', - LIMIT_FILESIZE = 1024 * 10; // 10KB - var IMAGE_DATA = { - pen001: [ - { - "created_at": "2011-11-13T08:57:39Z", - "ext": "png", - "filesize": 9969, - "height": 463, - "id": 1, - "updated_at": "2011-11-13T08:57:39Z", - "width": 441 - }, - { - "created_at": "2011-11-13T08:57:54Z", - "ext": "gif", - "filesize": 5418, - "height": 500, - "id": 2, - "updated_at": "2011-11-13T08:57:54Z", - "width": 500 - }, - { - "created_at": "2011-11-13T08:58:06Z", - "ext": "gif", - "filesize": 8758, - "height": 464, - "id": 3, - "updated_at": "2011-11-13T08:58:06Z", - "width": 366 - }, - { - "created_at": "2011-11-13T08:58:23Z", - "ext": "gif", - "filesize": 9383, - "height": 480, - "id": 4, - "updated_at": "2011-11-13T08:58:23Z", - "width": 392 - }, - { - "created_at": "2011-11-13T08:58:33Z", - "ext": "gif", - "filesize": 11061, - "height": 500, - "id": 5, - "updated_at": "2011-11-13T08:58:33Z", - "width": 500 - }, - { - "created_at": "2011-11-20T09:50:43Z", - "ext": "gif", - "filesize": 1131, - "height": 126, - "id": 6, - "updated_at": "2011-11-20T09:50:43Z", - "width": 259 - }, - { - "created_at": "2011-11-20T09:50:55Z", - "ext": "gif", - "filesize": 1125, - "height": 126, - "id": 7, - "updated_at": "2011-11-20T09:50:55Z", - "width": 259 - }, - { - "created_at": "2011-11-20T11:33:12Z", - "ext": "gif", - "filesize": 17919, - "height": 600, - "id": 8, - "updated_at": "2011-11-20T11:33:12Z", - "width": 800 - }, - { - "created_at": "2011-11-20T11:33:12Z", - "ext": "gif", - "filesize": 17919, - "height": 600, - "id": 9, - "updated_at": "2011-11-20T11:33:12Z", - "width": 800 - }, - { - "created_at": "2011-11-20T11:33:12Z", - "ext": "gif", - "filesize": 17919, - "height": 600, - "id": 10, - "updated_at": "2011-11-20T11:33:12Z", - "width": 800 - }, - { - "created_at": "2011-11-20T11:33:12Z", - "ext": "gif", - "filesize": 17919, - "height": 600, - "id": 11, - "updated_at": "2011-11-20T11:33:12Z", - "width": 800 - }, - { - "created_at": "2011-11-22T09:17:20Z", - "ext": "gif", - "filesize": 9055, - "height": 473, - "id": 12, - "updated_at": "2011-11-22T09:17:20Z", - "width": 405 - }, - { - "created_at": "2011-11-22T10:11:07Z", - "ext": "gif", - "filesize": 8758, - "height": 464, - "id": 13, - "updated_at": "2011-11-22T10:11:07Z", - "width": 366 - }, - { - "created_at": "2011-11-24T09:05:12Z", - "ext": "gif", - "filesize": 6431, - "height": 386, - "id": 16, - "updated_at": "2011-11-24T09:05:12Z", - "width": 453 - }, - { - "created_at": "2011-11-26T04:52:12Z", - "ext": "gif", - "filesize": 6421, - "height": 426, - "id": 17, - "updated_at": "2011-11-26T04:52:12Z", - "width": 306 - }, - { - "created_at": "2011-11-26T04:52:12Z", - "ext": "gif", - "filesize": 6421, - "height": 426, - "id": 18, - "updated_at": "2011-11-26T04:52:12Z", - "width": 306 - }, - { - "created_at": "2011-11-26T04:52:12Z", - "ext": "gif", - "filesize": 6421, - "height": 426, - "id": 19, - "updated_at": "2011-11-26T04:52:12Z", - "width": 306 - }, - { - "created_at": "2011-11-26T04:52:12Z", - "ext": "gif", - "filesize": 6421, - "height": 426, - "id": 20, - "updated_at": "2011-11-26T04:52:12Z", - "width": 306 - }, - { - "created_at": "2011-11-26T04:52:12Z", - "ext": "gif", - "filesize": 6421, - "height": 426, - "id": 21, - "updated_at": "2011-11-26T04:52:12Z", - "width": 306 - } - ] - } - - var ImageGroupIconClass = function( INDEX, data){ - var JQ_ICON_WRAP = jqItemOrigin.clone( true), - SRC = [ BASE_PATH, data.id, '.', data.ext].join( ''), - LOW_SRC = data.filesize && data.filesize > LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext].join( '') : null, - reversibleImage = null, - onEnterFlag = false, - imgW, imgH; - JQ_ICON_WRAP.children( 'div').eq( 0).html( data.filesize + 'bytes'); - jqContainer.append( JQ_ICON_WRAP.css( { left: INDEX * itemW})); - - function onImageLoad( url, _imgW, _imgH){ - if( reversibleImage === null) { - alert( url); - return; - } - imgW = _imgW || data.width || 64; - imgH = _imgH || data.height || 64; - JQ_ICON_WRAP.children( 'div').eq( 1).html( imgW +'x' +imgH); - var zoom = 128 /( imgW > imgH ? imgW : imgH), - h = Math.floor( imgH *zoom), - w = Math.floor( imgW *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( _g_onUpdateFunction) { - if( LOW_SRC === null){ - window[ _g_onUpdateFunction]( SRC, imgW, imgH); - window[ _g_onUpdateFunction] = null; - } else { - var _onLoad = pettanr.util.createGlobalFunc( [ - 'function( url, w, h){', - 'window["', _g_onUpdateFunction, '"]( url, w || ', data.width,', h || ', data.height,');', - 'window["', _g_onUpdateFunction, '"] = null;', - '}' - ].join( '')), - _onError = pettanr.util.createGlobalFunc( [ - 'function( url){', - 'window["', _g_onUpdateFunction, '"]( url, ', data.width || 64 ,', ', data.height || 64,');', - 'window["', _g_onUpdateFunction, '"] = null;', - '}' - ].join( '')); - pettanr.util.loadImage( SRC, window[ _onLoad], window[ _onError]); - window[ _onLoad] = window[ _onError] = undefined; - } - } - close(); - } - - return { - onEnter: function(){ - if( onEnterFlag === true) return; - reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onImageLoad); - 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); - onEnterInterval = _g_onUpdateFunction = 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( clickOK); - buttonW = pettanr.util.getElementSize( jqButton.get( 0)).width; - - delete IMAGE_GROUP_EXPROLER.init; - }, - jqWrap: null, - show: function( _onUpdateFunction){ - //onUpdateFunction = _onUpdateFunction; - if( _onUpdateFunction){ - _g_onUpdateFunction = pettanr.util.createGlobalFunction( _onUpdateFunction); - } else { - _g_onUpdateFunction = null; - } - pettanr.overlay.show( this); - - var CURRENT_GROUP_ARRAY = IMAGE_DATA[ 'pen001'] || [], - l = CURRENT_GROUP_ARRAY.length; - 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' - } - })(); - -/* ---------------------------------------- * WINDOWS_CONTROL * - contloler * - mouseEventListener @@ -1396,15 +893,12 @@ pettanr.editor = ( function(){ instance = this; delete this.onInit; }, - onFirstOpen: function( _w, _h){ - finder = pettanr.finder.createFinder( document.getElementById( 'image-exproler-container'), pettanr.driver.createPictureTree()); - delete this.onFirstOpen; - }, onOpen: function( _w, _h){ - finder.onOpen( _w, _h); + finder = finder || pettanr.finder.createFinder( pettanr.editor, document.getElementById( 'image-exproler-container'), pettanr.driver.createPictureTree()); + finder.resize( _w, _h ); }, - onResize: function( _w, _h){ - finder.resize( _w, _h); + onResize: function( _w, _h ){ + finder.resize( _w, _h ); } }, 'image-exproler', 'Album', 0, 215, 400, 350, false, true, true, 300, 300 @@ -1462,13 +956,13 @@ pettanr.editor = ( function(){ x = currentElement !== null ? currentElement.x : 0, y = currentElement !== null ? currentElement.y : 0, z = currentElement !== null ? currentElement.z : 0, - a = _elementType === COMIC_ELEMENT_TYPE_TEXT ? Math.floor( currentElement.angle()) : 0, + a = _elementType === PANEL_ELEMENT_TYPE_TEXT ? Math.floor( currentElement.angle()) : 0, w = currentElement !== null ? currentElement.w : 0, h = currentElement !== null ? currentElement.h : 0, - actualW = _elementType === COMIC_ELEMENT_TYPE_IMAGE ? currentElement.actualW() : 1, - actualH = _elementType === COMIC_ELEMENT_TYPE_IMAGE ? currentElement.actualH() : 1, - wPercent = _elementType === COMIC_ELEMENT_TYPE_IMAGE ? Math.floor( w / actualW *100) : 0, - hPercent = _elementType === COMIC_ELEMENT_TYPE_IMAGE ? Math.floor( h / actualH *100) : 0, + actualW = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualW() : 1, + actualH = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualH() : 1, + wPercent = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( w / actualW *100) : 0, + hPercent = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( h / actualH *100) : 0, keepAspect = currentElement !== null && currentElement.keepAspect === true; if( currentElementType !== _elementType){ @@ -1762,12 +1256,12 @@ pettanr.editor = ( function(){ } return { - open: function( _panelW, _panelH, _borderSize){ - panelW = _panelW || DEFAULT_PANEL_WIDTH; - panelH = _panelH || DEFAULT_PANEL_HEIGHT; + open: function( _panelW, _panelH, _borderSize ){ + panelW = Type.isFinite( _panelW ) === true ? _panelW : DEFAULT_PANEL_WIDTH; + panelH = Type.isFinite( _panelH ) === true ? _panelH : DEFAULT_PANEL_HEIGHT; //panelX = Math.floor( ( windowW -panelW) /2); //panelY = Math.floor( ( windowH -panelH) /2); - borderSize = _borderSize !== undefined ? _borderSize : borderSize; + borderSize = Type.isFinite( _borderSize ) === true ? _borderSize : borderSize; //setTimeout( PANEL_CONTROL.resize, 0); }, @@ -1780,6 +1274,12 @@ pettanr.editor = ( function(){ y: function(){ return panelY; }, + w: function(){ + return panelW; + }, + h: function(){ + return panelH; + }, resize: function( isResizerTopAction, _x, _y, _w, _h){ panelX = _x !== undefined ? _x : panelX; panelY = _y !== undefined ? _y : panelY; @@ -1853,66 +1353,64 @@ pettanr.editor = ( function(){ } } - return { - onMouseDown: function( _mouseX, _mouseY){ - var _x = _mouseX -panelX, - _y = _mouseY -panelY; + this.onMouseDown = function( _mouseX, _mouseY){ + var _x = _mouseX -panelX, + _y = _mouseY -panelY; + if( _x < x || x + w < _x || _y < y || y + h < _y) return false; + offsetY = _y; + startY = panelY; + startH = panelH; + isDragging = true; + MOUSE_CURSOR( 'n-resize'); + return true; + } + this.onMouseMove = function( _mouseX, _mouseY){ + var _x = _mouseX -panelX, + _y = _mouseY -panelY; + if( isDragging !== true){ if( _x < x || x + w < _x || _y < y || y + h < _y) return false; - offsetY = _y; - startY = panelY; - startH = panelH; - isDragging = true; - MOUSE_CURSOR( 'n-resize'); + COMIC_ELEMENT_OPERATION_MANAGER.hide(); + MOUSE_CURSOR( 'pointer'); return true; - }, - onMouseMove: function( _mouseX, _mouseY){ - var _x = _mouseX -panelX, - _y = _mouseY -panelY; - if( isDragging !== true){ - if( _x < x || x + w < _x || _y < y || y + h < _y) return false; - COMIC_ELEMENT_OPERATION_MANAGER.hide(); - MOUSE_CURSOR( 'pointer'); - return true; + } else { + var move = _y -offsetY; + if( isTop === true){ + if( panelH - move < MIN_PANEL_HEIGHT){ + move = panelH -MIN_PANEL_HEIGHT; + } + PANEL_CONTROL.resize( true, panelX, panelY + move, panelW, panelH - move); } else { - var move = _y -offsetY; - if( isTop === true){ - if( panelH - move < MIN_PANEL_HEIGHT){ - move = panelH -MIN_PANEL_HEIGHT; - } - PANEL_CONTROL.resize( true, panelX, panelY + move, panelW, panelH - move); - } else { - var _h = startH +move; - if( 0 < _h && _h < windowH -panelY -RESIZER_HEIGHT -5 -BORDER_WIDTH){ - PANEL_CONTROL.resize( false, panelX, panelY, panelW, _h < MIN_PANEL_HEIGHT ? MIN_PANEL_HEIGHT : _h); - } + var _h = startH +move; + if( 0 < _h && _h < windowH -panelY -RESIZER_HEIGHT -5 -BORDER_WIDTH){ + PANEL_CONTROL.resize( false, panelX, panelY, panelW, _h < MIN_PANEL_HEIGHT ? MIN_PANEL_HEIGHT : _h); } } - return true; - }, - onMouseUp: function( _mouseX, _mouseY){ - if( isDragging !== true) return; - ( startY !== panelY || startH !== panelH) && HISTORY_CONTROL.saveState( restoreState, [ NaN, startY, NaN, startH], [ NaN, panelY, NaN, panelH]); - isDragging = false; - MOUSE_CURSOR( ''); - }, - busy: function(){ - return isDragging - }, - onPanelResize: function( _x, _y, _w, _h){ - panelX = _x; - panelY = _y; - if( panelW !== _w){ - ELM.style.width = ( _w +2) +'px'; - panelW = _w; - } - panelH = _h; - y = isTop === true ? y : ( panelH +5 +BORDER_WIDTH); - w = panelW +2; } + return true; + } + this.onMouseUp = function( _mouseX, _mouseY){ + if( isDragging !== true) return; + ( startY !== panelY || startH !== panelH) && HISTORY_CONTROL.saveState( restoreState, [ NaN, startY, NaN, startH], [ NaN, panelY, NaN, panelH]); + isDragging = false; + MOUSE_CURSOR( ''); + } + this.busy = function(){ + return isDragging + } + this.onPanelResize = function( _x, _y, _w, _h){ + panelX = _x; + panelY = _y; + if( panelW !== _w){ + ELM.style.width = ( _w +2) +'px'; + panelW = _w; + } + panelH = _h; + y = isTop === true ? y : ( panelH +5 +BORDER_WIDTH); + w = panelW +2; } }; - var PANEL_RESIZER_TOP = new PanelResizerClass( 'panel-resizer-top', true), - PANEL_RESIZER_BOTTOM = new PanelResizerClass( 'panel-resizer-bottom', false); + var PANEL_RESIZER_TOP = new PanelResizerClass( 'panel-resizer-top', true ), + PANEL_RESIZER_BOTTOM = new PanelResizerClass( 'panel-resizer-bottom', false ); PanelResizerClass = undefined; @@ -1965,7 +1463,7 @@ pettanr.editor = ( function(){ SAVE( COMIC_ELEMENT_CONTROL.restoreReplace, [ currentElement, true], [ currentElement, false]); var _z = currentElement.z; LAYER_BACK_BUTTON.visible( _z > 0); - LAYER_FORWARD_BUTTON.visible( _z < COMIC_ELEMENT_ARRAY.length -1); + LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1); } function layerForward(){ if( currentElement === null) return; @@ -1974,7 +1472,7 @@ pettanr.editor = ( function(){ SAVE( COMIC_ELEMENT_CONTROL.restoreReplace, [ currentElement, false], [ currentElement, true]); var _z = currentElement.z; LAYER_BACK_BUTTON.visible( _z > 0); - LAYER_FORWARD_BUTTON.visible( _z < COMIC_ELEMENT_ARRAY.length -1); + LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1); } function del(){ if( currentElement === null) return; @@ -1984,14 +1482,17 @@ pettanr.editor = ( function(){ COMIC_ELEMENT_OPERATION_MANAGER.hide(); } function edit(){ - if( currentElement === null || currentElement.type !== COMIC_ELEMENT_TYPE_TEXT) return; - TEXT_EDITOR_CONTROL.show( currentElement); - buttonBackOrForward( true); + if( currentElement === null || currentElement.type !== PANEL_ELEMENT_TYPE_TEXT) return; + pettanr.textEditor.bootInOverlay( PANEL_CONTROL.x(), PANEL_CONTROL.y(), currentElement ); + buttonBackOrForward( true ); } function change(){ if( currentElement === null) return; buttonBackOrForward( true); - IMAGE_GROUP_EXPROLER.show( currentElement.url); + pettanr.premiumSatge.bootInOverlay( currentElement.getArtistID(), currentElement.resourcePicture ); + } + function onImageSelect( resourcePicture ){ + currentElement.resourcePicture( resourcePicture ); } return { init: function(){ @@ -2018,7 +1519,9 @@ pettanr.editor = ( function(){ delete CONSOLE_CONTROLER.init; }, - show: function( _currentElement, _w, _h){ + show: function( _currentElement, _w, _h ){ + CONSOLE_CONTROLER.init && CONSOLE_CONTROLER.init(); + visible === false && jqConsoleWrapper.show(); visible = true; currentElement = _currentElement; @@ -2026,17 +1529,17 @@ pettanr.editor = ( function(){ _z = _currentElement.z; if( currentType !== _currentType){ currentType = _currentType; - jqImgConsole.toggle( _currentType === COMIC_ELEMENT_TYPE_IMAGE); - jqTextConsole.toggle( _currentType === COMIC_ELEMENT_TYPE_TEXT); - consoleWidth = _currentType === COMIC_ELEMENT_TYPE_IMAGE ? imgConsoleWidth : textConsoleWidth; - consoleHeight = _currentType === COMIC_ELEMENT_TYPE_IMAGE ? imgConsoleHeight : textConsoleHeight; + jqImgConsole.toggle( _currentType === PANEL_ELEMENT_TYPE_IMAGE); + jqTextConsole.toggle( _currentType === PANEL_ELEMENT_TYPE_TEXT); + consoleWidth = _currentType === PANEL_ELEMENT_TYPE_IMAGE ? imgConsoleWidth : textConsoleWidth; + consoleHeight = _currentType === PANEL_ELEMENT_TYPE_IMAGE ? imgConsoleHeight : textConsoleHeight; } consoleX = Math.floor( ( _w -consoleWidth) /2); LAYER_BACK_BUTTON.visible( _z > 0); - LAYER_FORWARD_BUTTON.visible( _z < COMIC_ELEMENT_ARRAY.length -1); + LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1); DELETE_BUTTON.visible( true); - EDIT_BUTTON.visible( _currentType === COMIC_ELEMENT_TYPE_TEXT); + EDIT_BUTTON.visible( _currentType === PANEL_ELEMENT_TYPE_TEXT); CHANGE_BUTTON.visible( false); if( _w > consoleWidth * 1.5 && _h > consoleHeight * 1.5){ @@ -2134,7 +1637,7 @@ pettanr.editor = ( function(){ currentText = null; }, onStart: function( _currentText, _mouseX, _mouseY){ - if( _currentText.type !== COMIC_ELEMENT_TYPE_TEXT) return false; + if( _currentText.type !== PANEL_ELEMENT_TYPE_TEXT) return false; x = _currentText.x; y = _currentText.y; if( this.hitTest( _mouseX -x, _mouseY -y) === true){ @@ -2291,8 +1794,8 @@ pettanr.editor = ( function(){ return { update: draw, index: function( _mouseX, _mouseY){ - var p; - for( var i=4; i<8; i++){ + var p, i; + for( i=4; i<8; i++){ p = POSITION_ARRAY[ i]; if( p.x <= _mouseX && p.y <= _mouseY && p.x + p.w >= _mouseX && p.y +p.h >= _mouseY){ MOUSE_CURSOR( CURSOR_AND_FLIP[ i].cursor); @@ -2300,7 +1803,7 @@ pettanr.editor = ( function(){ return currentIndex = i; } } - for( var i=0; i<4; i++){ + for( i=0; i<4; i++){ p = POSITION_ARRAY[ i]; if( p.x <= _mouseX && p.y <= _mouseY && p.x + p.w >= _mouseX && p.y +p.h >= _mouseY){ MOUSE_CURSOR( CURSOR_AND_FLIP[ i].cursor); @@ -2314,7 +1817,7 @@ pettanr.editor = ( function(){ }, show: function( _currentElement){ currentElement = _currentElement; - currentIsTextElement = _currentElement.type === COMIC_ELEMENT_TYPE_TEXT; + currentIsTextElement = _currentElement.type === PANEL_ELEMENT_TYPE_TEXT; elmResizerContainerStyle.display = ''; }, hide: function(){ @@ -2323,7 +1826,7 @@ pettanr.editor = ( function(){ }, onStart: function( _currentElement, _mouseX, _mouseY){ currentElement = _currentElement; - currentIsTextElement = _currentElement.type === COMIC_ELEMENT_TYPE_TEXT; + currentIsTextElement = _currentElement.type === PANEL_ELEMENT_TYPE_TEXT; if( _currentElement.keepSize === true) return false; currentIndex = this.index( _mouseX, _mouseY); if( currentIndex === -1) return false; @@ -2333,7 +1836,7 @@ pettanr.editor = ( function(){ startY = baseY = _currentElement.y; startW = baseW = _currentElement.w; startH = baseH = _currentElement.h; - if( _currentElement.type === COMIC_ELEMENT_TYPE_IMAGE){ + if( _currentElement.type === PANEL_ELEMENT_TYPE_IMAGE){ startFilpV = _currentElement.flipV(); startFilpH = _currentElement.flipH(); } @@ -2386,7 +1889,7 @@ pettanr.editor = ( function(){ _h = MIN_ELEMENT_SIZE; } } else - if( currentElement.type === COMIC_ELEMENT_TYPE_TEXT){ + if( currentElement.type === PANEL_ELEMENT_TYPE_TEXT){ return; } else if( _w < -MIN_ELEMENT_SIZE || _h < -MIN_ELEMENT_SIZE){ @@ -2454,7 +1957,7 @@ pettanr.editor = ( function(){ onCancel: function(){ MOUSE_CURSOR( ''); COMIC_ELEMENT_OPERATION_MANAGER.resize( startX, startY, startW, startH); - currentElement.type === COMIC_ELEMENT_TYPE_IMAGE ? + currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.animate( startX, startY, startW, startH, startFilpV, startFilpH) : currentElement.animate( startX, startY, startW, startH, angle); }, @@ -2560,7 +2063,7 @@ pettanr.editor = ( function(){ if( currentElement !== _currentElement){ currentElement = _currentElement; - currentIsTextElement = ( _currentElement.type === COMIC_ELEMENT_TYPE_TEXT); + currentIsTextElement = ( _currentElement.type === PANEL_ELEMENT_TYPE_TEXT); currentIsTextElement === true ? TAIL_OPERATOR.show( _currentElement) : TAIL_OPERATOR.hide(); flipV = currentIsTextElement === false ? _currentElement.flipV() : 0; @@ -2606,7 +2109,7 @@ pettanr.editor = ( function(){ _a = arg[ 5], _flipV = arg[ 6], _flipH = arg[ 7]; if( !_currentElement && !currentOperator) return; - _currentElement.type === COMIC_ELEMENT_TYPE_IMAGE ? + _currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ? _currentElement.animate( _x, _y, _w, _h, _flipV, _flipH) : _currentElement.animate( _x, _y, _w, _h, _a); currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel(); @@ -2629,9 +2132,9 @@ pettanr.editor = ( function(){ busy: function(){ return currentOperator !== null; }, - hitTest: function( _mouseX, _mouseY, _comicElement){ + hitTest: function( _mouseX, _mouseY, _panelElement ){ var _x, _y, _w, _h; - if( _comicElement === currentElement){ + if( _panelElement === currentElement){ var _consoleX = CONSOLE_CONTROLER.x(); _x = currentx +( _consoleX < 0 ? _consoleX : 0) -HIT_AREA; _y = currenty -HIT_AREA; @@ -2640,11 +2143,12 @@ pettanr.editor = ( function(){ var _consoleY = CONSOLE_CONTROLER.y(); _h = ( _consoleY < currenth ? currenth : _consoleY +CONSOLE_CONTROLER.h()) +HIT_AREA *2; } else { - _x = _comicElement.x -HIT_AREA; - _y = _comicElement.y -HIT_AREA; - _w = _comicElement.w +HIT_AREA *2; - _h = _comicElement.h +HIT_AREA *2; + _x = _panelElement.x -HIT_AREA; + _y = _panelElement.y -HIT_AREA; + _w = _panelElement.w +HIT_AREA *2; + _h = _panelElement.h +HIT_AREA *2; } + log.html( [ _x, _y, _w, _h ].join( ' ') ); return _x <= _mouseX && _mouseX <= _x + _w && _y <= _mouseY && _mouseY <= _y + _h; }, onMouseDown: function( _currentElement, _mouseX, _mouseY){ @@ -2681,33 +2185,25 @@ pettanr.editor = ( function(){ * // COMIC_ELEMENT_OPERATION_MANAGER */ - var AbstractComicElement = function( JQ_WAPPER, COMIC_ELM_TYPE, update, x, y, w, h, z, timing){ - var OPERATOR = COMIC_ELEMENT_OPERATION_MANAGER; - return { - $: JQ_WAPPER, - type: COMIC_ELM_TYPE, - x: x, - y: y, - w: w, - h: h, - z: z, - timing: timing, - hitTest: function( _mouseX, _mouseY){ return OPERATOR.hitTest( _mouseX, _mouseY, this);}, - shift: function( _shiftX, _shiftY){ - update( this.x +_shiftX, this.y +_shiftY); - }, - busy: function(){ - return OPERATOR.busy(); - }, - onMouseMove: function( _mouseX, _mouseY){ - OPERATOR.onMouseMove( this, _mouseX, _mouseY); - }, - onMouseUp: function( _mouseX, _mouseY){ - OPERATOR.onMouseUp( this, _mouseX, _mouseY); - }, - onMouseDown: function( _mouseX, _mouseY){ - OPERATOR.onMouseDown( this, _mouseX, _mouseY); - } + var AbstractComicElement = function( COMIC_ELM_TYPE ){ + this.type = COMIC_ELM_TYPE; + this.hitTest = function( _mouseX, _mouseY ){ + return COMIC_ELEMENT_OPERATION_MANAGER.hitTest( _mouseX, _mouseY, this ); + } + this.shift = function( _shiftX, _shiftY ){ + this.resize( this.x + _shiftX, this.y + _shiftY); + } + this.busy = function(){ + return COMIC_ELEMENT_OPERATION_MANAGER.busy(); + } + this.onMouseMove = function( _mouseX, _mouseY ){ + COMIC_ELEMENT_OPERATION_MANAGER.onMouseMove( this, _mouseX, _mouseY ); + } + this.onMouseUp = function( _mouseX, _mouseY ){ + COMIC_ELEMENT_OPERATION_MANAGER.onMouseUp( this, _mouseX, _mouseY ); + } + this.onMouseDown = function( _mouseX, _mouseY ){ + COMIC_ELEMENT_OPERATION_MANAGER.onMouseDown( this, _mouseX, _mouseY ); } }; @@ -2715,131 +2211,109 @@ pettanr.editor = ( function(){ * ImageElementClass */ var jqImageElementOrigin; - var ImageElementClass = function( url, IMAGE_SET_ID, x, y, z, w, h, timing){ + var ImageElementClass = function( data ){ jqImageElementOrigin = jqImageElementOrigin || $( $( '#imgElementTemplete').remove().html()); - var JQ_WRAPPER = jqImageElementOrigin.clone( true), - OPERATOR = COMIC_ELEMENT_OPERATION_MANAGER, - SAVE = HISTORY_CONTROL.saveState, - HIT_AREA = MOUSE_HIT_AREA, - reversibleImage = null, - actualW = 0, actualH = 0, + var JQ_WRAPPER = jqImageElementOrigin.clone( true ), + w = data.width, + h = data.height, + x, y, z, flipH = w < 0 ? -1 : 1, flipV = h < 0 ? -1 : 1, - instance; - w = Math.floor( w); - h = Math.floor( h); - - function update( _x, _y, _w, _h, animate){ + resourcePicture = data.resource_picture, + actualW = data.resource_picture.width, + actualH = data.resource_picture.height, + reversibleImage = null, + instance = this; + w = Math.floor( w ); + h = Math.floor( h ); + + function onAnimeComplete(){ + reversibleImage && reversibleImage.resize( flipH * w, flipV * h ); + } + function updateResourcePicture( _resourcePicture ){ + resourcePicture = _resourcePicture; + + actualW = _resourcePicture.width; + actualH = _resourcePicture.height; + + var _reversibleImage = pettanr.image.createReversibleImage( + [ pettanr.CONST.RESOURCE_PICTURE_PATH, _resourcePicture.id, '.', _resourcePicture.ext ].join(''), + flipH * w, flipV * h + ); + if( reversibleImage !== null){ + JQ_WRAPPER.children( reversibleImage.elm ).replaceWith( _reversibleImage.elm ); + reversibleImage.destroy(); + } else { + JQ_WRAPPER.append( _reversibleImage.elm ); + } + reversibleImage = _reversibleImage; + } + /* global methods */ + this.$ = JQ_WRAPPER; + //this.x = x; + //this.y = y; + //this.w = w; + //this.h = h; + this.z = data.z; + this.timing = data.t; + this.init = function(){ + updateResourcePicture( data.resource_picture ); + instance.resize( data.x, data.y, data.width, data.height ); + delete instance.init; + } + this.flip = function( _updateH, _updateV ){ + if( _updateH !== true && _updateV !== true ) return; + flipH = _updateH === true ? -flipH : flipH; + flipV = _updateV === true ? -flipV : flipV; + reversibleImage.resize( flipH * w, flipV * h ); + } + this.flipV = function(){ + return flipV; + } + this.flipH = function(){ + return flipH; + } + this.resourcePicture = function( _resourcePicture ){ + if( _resourcePicture && _resourcePicture !== resourcePicture ){ + HISTORY_CONTROL.saveState( updateResourcePicture, resourcePicture, _resourcePicture ); + updateResourcePicture( _resourcePicture ); + } + return resourcePicture; + } + this.getArtistID = function(){ + return resourcePicture.artist_id || resourcePicture.artist.id || -1; + } + this.actualW = function(){ return actualW;} + this.actualH = function(){ return actualH;} + this.keepSize = false; + this.resize = function( _x, _y, _w, _h, animate ){ instance.x = x = _x !== undefined ? _x : x; instance.y = y = _y !== undefined ? _y : y; instance.w = w = _w !== undefined ? _w : w; instance.h = h = _h !== undefined ? _h : h; - JQ_WRAPPER[ animate === true ? 'animate' : 'css']( { + JQ_WRAPPER[ animate === true ? 'animate' : 'css' ]( { left: x, top: y, width: w, height: h - }, 250, onAnimeComplete); + }, 250, onAnimeComplete ); animate !== true && onAnimeComplete(); } - function onAnimeComplete(){ - reversibleImage.resize( flipH * w, flipV * h); + this.animate = function ( _x, _y, _w, _h, _flipH, _flipV ){ + flipH = _flipH !== undefined ? _flipH : flipH; + flipV = _flipV !== undefined ? _flipV : flipV; + instance.resize( _x, _y, _w, _h, true ); } - - function updateUrl( _url){ - if( url === _url) return; - url = _url || url; - var _reversibleImage = pettanr.image.createReversibleImage( url, flipH * w, flipV * h, function( _url, _actualW, _actualH){ - actualW = _actualW; - actualH = _actualH; - }); - if( reversibleImage !== null){ - JQ_WRAPPER.children( reversibleImage.elm).replaceWith( _reversibleImage.elm); - reversibleImage.destroy(); - } else { - JQ_WRAPPER.append( _reversibleImage.elm); - } - reversibleImage = _reversibleImage; + this.destroy = function(){ + delete instance.destroy; + + reversibleImage.destroy(); + JQ_WRAPPER.stop().remove(); + JQ_WRAPPER = reversibleImage = resourcePicture = data = instance = null; } - return pettanr.util.extend( - new AbstractComicElement( JQ_WRAPPER, COMIC_ELEMENT_TYPE_IMAGE, update, x, y, w, h, z, timing), - { - init: function(){ - instance = this; - updateUrl(); - update(); - delete this.init; - }, - flip: function( _flipH, _flipV){ - if( _flipH !== true && _flipV !== true) return; - flipH = _flipH === true ? -flipH : flipH; - flipV = _flipV === true ? -flipV : flipV; - reversibleImage.resize( flipH * w, flipV * h); - }, - flipV: function(){ - return flipV; - }, - flipH: function(){ - return flipH; - }, - url: function( _url, _actualW, _actualH){ - if( _url && _url !== url){ - SAVE( updateUrl, url, _url); - actualW = _actualW; - actualH = _actualH; - updateUrl( _url); - } - return url; - }, - actualW: function(){ return actualW;}, - actualH: function(){ return actualH;}, - keepSize: false, - resize: update, - animate: function ( _x, _y, _w, _h, _flipH, _flipV){ - flipH = _flipH !== undefined ? _flipH : flipH; - flipV = _flipV !== undefined ? _flipV : flipV; - update( _x, _y, _w, _h, true); - }, - getAsHTML: function( isAbsoluteUrl, isXHTML){ - return [ - '' : ' \/>' - ].join( ''); - }, - getAsJsonString: function(){ - var cr = pettanr.LINE_FEED_CODE_TEXTAREA; - return [ - '"new', this.timing, '": {', cr, - '"resource_picture_id": 1,', cr, - '"x": ', x, ',', cr, - '"y": ', y, ',', cr, - '"z": ', this.z, ',', cr, - '"width": ', w, ',', cr, - '"height": ', h, ',', cr, - '"flipv": ', flipV === true ? 1 : 0, ',', cr, - '"fliph": ', flipH === true ? 1 : 0, ',', cr, - '"t": ', this.timing, cr, - '}' - ].join( ''); - }, - destroy: function(){ - reversibleImage.destroy(); - JQ_WRAPPER.remove(); - JQ_WRAPPER = reversibleImage = OPERATOR = null; - delete this.destroy; - } - } - ); } + ImageElementClass.prototype = new AbstractComicElement( PANEL_ELEMENT_TYPE_IMAGE ); /* * / ImageElementClass * -------------------------------------------------------------------------------------------- @@ -2859,24 +2333,77 @@ pettanr.editor = ( function(){ * */ var jqTextElementOrigin; - var TextElementClass = function( type, a, text, x, y, z, w, h, timing){ + var TextElementClass = function( data ){ jqTextElementOrigin = jqTextElementOrigin || ( function(){ var _OLD_IE = $( $( '#textElementTempleteForOldIE').remove().html()), _MODERN = $( $( '#textElementTemplete').remove().html()); return pettanr.ua.isIE === true && pettanr.ua.ieRenderingVersion < 8 ? _OLD_IE : _MODERN; })(); - var JQ_WRAPPER = jqTextElementOrigin.clone( true), - XBROWSER_BALLOON = pettanr.balloon.createBalloon( w, h, a, type), - TEXT_ELM = JQ_WRAPPER.find( 'td,.speach-inner').eq( 0), - OPERATOR = COMIC_ELEMENT_OPERATION_MANAGER, - HIT_AREA = MOUSE_HIT_AREA, - SAVE = HISTORY_CONTROL.saveState, - instance; - - JQ_WRAPPER.find( 'img').eq( 0).replaceWith( XBROWSER_BALLOON.elm); + var JQ_WRAPPER = jqTextElementOrigin.clone( true ), + elmText = JQ_WRAPPER.find( 'td,.speach-inner' ).get( 0 ), + type = data.balloon_template_id, + text = ( function(){ + var _speachs = data.speaches_attributes; + for( var k in _speachs ){ + return _speachs[ k ].content || ''; + } + return ''; + })(), + balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail, type ), + x, y, w, h, a, + instance = this; + + JQ_WRAPPER.find( 'img' ).eq( 0 ).replaceWith( balloon.elm ); + + function updateType( _type ){ + if( type !== _type ){ + type = _type || type; + balloon.type( type ); + } + } + function updateAngle( _a ){ + if( _a !== undefined && a !== _a ){ + a = _a !== undefined ? _a : a; + balloon.angle( a ); + } + } + function updateText( _text ){ + text = _text || text || ''; + elmText.firstChild.data = text; + } + function resizeBalloon(){ + balloon && balloon.resize( a, w, h ); + } - function update( _x, _y, _w, _h, _a, animate){ + /* global methods */ + this.$ = JQ_WRAPPER; + //this.x = x; + //this.y = y; + //this.w = w; + //this.h = h; + this.z = data.z; + this.timing = data.t; + this.init = function(){ + updateText(); + instance.resize( data.x, data.y, data.width, data.height, data.tail ); + delete instance.init; + } + this.angle = function( _a ){ + _a !== undefined && instance.resize( x, y, w, h, _a ); + return a; + } + this.text = function( _text ){ + if( _text && text !== _text) { + HISTORY_CONTROL.saveState( updateText, text || '', _text ); + updateText( _text ); + } + return text; + } + this.getBalloonURL = function(){ + return balloon.getURL(); + } + this.resize = function( _x, _y, _w, _h, _a, animate ){ instance.x = x = _x !== undefined ? _x : x; instance.y = y = _y !== undefined ? _y : y; instance.w = w = _w !== undefined ? _w : w; @@ -2888,119 +2415,22 @@ pettanr.editor = ( function(){ top: y, width: w, height: h - }, 250, - function(){ - XBROWSER_BALLOON.resize( a, w, h); - } + }, 250, resizeBalloon ); - animate !== true && XBROWSER_BALLOON.resize( a, w, h); - } - - function updateType( _type){ - if( type !== _type){ - type = _type || type; - XBROWSER_BALLOON.type( type); - } + animate !== true && resizeBalloon(); } - function updateAngle( _a){ - if( _a !== undefined && a !== _a){ - a = _a !== undefined ? _a : a; - XBROWSER_BALLOON.angle( a); - } + this.animate = function ( _x, _y, _w, _h, _a ){ + instance.resize( _x, _y, _w, _h, _a, true ); } - function updateText( _text){ - text = _text || text || ''; - TEXT_ELM.html( text); + this.destroy = function(){ + delete instance.destroy; + + JQ_WRAPPER.stop().remove(); + balloon.destroy(); + JQ_WRAPPER = elmText = data = balloon = instance = null; } - - return pettanr.util.extend( - new AbstractComicElement( JQ_WRAPPER, COMIC_ELEMENT_TYPE_TEXT, update, x, y, w, h, z, timing), - { - init: function(){ - instance = this; - updateText(); - update(); - delete this.init; - }, - angle: function( _a){ - _a !== undefined && update( undefined, undefined, undefined, undefined, _a); - return a; - }, - text: function( _text){ - if( _text && text !== _text) { - SAVE( updateText, text || '', _text); - updateText( _text); - } - return text; - }, - resize: update, - animate: function ( _x, _y, _w, _h, _a){ - update( _x, _y, _w, _h, _a, true); - }, - destroy: function(){ - JQ_WRAPPER.remove(); - XBROWSER_BALLOON.destroy(); - OPERATOR = null; - delete this.destroy; - }, - getAsJSON: function(){ - - }, - getAsJsonString: function(){ - var cr = pettanr.LINE_FEED_CODE_TEXTAREA; - return [ - '"new', this.timing, '": {', cr, - '"balloon_template_id": ', 1, ',', cr, - '"system_picture_id": ', 1, ',', cr, - '"size": ', 1, ',', cr, - '"tail": ', a, ',', cr, - '"x": ', x, ',', cr, - '"y": ', y, ',', cr, - '"z": ', this.z, ',', cr, - '"t": ', this.timing, ',', cr, - '"width": ', w, ',', cr, - '"height": ', h, ',', cr, - '"speaches_attributes": {', cr, - '"newf', this.timing, '": {', cr, - '"content": "', text, '",', cr, - '"x": ', x, ',', cr, - '"y": ', y, ',', cr, - '"t": ', 0, ',', cr, - '"width": ', w, ',', cr, - '"height": ', h, cr, - '}', cr, - '}', cr, - '}' - ].join( ''); - }, - getAsHTML: function( isAbsoluteUrl, isXHTML){ - var url = XBROWSER_BALLOON.getURL(); - return [ - '' : ' \/>', - pettanr.LINE_FEED_CODE_TEXTAREA, - '
', text, '<\/span>', '<\/div>' - - ].join( ''); - }, - getAsXML: function(){} - } - ); } + TextElementClass.prototype = new AbstractComicElement( PANEL_ELEMENT_TYPE_TEXT ); /* -------------------------------------------------------------------------------------------- * COMIC_ELEMENT_CONTROL @@ -3026,96 +2456,99 @@ pettanr.editor = ( function(){ * * append comicElement * 1. 新しい comicElement の z-position を得る - * 2. z の同じ comicElementを見つけ、その前に加える。または一番先頭へ。(COMIC_ELEMENT_ARRAY) - * zが大きいほど、COMIC_ELEMENT_ARRAYの先頭へ。 - * 3. dom位置は、COMIC_ELEMENT_ARRAY とは反対に、前のものほど後ろへ。 + * 2. z の同じ comicElementを見つけ、その前に加える。または一番先頭へ。(PANEL_ELEMENT_ARRAY) + * zが大きいほど、PANEL_ELEMENT_ARRAYの先頭へ。 + * 3. dom位置は、PANEL_ELEMENT_ARRAY とは反対に、前のものほど後ろへ。 * * * remove comicElement * 1. remove * 2. renumber z */ - function appendComicElement( _comicElement) { - _comicElement.init && _comicElement.init(); - var z = _comicElement.z, - l = COMIC_ELEMENT_ARRAY.length, - _jqElm = _comicElement.$.stop().css( { + function appendComicElement( _panelElement ) { + var z = _panelElement.z, + l = PANEL_ELEMENT_ARRAY.length, + _jqElm = _panelElement.$.stop().css( { filter: '', opacity: '' }); - if( typeof z !== 'number' || z < 0 || z >= l){ - COMIC_ELEMENT_ARRAY.unshift( _comicElement); - ELM_CONTAINER.appendChild( _jqElm.get( 0)); + if( typeof z !== 'number' || z < 0 || z >= l ){ + PANEL_ELEMENT_ARRAY.unshift( _panelElement ); + ELM_CONTAINER.appendChild( _jqElm.get( 0 )); _jqElm.fadeIn(); + } else + if( l === 0 ){ + PANEL_ELEMENT_ARRAY.push( _panelElement ); + ELM_CONTAINER.appendChild( _jqElm.get( 0 )); } else { var insertIndex = 0; - for( var i = 0; i < l; ++i){ - if( COMIC_ELEMENT_ARRAY[ i].z <= z){ + for( var i = 0; i < l; ++i ){ + if( PANEL_ELEMENT_ARRAY[ i ].z <= z ){ insertIndex = i; break; } } - COMIC_ELEMENT_ARRAY[ insertIndex].$.before( _jqElm.fadeIn()); - COMIC_ELEMENT_ARRAY.splice( insertIndex, 0, _comicElement); + PANEL_ELEMENT_ARRAY[ insertIndex ].$.before( _jqElm.fadeIn() ); + PANEL_ELEMENT_ARRAY.splice( insertIndex, 0, _panelElement ); } renumber(); } - function removeComicElement( _comicElement) { - var l = COMIC_ELEMENT_ARRAY.length; + function removeComicElement( _panelElement ) { + var l = PANEL_ELEMENT_ARRAY.length; for( var i=0; i 0){ - COMIC_ELEMENT_ARRAY.shift().destroy(); + var _comicElm; + while( PANEL_ELEMENT_ARRAY.length > 0){ + _comicElm = PANEL_ELEMENT_ARRAY.shift(); + _comicElm.destroy && _comicElm.destroy(); } }, remove: removeComicElement, restore: restoreComicElement, replace: replaceComicElement, restoreReplace: restoreReplaceElement, - onPanelResize : function ( _panelX, _panelY, _panelW, _panelH, isResizerTopAction){ + onPanelResize : function ( _panelX, _panelY, _panelW, _panelH, isResizerTopAction ){ /* * リサイズが、ResizerTopによって行われた場合、comicElementのyを動かして見かけ上動かないようにする。 */ if( isResizerTopAction === true){ var _shiftX = _panelW -panelW, _shiftY = _panelH -panelH, - l = COMIC_ELEMENT_ARRAY.length; + l = PANEL_ELEMENT_ARRAY.length; for( var i = 0; i < l; i++){ - COMIC_ELEMENT_ARRAY[ i].shift( _shiftX, _shiftY); + PANEL_ELEMENT_ARRAY[ i].shift( _shiftX, _shiftY); } } panelX = _panelX; @@ -3170,20 +2622,20 @@ pettanr.editor = ( function(){ ELM_CONTAINER.style.left = _panelX +'px'; ELM_CONTAINER.style.top = _panelY +'px'; }, - onMouseMove: function( _mouseX, _mouseY){ - var l = COMIC_ELEMENT_ARRAY.length, + onMouseMove: function( _mouseX, _mouseY ){ + var l = PANEL_ELEMENT_ARRAY.length, _x = _mouseX -panelX, _y = _mouseY -panelY, _elm = currentElement; if( _elm !== null){ currentLockTest = currentLockTest === true && _x === 0 && _y === 0; - if( _elm.busy() === true){ + if( _elm.busy() === true ){ _elm.onMouseMove( _x, _y); return true; } - if( _elm.hitTest( _x, _y) === true){ - _elm.onMouseMove( _x, _y); // cursor + if( _elm.hitTest( _x, _y) === true ){ + _elm.onMouseMove( _x, _y ); // cursor return true; } if( currentLock === true){ @@ -3192,18 +2644,19 @@ pettanr.editor = ( function(){ } } for( var i=0; i' - ].join( '') - ); - HTML_ARRAY.push( '
'); - - return HTML_ARRAY.join( pettanr.LINE_FEED_CODE_TEXTAREA); - }, - getAsJsonString: function(){ - var JSON_STRING_ARRAY = [], - IMAGE_ARRAY = [], - BALLOON_ARRAY = [], - l = COMIC_ELEMENT_ARRAY.length, - _timing = 0, - _comicElement, - cr = pettanr.LINE_FEED_CODE_TEXTAREA; - - while( IMAGE_ARRAY.length + BALLOON_ARRAY.length < l){ - _comicElement = getComicElementByTiming(); - if( _comicElement === null) break; - _comicElement.type === COMIC_ELEMENT_TYPE_IMAGE ? - IMAGE_ARRAY.push( _comicElement.getAsJsonString()) : - BALLOON_ARRAY.push( _comicElement.getAsJsonString()); - } - function getComicElementByTiming(){ - while( _timing < l *2){ - for(var i=0; i