/*\r
* pettanR work.js\r
- * version 0.4.32\r
+ * version 0.4.33\r
* \r
* author:\r
* itozyun\r
pettanr.editor = pettanr.view.registerApplication( function(){\r
\r
var PANEL_ELEMENT_TYPE_IMAGE = 0,\r
- PANEL_ELEMENT_TYPE_TEXT = 1,\r
- MOUSE_LISTENER_ARRAY = [],\r
- PANEL_ELEMENT_ARRAY = [],\r
+ PANEL_ELEMENT_TYPE_TEXT = 1,\r
+ MOUSE_LISTENER_ARRAY = [],\r
+ PANEL_ELEMENT_ARRAY = [],\r
ELM_MOUSE_EVENT_CHATCHER = document.getElementById( 'mouse-operation-catcher'),\r
- MIN_PANEL_HEIGHT = 20,\r
- MIN_ELEMENT_SIZE = 19,\r
- MOUSE_HIT_AREA = 10,\r
+ MIN_PANEL_HEIGHT = 20,\r
+ MIN_ELEMENT_SIZE = 19,\r
+ MOUSE_HIT_AREA = 10,\r
jqMouseEventChacher,\r
jqEditor,\r
windowW, windowH,\r
- currentListener = null,\r
- currentCursor = '',\r
- instance = this,\r
+ currentListener = null,\r
+ currentCursor = '',\r
+ instance = this,\r
option,\r
- comicID = -1,\r
- panelID = -1,\r
- panelTimming = -1,\r
+ comicID = -1,\r
+ panelID = -1,\r
+ panelTimming = -1,\r
+ phase = -1,\r
log;\r
\r
/* ----------------------------------------\r
MENU_BAR_CONTROL.EDIT.createSelection( 'show Grid', 'ctrl + G', switchGrid, true, true, true);\r
\r
function addImage( e){\r
- setTimeout( IMAGE_EXPLORER_WINDOW.open, 0);\r
+ IMAGE_EXPLORER_WINDOW.open();// setTimeout( IMAGE_EXPLORER_WINDOW.open, 0);\r
instance.bodyBackOrForward( true );\r
e && e.preventDefault && e.preventDefault();\r
return false;\r
height: _h\r
});\r
},\r
- update: function( currentElement){\r
+ update: function( currentElement ){\r
\r
if( currentLock === true && currentElement === null) return;\r
\r
*/\r
var TAIL_OPERATOR = ( function(){\r
var MOUSE_CURSOR = updateMouseCursor,\r
- ELM_MOVER = document.getElementById( 'balloon-tail-mover'),\r
- SIZE = pettanr.util.getElementSize( ELM_MOVER).width,\r
- SIN = Math.sin,\r
- COS = Math.cos,\r
- ATAN = Math.atan,\r
- FLOOR = Math.floor,\r
- DEG_TO_RAD = Math.PI / 180,\r
- RAD_TO_DEG = 1 /DEG_TO_RAD,\r
- currentText = null,\r
+ ELM_MOVER = document.getElementById( 'balloon-tail-mover'),\r
+ SIZE = pettanr.util.getElementSize( ELM_MOVER).width,\r
+ SIN = Math.sin,\r
+ COS = Math.cos,\r
+ ATAN = Math.atan,\r
+ FLOOR = Math.floor,\r
+ DEG_TO_RAD = Math.PI / 180,\r
+ RAD_TO_DEG = 1 / DEG_TO_RAD,\r
+ currentText = null,\r
tailX, tailY,\r
x, y, w, h,\r
balloonW, balloonH, balloonA, radA,\r
startA;\r
\r
return {\r
- update: function ( _w, _h, _a){\r
+ update: function ( _w, _h, _a ){\r
balloonW = _w !== undefined ? _w : balloonW;\r
balloonH = _h !== undefined ? _h : balloonH;\r
balloonA = _a !== undefined ? _a : balloonA;\r
- radA = balloonA * DEG_TO_RAD;\r
- tailX = FLOOR( ( ( COS( radA) /2 +0.5) *( balloonW +SIZE)) -SIZE /2);\r
- tailY = FLOOR( ( ( SIN( radA) /2 +0.5) *( balloonH +SIZE)) -SIZE /2);\r
+ radA = ( balloonA - 90 ) * DEG_TO_RAD;\r
+ tailX = FLOOR( ( ( COS( radA ) / 2 + 0.5 ) * ( balloonW + SIZE )) - SIZE / 2);\r
+ tailY = FLOOR( ( ( SIN( radA ) / 2 + 0.5 ) * ( balloonH + SIZE )) - SIZE / 2);\r
ELM_MOVER.style.left = tailX +'px';\r
ELM_MOVER.style.top = tailY +'px';\r
//log.html( [ balloonW, balloonH, balloonA].join());\r
* visibilityのほうがいい, display:none だと ie で描画が狂う\r
*/\r
ELM_MOVER.style.visibility = '';\r
- this.update( _currentText.w, _currentText.h, _currentText.angle());\r
+ TAIL_OPERATOR.update( _currentText.w, _currentText.h, _currentText.angle() );\r
currentText = _currentText;\r
},\r
hitTest: function( _mouseX, _mouseY){\r
- var _x = tailX -SIZE /2,\r
- _y = tailY -SIZE /2;\r
+ var _x = tailX -SIZE / 2,\r
+ _y = tailY -SIZE / 2;\r
ret = _x <= _mouseX && _y <= _mouseY && _x +SIZE >= _mouseX && _y +SIZE >= _mouseY;\r
ret === true && MOUSE_CURSOR( 'move');\r
return ret;\r
currentText = null;\r
},\r
onStart: function( _currentText, _mouseX, _mouseY){\r
- if( _currentText.type !== PANEL_ELEMENT_TYPE_TEXT) return false;\r
+ if( _currentText.type !== PANEL_ELEMENT_TYPE_TEXT ) return false;\r
x = _currentText.x;\r
y = _currentText.y;\r
- if( this.hitTest( _mouseX -x, _mouseY -y) === true){\r
+ if( TAIL_OPERATOR.hitTest( _mouseX -x, _mouseY -y ) === true){\r
w = _currentText.w;\r
h = _currentText.h;\r
currentText = _currentText;\r
return false;\r
},\r
onDrag: function( _mouseX, _mouseY){\r
- _mouseX = _mouseX -x -w /2;\r
- _mouseY = _mouseY -y -h /2; //Balloonの中心を0,0とする座標系に変換\r
- \r
- this.update( w, h,\r
+ _mouseX = _mouseX - x - w / 2;\r
+ _mouseY = _mouseY - y - h / 2; //Balloonの中心を0,0とする座標系に変換\r
+ TAIL_OPERATOR.update( w, h,\r
_mouseX !== 0 ?\r
- ATAN( _mouseY /_mouseX) *RAD_TO_DEG +( _mouseX < 0 ? 180 : 0) :\r
- _mouseY > 0 ? 90 : -90\r
+ ATAN( _mouseY / _mouseX ) * RAD_TO_DEG + ( _mouseX > 0 ? 90 : 270 ) :\r
+ _mouseY > 0 ? 180 : 0\r
);\r
- currentText && currentText.angle( Math.floor( balloonA + 0.5 ));\r
- INFOMATION_WINDOW.update( currentText);\r
+ currentText && currentText.angle( FLOOR( balloonA + 0.5 ));\r
+ INFOMATION_WINDOW.update( currentText );\r
},\r
onFinish: function(){\r
startA !== currentText.angle() && COMIC_ELEMENT_OPERATION_MANAGER.saveStatus( x, y, w, h, startA);\r
*/\r
var jqImageElementOrigin;\r
var ImageElementClass = function( data ){\r
- jqImageElementOrigin = jqImageElementOrigin || $( $( '#imgElementTemplete').remove().html());\r
- \r
- var JQ_WRAPPER = jqImageElementOrigin.clone( true ),\r
- w = data.width,\r
- h = data.height,\r
- x, y, z,\r
- flipH = w < 0 ? -1 : 1,\r
- flipV = h < 0 ? -1 : 1,\r
+ jqImageElementOrigin = jqImageElementOrigin || $( $( '#imgElementTemplete' ).remove().html() );\r
+ \r
+ var jqWrap = jqImageElementOrigin.clone( true ),\r
+ flipH = data.width < 0 ? -1 : 1,\r
+ flipV = data.height < 0 ? -1 : 1,\r
resourcePicture = data.resource_picture,\r
- actualW = data.resource_picture.width,\r
- actualH = data.resource_picture.height,\r
+ actualW = data.resource_picture.width,\r
+ actualH = data.resource_picture.height,\r
reversibleImage = null,\r
- instance = this;\r
- w = Math.floor( w );\r
- h = Math.floor( h );\r
-\r
- function onAnimeComplete(){\r
+ instance = this,\r
+ x, y, z, w, h;\r
+ function flipReversibleImage(){\r
reversibleImage && reversibleImage.resize( flipH * w, flipV * h );\r
}\r
function updateResourcePicture( _resourcePicture ){\r
[ pettanr.CONST.RESOURCE_PICTURE_PATH, _resourcePicture.id, '.', _resourcePicture.ext ].join(''),\r
flipH * w, flipV * h\r
);\r
- if( reversibleImage !== null){\r
- JQ_WRAPPER.children( reversibleImage.elm ).replaceWith( _reversibleImage.elm );\r
+ if( reversibleImage !== null ){\r
+ jqWrap.children( reversibleImage.elm ).replaceWith( _reversibleImage.elm );\r
reversibleImage.destroy();\r
} else {\r
- JQ_WRAPPER.append( _reversibleImage.elm );\r
+ jqWrap.append( _reversibleImage.elm );\r
}\r
reversibleImage = _reversibleImage;\r
}\r
/* global methods */\r
- this.$ = JQ_WRAPPER;\r
+ this.$ = jqWrap;\r
//this.x = x;\r
//this.y = y;\r
//this.w = w;\r
//this.h = h; \r
this.z = data.z;\r
this.timing = data.t;\r
+ this.keepSize = false;\r
this.init = function(){\r
updateResourcePicture( data.resource_picture );\r
- instance.resize( data.x, data.y, data.width, data.height );\r
+ instance.resize( data.x, data.y, Math.abs( data.width ), Math.abs( data.height ) );\r
delete instance.init;\r
}\r
this.flip = function( _updateH, _updateV ){\r
flipV = _updateV === true ? -flipV : flipV;\r
reversibleImage.resize( flipH * w, flipV * h );\r
}\r
- this.flipV = function(){\r
- return flipV;\r
- }\r
- this.flipH = function(){\r
- return flipH;\r
- }\r
+ this.flipV = function(){ return flipV;}\r
+ this.flipH = function(){ return flipH;}\r
this.resourcePicture = function( _resourcePicture ){\r
if( _resourcePicture && _resourcePicture !== resourcePicture ){\r
HISTORY_CONTROL.saveState( updateResourcePicture, resourcePicture, _resourcePicture );\r
}\r
this.actualW = function(){ return actualW;}\r
this.actualH = function(){ return actualH;}\r
- this.keepSize = false;\r
this.resize = function( _x, _y, _w, _h, animate ){\r
- instance.x = x = _x !== undefined ? _x : x;\r
- instance.y = y = _y !== undefined ? _y : y;\r
- instance.w = w = _w !== undefined ? _w : w;\r
- instance.h = h = _h !== undefined ? _h : h;\r
- JQ_WRAPPER[ animate === true ? 'animate' : 'css' ]( { \r
+ instance.x = x = Type.isFinite( _x ) === true ? _x : x;\r
+ instance.y = y = Type.isFinite( _y ) === true ? _y : y;\r
+ instance.w = w = Type.isFinite( _w ) === true ? _w : w;\r
+ instance.h = h = Type.isFinite( _h ) === true ? _h : h;\r
+ jqWrap[ animate === true ? 'animate' : 'css' ]( { \r
left: x,\r
top: y,\r
width: w,\r
height: h\r
- }, 250, onAnimeComplete );\r
- animate !== true && onAnimeComplete();\r
+ }, 250, flipReversibleImage );\r
+ animate !== true && flipReversibleImage();\r
}\r
this.animate = function ( _x, _y, _w, _h, _flipH, _flipV ){\r
flipH = _flipH !== undefined ? _flipH : flipH;\r
delete instance.destroy;\r
\r
reversibleImage.destroy();\r
- JQ_WRAPPER.stop().remove();\r
- JQ_WRAPPER = reversibleImage = resourcePicture = data = instance = null;\r
+ jqWrap.stop().remove();\r
+ jqWrap = reversibleImage = resourcePicture = data = instance = null;\r
}\r
}\r
ImageElementClass.prototype = new AbstractComicElement( PANEL_ELEMENT_TYPE_IMAGE );\r
updateText();\r
instance.resize( data.x, data.y, data.width, data.height, data.tail );\r
delete instance.init;\r
- }\r
+ };\r
this.angle = function( _a ){\r
_a !== undefined && instance.resize( x, y, w, h, _a );\r
- return a >= 0 ? a : a + 360;\r
- }\r
+ return a;\r
+ };\r
this.text = function( _text ){\r
if( _text && text !== _text) {\r
HISTORY_CONTROL.saveState( updateText, text || '', _text );\r
updateText( _text );\r
}\r
return text;\r
- }\r
- this.getBalloonURL = function(){\r
- return balloon.getURL();\r
- }\r
+ };\r
this.resize = function( _x, _y, _w, _h, _a, animate ){\r
instance.x = x = _x !== undefined ? _x : x;\r
instance.y = y = _y !== undefined ? _y : y;\r
}, 250, resizeBalloon\r
); \r
animate !== true && resizeBalloon();\r
- }\r
+ };\r
this.animate = function ( _x, _y, _w, _h, _a ){\r
instance.resize( _x, _y, _w, _h, _a, true );\r
- }\r
+ };\r
this.destroy = function(){\r
delete instance.destroy;\r
\r
JQ_WRAPPER.stop().remove();\r
balloon.destroy();\r
JQ_WRAPPER = elmText = data = balloon = instance = null;\r
- }\r
+ };\r
}\r
TextElementClass.prototype = new AbstractComicElement( PANEL_ELEMENT_TYPE_TEXT );\r
\r
* 2. renumber z\r
*/\r
function appendComicElement( _panelElement ) {\r
- var z = _panelElement.z,\r
+ var z = Type.isFinite( _panelElement.z ) === true ? _panelElement.z : -1,\r
l = PANEL_ELEMENT_ARRAY.length,\r
_jqElm = _panelElement.$.stop().css( {\r
filter: '',\r
opacity: ''\r
});\r
- if( typeof z !== 'number' || z < 0 || z >= l ){\r
+ if( z < 0 ){\r
PANEL_ELEMENT_ARRAY.unshift( _panelElement );\r
- ELM_CONTAINER.appendChild( _jqElm.get( 0 ));\r
+ // ELM_CONTAINER.appendChild( _jqElm.get( 0 ));\r
+ renumber();\r
_jqElm.fadeIn();\r
- } else\r
- if( l === 0 ){\r
- PANEL_ELEMENT_ARRAY.push( _panelElement );\r
- ELM_CONTAINER.appendChild( _jqElm.get( 0 ));\r
} else {\r
- var insertIndex = 0;\r
for( var i = 0; i < l; ++i ){\r
- if( PANEL_ELEMENT_ARRAY[ i ].z <= z ){\r
- insertIndex = i;\r
- break;\r
- }\r
+ if( PANEL_ELEMENT_ARRAY[ i ].z < z ) break;\r
}\r
- PANEL_ELEMENT_ARRAY[ insertIndex ].$.before( _jqElm.fadeIn() );\r
- PANEL_ELEMENT_ARRAY.splice( insertIndex, 0, _panelElement );\r
+ if( i === l ){\r
+ PANEL_ELEMENT_ARRAY.push( _panelElement );\r
+ //ELM_CONTAINER.appendChild( _jqElm.get( 0 ));\r
+ } else {\r
+ PANEL_ELEMENT_ARRAY.splice( i, 0, _panelElement );\r
+ //PANEL_ELEMENT_ARRAY[ insertIndex ].$.before( _jqElm );\r
+ }\r
+ renumber();\r
+ _jqElm.fadeIn();\r
}\r
- renumber();\r
}\r
function removeComicElement( _panelElement ) {\r
var l = PANEL_ELEMENT_ARRAY.length;\r
- for( var i=0; i<l; ++i){\r
+ for( var i=0; i<l; ++i ){\r
if( PANEL_ELEMENT_ARRAY[ i ] === _panelElement ){\r
PANEL_ELEMENT_ARRAY.splice( i, 1 );\r
renumber();\r
return;\r
}\r
}\r
- function onFadeOut(){\r
- this.parentNode.removeChild( this );\r
- }\r
}\r
+ function onFadeOut(){\r
+ this.parentNode.removeChild( this );\r
+ } \r
function restoreComicElement( arg ){\r
var isAppend = arg[ 0 ],\r
comicElement = arg[ 1 ];\r
for( var i=0; i < l; ++i){\r
_panelElement = PANEL_ELEMENT_ARRAY[ i ];\r
jqElm = _panelElement.$;\r
+ i === 0 && ELM_CONTAINER.appendChild( jqElm.get( 0 ));\r
jqNext && jqNext.before( jqElm );\r
- _panelElement.z = l -i -1;\r
+ if( phase === 1 ) _panelElement.z = l - i - 1;\r
jqNext = jqElm;\r
}\r
}\r
function replaceComicElement( _panelElement, goForward ){\r
// PANEL_ELEMENT_ARRAYの再構築\r
var l = PANEL_ELEMENT_ARRAY.length,\r
- i = ( function(){\r
- for( var ret = 0; ret < l; ++ret ){\r
- if( PANEL_ELEMENT_ARRAY[ ret] === _panelElement ) return ret;\r
- }\r
- return -1;\r
- })();\r
+ i = -1;\r
+ for( var j = 0; j < l; ++j ){\r
+ if( PANEL_ELEMENT_ARRAY[ j ] === _panelElement ){\r
+ i = j;\r
+ break;\r
+ };\r
+ }\r
if( i === -1) return false;\r
- if( goForward === true){\r
- if( i === 0) return false;\r
- PANEL_ELEMENT_ARRAY.splice( i, 1);\r
- PANEL_ELEMENT_ARRAY.splice( i -1, 0, _panelElement);\r
+ if( goForward === true ){\r
+ if( i === 0 ) return false;\r
+ PANEL_ELEMENT_ARRAY.splice( i, 1 );\r
+ PANEL_ELEMENT_ARRAY.splice( i - 1, 0, _panelElement );\r
} else {\r
- if( i === l -1) return false;\r
- PANEL_ELEMENT_ARRAY.splice( i, 1);\r
- PANEL_ELEMENT_ARRAY.splice( i +1, 0, _panelElement);\r
+ if( i === l - 1 ) return false;\r
+ PANEL_ELEMENT_ARRAY.splice( i, 1 );\r
+ PANEL_ELEMENT_ARRAY.splice( i + 1, 0, _panelElement );\r
}\r
- renumber();\r
+ renumber( true );\r
return true;\r
}\r
- function restoreReplaceElement( arg){\r
+ function restoreReplaceElement( arg ){\r
replaceComicElement( arg[ 0], arg[ 1]);\r
}\r
function onTextInput( _panelElement ){\r
}\r
},\r
onImageSelect: function( data, isPanelPictureData ){\r
+ var _panelElement;\r
if( isPanelPictureData !== true ){\r
- data = {\r
+ _panelElement = new ImageElementClass( {\r
resource_picture:data,\r
- x: Math.floor( panelW /2 - data.width /2 ),\r
- y: Math.floor( panelH /2 - data.height /2 ),\r
+ x: Math.floor( panelW / 2 - data.width / 2 ),\r
+ y: Math.floor( panelH / 2 - data.height / 2 ),\r
z: -1,\r
t: PANEL_ELEMENT_ARRAY.length,\r
- width: data.width,\r
- height: data.height\r
- }\r
+ width: 1,\r
+ height: 1\r
+ });\r
+ _panelElement.init && _panelElement.init();\r
+ appendComicElement( _panelElement );\r
+ _panelElement.animate( undefined, undefined, Math.abs( data.width ), Math.abs( data.height ) );\r
+ } else {\r
+ _panelElement = new ImageElementClass( data );\r
+ _panelElement.init && _panelElement.init();\r
+ appendComicElement( _panelElement );\r
}\r
- var _panelElement = new ImageElementClass( data );\r
- _panelElement.init && _panelElement.init();\r
- appendComicElement( _panelElement );\r
- _panelElement.animate( undefined, undefined, data.width, data.height );\r
- SAVE( restoreComicElement, [ false, _panelElement], [ true, _panelElement], true );\r
+ SAVE( restoreComicElement, [ false, _panelElement], [ true, _panelElement ], true );\r
},\r
createTextElement: function( data ){\r
var _panelElement;\r
delete instance.firstOpen;\r
}\r
this.onOpen = function( _w, _h, _file ){\r
- comicID = -1;\r
- panelID = -1;\r
+ comicID = -1;\r
+ panelID = -1;\r
panelTimming = -1;\r
+ phase = 0;\r
\r
var panelW, panelH,\r
borderSize,\r
windowW = _w;\r
windowH = _h;\r
instance.onPaneResize( _w, _h );\r
+ \r
+ phase = 1;\r
}\r
this.onClose = function(){\r
+ phase = 2;\r
HISTORY_CONTROL.close();\r
\r
WINDOWS_CONTROL.close();\r
\r
// last\r
MENU_BAR_CONTROL.open();\r
+ \r
+ phase = -1;\r
}\r
this.onPaneResize = function( _windowW, _windowH){\r
windowW = _windowW || windowW;\r
isXHTML !== true ? '>' : ' \/>'\r
].join( ''); \r
} else {\r
- url = _panelElement.getBalloonURL();\r
+ url = pettanr.balloon.getBalloonUrl( _panelElement.w, _panelElement.h, _panelElement.angle() );\r
return [\r
'<img ',\r
'src="', isAbsoluteUrl !== true ? url : pettanr.util.getAbsolutePath( url ), '" ',\r