11 * ----------------------------------------
\r
18 * THIS_IS_CONST = 'this is const';
\r
24 * jqWrapper, JQ_WRAPPER
\r
26 * value of dom element
\r
27 * elmWrapper, ELM_WRAP
\r
29 * value of vml element
\r
35 /* ----------------------------------------
\r
37 * - MENU_BAR_CONTROL
\r
42 * - INFOMATION_WINDOW
\r
44 * - HELP_DOCUMENTS_WINDOW
\r
47 * - WHITE_GLASS_CONTROL
\r
51 * - PanelResizerClass
\r
52 * - PANEL_RESIZER_TOP
\r
53 * - PANEL_RESIZER_BOTTOM
\r
54 * - CONSOLE_CONTROLER
\r
58 * - POSITION_OPERATOR
\r
59 * - COMIC_ELEMENT_OPERATION_MANAGER
\r
61 * - ImageElementClass
\r
62 * - TextElementClass
\r
64 * - COMIC_ELEMENT_CONTROL
\r
68 pettanr.editor = pettanr.view.registerApplication( function(){
\r
70 var PANEL_ELEMENT_TYPE_IMAGE = 0,
\r
71 PANEL_ELEMENT_TYPE_TEXT = 1,
\r
72 MOUSE_LISTENER_ARRAY = [],
\r
73 PANEL_ELEMENT_ARRAY = [],
\r
74 ELM_MOUSE_EVENT_CHATCHER = document.getElementById( 'mouse-operation-catcher'),
\r
75 MIN_PANEL_HEIGHT = 20,
\r
76 MIN_ELEMENT_SIZE = 19,
\r
77 MOUSE_HIT_AREA = 10,
\r
78 jqMouseEventChacher,
\r
81 currentListener = null,
\r
90 /* ----------------------------------------
\r
92 * - mouseEventListener
\r
103 var MENU_BAR_CONTROL = ( function(){
\r
104 var ELM_BAR = document.getElementById( 'menu-bar'),
\r
105 ELM_ITEM_CLASSNAME = 'menu-bar-item',
\r
106 ELM_ITEM_ORIGN = ( function(){
\r
107 var ret = document.createElement( 'div'),
\r
108 div = document.createElement( 'div'),
\r
109 ul = document.createElement( 'ul');
\r
110 ret.className = ELM_ITEM_CLASSNAME;
\r
111 ret.appendChild( div);
\r
112 ret.appendChild( ul);
\r
115 ELM_SELECTION_ORIGN = ( function(){
\r
116 var ret = document.createElement( 'li'),
\r
117 a = document.createElement( 'a'),
\r
118 span = document.createElement( 'span'),
\r
119 key = document.createElement( 'kbd');
\r
120 a.appendChild( span);
\r
121 a.appendChild( key);
\r
122 ret.appendChild( a);
\r
127 barH = pettanr.util.getElementSize( ELM_BAR).height,
\r
128 itemW = pettanr.util.getElementSize( ELM_ITEM_ORIGN).width,
\r
129 selectionW = pettanr.util.getElementSize( ELM_ITEM_ORIGN.getElementsByTagName( 'ul')[ 0]).width,
\r
131 ELM_BAR.style.top = ( -barH) +'px';
\r
133 var MenubarSelectionClass = function( container, title, shortcut, visible, separateAfter){
\r
134 var ELM_WRAPPER = ELM_SELECTION_ORIGN.cloneNode( true),
\r
135 ELM_TITLE = ELM_WRAPPER.getElementsByTagName( 'span')[ 0],
\r
136 elmShortcut = ELM_WRAPPER.getElementsByTagName( 'kbd')[ 0];
\r
139 elmShortcut.innerHTML = shortcut;
\r
141 elmShortcut.parentNode.removeChild( elmShortcut);
\r
143 elmShortcut = null;
\r
145 container.appendChild( ELM_WRAPPER);
\r
147 updateTitle( title);
\r
148 updateVisible( visible);
\r
150 function updateTitle( _title){
\r
151 ELM_TITLE.innerHTML = title = _title;
\r
153 function updateVisible( _visible){
\r
154 if( _visible !== undefined){
\r
155 visible = !!_visible;
\r
156 ELM_WRAPPER.className = visible === true ? '' : 'disabled';
\r
161 title: function( _title){
\r
162 _title !== undefined && updateTitle( _title);
\r
165 visible: function( _visible){
\r
166 visible !== !!_visible && updateVisible( _visible);
\r
169 separateAfter: separateAfter
\r
173 var MenuBarItemClass = function( title){
\r
174 var ELM_WRAPPER = ELM_ITEM_ORIGN.cloneNode( true),
\r
175 ELM_TITLE = ELM_WRAPPER.getElementsByTagName( 'div')[ 0],
\r
176 ELM_SELECTION = ELM_WRAPPER.getElementsByTagName( 'ul')[ 0],
\r
177 INDEX = ITEM_ARRAY.length,
\r
178 SELECTION_CALLBACK_ARRAY = [],
\r
181 ELM_TITLE.innerHTML = title;
\r
183 ELM_WRAPPER.style.left = ( itemW * INDEX) +'px';
\r
184 ELM_BAR.appendChild( ELM_WRAPPER);
\r
186 function onClick( e){
\r
187 var i = pettanr.util.getChildIndex( this.parentNode, this);
\r
188 i !== -1 && this.className !== 'disabled' && SELECTION_CALLBACK_ARRAY[ i]( i);
\r
189 e.stopPropagation();
\r
196 $( ELM_SELECTION).children( 'li').click( onClick);
\r
200 if( visible === true) return;
\r
201 jqStage.append( ELM_WRAPPER);
\r
202 ELM_WRAPPER.className = ELM_ITEM_CLASSNAME +'-focus';
\r
203 this.onShow && setTimeout( this.onShow, 0);
\r
207 if( visible === false) return;
\r
208 ELM_BAR.appendChild( ELM_WRAPPER);
\r
209 ELM_WRAPPER.className = ELM_ITEM_CLASSNAME;
\r
210 this.onHide && setTimeout( this.onHide, 0);
\r
213 createSelection: function( title, shortcut, callback, visible, separateBefore, separateAfter){
\r
214 var ret = MenubarSelectionClass.apply( {}, [ ELM_SELECTION, title, shortcut, visible, separateAfter]),
\r
215 before = SELECTION_CALLBACK_ARRAY.length > 0 ? SELECTION_CALLBACK_ARRAY[ SELECTION_CALLBACK_ARRAY.length -1] : null;
\r
216 SELECTION_CALLBACK_ARRAY.push( callback);
\r
217 if( before !== null && ( separateBefore === true || before.separateAfter === true)){
\r
218 ret.elm.style.borderTop = '1px solid #ccc';
\r
226 function createMenubarItem( title){
\r
227 var _item = new MenuBarItemClass( title);
\r
228 ITEM_ARRAY.push( _item);
\r
233 jqStage = jqEditor;
\r
234 jqBar = $( ELM_BAR).animate( { top: 0});
\r
236 var l = ITEM_ARRAY.length;
\r
237 for( var i=0; i<l; ++i){
\r
238 ITEM_ARRAY[ i].init();
\r
241 delete MENU_BAR_CONTROL.init;
\r
244 MENU_BAR_CONTROL.init && MENU_BAR_CONTROL.init();
\r
245 // ELM_BAR.style.top = ( -barH) +'px';
\r
249 var l = ITEM_ARRAY.length;
\r
250 for( var i=0; i<l; ++i){
\r
251 ITEM_ARRAY[ i].hide();
\r
255 onMouseMove: function( _mouseX, _mouseY){
\r
256 if( barH >= _mouseY){
\r
259 var l = ITEM_ARRAY.length;
\r
260 for( var i=0; i<l; ++i){
\r
261 ITEM_ARRAY[ i].hide();
\r
265 onMouseUp: function( _mouseX, _mouseY){
\r
268 onMouseDown: function( _mouseX, _mouseY){
\r
269 var l = ITEM_ARRAY.length;
\r
270 if( barH < _mouseY || itemW * l < _mouseX) return false;
\r
271 for( var i=0; i<l; ++i){
\r
272 if( i * itemW <= _mouseX && _mouseX < ( i +1) * itemW){
\r
273 ITEM_ARRAY[ i].show();
\r
275 ITEM_ARRAY[ i].hide();
\r
280 busy: function( _busy){
\r
283 onWindowResize: function( _windowW, _windowH){
\r
286 QUIT: createMenubarItem( 'Quit'),
\r
287 EDIT: createMenubarItem( 'Edit'),
\r
288 WINDOW: createMenubarItem( 'Window'),
\r
289 HELP: pettanr.util.extend( createMenubarItem( 'Help'), {
\r
290 createAjaxSelection: function( callback){
\r
291 var elmLoading = document.createElement( 'li'),
\r
293 elmSelection = this.elm.getElementsByTagName( 'ul')[ 0];
\r
294 elmSelection.appendChild( elmLoading);
\r
295 elmLoading.className = 'loading';
\r
296 elmLoading.style.height = '90px';
\r
298 this.onShow = callback;
\r
301 delete this.createAjaxSelection;
\r
303 elmSelection.removeChild( elmLoading);
\r
304 $( elmSelection).children( 'li').click( that.onClick);
\r
305 elmLoading = elmSelection = null;
\r
306 delete that.onShow;
\r
315 /* ----------------------------------------
\r
319 var HISTORY_CONTROL = ( function() {
\r
320 var STACK_BACK = [],
\r
321 STACK_FORWARD = [],
\r
322 MENUBAR_BACK = MENU_BAR_CONTROL.EDIT.createSelection( 'back', 'ctrl + z', back, false),
\r
323 MENUBAR_FORWARD = MENU_BAR_CONTROL.EDIT.createSelection( 'forward', 'ctrl + y', forward, false, false, true),
\r
326 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 90, false, true, back); // ctrl + Z
\r
327 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 90, true, true, forward); // ctrl + shift + Z
\r
328 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 89, false, true, forward); // ctrl + Y
\r
332 * currentを控えてSTACK_FORWARD.push(current)
\r
333 * STACK_BACK.pop()を実行してcurrentに
\r
335 if( STACK_BACK.length === 0) return;
\r
337 var state = STACK_BACK.pop();
\r
338 state && state.fn( state.argBack);
\r
339 MENUBAR_BACK.visible( STACK_BACK.length !== 0);
\r
340 SAVE_CONTROL.panelUpdated( STACK_BACK.length !== 0);
\r
342 STACK_FORWARD.push( state);
\r
343 MENUBAR_FORWARD.visible( true);
\r
345 function forward(){
\r
346 if( STACK_FORWARD.length === 0) return;
\r
348 var state = STACK_FORWARD.pop();
\r
349 state.fn( state.argForword);
\r
350 MENUBAR_FORWARD.visible( STACK_FORWARD.length !== 0);
\r
352 STACK_BACK.push( state);
\r
353 MENUBAR_BACK.visible( true);
\r
354 SAVE_CONTROL.panelUpdated( true);
\r
356 function destroyStack( _stack, _destroy){
\r
359 var _argBack = _stack.argBack,
\r
360 _argForword = _stack.argForword,
\r
362 if( Type.isArray( _argBack ) === true ){ // isArray
\r
363 while( _argBack.length > 0){
\r
364 _value = _argBack.shift();
\r
365 _destroy === true && typeof _value.destroy === 'function' && _value.destroy();
\r
368 if( Type.isArray( _argForword ) === true ){
\r
369 while( _argForword.length > 0){
\r
370 _value = _argForword.shift();
\r
371 _destroy === true && typeof _value.destroy === 'function' && _value.destroy();
\r
377 log = $( '#history-log');
\r
378 delete HISTORY_CONTROL.init;
\r
381 HISTORY_CONTROL.init && HISTORY_CONTROL.init();
\r
384 MENUBAR_BACK.visible( false);
\r
385 MENUBAR_FORWARD.visible( false);
\r
386 while( STACK_BACK.length > 0){
\r
387 destroyStack( STACK_BACK.shift(), true);
\r
389 while( STACK_FORWARD.length > 0){
\r
390 destroyStack( STACK_FORWARD.shift(), true);
\r
393 saveState: function( _function, _argBack, _argForword, _destroy) {
\r
397 argForword: _argForword,
\r
400 MENUBAR_BACK.visible( true);
\r
401 SAVE_CONTROL.panelUpdated( true);
\r
404 while( STACK_FORWARD.length > 0){
\r
405 _stack = STACK_FORWARD.shift();
\r
406 destroyStack( _stack, _stack.destroy);
\r
408 MENUBAR_FORWARD.visible( false);
\r
413 /* ----------------------------------------
\r
417 var SAVE_CONTROL = ( function(){
\r
418 var SAVE = MENU_BAR_CONTROL.QUIT.createSelection( 'save', 'ctrl + S', quit, false),
\r
419 SAVE_AND_QUIT = MENU_BAR_CONTROL.QUIT.createSelection( 'save & quit', null, quit, false, false, true),
\r
420 SAVE_AS_HTML = MENU_BAR_CONTROL.QUIT.createSelection( 'get as html', null, outputAsHtml, true, false, true),
\r
421 SAVE_AS_JSON_STRING = MENU_BAR_CONTROL.QUIT.createSelection( 'get JsonStr', null, outputAsJsonString, true, false, true),
\r
422 QUIT = MENU_BAR_CONTROL.QUIT.createSelection( 'quit', null, quit, true, true),
\r
426 pettanr.editor.shutdown();
\r
429 function outputAsHtml(){
\r
430 pettanr.outputConsole.bootInOverlay(
\r
431 pettanr.outputConsole.HTML,
\r
432 comicID, panelID, panelTimming,
\r
433 PANEL_CONTROL.w(), PANEL_CONTROL.h(),
\r
434 1, // border, BackgroundImage
\r
435 PANEL_ELEMENT_ARRAY
\r
438 function outputAsJsonString(){
\r
439 pettanr.outputConsole.bootInOverlay(
\r
440 pettanr.outputConsole.JSON,
\r
441 comicID, panelID, panelTimming,
\r
442 PANEL_CONTROL.w(), PANEL_CONTROL.h(),
\r
443 1, // border, BackgroundImage
\r
444 PANEL_ELEMENT_ARRAY
\r
448 open: function(){},
\r
449 close: function(){},
\r
451 panelUpdated: function( _updated){
\r
452 if( _updated !== undefined && updated !== _updated ){
\r
453 SAVE.visible( !!_updated );
\r
454 SAVE_AND_QUIT.visible( !!_updated );
\r
455 updated = !!_updated;
\r
465 /* ----------------------------------------
\r
468 * - mouseEventListener
\r
470 var WINDOWS_CONTROL = ( function(){
\r
472 * 表示上手前にあるwindowは、WINDOW_ARRAYの先頭にあり、htmlでは後ろにある。
\r
474 var DEFAULT_MIN_WINDOW_WIDTH = 200,
\r
475 DEFAULT_MIN_WINDOW_HEIGHT = 200,
\r
477 WINDOW_BODY_BODER_SIZE = 1,
\r
480 currentWindowIndex = -1,
\r
483 var jqWindowOrigin,
\r
485 var WindowClass = function( bodyTempleteID, title, x, y, w, h, visible, CLOSE_BUTTON_ENABLED, RESIZE_BUTTON_ENABLED, minWindowW, minWindowH){
\r
486 var MOUSE_CURSOR = updateMouseCursor,
\r
487 MENUBAR_SELWCTION = MENU_BAR_CONTROL.WINDOW.createSelection(
\r
488 ( visible !== true ? 'show ' : 'hide ') +title,
\r
489 null, onMenuClick, true
\r
492 jqWrapper, jqHeader, jqFooter = null,
\r
493 elmBody, elmBodyStyle,
\r
494 startX, startY, startW, startH,
\r
496 headerH, bodyH, footerH = 0,
\r
497 isDragging = false,
\r
498 isResizing = false,
\r
499 bodyIsTachable = false,
\r
502 function onMenuClick(){
\r
503 visible === true ? instance.close() : instance.open();
\r
505 function update( _x, _y, _w, _h){
\r
506 _x = _x !== undefined ? _x : x;
\r
507 _y = _y !== undefined ? _y : y;
\r
508 _y = _y > MENU_BAR_CONTROL.h ? _y : MENU_BAR_CONTROL.h;
\r
509 _w = _w !== undefined ? _w : w;
\r
510 _h = _h !== undefined ? _h : h;
\r
517 bodyH = _h -headerH -footerH;
\r
518 elmBodyStyle.height = bodyH +'px';
\r
519 ( w !== _w || h !== _h) && instance.onResize && instance.onResize( _w, bodyH);
\r
525 function bodyBackOrForward( isBack){
\r
526 if( !instance) return;
\r
527 if( bodyIsTachable === !isBack) return;
\r
528 elmBodyStyle.position = isBack === true ? 'relative' : 'absolute';
\r
529 elmBodyStyle.left = isBack === true ? 0 : x +'px';
\r
530 elmBodyStyle.top = isBack === true ? 0 : y +headerH +'px';
\r
531 elmBodyStyle.width = isBack === true ? '' : ( w -WINDOW_BODY_BODER_SIZE *2) +'px';
\r
532 bodyIsTachable === isBack && isBack === true ? jqHeader.after( elmBody) : jqStage.append( elmBody);
\r
533 bodyIsTachable = !isBack;
\r
535 function onWindowResize( e){
\r
536 bodyBackOrForward( true);
\r
544 MOUSE_CURSOR( 'nw-resize');
\r
545 e.stopPropagation();
\r
549 init: function( jqContainer){
\r
551 * setTimeout で呼ばれるグローバルメソッド内では、this でなく instance を使う.
\r
555 jqWindowOrigin = jqWindowOrigin || ( function(){
\r
556 return $( $( '#windowTemplete').remove().html());
\r
558 closeButtonWidth = closeButtonWidth || ( function(){
\r
559 return pettanr.util.getElementSize( jqWindowOrigin.clone( true).find( '.window-close-button').get( 0)).width;
\r
562 jqStage = jqEditor;
\r
563 this.$ = jqWrapper = jqWindowOrigin.clone( true);
\r
564 jqHeader = jqWrapper.children( '.window-header').eq( 0).html( title);
\r
565 headerH = pettanr.util.getElementSize( jqHeader.get( 0)).height;
\r
566 elmBody = jqWrapper.children( '.window-body').get( 0);
\r
567 elmBodyStyle = elmBody.style;
\r
569 if( bodyTempleteID) {
\r
570 jqWrapper.find( '.window-body-insert-position').replaceWith( $( $( '#' +bodyTempleteID).remove().html()));
\r
572 jqWrapper.find( '.window-body-insert-position').remove();
\r
574 CLOSE_BUTTON_ENABLED !== true && jqWrapper.find( '.window-close-button').remove();
\r
576 this.onInit && this.onInit();
\r
579 x: function(){ return x;},
\r
580 y: function(){ return y;},
\r
581 w: function(){ return w;},
\r
582 h: function(){ return h;},
\r
584 title: function( _title){
\r
585 typeof _title === 'string' && jqHeader.html( _title);
\r
586 title = typeof _title === 'string' ? _title : title;
\r
590 firstOpen: function(){
\r
591 if( RESIZE_BUTTON_ENABLED === true){
\r
592 footerH = pettanr.util.getElementSize( jqWrapper.find( '.window-footer').get( 0)).height;
\r
593 //jqWrapper.find( '.window-resize-button').eq( 0).mousedown( onWindowResize);
\r
595 jqWrapper.find( '.window-footer').remove();
\r
597 this.onFirstOpen && this.onFirstOpen( w, h -headerH -footerH);
\r
599 update( x, y, w, h);
\r
601 delete this.firstOpen;
\r
604 if( visible === true) return;
\r
605 instance.visible = visible = true;
\r
606 openWindow( instance);
\r
607 MENUBAR_SELWCTION.title( 'hide ' +title);
\r
609 for( var i=0, l = WINDOW_ARRAY.length; i<l; ++i){
\r
610 if( WINDOW_ARRAY[ i] === instance){
\r
611 WINDOW_ARRAY.splice( i, 1);
\r
612 WINDOW_ARRAY.unshift( instance);
\r
613 currentWindow = null;
\r
614 currentWindowIndex = -1;
\r
618 onFadeIn: function(){
\r
619 instance.firstOpen && instance.firstOpen();
\r
620 instance.onOpen && setTimeout( callOnOpen, 0);
\r
621 function callOnOpen(){
\r
622 instance.onOpen( w, bodyH);
\r
625 onFadeOut: function(){
\r
626 var elmWrapper = jqWrapper.get(0);
\r
627 elmWrapper.parentNode.removeChild( elmWrapper);
\r
628 instance.onClose && setTimeout( instance.onClose, 0);
\r
631 if( visible === false) return;
\r
632 instance.visible = visible = false;
\r
633 jqWrapper.fadeOut( instance.onFadeOut);
\r
634 MENUBAR_SELWCTION.title( 'show ' +title);
\r
636 bodyBackOrForward: bodyBackOrForward,
\r
637 onMouseDown: function( _mouseX, _mouseY){
\r
638 if( RESIZE_BUTTON_ENABLED === true && x +w -20 <= _mouseX && _mouseX < x +w && y +headerH +bodyH < _mouseY && _mouseY <= y +h){
\r
639 bodyBackOrForward( true);
\r
647 MOUSE_CURSOR( 'nw-resize');
\r
651 if( x > _mouseX || y > _mouseY || x +w < _mouseX || y +headerH < _mouseY ) return;
\r
652 if( CLOSE_BUTTON_ENABLED === true && x +w -closeButtonWidth < _mouseX){
\r
658 MOUSE_CURSOR( 'move');
\r
666 onMouseUp: function( _mouseX, _mouseY){
\r
667 isDragging = isResizing = false;
\r
670 onMouseMove: function( _mouseX, _mouseY){
\r
671 var _updateX = _mouseX -offsetX,
\r
672 _updateY = _mouseY -offsetY;
\r
674 if( isResizing === true){
\r
675 var _w = startW +_updateX,
\r
676 _h = startH +_updateY;
\r
677 update( startX, startY, _w < minWindowW ? minWindowW : _w, _h < minWindowH ? minWindowH : _h);
\r
680 if( isDragging === true) {
\r
681 update( startX +_updateX, startY +_updateY);
\r
684 if( x > _mouseX || x +w < _mouseX ) return;
\r
686 ( y <= _mouseY && y +headerH >= _mouseY ) ?
\r
687 MOUSE_CURSOR( 'pointer') : // hit to header
\r
689 bodyBackOrForward( y +headerH > _mouseY || y +headerH +bodyH < _mouseY);
\r
691 onMouseOut: function( _mouseX, _mouseY){
\r
692 bodyIsTachable === true && bodyBackOrForward( true);
\r
693 isDragging = false;
\r
697 return isDragging === true || isResizing === true;
\r
699 bodyHeight: function(){
\r
705 function getCurrentIndex( _mouseX, _mouseY){
\r
706 if( currentWindow && currentWindow.busy() === true) return currentWindowIndex;
\r
707 var l = WINDOW_ARRAY.length,
\r
708 _currentWindow = null,
\r
710 currentWindowIndex = -1;
\r
711 for( var i=0; i<l; i++){
\r
712 _win = WINDOW_ARRAY[ i];
\r
713 if( _win.visible !== true) continue;
\r
716 if( _x <= _mouseX && _y <= _mouseY && _x +_win.w() >= _mouseX && _y +_win.h() >= _mouseY){
\r
717 _currentWindow = _win;
\r
718 currentWindowIndex = i;
\r
722 currentWindow && currentWindow !== _currentWindow && currentWindow.onMouseOut( _mouseX, _mouseY);
\r
723 currentWindow = _currentWindow;
\r
724 return currentWindowIndex;
\r
726 function openWindow( _window){
\r
727 if( _window.visible !== true) return;
\r
728 var _jqWindow = _window.$;
\r
729 jqContainer.append( _jqWindow);// appendした後に fadeIn() しないと ie で filterが適用されない.
\r
730 _jqWindow.fadeIn( _window.onFadeIn);
\r
736 jqContainer = $( '#window-container');
\r
738 var l = WINDOW_ARRAY.length,
\r
740 for( var i=l-1; i >= 0; --i){
\r
741 _window = WINDOW_ARRAY[ i];
\r
742 _window.init && _window.init( jqContainer);
\r
743 _window.visible === true && openWindow( _window);
\r
745 log = $( '#window-log');
\r
747 delete WINDOWS_CONTROL.init;
\r
750 WINDOWS_CONTROL.init && WINDOWS_CONTROL.init();
\r
755 onMouseMove: function( _mouseX, _mouseY){
\r
756 var _index = getCurrentIndex( _mouseX, _mouseY);
\r
758 currentWindow.onMouseMove( _mouseX, _mouseY);
\r
761 if( _index > 0){ // 先頭のクリックでない場合
\r
763 WINDOW_ARRAY.splice( currentWindowIndex, 1);
\r
764 WINDOW_ARRAY.unshift( currentWindow);
\r
766 jqContainer.append( currentWindow.$);
\r
767 currentWindowIndex = 0;
\r
772 onMouseUp: function( _mouseX, _mouseY){
\r
773 if( getCurrentIndex( _mouseX, _mouseY) === 0){
\r
774 currentWindow.onMouseUp( _mouseX, _mouseY);
\r
779 onMouseDown: function( _mouseX, _mouseY){
\r
780 if( getCurrentIndex( _mouseX, _mouseY) === 0){
\r
781 currentWindow.onMouseDown( _mouseX, _mouseY);
\r
787 return currentWindow !== null;
\r
789 onWindowResize: function( _windowW, _windowH){
\r
794 createWindow: function( EXTENDS, bodyTempleteID, title, x, y, w, h, opt_visible, opt_closeButtonEnabled, opt_resizeButtonEnabled, opt_minWindowW, opt_minWindowH){
\r
795 opt_visible = opt_visible !== false;
\r
796 opt_closeButtonEnabled = opt_closeButtonEnabled === true;
\r
797 opt_resizeButtonEnabled = opt_resizeButtonEnabled === true;
\r
798 opt_minWindowW = opt_minWindowW || ( w < DEFAULT_MIN_WINDOW_WIDTH) ? w : DEFAULT_MIN_WINDOW_WIDTH;
\r
799 opt_minWindowH = opt_minWindowH || ( h < DEFAULT_MIN_WINDOW_HEIGHT) ? h : DEFAULT_MIN_WINDOW_HEIGHT;
\r
801 var _window = pettanr.util.extend(
\r
803 bodyTempleteID, title, x, y, w, h, opt_visible, opt_closeButtonEnabled, opt_resizeButtonEnabled, opt_minWindowW, opt_minWindowH
\r
807 WINDOW_ARRAY.unshift( _window);
\r
808 WINDOWS_CONTROL.init === undefined && _window.init( jqContainer);
\r
809 WINDOWS_CONTROL.init === undefined && openWindow( _window);
\r
815 /* ----------------------------------------
\r
819 var TOOL_BOX_WINDOW = ( function(){
\r
820 var addImageButton, addTextButton, editBgButton, switchGridButton, popupHelpButton, postButton,
\r
823 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 73, false, true, addImage);
\r
824 MENU_BAR_CONTROL.EDIT.createSelection( 'Add Image', 'ctrl + I', addImage, true, true, false);
\r
826 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 84, false, true, addText);
\r
827 MENU_BAR_CONTROL.EDIT.createSelection( 'Add Text', 'ctrl + T', addText, true, false, true);
\r
829 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 71, false, true, switchGrid);
\r
830 MENU_BAR_CONTROL.EDIT.createSelection( 'show Grid', 'ctrl + G', switchGrid, true, true, true);
\r
832 function addImage( e){
\r
833 setTimeout( COMIC_ELEMENT_CONTROL.createImageElement, 0);
\r
834 e && e.preventDefault && e.preventDefault();
\r
837 function addText( e){
\r
838 setTimeout( COMIC_ELEMENT_CONTROL.createTextElement, 0);
\r
839 e && e.preventDefault && e.preventDefault();
\r
842 function switchGrid( e){
\r
843 setTimeout( GRID_CONTROL.update, 0);
\r
844 e && e.preventDefault && e.preventDefault();
\r
847 function popupHelp( e){
\r
848 instance.bodyBackOrForward( true);
\r
849 setTimeout( HELP_DOCUMENTS_WINDOW.open, 0);
\r
850 e && e.preventDefault && e.preventDefault();
\r
853 function editBG( e){
\r
854 instance.bodyBackOrForward( true);
\r
855 setTimeout( INFOMATION_WINDOW.open, 0);
\r
856 e && e.preventDefault && e.preventDefault();
\r
860 return WINDOWS_CONTROL.createWindow(
\r
862 onInit: function(){
\r
864 delete this.onInit;
\r
866 onFirstOpen: function(){
\r
867 addImageButton = $( '#toolbox-add-image-button').click( addImage);
\r
868 addTextButton = $( '#toolbox-add-text-button').click( addText);
\r
869 editBgButton = $( '#toolbox-edit-bg-button').click( editBG);
\r
870 switchGridButton = $( '#toolbox-switch-grid').click( switchGrid);
\r
871 popupHelpButton = $( '#toolbox-popup-help-button').click( popupHelp);
\r
873 postButton = $( '#toolbox-post-button');
\r
875 delete this.onFirstOpen;
\r
878 'toolbox-window', 'Tool box', 0, 215, 110, 290, true
\r
883 /* ----------------------------------------
\r
887 var IMAGE_EXPLORER_WINDOW = ( function(){
\r
888 var instance, finder;
\r
890 return WINDOWS_CONTROL.createWindow(
\r
892 onInit: function(){
\r
894 delete this.onInit;
\r
896 onOpen: function( _w, _h){
\r
897 finder = finder || pettanr.finder.createFinder( pettanr.editor, document.getElementById( 'image-exproler-container'), pettanr.driver.createPictureTree());
\r
898 finder.resize( _w, _h );
\r
900 onResize: function( _w, _h ){
\r
901 finder.resize( _w, _h );
\r
904 'image-exproler', 'Album', 0, 215, 400, 350, false, true, true, 300, 300
\r
909 /* ----------------------------------------
\r
910 * INFOMATION_WINDOW
\r
913 var INFOMATION_WINDOW = ( function(){
\r
914 var FADE_EFFECT_ENABLED = true, //pettanr.ua.isIE === false || pettanr.ua.ieVersion >= 8,
\r
915 FADE_IN_EFFECT = FADE_EFFECT_ENABLED === true ? 'fadeIn' : 'show',
\r
916 FADE_OUT_EFFECT = FADE_EFFECT_ENABLED === true ? 'fadeOut' : 'hide',
\r
917 backgroundInfomationElm,
\r
918 jqComicElementInformation,
\r
919 inputX, inputY, inputZ, inputA, inputW, inputH, inputAspectRatio,
\r
920 inputPercentW, inputPercentH,
\r
921 currentComicElement = null,
\r
922 currentElementType = -1,
\r
923 currentLock = false;
\r
925 return WINDOWS_CONTROL.createWindow(
\r
927 onFirstOpen: function( _w, _h){
\r
928 backgroundInfomationElm = $( '#panel-background-information');
\r
930 jqComicElementInformation = $( '#comic-element-infomation').hide().css( {
\r
933 var TAB_GROUP_ID = 'comic-element-attribute';
\r
934 var CREATER = pettanr.form.createInputText;//pettanr.key.createEditableText;
\r
935 inputX = CREATER( document.getElementById( 'comic-element-x'), null, TAB_GROUP_ID);
\r
936 inputY = CREATER( document.getElementById( 'comic-element-y'), null, TAB_GROUP_ID);
\r
937 inputZ = CREATER( document.getElementById( 'comic-element-z'), null, TAB_GROUP_ID);
\r
938 inputA = CREATER( document.getElementById( 'comic-element-a'), null, TAB_GROUP_ID);
\r
939 inputW = CREATER( document.getElementById( 'comic-element-w'), null, TAB_GROUP_ID);
\r
940 inputH = CREATER( document.getElementById( 'comic-element-h'), null, TAB_GROUP_ID);
\r
941 inputPercentW = CREATER( document.getElementById( 'comic-element-w-percent'), null, TAB_GROUP_ID);
\r
942 inputPercentH = CREATER( document.getElementById( 'comic-element-h-percent'), null, TAB_GROUP_ID);
\r
943 inputAspectRatio = $( '#comic-element-keep-aspect');
\r
944 delete this.onFirstOpen;
\r
946 onResize: function( _w, _h){
\r
947 jqComicElementInformation.css( {
\r
951 update: function( currentElement){
\r
953 if( currentLock === true && currentElement === null) return;
\r
955 var _elementType = currentElement === null ? -1 : currentElement.type,
\r
956 x = currentElement !== null ? currentElement.x : 0,
\r
957 y = currentElement !== null ? currentElement.y : 0,
\r
958 z = currentElement !== null ? currentElement.z : 0,
\r
959 a = _elementType === PANEL_ELEMENT_TYPE_TEXT ? Math.floor( currentElement.angle()) : 0,
\r
960 w = currentElement !== null ? currentElement.w : 0,
\r
961 h = currentElement !== null ? currentElement.h : 0,
\r
962 actualW = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualW() : 1,
\r
963 actualH = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualH() : 1,
\r
964 wPercent = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( w / actualW *100) : 0,
\r
965 hPercent = _elementType === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( h / actualH *100) : 0,
\r
966 keepAspect = currentElement !== null && currentElement.keepAspect === true;
\r
968 if( currentElementType !== _elementType){
\r
969 if( _elementType !== -1){
\r
970 if( _elementType === 1){
\r
971 inputA.visible( true);
\r
972 inputPercentW.visible( false);
\r
973 inputPercentH.visible( false);
\r
974 inputAspectRatio.hide();
\r
976 inputA.visible( false);
\r
977 inputPercentW.visible( true);
\r
978 inputPercentH.visible( true);
\r
979 inputAspectRatio.show();
\r
981 currentElementType === -1 && jqComicElementInformation.stop().css( {
\r
984 })[ FADE_IN_EFFECT]();
\r
986 currentElementType !== -1 && jqComicElementInformation.stop().css({
\r
989 })[ FADE_OUT_EFFECT]();
\r
991 currentElementType = _elementType;
\r
993 if( currentElementType !== -1){
\r
997 _elementType === 1 && inputA.value( a);
\r
1000 _elementType === 0 && inputPercentW.value( wPercent);
\r
1001 _elementType === 0 && inputPercentH.value( hPercent);
\r
1006 lock: function( _currentLock){
\r
1007 currentLock = !!_currentLock;
\r
1008 this.bodyBackOrForward( !currentLock);
\r
1011 'infomation-window', 'Infomation', 0, 30, 200, 180, true
\r
1015 /* ----------------------------------------
\r
1019 var HELP_DOCUMENTS_WINDOW = ( function(){
\r
1020 var visible = true,
\r
1024 currentPageIndex = 0,
\r
1026 HELP = MENU_BAR_CONTROL.HELP,
\r
1027 onLoadFunction = HELP.createAjaxSelection( onAjaxStart),
\r
1030 function onAjaxStart( _pageIndex){
\r
1031 currentPageIndex = _pageIndex || currentPageIndex;
\r
1032 if( onHelpLoad !== null){
\r
1034 url: 'help/jp.xml',
\r
1036 success: onHelpLoad
\r
1038 onHelpLoad = null;
\r
1040 onAjaxStart = new Function;
\r
1042 var onHelpLoad = function( _xml){
\r
1043 var jqXML = $( _xml),
\r
1044 helpTitle = jqXML.find( 'pages').eq( 0).attr( 'title'),
\r
1045 elmNavi = document.createElement( 'div'),
\r
1046 elmItemOrigin = document.createElement( 'a'),
\r
1047 elmPages = document.createElement( 'div'),
\r
1048 elmPageOrigin = document.createElement( 'div'),
\r
1049 elmTitleOrigin = document.createElement( 'h2'),
\r
1051 elmNavi.className = 'sidenavi';
\r
1052 elmItemOrigin.className = 'sidenavi-item';
\r
1053 elmItemOrigin.href = '#';
\r
1054 elmPages.className = 'page-contents';
\r
1055 elmPageOrigin.className = 'page-content main';
\r
1056 elmPageOrigin.appendChild( elmTitleOrigin);
\r
1058 //helpTitle && instance.title( helpTitle);
\r
1060 jqXML.find( 'page').each( function(){
\r
1061 var xmlPage = $( this),
\r
1062 title = xmlPage.attr( 'title'),
\r
1063 content = xmlPage.text();
\r
1065 elmItemOrigin.innerHTML = title;
\r
1066 elmNavi.appendChild( elmItemOrigin.cloneNode( true));
\r
1068 elmTitleOrigin.innerHTML = title;
\r
1070 elmPage = elmPageOrigin.cloneNode( true);
\r
1071 elmPage.innerHTML = content;
\r
1073 pettanr.util.cleanElement( elmPage);
\r
1075 if( elmPage.childNodes.length > 0){
\r
1076 elmPage.insertBefore( elmTitleOrigin.cloneNode( true), elmPage.childNodes[0]);
\r
1078 elmPage.appendChild( elmTitleOrigin.cloneNode( true));
\r
1080 elmPages.appendChild( elmPage);
\r
1082 HELP.createSelection( title, null, onSelectionClick, true);
\r
1086 onLoadFunction = null;
\r
1088 jqAjaxContents.removeClass( 'loading').append( elmNavi, elmPages);
\r
1090 jqNaviItems = jqAjaxContents.find( 'a.' +elmItemOrigin.className).click( onNaviClick);
\r
1091 jqPages = jqAjaxContents.find( '.page-content');
\r
1092 jqPages.find( 'a').click( onInnerLinkClick);
\r
1094 setTimeout( jumpPage, 0);
\r
1096 function onSelectionClick( _pageIndex){
\r
1097 HELP_DOCUMENTS_WINDOW.open();
\r
1098 jumpPage( _pageIndex);
\r
1100 function jumpPage( _index){
\r
1101 if( typeof _index === 'number' && 0 <= _index && _index < numPage && currentPageIndex !== _index){
\r
1102 currentPageIndex = _index;
\r
1104 jqNaviItems.removeClass( 'current').eq( currentPageIndex).addClass( 'current');
\r
1105 jqPages.hide().eq( currentPageIndex).show();
\r
1107 function onNaviClick( e){
\r
1109 jumpPage( pettanr.util.getChildIndex( this.parentNode, this));
\r
1110 e.stopPropagation();
\r
1113 function onInnerLinkClick( e){
\r
1114 var jump = ( this.href || '').split( '#jump'),
\r
1117 jumpPage( '' + parseFloat( n) === n ? parseFloat( n) : -1);
\r
1118 e.stopPropagation();
\r
1121 return WINDOWS_CONTROL.createWindow(
\r
1123 onInit: function(){
\r
1125 jqAjaxContents = this.$.find( '.window-body').addClass( 'loading');
\r
1126 delete this.onInit;
\r
1128 onFirstOpen: function( _w, _h){
\r
1129 jqAjaxContents.css( { height: _h});
\r
1131 delete this.onFirstOpen;
\r
1133 onResize: function( _w, _h){
\r
1134 jqAjaxContents && jqAjaxContents.css( { height: _h});
\r
1137 null, 'Help', 0, 215, 400, 350, false, true, true, 300, 300
\r
1141 /* ----------------------------------------
\r
1144 * - panelResizeListener
\r
1146 var GRID_CONTROL = ( function(){
\r
1147 var ELM_GRID = document.getElementById( 'grid'),
\r
1148 BG_URL = "url('images/grid.gif')",
\r
1154 jqGrid = $( ELM_GRID);
\r
1155 delete GRID_CONTROL.init;
\r
1158 GRID_CONTROL.init && GRID_CONTROL.init();
\r
1160 close: function(){
\r
1163 onPanelResize: function( _panelX, _panelY){
\r
1164 ELM_GRID.style.backgroundPosition = [ _panelX % 10, 'px ', _panelY % 10, 'px'].join( '');
\r
1165 ELM_GRID.style.height = windowH +'px';
\r
1167 enabled: function(){
\r
1170 update: function(){
\r
1174 }).stop()[ visible === true ? 'fadeOut' : 'fadeIn']();
\r
1176 visible = !visible;
\r
1178 if( visible === true && BG_URL !== null){
\r
1179 ELM_GRID.style.backgroundImage = BG_URL;
\r
1187 /* ----------------------------------------
\r
1188 * WHITE_GLASS_CONTROL
\r
1189 * - panelResizeListener
\r
1191 var WHITE_GLASS_CONTROL = ( function(){
\r
1192 var styleTop = document.getElementById( 'whiteGlass-top').style,
\r
1193 styleLeft = document.getElementById( 'whiteGlass-left').style,
\r
1194 styleRight = document.getElementById( 'whiteGlass-right').style,
\r
1195 styleBottom = document.getElementById( 'whiteGlass-bottom').style;
\r
1198 onPanelResize: function( _panelX, _panelY, _panelW, _panelH){
\r
1201 marginTop = _panelY,
\r
1202 marginBottom = windowH -_h -marginTop,
\r
1203 marginX = _panelX,
\r
1204 rightWidth = windowW -_w -marginX;
\r
1206 styleTop.height = ( marginTop < 0 ? 0 : marginTop) +'px';
\r
1208 styleLeft.top = marginTop +'px';
\r
1209 styleLeft.width = ( marginX < 0 ? 0 : marginX) +'px';
\r
1210 styleLeft.height = ( _h + marginBottom) +'px';
\r
1212 styleRight.top = marginTop +'px';
\r
1213 styleRight.left = _w +marginX +'px';
\r
1214 styleRight.width = ( rightWidth < 0 ? 0 : rightWidth) +'px';
\r
1215 styleRight.height = ( _h + marginBottom) +'px';
\r
1217 styleBottom.top = ( _h +marginTop) +'px';
\r
1218 styleBottom.left = marginX +'px';
\r
1219 styleBottom.width = _w +'px';
\r
1220 styleBottom.height = ( marginBottom < 0 ? 0 : marginBottom) +'px';
\r
1226 /* ----------------------------------------
\r
1229 * - mouseEventListener
\r
1231 * panel-border の表示と onPanelResize の通知.
\r
1235 var PANEL_CONTROL = ( function(){
\r
1236 var ELM_PANEL = document.getElementById('panel-tools-container'),
\r
1237 ELM_PANEL_STYLE = ELM_PANEL.style,
\r
1238 DEFAULT_PANEL_WIDTH = 400,
\r
1239 DEFAULT_PANEL_HEIGHT = 300,
\r
1241 panelW, panelH, panelX, panelY,
\r
1242 offsetX, offsetY, startX, startY,
\r
1243 isDragging = false,
\r
1244 isDraggable = false;
\r
1246 pettanr.key.addKeyUpdateEvent( pettanr.view.EDITOR, 32, false, false, onSpaceUpdate);
\r
1248 function onSpaceUpdate(e){
\r
1249 if( e.type === 'keyup'){
\r
1250 currentListener === null && updateMouseCursor( '');
\r
1251 isDraggable = false;
\r
1253 currentListener === null && updateMouseCursor( 'move');
\r
1254 isDraggable = true;
\r
1259 open: function( _panelW, _panelH, _borderSize ){
\r
1260 panelW = Type.isFinite( _panelW ) === true ? _panelW : DEFAULT_PANEL_WIDTH;
\r
1261 panelH = Type.isFinite( _panelH ) === true ? _panelH : DEFAULT_PANEL_HEIGHT;
\r
1262 //panelX = Math.floor( ( windowW -panelW) /2);
\r
1263 //panelY = Math.floor( ( windowH -panelH) /2);
\r
1264 borderSize = Type.isFinite( _borderSize ) === true ? _borderSize : borderSize;
\r
1266 //setTimeout( PANEL_CONTROL.resize, 0);
\r
1268 close: function(){
\r
1283 resize: function( isResizerTopAction, _x, _y, _w, _h){
\r
1284 panelX = _x !== undefined ? _x : panelX;
\r
1285 panelY = _y !== undefined ? _y : panelY;
\r
1286 panelW = _w !== undefined ? _w : panelW;
\r
1287 panelH = _h !== undefined ? _h : panelH;
\r
1289 ELM_PANEL_STYLE.left = ( panelX -borderSize) +'px';
\r
1290 ELM_PANEL_STYLE.top = ( panelY -borderSize) +'px';
\r
1291 ELM_PANEL_STYLE.width = panelW +'px';
\r
1292 ELM_PANEL_STYLE.height = panelH +'px';
\r
1294 PANEL_RESIZER_TOP.onPanelResize( panelX, panelY, panelW, panelH);
\r
1295 PANEL_RESIZER_BOTTOM.onPanelResize( panelX, panelY, panelW, panelH);
\r
1296 GRID_CONTROL.onPanelResize( panelX, panelY);
\r
1297 WHITE_GLASS_CONTROL.onPanelResize( panelX, panelY, panelW, panelH);
\r
1298 COMIC_ELEMENT_CONTROL.onPanelResize( panelX, panelY, panelW, panelH, isResizerTopAction === true);
\r
1300 onWindowResize: function( _windowW, _windowH){
\r
1301 panelX = Math.floor(( _windowW - panelW) / 2);
\r
1302 panelY = Math.floor(( _windowH - panelH) / 2);
\r
1303 PANEL_CONTROL.resize();
\r
1305 onMouseMove: function( _mouseX, _mouseY){
\r
1306 if( isDraggable === true && isDragging === true){
\r
1307 PANEL_CONTROL.resize( false, startX +_mouseX -offsetX, startY +_mouseY -offsetY);
\r
1310 onMouseUp: function( _mouseX, _mouseY){
\r
1311 if( isDraggable === true){
\r
1312 isDragging = false;
\r
1313 updateMouseCursor( '');
\r
1316 onMouseDown: function( _mouseX, _mouseY){
\r
1317 if( isDraggable === true){
\r
1318 offsetX = _mouseX;
\r
1319 offsetY = _mouseY;
\r
1322 isDragging = true;
\r
1323 updateMouseCursor( 'move');
\r
1328 return isDragging === true;
\r
1333 /* --------------------------------------------------------------------------------------------
\r
1334 * PanelResizerClass
\r
1335 * - mouseEventListener
\r
1337 var PanelResizerClass = function( ID, isTop){
\r
1338 var ELM = document.getElementById( ID),
\r
1340 RESIZER_HEIGHT = 30,
\r
1341 x = -BORDER_WIDTH /2,
\r
1342 y = isTop === true ? ( -5 -RESIZER_HEIGHT -BORDER_WIDTH) : 0,
\r
1344 h = RESIZER_HEIGHT,
\r
1345 panelX, panelY, panelW, panelH,
\r
1346 offsetY, startY, startH,
\r
1347 isDragging = false,
\r
1348 MOUSE_CURSOR = updateMouseCursor;
\r
1350 function restoreState( arg){
\r
1351 if( arg && arg.length > 3){
\r
1352 PANEL_CONTROL.resize( isTop, arg[ 0] || panelX, arg[ 1] || panelY, arg[ 2] || panelW, arg[ 3] || panelH);
\r
1356 this.onMouseDown = function( _mouseX, _mouseY){
\r
1357 var _x = _mouseX -panelX,
\r
1358 _y = _mouseY -panelY;
\r
1359 if( _x < x || x + w < _x || _y < y || y + h < _y) return false;
\r
1363 isDragging = true;
\r
1364 MOUSE_CURSOR( 'n-resize');
\r
1367 this.onMouseMove = function( _mouseX, _mouseY){
\r
1368 var _x = _mouseX -panelX,
\r
1369 _y = _mouseY -panelY;
\r
1370 if( isDragging !== true){
\r
1371 if( _x < x || x + w < _x || _y < y || y + h < _y) return false;
\r
1372 COMIC_ELEMENT_OPERATION_MANAGER.hide();
\r
1373 MOUSE_CURSOR( 'pointer');
\r
1376 var move = _y -offsetY;
\r
1377 if( isTop === true){
\r
1378 if( panelH - move < MIN_PANEL_HEIGHT){
\r
1379 move = panelH -MIN_PANEL_HEIGHT;
\r
1381 PANEL_CONTROL.resize( true, panelX, panelY + move, panelW, panelH - move);
\r
1383 var _h = startH +move;
\r
1384 if( 0 < _h && _h < windowH -panelY -RESIZER_HEIGHT -5 -BORDER_WIDTH){
\r
1385 PANEL_CONTROL.resize( false, panelX, panelY, panelW, _h < MIN_PANEL_HEIGHT ? MIN_PANEL_HEIGHT : _h);
\r
1391 this.onMouseUp = function( _mouseX, _mouseY){
\r
1392 if( isDragging !== true) return;
\r
1393 ( startY !== panelY || startH !== panelH) && HISTORY_CONTROL.saveState( restoreState, [ NaN, startY, NaN, startH], [ NaN, panelY, NaN, panelH]);
\r
1394 isDragging = false;
\r
1395 MOUSE_CURSOR( '');
\r
1397 this.busy = function(){
\r
1400 this.onPanelResize = function( _x, _y, _w, _h){
\r
1403 if( panelW !== _w){
\r
1404 ELM.style.width = ( _w +2) +'px';
\r
1408 y = isTop === true ? y : ( panelH +5 +BORDER_WIDTH);
\r
1412 var PANEL_RESIZER_TOP = new PanelResizerClass( 'panel-resizer-top', true ),
\r
1413 PANEL_RESIZER_BOTTOM = new PanelResizerClass( 'panel-resizer-bottom', false );
\r
1415 PanelResizerClass = undefined;
\r
1417 /* --------------------------------------------------------------------------------------------
\r
1418 * CONSOLE_CONTROLER
\r
1420 var CONSOLE_CONTROLER = ( function(){
\r
1421 var LAYER_BACK_BUTTON = MENU_BAR_CONTROL.EDIT.createSelection( 'layer back', 'ctrl + B', layerBack, false, true, false),
\r
1422 LAYER_FORWARD_BUTTON = MENU_BAR_CONTROL.EDIT.createSelection( 'layer forward', 'ctrl + F', layerForward, false, false, false),
\r
1423 DELETE_BUTTON = MENU_BAR_CONTROL.EDIT.createSelection( 'delete', 'ctrl + D', del, false, true, true),
\r
1424 EDIT_BUTTON = MENU_BAR_CONTROL.EDIT.createSelection( 'Edit Text', 'ctrl + E', edit, false, true, false),
\r
1425 CHANGE_BUTTON = MENU_BAR_CONTROL.EDIT.createSelection( 'change', 'ctrl + U', change, false, false, true),
\r
1426 SAVE = HISTORY_CONTROL.saveState,
\r
1431 jqImgConsole, jqTextConsole,
\r
1432 currentElement = null,
\r
1435 imgConsoleWidth, imgConsoleHeight,
\r
1436 textConsoleWidth, textConsoleHeight,
\r
1437 consoleWidth, consoleHeight,
\r
1438 consoleX, consoleY,
\r
1440 buttonClickable = false;
\r
1442 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 66, false, true, layerBack);
\r
1443 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 70, false, true, layerForward);
\r
1445 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 68, false, true, del);
\r
1446 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 69, false, true, edit);
\r
1447 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 85, false, true, change);
\r
1449 function buttonBackOrForward( isBack){
\r
1450 var offest = jqConsoleWrapper.offset();
\r
1451 jqConsoleWrapper.css( {
\r
1452 position: isBack === true ? '' : 'absolute',
\r
1453 left: isBack === true ? consoleX : offest.left,
\r
1454 top: isBack === true ? consoleY : offest.top
\r
1456 buttonClickable === isBack && ( isBack === true ? jqConsoleParent : jqStage).append( jqConsoleWrapper);
\r
1457 buttonClickable = !isBack;
\r
1459 function layerBack(){
\r
1460 if( currentElement === null) return;
\r
1461 if( COMIC_ELEMENT_CONTROL.replace( currentElement, false) === false) return;
\r
1462 INFOMATION_WINDOW.update( currentElement);
\r
1463 SAVE( COMIC_ELEMENT_CONTROL.restoreReplace, [ currentElement, true], [ currentElement, false]);
\r
1464 var _z = currentElement.z;
\r
1465 LAYER_BACK_BUTTON.visible( _z > 0);
\r
1466 LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1);
\r
1468 function layerForward(){
\r
1469 if( currentElement === null) return;
\r
1470 if( COMIC_ELEMENT_CONTROL.replace( currentElement, true) === false) return;
\r
1471 INFOMATION_WINDOW.update( currentElement);
\r
1472 SAVE( COMIC_ELEMENT_CONTROL.restoreReplace, [ currentElement, false], [ currentElement, true]);
\r
1473 var _z = currentElement.z;
\r
1474 LAYER_BACK_BUTTON.visible( _z > 0);
\r
1475 LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1);
\r
1478 if( currentElement === null) return;
\r
1479 buttonBackOrForward( true);
\r
1480 COMIC_ELEMENT_CONTROL.remove( currentElement);
\r
1481 SAVE( COMIC_ELEMENT_CONTROL.restore, [ true, currentElement], [ false, currentElement], true);
\r
1482 COMIC_ELEMENT_OPERATION_MANAGER.hide();
\r
1485 if( currentElement === null || currentElement.type !== PANEL_ELEMENT_TYPE_TEXT) return;
\r
1486 pettanr.textEditor.bootInOverlay( PANEL_CONTROL.x(), PANEL_CONTROL.y(), currentElement );
\r
1487 buttonBackOrForward( true);
\r
1489 function change(){
\r
1490 if( currentElement === null) return;
\r
1491 buttonBackOrForward( true);
\r
1492 pettanr.premiumSatge.bootInOverlay( currentElement.getArtistID(), currentElement.resourcePicture );
\r
1494 function onImageSelect( resourcePicture ){
\r
1495 currentElement.resourcePicture( resourcePicture );
\r
1499 jqStage = jqEditor;
\r
1500 jqConsoleTail = $( '#comic-element-consol-tail');
\r
1501 jqImgConsole = $( '#image-element-consol').hide();
\r
1502 var imgConsoleSize = pettanr.util.getElementSize( jqImgConsole.get( 0));
\r
1503 imgConsoleWidth = imgConsoleSize.width;
\r
1504 imgConsoleHeight = imgConsoleSize.height;
\r
1506 jqTextConsole = $( '#text-element-consol').hide();
\r
1507 var textConsoleSize = pettanr.util.getElementSize( jqTextConsole.get( 0));
\r
1508 textConsoleWidth = textConsoleSize.width;
\r
1509 textConsoleHeight = textConsoleSize.height;
\r
1511 jqConsoleWrapper = $( '#comic-element-consol-wrapper').hide();
\r
1512 jqConsoleParent = jqConsoleWrapper.parent();
\r
1514 $( '#edit-text-button').click( edit);
\r
1515 $( '#delete-image-button, #delete-text-button').click( del);
\r
1516 $( '#change-image-button').click( change);
\r
1517 $( '#layer-forward-button, #forward-text-button').click( layerForward);
\r
1518 $( '#layer-back-button, #back-text-button').click( layerBack);
\r
1520 delete CONSOLE_CONTROLER.init;
\r
1522 show: function( _currentElement, _w, _h ){
\r
1523 CONSOLE_CONTROLER.init && CONSOLE_CONTROLER.init();
\r
1525 visible === false && jqConsoleWrapper.show();
\r
1527 currentElement = _currentElement;
\r
1528 var _currentType = _currentElement.type,
\r
1529 _z = _currentElement.z;
\r
1530 if( currentType !== _currentType){
\r
1531 currentType = _currentType;
\r
1532 jqImgConsole.toggle( _currentType === PANEL_ELEMENT_TYPE_IMAGE);
\r
1533 jqTextConsole.toggle( _currentType === PANEL_ELEMENT_TYPE_TEXT);
\r
1534 consoleWidth = _currentType === PANEL_ELEMENT_TYPE_IMAGE ? imgConsoleWidth : textConsoleWidth;
\r
1535 consoleHeight = _currentType === PANEL_ELEMENT_TYPE_IMAGE ? imgConsoleHeight : textConsoleHeight;
\r
1537 consoleX = Math.floor( ( _w -consoleWidth) /2);
\r
1539 LAYER_BACK_BUTTON.visible( _z > 0);
\r
1540 LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length -1);
\r
1541 DELETE_BUTTON.visible( true);
\r
1542 EDIT_BUTTON.visible( _currentType === PANEL_ELEMENT_TYPE_TEXT);
\r
1543 CHANGE_BUTTON.visible( false);
\r
1545 if( _w > consoleWidth * 1.5 && _h > consoleHeight * 1.5){
\r
1546 consoleY = Math.floor( ( _h -consoleHeight) /2);
\r
1547 jqConsoleWrapper.css( {
\r
1550 }).removeClass( 'console-out');
\r
1552 consoleY = _h +tailSize;
\r
1553 jqConsoleWrapper.css( {
\r
1556 }).addClass( 'console-out');
\r
1559 hide: function (){
\r
1560 visible === true && jqConsoleWrapper.hide();
\r
1562 currentElement = null;
\r
1563 LAYER_BACK_BUTTON.visible( false);
\r
1564 LAYER_FORWARD_BUTTON.visible( false);
\r
1565 DELETE_BUTTON.visible( false);
\r
1566 EDIT_BUTTON.visible( false);
\r
1567 CHANGE_BUTTON.visible( false);
\r
1569 x: function(){ return consoleX;},
\r
1570 y: function(){ return consoleY;},
\r
1571 w: function(){ return consoleWidth;},
\r
1572 h: function(){ return consoleHeight;},
\r
1573 onMouseMove: function( _mouseX, _mouseY){
\r
1574 if( consoleX > _mouseX || consoleY > _mouseY || consoleX +consoleWidth < _mouseX || consoleY +consoleHeight < _mouseY){
\r
1575 buttonClickable === true && buttonBackOrForward( true);
\r
1578 buttonClickable === false && buttonBackOrForward( false);
\r
1581 onMouseOut: function( _mouseX, _mouseY){
\r
1582 buttonClickable === true && buttonBackOrForward( true);
\r
1587 /* --------------------------------------------------------------------------------------------
\r
1589 * - comicElementOperator
\r
1591 var TAIL_OPERATOR = ( function(){
\r
1592 var MOUSE_CURSOR = updateMouseCursor,
\r
1593 ELM_MOVER = document.getElementById( 'balloon-tail-mover'),
\r
1594 SIZE = pettanr.util.getElementSize( ELM_MOVER).width,
\r
1598 FLOOR = Math.floor,
\r
1599 DEG_TO_RAD = Math.PI / 180,
\r
1600 RAD_TO_DEG = 1 /DEG_TO_RAD,
\r
1601 currentText = null,
\r
1604 balloonW, balloonH, balloonA, radA,
\r
1609 update: function ( _w, _h, _a){
\r
1610 balloonW = _w !== undefined ? _w : balloonW;
\r
1611 balloonH = _h !== undefined ? _h : balloonH;
\r
1612 balloonA = _a !== undefined ? _a : balloonA;
\r
1613 radA = balloonA *DEG_TO_RAD;
\r
1614 tailX = FLOOR( ( ( COS( radA) /2 +0.5) *( balloonW +SIZE)) -SIZE /2);
\r
1615 tailY = FLOOR( ( ( SIN( radA) /2 +0.5) *( balloonH +SIZE)) -SIZE /2);
\r
1616 ELM_MOVER.style.left = tailX +'px';
\r
1617 ELM_MOVER.style.top = tailY +'px';
\r
1618 //log.html( [ balloonW, balloonH, balloonA].join());
\r
1620 show: function( _currentText){
\r
1622 * visibilityのほうがいい, display:none だと ie で描画が狂う
\r
1624 ELM_MOVER.style.visibility = '';
\r
1625 this.update( _currentText.w, _currentText.h, _currentText.angle());
\r
1626 currentText = _currentText;
\r
1628 hitTest: function( _mouseX, _mouseY){
\r
1629 var _x = tailX -SIZE /2,
\r
1630 _y = tailY -SIZE /2;
\r
1631 ret = _x <= _mouseX && _y <= _mouseY && _x +SIZE >= _mouseX && _y +SIZE >= _mouseY;
\r
1632 ret === true && MOUSE_CURSOR( 'move');
\r
1636 ELM_MOVER.style.visibility = 'hidden';
\r
1637 currentText = null;
\r
1639 onStart: function( _currentText, _mouseX, _mouseY){
\r
1640 if( _currentText.type !== PANEL_ELEMENT_TYPE_TEXT) return false;
\r
1641 x = _currentText.x;
\r
1642 y = _currentText.y;
\r
1643 if( this.hitTest( _mouseX -x, _mouseY -y) === true){
\r
1644 w = _currentText.w;
\r
1645 h = _currentText.h;
\r
1646 currentText = _currentText;
\r
1647 startA = _currentText.angle();
\r
1652 onDrag: function( _mouseX, _mouseY){
\r
1653 _mouseX = _mouseX -x -w /2;
\r
1654 _mouseY = _mouseY -y -h /2; //Balloonの中心を0,0とする座標系に変換
\r
1656 this.update( w, h,
\r
1658 ATAN( _mouseY /_mouseX) *RAD_TO_DEG +( _mouseX < 0 ? 180 : 0) :
\r
1659 _mouseY > 0 ? 90 : -90
\r
1661 currentText && currentText.angle( balloonA);
\r
1662 INFOMATION_WINDOW.update( currentText);
\r
1664 onFinish: function(){
\r
1665 startA !== currentText.angle() && COMIC_ELEMENT_OPERATION_MANAGER.saveStatus( x, y, w, h, startA);
\r
1666 startA !== currentText.angle() && COMIC_ELEMENT_OPERATION_MANAGER.resize( x, y, w, h, currentText.angle());
\r
1667 currentText = null;
\r
1669 onCancel: function(){
\r
1670 currentText.angle( startA);
\r
1671 COMIC_ELEMENT_OPERATION_MANAGER.resize( x, y, w, h, startA);
\r
1672 currentText = null;
\r
1677 /* --------------------------------------------------------------------------------------------
\r
1679 * - comicElementOperator
\r
1681 var RESIZE_OPERATOR = ( function(){
\r
1682 var MOUSE_CURSOR = updateMouseCursor,
\r
1683 GRID_ENABLED = GRID_CONTROL.enabled;
\r
1685 var HIT_AREA = MOUSE_HIT_AREA,
\r
1686 POSITION_ARRAY = [],
\r
1687 FLOOR = Math.floor,
\r
1688 CURSOR_AND_FLIP = [
\r
1689 { cursor: 'n-resize', v: 3},
\r
1690 { cursor: 'e-resize', h: 2},
\r
1691 { cursor: 'e-resize', h: 1},
\r
1692 { cursor: 'n-resize', v: 0},
\r
1693 { cursor: 'nw-resize', h: 5, v: 6, vh: 7},
\r
1694 { cursor: 'ne-resize', h: 4, v: 7, vh: 6},
\r
1695 { cursor: 'ne-resize', h: 7, v: 4, vh: 5},
\r
1696 { cursor: 'nw-resize', h: 6, v: 5, vh: 4}
\r
1698 elmResizerContainer = document.getElementById( 'comic-element-resizer-container'),
\r
1699 elmResizerContainerStyle = elmResizerContainer.style,
\r
1700 elmResizerTopStyle = document.getElementById( 'comic-element-resizer-top').style,
\r
1701 elmResizerLeftStyle = document.getElementById( 'comic-element-resizer-left').style,
\r
1702 elmResizerRightStyle = document.getElementById( 'comic-element-resizer-right').style,
\r
1703 elmResizerBottomStyle = document.getElementById( 'comic-element-resizer-bottom').style,
\r
1705 currentIndex = -1,
\r
1707 currentIsTextElement = false;
\r
1709 elmResizerContainerStyle.display = 'none';
\r
1711 var RESIZE_WORK_ARRAY = [
\r
1712 { x: 0, w: 0, y: 1, h: -1}, //top
\r
1713 { x: 1, w: -1, y: 0, h: 0}, //left
\r
1714 { x: 0, w: 1, y: 0, h: 0}, //right
\r
1715 { x: 0, w: 0, y: 0, h: 1}, //bottom
\r
1716 { x: 1, w: -1, y: 1, h: -1}, //top-left
\r
1717 { x: 0, w: 1, y: 1, h: -1}, //top-right
\r
1718 { x: 1, w: -1, y: 0, h: 1}, //bottom-left
\r
1719 { x: 0, w: 1, y: 0, h: 1} //bottom-right
\r
1721 startX, startY, startW, startH, startFilpV, startFilpH, startAspect,
\r
1722 baseX, baseY, baseW, baseH,
\r
1723 currentX, currentY, currentW, currentH,
\r
1728 function draw( _x, _y, _w, _h){
\r
1729 x = _x !== undefined ? _x : x;
\r
1730 y = _y !== undefined ? _y : y;
\r
1731 w = _w !== undefined ? _w : w;
\r
1732 h = _h !== undefined ? _h : h;
\r
1734 elmResizerContainerStyle.left = x +'px';
\r
1735 elmResizerContainerStyle.top = y +'px';
\r
1736 elmResizerContainerStyle.width = w +'px';
\r
1737 elmResizerContainerStyle.height = h +'px';
\r
1738 elmResizerTopStyle.left = FLOOR( w /2 -10 /2) +'px';
\r
1739 elmResizerLeftStyle.top = FLOOR( h /2 -10 /2) +'px';
\r
1740 elmResizerRightStyle.top = FLOOR( h /2 -10 /2) +'px';
\r
1741 elmResizerBottomStyle.left = FLOOR( w /2 -10 /2) +'px';
\r
1743 alert( [x, y, w, h].join( ','));
\r
1748 POSITION_ARRAY.splice( 0, POSITION_ARRAY.length);
\r
1749 POSITION_ARRAY.push(
\r
1750 {x: x +5, y: y -HIT_AREA, w: w -5 *2, h: HIT_AREA +5},
\r
1751 {x: x -HIT_AREA, y: y +HIT_AREA +5, w: HIT_AREA +5, h: h -5 *2},
\r
1752 {x: x +w -5, y: y +HIT_AREA +5, w: HIT_AREA +5, h: h -5 *2},
\r
1753 {x: x +5, y: y +h -5, w: w -5 *2, h: HIT_AREA +5},
\r
1754 {x: x -HIT_AREA, y: y -HIT_AREA, w: HIT_AREA +5, h: HIT_AREA +5},
\r
1755 {x: x +w -HIT_AREA, y: y -HIT_AREA, w: HIT_AREA +5, h: HIT_AREA +5},
\r
1756 {x: x -HIT_AREA, y: y +h -5, w: HIT_AREA +5, h: HIT_AREA +5},
\r
1757 {x: x +w -5, y: y +h -5, w: HIT_AREA +5, h: HIT_AREA +5}
\r
1761 function update( _x, _y, _w, _h){
\r
1762 x = _x !== undefined ? _x : currentX;
\r
1763 y = _y !== undefined ? _y : currentY;
\r
1764 w = _w !== undefined ? _w : currentW;
\r
1765 h = _h !== undefined ? _h : currentH;
\r
1767 if( currentIsTextElement === false && currentIndex > 3 && pettanr.key.shiftEnabled() === true){
\r
1768 if( startAspect >= 1){
\r
1770 w = Math.floor( startAspect * h);
\r
1771 x = x +( currentIndex % 2 === 0 ? _w -w : 0);
\r
1774 h = Math.floor( w / startAspect);
\r
1775 y = y + ( currentIndex <= 5 ? _h -h : 0);
\r
1778 draw( x, y, w, h);
\r
1779 currentElement.resize( x, y, w, h);
\r
1780 currentIsTextElement === true && TAIL_OPERATOR.update( w, h);
\r
1781 CONSOLE_CONTROLER.show( currentElement, w, h);
\r
1782 INFOMATION_WINDOW.update( currentElement);
\r
1785 function flip( _flipH, _flipV){
\r
1786 var p = CURSOR_AND_FLIP[ currentIndex];
\r
1787 currentIndex = _flipH === true || _flipV === true ? p[
\r
1788 _flipH === true && _flipV === true ? 'vh' : ( _flipH === true ? 'h' : 'v')
\r
1790 MOUSE_CURSOR( CURSOR_AND_FLIP[ currentIndex].cursor);
\r
1791 elmResizerContainer.className = 'current-resizer-is-' +currentIndex;
\r
1792 currentElement.flip( _flipH, _flipV);
\r
1796 index: function( _mouseX, _mouseY){
\r
1798 for( i=4; i<8; i++){
\r
1799 p = POSITION_ARRAY[ i];
\r
1800 if( p.x <= _mouseX && p.y <= _mouseY && p.x + p.w >= _mouseX && p.y +p.h >= _mouseY){
\r
1801 MOUSE_CURSOR( CURSOR_AND_FLIP[ i].cursor);
\r
1802 elmResizerContainer.className = 'current-resizer-is-' +i;
\r
1803 return currentIndex = i;
\r
1806 for( i=0; i<4; i++){
\r
1807 p = POSITION_ARRAY[ i];
\r
1808 if( p.x <= _mouseX && p.y <= _mouseY && p.x + p.w >= _mouseX && p.y +p.h >= _mouseY){
\r
1809 MOUSE_CURSOR( CURSOR_AND_FLIP[ i].cursor);
\r
1810 elmResizerContainer.className = 'current-resizer-is-' +i;
\r
1811 return currentIndex = i;
\r
1814 MOUSE_CURSOR( '');
\r
1815 elmResizerContainer.className = '';
\r
1818 show: function( _currentElement){
\r
1819 currentElement = _currentElement;
\r
1820 currentIsTextElement = _currentElement.type === PANEL_ELEMENT_TYPE_TEXT;
\r
1821 elmResizerContainerStyle.display = '';
\r
1824 currentElement = null;
\r
1825 elmResizerContainerStyle.display = 'none';
\r
1827 onStart: function( _currentElement, _mouseX, _mouseY){
\r
1828 currentElement = _currentElement;
\r
1829 currentIsTextElement = _currentElement.type === PANEL_ELEMENT_TYPE_TEXT;
\r
1830 if( _currentElement.keepSize === true) return false;
\r
1831 currentIndex = this.index( _mouseX, _mouseY);
\r
1832 if( currentIndex === -1) return false;
\r
1833 offsetX = _mouseX;
\r
1834 offsetY = _mouseY;
\r
1835 startX = baseX = _currentElement.x;
\r
1836 startY = baseY = _currentElement.y;
\r
1837 startW = baseW = _currentElement.w;
\r
1838 startH = baseH = _currentElement.h;
\r
1839 if( _currentElement.type === PANEL_ELEMENT_TYPE_IMAGE){
\r
1840 startFilpV = _currentElement.flipV();
\r
1841 startFilpH = _currentElement.flipH();
\r
1843 startAspect = startW /startH;
\r
1846 onDrag: function( _mouseX, _mouseY){
\r
1847 var com = RESIZE_WORK_ARRAY[ currentIndex],
\r
1848 moveX = _mouseX -offsetX,
\r
1849 moveY = _mouseY -offsetY,
\r
1850 _updated = moveX !== 0 || moveY !== 0,
\r
1859 * Opera 11+ often forget values, why ??
\r
1861 while( _x === undefined || _y === undefined || _w === undefined || _h === undefined){
\r
1862 _x = _x !== undefined ? _x : baseX +moveX *com.x;
\r
1863 _y = _y !== undefined ? _y : baseY +moveY *com.y;
\r
1864 _w = _w !== undefined ? _w : baseW +moveX *com.w;
\r
1865 _h = _h !== undefined ? _h : baseH +moveY *com.h;
\r
1866 error += _thisError === 0 ? 0 : 1;
\r
1868 if( _thisError > 9999){
\r
1870 //alert( 'opera error' +error);
\r
1876 if( _w >= MIN_ELEMENT_SIZE && _h >= MIN_ELEMENT_SIZE){
\r
1879 if( _w >= -MIN_ELEMENT_SIZE && _h >= -MIN_ELEMENT_SIZE){
\r
1881 if( _w < MIN_ELEMENT_SIZE){
\r
1882 //_x += Math.abs( MIN_ELEMENT_SIZE -_w);
\r
1884 _w = MIN_ELEMENT_SIZE;
\r
1886 if( _h < MIN_ELEMENT_SIZE){
\r
1887 //_y += Math.abs( MIN_ELEMENT_SIZE -_h);
\r
1889 _h = MIN_ELEMENT_SIZE;
\r
1892 if( currentElement.type === PANEL_ELEMENT_TYPE_TEXT){
\r
1895 if( _w < -MIN_ELEMENT_SIZE || _h < -MIN_ELEMENT_SIZE){
\r
1897 if( _w < -MIN_ELEMENT_SIZE && _h > MIN_ELEMENT_SIZE){
\r
1900 baseX = _x = _x +_w;
\r
1902 baseW = _w = _memoryX -_x;
\r
1904 flip( true, false);
\r
1905 flipV = currentElement.flipV();
\r
1907 if( _w > MIN_ELEMENT_SIZE && _h < -MIN_ELEMENT_SIZE){
\r
1911 baseY = _y = _y +_h;
\r
1913 baseH = _h = _memoryY -_y;
\r
1914 flip( false, true);
\r
1915 flipH = currentElement.flipH();
\r
1920 baseX = _x = _x +_w;
\r
1921 baseY = _y = _y +_h;
\r
1922 baseW = _w = _memoryX -_x;
\r
1923 baseH = _h = _memoryY -_y;
\r
1924 flip( true, true);
\r
1925 flipV = currentElement.flipV();
\r
1926 flipH = currentElement.flipH();
\r
1929 offsetX = _mouseX;
\r
1930 offsetY = _mouseY;
\r
1936 _updated === true && update( _x, _y, _w, _h);
\r
1939 'currentIndex:', currentIndex,
\r
1940 'baseW', baseW, 'baseH', baseH,'<br>',
\r
1941 'mouse', _mouseX, _mouseY,'<br>',
\r
1942 'move', moveX, moveY,'<br>',
\r
1943 'xy', _x, _y, 'wh',_w, _h,'<br>',
\r
1944 'com.w', com.w, 'com.h', com.h,'<br>',
\r
1945 'current',currentW, currentH,'<br>',
\r
1950 onFinish: function(){
\r
1951 MOUSE_CURSOR( '');
\r
1952 if( w === startW && h === startH && x === startX && y === startY) return;
\r
1953 COMIC_ELEMENT_OPERATION_MANAGER.resize( x, y, w, h);
\r
1954 currentElement.resize( x, y, w, h);
\r
1955 COMIC_ELEMENT_OPERATION_MANAGER.saveStatus( startX, startY, startW, startH, undefined, startFilpV, startFilpH);
\r
1957 onCancel: function(){
\r
1958 MOUSE_CURSOR( '');
\r
1959 COMIC_ELEMENT_OPERATION_MANAGER.resize( startX, startY, startW, startH);
\r
1960 currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
\r
1961 currentElement.animate( startX, startY, startW, startH, startFilpV, startFilpH) :
\r
1962 currentElement.animate( startX, startY, startW, startH, angle);
\r
1964 lock: function( _lock){
\r
1965 if( _lock !== undefined){
\r
1966 elmResizerContainerStyle.borderColor = _lock === true ? 'blue' : '';
\r
1971 onShiftUpdate: update,
\r
1972 onCtrlUpdate: update
\r
1976 /* --------------------------------------------------------------------------------------------
\r
1977 * POSITION_OPERATOR
\r
1978 * - comicElementOperator
\r
1980 var POSITION_OPERATOR = ( function(){
\r
1981 var MOUSE_CURSOR = updateMouseCursor,
\r
1982 GRID_ENABLED = GRID_CONTROL.enabled;
\r
1984 var currentElement,
\r
1990 function update( _x, _y){
\r
1991 x = _x !== undefined ? _x : x;
\r
1992 y = _y !== undefined ? _y : y;
\r
1993 RESIZE_OPERATOR.update( x, y);
\r
1994 currentElement.resize( x, y);
\r
1995 INFOMATION_WINDOW.update( currentElement);
\r
1999 onStart: function( _currentElement, _mouseX, _mouseY){
\r
2000 currentElement = _currentElement;
\r
2001 offsetX = _mouseX;
\r
2002 offsetY = _mouseY;
\r
2003 startX = x = _currentElement.x;
\r
2004 startY = y = _currentElement.y;
\r
2005 MOUSE_CURSOR( 'move');
\r
2007 onDrag: function( _mouseX, _mouseY){
\r
2008 var moveX = _mouseX -offsetX,
\r
2009 moveY = _mouseY -offsetY,
\r
2010 _x = startX +moveX,
\r
2011 _y = startY +moveY;
\r
2012 if( GRID_ENABLED() === true){
\r
2013 _x = Math.floor( _x / 10) * 10;
\r
2014 _y = Math.floor( _y / 10) * 10;
\r
2018 onFinish: function(){
\r
2019 MOUSE_CURSOR( '');
\r
2020 if( x === startX && y === startY) return;
\r
2021 COMIC_ELEMENT_OPERATION_MANAGER.resize( x, y);
\r
2022 currentElement.resize( x, y);
\r
2023 COMIC_ELEMENT_OPERATION_MANAGER.saveStatus( startX, startY);
\r
2025 onCancel: function(){
\r
2026 MOUSE_CURSOR( '');
\r
2027 COMIC_ELEMENT_OPERATION_MANAGER.resize( startX, startY);
\r
2028 currentElement.animate( startX, startY);
\r
2030 onShiftUpdate: update,
\r
2031 onCtrlUpdate: update
\r
2036 /* --------------------------------------------------------------------------------------------
\r
2037 * COMIC_ELEMENT_OPERATION_MANAGER
\r
2039 var COMIC_ELEMENT_OPERATION_MANAGER = ( function(){
\r
2040 var MOUSE_CURSOR = updateMouseCursor,
\r
2041 SAVE = HISTORY_CONTROL.saveState,
\r
2042 GRID_ENABLED = GRID_CONTROL.enabled,
\r
2043 HIT_AREA = MOUSE_HIT_AREA,
\r
2044 currentIsTextElement = false,
\r
2045 currentOperator = null,
\r
2046 currentElement = null,
\r
2047 currentx, currenty, currentw, currenth, angle, flipV, flipH;
\r
2049 function resize( _x, _y, _w, _h, _angle){
\r
2050 currentx = _x !== undefined ? _x : currentx;
\r
2051 currenty = _y !== undefined ? _y : currenty;
\r
2052 currentw = _w !== undefined ? _w : currentw;
\r
2053 currenth = _h !== undefined ? _h : currenth;
\r
2054 angle = _angle !== undefined ? _angle : angle;
\r
2056 RESIZE_OPERATOR.update( currentx, currenty, currentw, currenth);
\r
2057 currentIsTextElement === true && TAIL_OPERATOR.update( currentw, currenth, angle);
\r
2058 CONSOLE_CONTROLER.show( currentElement, currentw, currenth);
\r
2059 INFOMATION_WINDOW.update( currentElement);
\r
2061 function show( _currentElement){
\r
2062 currentElement === null && RESIZE_OPERATOR.show( _currentElement);
\r
2063 if( currentElement !== _currentElement){
\r
2064 currentElement = _currentElement;
\r
2066 currentIsTextElement = ( _currentElement.type === PANEL_ELEMENT_TYPE_TEXT);
\r
2067 currentIsTextElement === true ? TAIL_OPERATOR.show( _currentElement) : TAIL_OPERATOR.hide();
\r
2069 flipV = currentIsTextElement === false ? _currentElement.flipV() : 0;
\r
2070 flipH = currentIsTextElement === false ? _currentElement.flipH() : 0;
\r
2073 _currentElement.x, _currentElement.y, _currentElement.w, _currentElement.h,
\r
2074 currentIsTextElement === true ? _currentElement.angle() : 0
\r
2079 pettanr.key.addKeyUpdateEvent( pettanr.view.EDITOR, 16, undefined, undefined, function( e){
\r
2080 currentOperator !== null && currentOperator.onShiftUpdate && currentOperator.onShiftUpdate();
\r
2082 pettanr.key.addKeyUpdateEvent( pettanr.view.EDITOR, 17, undefined, undefined, function( e){
\r
2083 currentOperator !== null && currentOperator.onCtrlUpdate && currentOperator.onCtrlUpdate();
\r
2085 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 27, false, false, function( e){
\r
2086 currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel();
\r
2087 currentOperator = null;
\r
2093 close: function(){
\r
2097 currentElement !== null && RESIZE_OPERATOR.hide();
\r
2098 currentElement = null;
\r
2099 MOUSE_CURSOR( '');
\r
2100 TAIL_OPERATOR.hide();
\r
2101 CONSOLE_CONTROLER.hide();
\r
2102 INFOMATION_WINDOW.update( null);
\r
2105 restoreState: function( arg){
\r
2106 if( arg && arg.length !== 8) return;
\r
2107 var _currentElement = arg[ 0],
\r
2108 _x = arg[ 1], _y = arg[ 2], _w = arg[ 3], _h = arg[ 4],
\r
2110 _flipV = arg[ 6], _flipH = arg[ 7];
\r
2111 if( !_currentElement && !currentOperator) return;
\r
2112 _currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
\r
2113 _currentElement.animate( _x, _y, _w, _h, _flipV, _flipH) :
\r
2114 _currentElement.animate( _x, _y, _w, _h, _a);
\r
2115 currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel();
\r
2116 currentOperator = null;
\r
2117 currentElement === _currentElement ? resize( _x, _y, _w, _h, _a) : show( _currentElement);
\r
2119 saveStatus: function( startX, startY, startW, startH, startA, startFilpV, startFilpH){
\r
2120 startX = startX !== undefined ? startX : currentx;
\r
2121 startY = startY !== undefined ? startY : currenty;
\r
2122 startW = startW !== undefined ? startW : currentw;
\r
2123 startH = startH !== undefined ? startH : currenth;
\r
2124 startA = startA !== undefined ? startA : angle;
\r
2125 startFilpV = startFilpV !== undefined ? startFilpV : flipV;
\r
2126 startFilpH = startFilpH !== undefined ? startFilpH : flipH;
\r
2127 currentElement && SAVE( COMIC_ELEMENT_OPERATION_MANAGER.restoreState,
\r
2128 [ currentElement, startX, startY, startW, startH, startA, startFilpV, startFilpH],
\r
2129 [ currentElement, currentx, currenty, currentw, currenth, angle, flipV, flipH]
\r
2133 return currentOperator !== null;
\r
2135 hitTest: function( _mouseX, _mouseY, _panelElement ){
\r
2136 var _x, _y, _w, _h;
\r
2137 if( _panelElement === currentElement){
\r
2138 var _consoleX = CONSOLE_CONTROLER.x();
\r
2139 _x = currentx +( _consoleX < 0 ? _consoleX : 0) -HIT_AREA;
\r
2140 _y = currenty -HIT_AREA;
\r
2141 var _consoleW = CONSOLE_CONTROLER.w();
\r
2142 _w = ( _consoleW < currentw ? currentw : _consoleW) +HIT_AREA *2;
\r
2143 var _consoleY = CONSOLE_CONTROLER.y();
\r
2144 _h = ( _consoleY < currenth ? currenth : _consoleY +CONSOLE_CONTROLER.h()) +HIT_AREA *2;
\r
2146 _x = _panelElement.x -HIT_AREA;
\r
2147 _y = _panelElement.y -HIT_AREA;
\r
2148 _w = _panelElement.w +HIT_AREA *2;
\r
2149 _h = _panelElement.h +HIT_AREA *2;
\r
2151 log.html( [ _x, _y, _w, _h ].join( ' ') );
\r
2152 return _x <= _mouseX && _mouseX <= _x + _w && _y <= _mouseY && _mouseY <= _y + _h;
\r
2154 onMouseDown: function( _currentElement, _mouseX, _mouseY){
\r
2155 //show( _currentElement);
\r
2156 if( currentIsTextElement === true && TAIL_OPERATOR.onStart( _currentElement, _mouseX, _mouseY) === true){
\r
2157 currentOperator = TAIL_OPERATOR;
\r
2159 if( RESIZE_OPERATOR.onStart( _currentElement, _mouseX, _mouseY) === true){
\r
2160 currentOperator = RESIZE_OPERATOR;
\r
2162 POSITION_OPERATOR.onStart( _currentElement, _mouseX, _mouseY)
\r
2163 currentOperator = POSITION_OPERATOR;
\r
2166 onMouseMove: function( _currentElement, _mouseX, _mouseY){
\r
2167 show( _currentElement);
\r
2168 if( currentOperator !== null){
\r
2169 currentOperator.onDrag( _mouseX, _mouseY);
\r
2171 if( currentElement !== null){
\r
2172 CONSOLE_CONTROLER.onMouseMove( _mouseX -currentx, _mouseY -currenty);
\r
2173 if( currentIsTextElement === false || TAIL_OPERATOR.hitTest( _mouseX -currentx, _mouseY -currenty) === false){
\r
2174 RESIZE_OPERATOR.index( _mouseX, _mouseY);
\r
2178 onMouseUp: function( _currentElement, _mouseX, _mouseY){
\r
2179 currentOperator !== null && currentOperator.onFinish();
\r
2180 currentOperator = null;
\r
2185 * // COMIC_ELEMENT_OPERATION_MANAGER
\r
2188 var AbstractComicElement = function( COMIC_ELM_TYPE ){
\r
2189 this.type = COMIC_ELM_TYPE;
\r
2190 this.hitTest = function( _mouseX, _mouseY ){
\r
2191 return COMIC_ELEMENT_OPERATION_MANAGER.hitTest( _mouseX, _mouseY, this );
\r
2193 this.shift = function( _shiftX, _shiftY ){
\r
2194 this.resize( this.x + _shiftX, this.y + _shiftY);
\r
2196 this.busy = function(){
\r
2197 return COMIC_ELEMENT_OPERATION_MANAGER.busy();
\r
2199 this.onMouseMove = function( _mouseX, _mouseY ){
\r
2200 COMIC_ELEMENT_OPERATION_MANAGER.onMouseMove( this, _mouseX, _mouseY );
\r
2202 this.onMouseUp = function( _mouseX, _mouseY ){
\r
2203 COMIC_ELEMENT_OPERATION_MANAGER.onMouseUp( this, _mouseX, _mouseY );
\r
2205 this.onMouseDown = function( _mouseX, _mouseY ){
\r
2206 COMIC_ELEMENT_OPERATION_MANAGER.onMouseDown( this, _mouseX, _mouseY );
\r
2210 /* --------------------------------------------------------------------------------------------
\r
2211 * ImageElementClass
\r
2213 var jqImageElementOrigin;
\r
2214 var ImageElementClass = function( data ){
\r
2215 jqImageElementOrigin = jqImageElementOrigin || $( $( '#imgElementTemplete').remove().html());
\r
2217 var JQ_WRAPPER = jqImageElementOrigin.clone( true ),
\r
2218 SAVE = HISTORY_CONTROL.saveState,
\r
2219 HIT_AREA = MOUSE_HIT_AREA,
\r
2223 flipH = w < 0 ? -1 : 1,
\r
2224 flipV = h < 0 ? -1 : 1,
\r
2225 resourcePicture = data.resource_picture,
\r
2226 actualW = data.resource_picture.width,
\r
2227 actualH = data.resource_picture.height,
\r
2228 reversibleImage = null,
\r
2230 w = Math.floor( w );
\r
2231 h = Math.floor( h );
\r
2233 function onAnimeComplete(){
\r
2234 reversibleImage.resize( flipH * w, flipV * h );
\r
2236 function updateResourcePicture( _resourcePicture ){
\r
2237 resourcePicture = _resourcePicture;
\r
2239 actualW = _resourcePicture.width;
\r
2240 actualH = _resourcePicture.height;
\r
2242 var _reversibleImage = pettanr.image.createReversibleImage(
\r
2243 [ pettanr.CONST.RESOURCE_PICTURE_PATH, _resourcePicture.id, '.', _resourcePicture.ext ].join(''),
\r
2244 flipH * w, flipV * h
\r
2246 if( reversibleImage !== null){
\r
2247 JQ_WRAPPER.children( reversibleImage.elm ).replaceWith( _reversibleImage.elm );
\r
2248 reversibleImage.destroy();
\r
2250 JQ_WRAPPER.append( _reversibleImage.elm );
\r
2252 reversibleImage = _reversibleImage;
\r
2254 /* global methods */
\r
2255 this.$ = JQ_WRAPPER;
\r
2261 this.timing = data.t;
\r
2262 this.init = function(){
\r
2263 updateResourcePicture( data.resource_picture );
\r
2264 instance.resize( data.x, data.y, data.width, data.height );
\r
2265 delete instance.init;
\r
2267 this.flip = function( _updateH, _updateV ){
\r
2268 if( _updateH !== true && _updateV !== true ) return;
\r
2269 flipH = _updateH === true ? -flipH : flipH;
\r
2270 flipV = _updateV === true ? -flipV : flipV;
\r
2271 reversibleImage.resize( flipH * w, flipV * h );
\r
2273 this.flipV = function(){
\r
2276 this.flipH = function(){
\r
2279 this.resourcePicture = function( _resourcePicture ){
\r
2280 if( _resourcePicture && _resourcePicture !== resourcePicture ){
\r
2281 SAVE( updateResourcePicture, resourcePicture, _resourcePicture );
\r
2282 updateResourcePicture( _resourcePicture );
\r
2284 return resourcePicture;
\r
2286 this.getArtistID = function(){
\r
2287 return resourcePicture.artist_id || resourcePicture.artist.id || -1;
\r
2289 this.actualW = function(){ return actualW;}
\r
2290 this.actualH = function(){ return actualH;}
\r
2291 this.keepSize = false;
\r
2292 this.resize = function( _x, _y, _w, _h, animate ){
\r
2293 instance.x = x = _x !== undefined ? _x : x;
\r
2294 instance.y = y = _y !== undefined ? _y : y;
\r
2295 instance.w = w = _w !== undefined ? _w : w;
\r
2296 instance.h = h = _h !== undefined ? _h : h;
\r
2297 JQ_WRAPPER[ animate === true ? 'animate' : 'css' ]( {
\r
2302 }, 250, onAnimeComplete );
\r
2303 animate !== true && onAnimeComplete();
\r
2305 this.animate = function ( _x, _y, _w, _h, _flipH, _flipV ){
\r
2306 flipH = _flipH !== undefined ? _flipH : flipH;
\r
2307 flipV = _flipV !== undefined ? _flipV : flipV;
\r
2308 instance.resize( _x, _y, _w, _h, true);
\r
2310 this.destroy = function(){
\r
2311 reversibleImage.destroy();
\r
2312 JQ_WRAPPER.remove();
\r
2313 JQ_WRAPPER = reversibleImage = resourcePicture = data = instance = SAVE = null;
\r
2314 delete this.destroy;
\r
2317 ImageElementClass.prototype = new AbstractComicElement( PANEL_ELEMENT_TYPE_IMAGE );
\r
2319 * / ImageElementClass
\r
2320 * --------------------------------------------------------------------------------------------
\r
2324 /* --------------------------------------------------------------------------------------------
\r
2325 * TextElementClass
\r
2329 * 1.speach balloon
\r
2332 * 4.black-box( dq style)
\r
2333 * 5.blue-box( ff style)
\r
2336 var jqTextElementOrigin;
\r
2337 var TextElementClass = function( data ){
\r
2338 jqTextElementOrigin = jqTextElementOrigin || ( function(){
\r
2339 var _OLD_IE = $( $( '#textElementTempleteForOldIE').remove().html()),
\r
2340 _MODERN = $( $( '#textElementTemplete').remove().html());
\r
2341 return pettanr.ua.isIE === true && pettanr.ua.ieRenderingVersion < 8 ? _OLD_IE : _MODERN;
\r
2344 var JQ_WRAPPER = jqTextElementOrigin.clone( true ),
\r
2345 TEXT_ELM = JQ_WRAPPER.find( 'td,.speach-inner').eq( 0),
\r
2346 HIT_AREA = MOUSE_HIT_AREA,
\r
2347 SAVE = HISTORY_CONTROL.saveState,
\r
2348 type = data.balloon_template_id,
\r
2349 text = ( function(){
\r
2350 var _speachs = data.speaches_attributes;
\r
2351 for( var k in _speachs ){
\r
2352 return _speachs[ k ].content || '';
\r
2356 balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail, type ),
\r
2360 JQ_WRAPPER.find( 'img').eq( 0).replaceWith( balloon.elm );
\r
2362 function updateType( _type ){
\r
2363 if( type !== _type ){
\r
2364 type = _type || type;
\r
2365 balloon.type( type );
\r
2368 function updateAngle( _a ){
\r
2369 if( _a !== undefined && a !== _a ){
\r
2370 a = _a !== undefined ? _a : a;
\r
2371 balloon.angle( a );
\r
2374 function updateText( _text ){
\r
2375 text = _text || text || '';
\r
2376 TEXT_ELM.html( text );
\r
2379 /* global methods */
\r
2380 this.$ = JQ_WRAPPER;
\r
2386 this.timing = data.t;
\r
2387 this.init = function(){
\r
2389 instance.resize( data.x, data.y, data.width, data.height, data.tail );
\r
2390 delete instance.init;
\r
2392 this.angle = function( _a ){
\r
2393 _a !== undefined && instance.resize( undefined, undefined, undefined, undefined, _a);
\r
2396 this.text = function( _text){
\r
2397 if( _text && text !== _text) {
\r
2398 SAVE( updateText, text || '', _text);
\r
2399 updateText( _text);
\r
2403 this.getBalloonURL = function(){
\r
2404 return balloon.getURL();
\r
2406 this.resize = function( _x, _y, _w, _h, _a, animate ){
\r
2407 instance.x = x = _x !== undefined ? _x : x;
\r
2408 instance.y = y = _y !== undefined ? _y : y;
\r
2409 instance.w = w = _w !== undefined ? _w : w;
\r
2410 instance.h = h = _h !== undefined ? _h : h;
\r
2411 a = _a !== undefined ? _a : a;
\r
2413 JQ_WRAPPER[ animate === true ? 'animate' : 'css']( {
\r
2420 balloon.resize( a, w, h);
\r
2423 animate !== true && balloon.resize( a, w, h);
\r
2425 this.animate = function ( _x, _y, _w, _h, _a ){
\r
2426 instance.resize( _x, _y, _w, _h, _a, true);
\r
2428 this.destroy = function(){
\r
2429 JQ_WRAPPER.remove();
\r
2430 balloon.destroy();
\r
2432 delete instance.destroy;
\r
2435 TextElementClass.prototype = new AbstractComicElement( PANEL_ELEMENT_TYPE_TEXT );
\r
2437 /* --------------------------------------------------------------------------------------------
\r
2438 * COMIC_ELEMENT_CONTROL
\r
2439 * - mouseEventListener
\r
2441 var COMIC_ELEMENT_CONTROL = ( function(){
\r
2442 var SAVE = HISTORY_CONTROL.saveState,
\r
2443 ELM_CONTAINER = document.getElementById( 'comic-element-container'),
\r
2444 currentElement = null,
\r
2445 currentLockTest = false,
\r
2446 currentLock = false,
\r
2447 panelX, panelY, panelW, panelH,
\r
2450 * append, remove, replace
\r
2452 * comicElement には、z-position と dom-index がある。
\r
2453 * z-position は 表示上の位置。大きいほど前に表示される( z-index)
\r
2454 * dom-index は 意味上の順番。htmlタグの登場順で、検索結果や音声読み上げブラウザで正しく意味が取れる順番。
\r
2456 * editerでは、実際には z-index は使わず、htmlの順序で前後を表現する。
\r
2457 * dom-index は、数値のみ保持して、投稿時にcomicElementを適宜に並び替える。
\r
2459 * append comicElement
\r
2460 * 1. 新しい comicElement の z-position を得る
\r
2461 * 2. z の同じ comicElementを見つけ、その前に加える。または一番先頭へ。(PANEL_ELEMENT_ARRAY)
\r
2462 * zが大きいほど、PANEL_ELEMENT_ARRAYの先頭へ。
\r
2463 * 3. dom位置は、PANEL_ELEMENT_ARRAY とは反対に、前のものほど後ろへ。
\r
2466 * remove comicElement
\r
2470 function appendComicElement( _panelElement ) {
\r
2471 var z = _panelElement.z,
\r
2472 l = PANEL_ELEMENT_ARRAY.length,
\r
2473 _jqElm = _panelElement.$.stop().css( {
\r
2477 if( typeof z !== 'number' || z < 0 || z >= l ){
\r
2478 PANEL_ELEMENT_ARRAY.unshift( _panelElement );
\r
2479 ELM_CONTAINER.appendChild( _jqElm.get( 0 ));
\r
2483 PANEL_ELEMENT_ARRAY.push( _panelElement );
\r
2484 ELM_CONTAINER.appendChild( _jqElm.get( 0 ));
\r
2486 var insertIndex = 0;
\r
2487 for( var i = 0; i < l; ++i ){
\r
2488 if( PANEL_ELEMENT_ARRAY[ i ].z <= z ){
\r
2493 PANEL_ELEMENT_ARRAY[ insertIndex ].$.before( _jqElm.fadeIn() );
\r
2494 PANEL_ELEMENT_ARRAY.splice( insertIndex, 0, _panelElement );
\r
2498 function removeComicElement( _panelElement ) {
\r
2499 var l = PANEL_ELEMENT_ARRAY.length;
\r
2500 for( var i=0; i<l; ++i){
\r
2501 if( PANEL_ELEMENT_ARRAY[ i ] === _panelElement ){
\r
2502 PANEL_ELEMENT_ARRAY.splice( i, 1 );
\r
2504 _panelElement.$.stop().css( {
\r
2507 }).fadeOut( onFadeOut );
\r
2508 currentElement = currentElement === _panelElement ? null : currentElement;
\r
2512 function onFadeOut(){
\r
2513 this.parentNode.removeChild( this );
\r
2516 function restoreComicElement( arg ){
\r
2517 var isAppend = arg[ 0 ],
\r
2518 comicElement = arg[ 1 ];
\r
2519 isAppend === true ? appendComicElement( comicElement ) : removeComicElement( comicElement );
\r
2522 * PANEL_ELEMENT_ARRAY の順番を基準に、zの再計算
\r
2525 function renumber(){
\r
2526 var l = PANEL_ELEMENT_ARRAY.length,
\r
2527 _panelElement, jqElm, jqNext;
\r
2528 for( var i=0; i < l; ++i){
\r
2529 _panelElement = PANEL_ELEMENT_ARRAY[ i ];
\r
2530 jqElm = _panelElement.$;
\r
2531 jqNext && jqNext.before( jqElm );
\r
2532 _panelElement.z = l -i -1;
\r
2536 function replaceComicElement( _panelElement, goForward ){
\r
2537 // PANEL_ELEMENT_ARRAYの再構築
\r
2538 var l = PANEL_ELEMENT_ARRAY.length,
\r
2540 for( var ret = 0; ret < l; ++ret ){
\r
2541 if( PANEL_ELEMENT_ARRAY[ ret] === _panelElement ) return ret;
\r
2545 if( i === -1) return false;
\r
2546 if( goForward === true){
\r
2547 if( i === 0) return false;
\r
2548 PANEL_ELEMENT_ARRAY.splice( i, 1);
\r
2549 PANEL_ELEMENT_ARRAY.splice( i -1, 0, _panelElement);
\r
2551 if( i === l -1) return false;
\r
2552 PANEL_ELEMENT_ARRAY.splice( i, 1);
\r
2553 PANEL_ELEMENT_ARRAY.splice( i +1, 0, _panelElement);
\r
2558 function restoreReplaceElement( arg){
\r
2559 replaceComicElement( arg[ 0], arg[ 1]);
\r
2564 log = $( '#operation-catcher-log');
\r
2566 delete COMIC_ELEMENT_CONTROL.init;
\r
2569 COMIC_ELEMENT_CONTROL.init && COMIC_ELEMENT_CONTROL.init();
\r
2571 close: function(){
\r
2573 while( PANEL_ELEMENT_ARRAY.length > 0){
\r
2574 _comicElm = PANEL_ELEMENT_ARRAY.shift();
\r
2575 _comicElm.destroy && _comicElm.destroy();
\r
2578 remove: removeComicElement,
\r
2579 restore: restoreComicElement,
\r
2580 replace: replaceComicElement,
\r
2581 restoreReplace: restoreReplaceElement,
\r
2582 onPanelResize : function ( _panelX, _panelY, _panelW, _panelH, isResizerTopAction ){
\r
2584 * リサイズが、ResizerTopによって行われた場合、comicElementのyを動かして見かけ上動かないようにする。
\r
2586 if( isResizerTopAction === true){
\r
2587 var _shiftX = _panelW -panelW,
\r
2588 _shiftY = _panelH -panelH,
\r
2589 l = PANEL_ELEMENT_ARRAY.length;
\r
2590 for( var i = 0; i < l; i++){
\r
2591 PANEL_ELEMENT_ARRAY[ i].shift( _shiftX, _shiftY);
\r
2599 ELM_CONTAINER.style.width = _panelW +'px';
\r
2600 ELM_CONTAINER.style.height = _panelH +'px';
\r
2601 ELM_CONTAINER.style.left = _panelX +'px';
\r
2602 ELM_CONTAINER.style.top = _panelY +'px';
\r
2604 onMouseMove: function( _mouseX, _mouseY ){
\r
2605 var l = PANEL_ELEMENT_ARRAY.length,
\r
2606 _x = _mouseX -panelX,
\r
2607 _y = _mouseY -panelY,
\r
2608 _elm = currentElement;
\r
2610 if( _elm !== null){
\r
2611 currentLockTest = currentLockTest === true && _x === 0 && _y === 0;
\r
2612 if( _elm.busy() === true ){
\r
2613 _elm.onMouseMove( _x, _y);
\r
2616 if( _elm.hitTest( _x, _y) === true ){
\r
2617 _elm.onMouseMove( _x, _y ); // cursor
\r
2620 if( currentLock === true){
\r
2621 currentLockTest = true;
\r
2625 for( var i=0; i<l; i++){
\r
2626 _elm = PANEL_ELEMENT_ARRAY[ i ];
\r
2628 if( _elm.hitTest( _x, _y ) === true ){
\r
2629 _elm.onMouseMove( _x, _y ); // cursor
\r
2630 log.html( [ _x, _y, i].join( ','));
\r
2631 currentElement = _elm;
\r
2634 log.html( [ _elm.x, _elm.y, i].join( ','));
\r
2637 currentElement = null;
\r
2638 COMIC_ELEMENT_OPERATION_MANAGER.hide();
\r
2641 onMouseUp: function( _mouseX, _mouseY){
\r
2642 var ret = currentElement !== null && currentElement.busy() === true;
\r
2643 ret === true && currentElement.onMouseUp( _mouseX -startX || panelX, _mouseY -startY || panelY);
\r
2644 currentLock = currentLockTest === true && currentElement.hitTest( _mouseX -panelX, _mouseY -panelY) === true;
\r
2645 RESIZE_OPERATOR.lock( currentLock);
\r
2646 INFOMATION_WINDOW.lock( currentLock);
\r
2649 onMouseDown: function( _mouseX, _mouseY){
\r
2652 if( currentElement === null) return false
\r
2653 currentElement.onMouseDown( _mouseX -startX, _mouseY -startY);
\r
2654 currentLockTest = true;
\r
2658 return currentElement !== null;
\r
2660 createImageElement: function( data ){
\r
2661 if( Type.isObject( data ) === false ){
\r
2662 pettanr.premiumSatge.bootInOverlay( 1, onImageSelect );
\r
2664 onImageSelect( data, true );
\r
2666 function onImageSelect( data, isPanelPictureData ){
\r
2667 if( isPanelPictureData !== true ){
\r
2669 resource_picture:data,
\r
2670 x: Math.floor( panelW /2 - data.width /2 ),
\r
2671 y: Math.floor( panelH /2 - data.height /2 ),
\r
2673 t: PANEL_ELEMENT_ARRAY.length,
\r
2674 width: data.width,
\r
2675 height: data.height
\r
2678 var _panelElement = new ImageElementClass( data );
\r
2679 _panelElement.init && _panelElement.init();
\r
2680 appendComicElement( _panelElement );
\r
2681 _panelElement.animate( undefined, undefined, data.width, data.height );
\r
2682 SAVE( restoreComicElement, [ false, _panelElement], [ true, _panelElement], true );
\r
2685 createTextElement: function( data ){
\r
2686 var _panelElement;
\r
2687 if( Type.isObject( data ) === false ){
\r
2689 balloon_template_id:1,
\r
2692 x: Math.floor( panelW /2 - 100 +Math.random() *10 ),
\r
2693 y: Math.floor( panelH /2 - 100 +Math.random() *10 ),
\r
2695 t: PANEL_ELEMENT_ARRAY.length,
\r
2698 speaches_attributes: {
\r
2704 _panelElement = new TextElementClass( data );
\r
2705 _panelElement.init();
\r
2706 pettanr.textEditor.bootInOverlay( PANEL_CONTROL.x(), PANEL_CONTROL.y(), _panelElement, onTextInput );
\r
2708 _panelElement = new TextElementClass( data );
\r
2709 _panelElement.init();
\r
2710 onTextInput( _panelElement );
\r
2712 function onTextInput( _panelElement ){
\r
2713 appendComicElement( _panelElement );
\r
2714 SAVE( restoreComicElement, [ false, _panelElement ], [ true, _panelElement ], true );
\r
2721 * end of COMIC_ELEMENT_CONTROL
\r
2726 function updateMouseCursor( _cursor){
\r
2727 if( currentCursor !== _cursor){
\r
2728 currentCursor = _cursor;
\r
2729 setTimeout( update, 0);
\r
2731 function update(){
\r
2732 ELM_MOUSE_EVENT_CHATCHER.style.cursor = currentCursor;
\r
2735 function centering(){
\r
2736 instance.onPaneResize( windowW, windowH);
\r
2738 function mouseEventRellay( e){
\r
2739 var _mouseX = e.pageX,
\r
2740 _mouseY = e.pageY,
\r
2741 rellayMethod = e.type === 'mousedown' ?
\r
2743 ( e.type === 'mousemove' ? 'onMouseMove' : 'onMouseUp');
\r
2744 if( currentListener !== null && currentListener.busy() === true){
\r
2745 currentListener[ rellayMethod]( _mouseX, _mouseY);
\r
2747 currentListener = null;
\r
2748 var l = MOUSE_LISTENER_ARRAY.length,
\r
2750 for( var i=0; i<l; ++i){
\r
2751 _listener = MOUSE_LISTENER_ARRAY[ i];
\r
2752 if( _listener[ rellayMethod]( _mouseX, _mouseY) === true){
\r
2753 currentListener = _listener;
\r
2759 //!document.selection && window.getSelection().removeAllRanges();
\r
2760 e.stopPropagation();
\r
2764 /* grobal method */
\r
2765 this.rootElement = document.getElementById( 'editor' );
\r
2766 this.displayName = pettanr.view.EDITOR;
\r
2767 this.ID = pettanr.view.EDITOR;
\r
2768 this.MIN_WIDTH = 320;
\r
2769 this.MIN_HEIGHT = 320;
\r
2770 this.firstOpen = function(){
\r
2772 * MOUSE_LISTENER_ARRAY は、表示順に格納.手前の要素が最初
\r
2773 * MENU_BAR_CONTROL,
\r
2775 * COMIC_ELEMENT_CONTROL,
\r
2777 * .busy() === true なら、そのままonMouseMove()にイベントを流す.
\r
2778 * onMouseMove()に流してみて、false が帰れば、次にリスナーにも流す.
\r
2780 MOUSE_LISTENER_ARRAY.push( MENU_BAR_CONTROL, WINDOWS_CONTROL, PANEL_RESIZER_TOP, PANEL_RESIZER_BOTTOM, COMIC_ELEMENT_CONTROL, PANEL_CONTROL);
\r
2784 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 96, false, true, centering); // ctrl + 0
\r
2785 pettanr.key.addKeyDownEvent( pettanr.view.EDITOR, 48, false, true, centering); // ctrl + 0
\r
2786 MENU_BAR_CONTROL.EDIT.createSelection( 'centering', 'ctrl + 0', centering, true, true, true);
\r
2788 * jqMouseEventChacher は透明な要素で、
\r
2789 * マウスイベントをcurrentElement(currentElement)に伝えるのが仕事
\r
2790 * このような実装になるのは、ここの表示オブジェクトにイベントを設定した場合、表示が追いつかずマウスカーソルが外れたタイミングでイベントが終わってしまうため。
\r
2792 jqMouseEventChacher = $( ELM_MOUSE_EVENT_CHATCHER)
\r
2793 .mousemove( mouseEventRellay)
\r
2794 .mousedown( mouseEventRellay)
\r
2795 .mouseup( mouseEventRellay)
\r
2796 .mouseout( mouseEventRellay);
\r
2798 delete instance.firstOpen;
\r
2800 this.onOpen = function( _w, _h, _file ){
\r
2803 panelTimming = -1;
\r
2805 var panelW, panelH,
\r
2807 fileData, panelElements, panelElm;
\r
2809 if( pettanr.file.isFileInstance( _file ) === true ){
\r
2810 if( pettanr.driver.isPettanrFileInstance( _file ) === true ){
\r
2811 if( _file.getType() === pettanr.driver.FILE_TYPE.COMIC ){
\r
2812 fileData = _file.read();
\r
2813 panelW = fileData.width;
\r
2814 panelH = fileData.height;
\r
2815 comicID = fileData.id || -1;
\r
2817 if( _file.getType() === pettanr.driver.FILE_TYPE.PANEL ){
\r
2818 fileData = _file.read();
\r
2819 panelW = fileData.width;
\r
2820 panelH = fileData.height;
\r
2821 borderSize = fileData.border;
\r
2822 panelElements = fileData.panel_elements;
\r
2823 comicID = fileData.comic ? fileData.comic.id || -1 : -1;
\r
2824 panelID = fileData.id || -1;
\r
2825 panelTimming = fileData.t || -1;
\r
2826 if( Type.isArray( panelElements ) === true ){
\r
2827 for( var i=0; i<panelElements.length; ++i){
\r
2828 panelElm = panelElements[ i ];
\r
2829 if( panelElm.resource_picture ){
\r
2830 COMIC_ELEMENT_CONTROL.createImageElement( panelElm );
\r
2832 if( panelElm.balloon_template_id ){
\r
2833 COMIC_ELEMENT_CONTROL.createTextElement( panelElm );
\r
2842 jqEditor = jqEditor || $( '#editor');
\r
2844 HISTORY_CONTROL.open();
\r
2846 WINDOWS_CONTROL.open();
\r
2848 GRID_CONTROL.open();
\r
2849 PANEL_CONTROL.open( panelW, panelH, borderSize );
\r
2851 COMIC_ELEMENT_OPERATION_MANAGER.open();
\r
2852 COMIC_ELEMENT_CONTROL.open();
\r
2854 instance.firstOpen !== undefined && instance.firstOpen();
\r
2857 MENU_BAR_CONTROL.open();
\r
2861 instance.onPaneResize( _w, _h );
\r
2863 this.onClose = function(){
\r
2864 HISTORY_CONTROL.close();
\r
2866 WINDOWS_CONTROL.close();
\r
2868 GRID_CONTROL.close();
\r
2869 PANEL_CONTROL.close();
\r
2871 COMIC_ELEMENT_OPERATION_MANAGER.close();
\r
2872 COMIC_ELEMENT_CONTROL.close();
\r
2875 MENU_BAR_CONTROL.open();
\r
2877 this.onPaneResize = function( _windowW, _windowH){
\r
2878 windowW = _windowW || windowW;
\r
2879 windowH = _windowH || windowH;
\r
2883 jqEditor.get( 0).style.height = _windowH +'px';
\r
2884 ELM_MOUSE_EVENT_CHATCHER.style.height = _windowH +'px';
\r
2886 WINDOWS_CONTROL.onWindowResize( _windowW, _windowH);
\r
2887 MENU_BAR_CONTROL.onWindowResize( _windowW, _windowH);
\r
2888 PANEL_CONTROL.onWindowResize( _windowW, _windowH);
\r
2893 pettanr.comicConsole = pettanr.view.registerApplication( function(){
\r
2895 ID = 'comicConsole',
\r
2896 elmWrap = document.getElementById( 'comic-console-wrapper' ),
\r
2897 elmHeader = document.getElementById( 'comic-console-header' ),
\r
2898 elmProgress = document.getElementById( 'comic-console-progress' ),
\r
2899 inputTitle, inputW, inputH, inputVisible, inputEditable,
\r
2900 elmUploader = null,
\r
2905 isUploading = false,
\r
2907 //pettanr.key.addKeyDownEvent( ID, 69, false, false, clickOK);
\r
2909 function clickOK(){
\r
2910 if( !elmForm || !elmIframe || isUploading === true ) return false;
\r
2912 isUploading = true;
\r
2913 elmProgress.innerHTML = '■';
\r
2917 function copyAndSubmit(){
\r
2918 var _inputList = elmForm.getElementsByTagName( 'input' ),
\r
2920 for( var i=0, l= _inputList.length; i<l; ++i){
\r
2921 _input = _inputList[ i ];
\r
2922 _name = _input.name;
\r
2923 if( _name === 'comic[title]'){
\r
2924 _input.value = inputTitle.value();
\r
2926 if( _name === 'comic[width]'){
\r
2927 _input.value = inputW.value();
\r
2929 if( _name === 'comic[height]'){
\r
2930 _input.value = inputH.value();
\r
2933 var _selectList = elmForm.getElementsByTagName( 'select' ),
\r
2934 _select, _optionList;
\r
2935 for( i=0, l= _selectList.length; i<l; ++i){
\r
2936 _select = _selectList[ i ];
\r
2937 _name = _select.name;
\r
2938 _optionList = _select.getElementsByTagName( 'option' )
\r
2939 if( _name === 'comic[visible]'){
\r
2940 _select.selectedIndex = 1;
\r
2942 if( _name === 'comic[editable]'){
\r
2943 _select.selectedIndex = 0;
\r
2949 elmProgress.innerHTML = 'submit() err..';
\r
2950 isUploading = false;
\r
2951 setTimeout( clickCancel , 3000);
\r
2954 if( pettanr.ua.isIE){
\r
2955 elmIframe.onreadystatechange = detectIframe;
\r
2957 elmIframe.onload = onIframeUpdate;
\r
2959 elmProgress.innerHTML = 'uploading..';
\r
2962 * ie の 場合、readyState をチェック.
\r
2964 function detectIframe(){
\r
2965 if ( elmIframe.readyState === 'complete') {
\r
2966 elmIframe.onreadystatechange = new Function();
\r
2967 elmIframe.onreadystatechange = null;
\r
2971 function onIframeUpdate(){
\r
2972 elmIframe.onload = null;
\r
2973 ( elmIframe.contentWindow || elmIframe.contentDocument.parentWindow ).close();
\r
2975 elmProgress.innerHTML = 'success!';
\r
2976 setTimeout( clickCancel , 1000);
\r
2977 isUploading = false;
\r
2980 function clickCancel(){
\r
2981 if( isUploading === true) return false;
\r
2982 pettanr.comicConsole.shutdown();
\r
2984 function detectForm(){
\r
2985 elmForm = elmUploader.getElementsByTagName( 'form' )[ 0 ];
\r
2987 window.clearInterval( timer);
\r
2989 pettanr.util.createIframe( 'targetFrameCreateComic', onCreateIframe );
\r
2990 elmProgress.innerHTML = 'create iframe';
\r
2993 function onCreateIframe( _iframe ){
\r
2994 elmUploader.appendChild( _iframe );
\r
2995 elmIframe = _iframe;
\r
2996 elmForm.target = _iframe.name;
\r
2997 elmProgress.innerHTML = '';
\r
3000 /* grobal method */
\r
3001 this.rootElement = document.getElementById( 'comic-console-wrapper' );
\r
3002 this.displayName = ID;
\r
3004 this.MIN_WIDTH = 320;
\r
3005 this.MIN_HEIGHT = 320;
\r
3006 this.init = function(){
\r
3007 jqWrap = $( '#comic-console-wrapper').hide();
\r
3008 $( '#comic-console-post-button').click( clickOK );
\r
3009 $( '#comic-console-cancel-button').click( clickCancel );
\r
3011 var CREATER = pettanr.form.createInputText;//pettanr.key.createEditableText;
\r
3012 inputTitle = CREATER( document.getElementById( 'comic-console-title'), null, ID);
\r
3013 inputW = CREATER( document.getElementById( 'comic-console-width'), null, ID);
\r
3014 inputH = CREATER( document.getElementById( 'comic-console-height'), null, ID);
\r
3015 inputVisible = CREATER( document.getElementById( 'comic-console-visible'), null, ID);
\r
3016 inputEditable = CREATER( document.getElementById( 'comic-console-editable'), null, ID);
\r
3018 delete instance.init;
\r
3020 this.onOpen = function( w, h ){
\r
3021 instance.init && instance.init();
\r
3025 inputTitle.start();
\r
3027 elmUploader = document.createElement( 'div' );
\r
3028 elmUploader.id = 'newcomic';
\r
3029 elmUploader.style.cssText = 'height:1px;line-height:1px;visibility:hidden;overflow:hidden;';
\r
3030 elmWrap.appendChild( elmUploader);
\r
3032 var elmScript = document.createElement( 'script');
\r
3033 elmScript.type = 'text\/javascript';
\r
3034 elmScript.src = pettanr.CONST.CREATE_COMIC_JS;
\r
3035 elmWrap.appendChild( elmScript);
\r
3037 elmProgress.innerHTML = 'loading form.';
\r
3039 if( timer === null){
\r
3040 timer = window.setInterval( detectForm, 250);
\r
3043 instance.onPaneResize( w, h );
\r
3045 this.onPaneResize = function( _windowW, _windowH){
\r
3048 left: Math.floor( ( _windowW - jqWrap.width()) /2),
\r
3049 top: Math.floor( ( _windowH - jqWrap.height()) /2)
\r
3053 this.onClose = function(){
\r
3054 elmForm !== null && $( elmUploader ).remove();
\r
3056 isUploading = false;
\r
3058 if( elmScript !== null ){
\r
3059 document.body.removeChild( elmScript);
\r
3060 elmScript = null;
\r
3062 if( timer !== null){
\r
3063 window.clearInterval( timer);
\r
3071 pettanr.uploadConsole = pettanr.view.registerApplication( function(){
\r
3072 var jqWrap, windowW, windowH,
\r
3073 ID = 'uploadConsole',
\r
3074 TARGET_FRAME_NAME = 'targetFrame',
\r
3075 elmContainer = document.getElementById( 'uploader'),
\r
3076 elmProgress = document.getElementById( 'upload-console-progress'),
\r
3082 isUploading = false,
\r
3085 * upload ボタンが押されたらまず iframe をつくる.
3087 function clickOK(){
\r
3088 if( !elmForm || !elmIframe || isUploading === true ) return false;
\r
3089 if( elmFile.value.length === 0) return false;
\r
3090 elmProgress.innerHTML = 'uploading.';
\r
3091 isUploading = true;
\r
3096 * form の target に iframe を指定したのち submit();
3098 function submit(){
\r
3102 elmProgress.innerHTML = 'submit() err..';
\r
3103 isUploading = false;
\r
3104 setTimeout( clickCancel , 3000);
\r
3108 if( pettanr.ua.isIE){
\r
3109 elmIframe.onreadystatechange = detectIframe;
\r
3111 elmIframe.onload = onLoad;
\r
3113 elmProgress.innerHTML = 'uploading..';
\r
3116 * ie の 場合、readyState をチェック.
3118 function detectIframe(){
\r
3119 if ( elmIframe.readyState === 'complete') {
\r
3120 elmIframe.onreadystatechange = new Function();
\r
3121 elmIframe.onreadystatechange = null;
\r
3125 function onLoad(){
\r
3126 elmIframe.onload = null;
\r
3127 ( elmIframe.contentWindow || elmIframe.contentDocument.parentWindow ).close();
\r
3128 elmProgress.innerHTML = 'success!';
\r
3129 setTimeout( clickCancel , 1000);
\r
3130 isUploading = false;
\r
3133 function detectForm(){
\r
3134 elmForm = elmContainer.getElementsByTagName( 'form' )[ 0 ];
\r
3136 var _inputList = elmForm.getElementsByTagName( 'input' ),
\r
3138 for( var i=0, l= _inputList.length; i<l; ++i){
\r
3139 _input = _inputList[ i ];
\r
3140 if( _input.type === 'file'){
\r
3143 if( _input.type === 'submit'){
\r
3144 _input.style.display = 'none';
\r
3147 window.clearInterval( timer);
\r
3149 pettanr.util.createIframe( TARGET_FRAME_NAME, onCreateIframe);
\r
3150 elmProgress.innerHTML = 'create iframe';
\r
3153 function onCreateIframe( _iframe ){
\r
3154 elmContainer.appendChild( _iframe );
\r
3155 elmIframe = _iframe;
\r
3156 elmForm.target = _iframe.name;
\r
3157 elmProgress.innerHTML = '';
\r
3158 instance.onPaneResize( windowW, windowH );
\r
3163 function clickCancel(){
\r
3164 if( isUploading === true) return false;
\r
3165 pettanr.uploadConsole.shutdown();
\r
3169 /* grobal method */
\r
3170 this.rootElement = document.getElementById( 'upload-console-wrapper' );
\r
3171 this.displayName = ID;
\r
3173 this.MIN_WIDTH = 320;
\r
3174 this.MIN_HEIGHT = 320;
\r
3175 this.init = function(){
\r
3176 jqWrap = $( '#upload-console-wrapper').hide();
\r
3177 $( '#upload-console-post-button').click( clickOK );
\r
3178 $( '#upload-console-cancel-button').click( clickCancel );
\r
3180 delete instance.init;
\r
3182 this.onOpen = function( w, h){
\r
3183 instance.init && instance.init();
\r
3185 * ie 6, 7 で fadeIn 中の要素に appendChild すると クラッシュするので、document.body に追加.
3187 elmScript = document.createElement( 'script');
\r
3188 elmScript.type = 'text\/javascript';
\r
3189 elmScript.src = pettanr.CONST.UPLOAD_PICTURE_JS;
\r
3190 document.body.appendChild( elmScript);
\r
3194 if( timer === null){
\r
3195 timer = window.setInterval( detectForm, 250);
\r
3198 elmProgress.innerHTML = 'loading form.';
\r
3200 instance.onPaneResize( w, h);
\r
3202 this.onPaneResize = function( _windowW, _windowH){
\r
3203 windowW = _windowW;
\r
3204 windowH = _windowH;
\r
3207 left: Math.floor( ( _windowW -jqWrap.width()) /2),
\r
3208 top: Math.floor( ( _windowH -jqWrap.height()) /2)
\r
3212 this.onClose = function(){
\r
3213 elmForm !== null && $( elmContainer.children ).remove();
\r
3214 elmForm = elmFile = elmIframe = null;
\r
3215 isUploading = false;
\r
3217 if( elmScript !== null ){
\r
3218 document.body.removeChild( elmScript);
\r
3219 elmScript = null;
\r
3221 if( timer !== null){
\r
3222 window.clearInterval( timer);
\r
3229 pettanr.panelConsole = pettanr.view.registerApplication( function(){
\r
3230 var jqWrap, windowW, windowH,
\r
3231 ID = 'panelConsole',
\r
3232 TARGET_FRAME_NAME = 'targetFrameCreateNewPanel',
\r
3233 elmContainer = document.getElementById( 'newpanel'),
\r
3234 elmProgress = document.getElementById( 'panel-console-progress'),
\r
3239 isUploading = false,
\r
3242 * upload ボタンが押されたらまず iframe をつくる.
\r
3244 function clickOK(){
\r
3245 if( !elmForm || !elmIframe || isUploading === true ) return false;
\r
3246 elmProgress.innerHTML = 'uploading.';
\r
3247 isUploading = true;
\r
3252 * form の target に iframe を指定したのち submit();
\r
3254 function submit(){
\r
3258 elmProgress.innerHTML = 'submit() err..';
\r
3259 isUploading = false;
\r
3260 setTimeout( clickCancel , 3000);
\r
3264 if( pettanr.ua.isIE){
\r
3265 elmIframe.onreadystatechange = detectIframe;
\r
3267 elmIframe.onload = onLoad;
\r
3269 elmProgress.innerHTML = 'uploading..';
\r
3272 * ie の 場合、readyState をチェック.
\r
3274 function detectIframe(){
\r
3275 if ( elmIframe.readyState === 'complete') {
\r
3276 elmIframe.onreadystatechange = new Function();
\r
3277 elmIframe.onreadystatechange = null;
\r
3281 function onLoad(){
\r
3282 elmIframe.onload = null;
\r
3283 ( elmIframe.contentWindow || elmIframe.contentDocument.parentWindow ).close();
\r
3284 elmProgress.innerHTML = 'success!';
\r
3285 setTimeout( clickCancel , 1000);
\r
3286 isUploading = false;
\r
3289 function detectForm(){
\r
3290 elmForm = elmContainer.getElementsByTagName( 'form' )[ 0 ];
\r
3292 var _inputList = elmForm.getElementsByTagName( 'input' ),
\r
3294 for( var i=0, l= _inputList.length; i<l; ++i){
\r
3295 _input = _inputList[ i ];
\r
3296 if( _input.type === 'submit'){
\r
3297 _input.style.display = 'none';
\r
3300 window.clearInterval( timer);
\r
3302 pettanr.util.createIframe( TARGET_FRAME_NAME, onCreateIframe);
\r
3303 elmProgress.innerHTML = 'create iframe';
\r
3306 function onCreateIframe( _iframe ){
\r
3307 elmContainer.appendChild( _iframe );
\r
3308 elmIframe = _iframe;
\r
3309 elmForm.target = _iframe.name;
\r
3310 elmProgress.innerHTML = '';
\r
3311 instance.onPaneResize( windowW, windowH );
\r
3316 function clickCancel(){
\r
3317 if( isUploading === true) return false;
\r
3318 pettanr.panelConsole.shutdown();
\r
3322 /* grobal method */
\r
3323 this.rootElement = document.getElementById( 'panel-console-wrapper' );
\r
3324 this.displayName = ID;
\r
3326 this.MIN_WIDTH = 320;
\r
3327 this.MIN_HEIGHT = 320;
\r
3328 this.init = function(){
\r
3329 jqWrap = $( '#panel-console-wrapper').hide();
\r
3330 $( '#panel-console-post-button').click( clickOK );
\r
3331 $( '#panel-console-cancel-button').click( clickCancel );
\r
3333 delete instance.init;
\r
3335 this.onOpen = function( w, h ){
\r
3336 instance.init && instance.init();
\r
3338 * ie 6, 7 で fadeIn 中の要素に appendChild すると クラッシュするので、document.body に追加.
\r
3340 elmScript = document.createElement( 'script');
\r
3341 elmScript.type = 'text\/javascript';
\r
3342 elmScript.src = pettanr.CONST.CREATE_PANEL_JS;
\r
3343 document.body.appendChild( elmScript);
\r
3347 if( timer === null){
\r
3348 timer = window.setInterval( detectForm, 250 );
\r
3351 elmProgress.innerHTML = 'loading form.';
\r
3353 instance.onPaneResize( w, h );
\r
3355 this.onPaneResize = function( _windowW, _windowH ){
\r
3356 windowW = _windowW;
\r
3357 windowH = _windowH;
\r
3360 left: Math.floor( ( _windowW -jqWrap.width()) /2),
\r
3361 top: Math.floor( ( _windowH -jqWrap.height()) /2)
\r
3365 this.onClose = function(){
\r
3366 elmForm !== null && $( elmContainer.children ).remove();
\r
3367 elmForm = elmIframe = null;
\r
3368 isUploading = false;
\r
3370 if( elmScript !== null ){
\r
3371 document.body.removeChild( elmScript);
\r
3372 elmScript = null;
\r
3374 if( timer !== null){
\r
3375 window.clearInterval( timer);
\r
3382 pettanr.artistConsole = pettanr.view.registerApplication( function(){
\r
3383 var jqWrap, windowW, windowH,
\r
3384 ID = 'artistConsole',
\r
3385 TARGET_FRAME_NAME = 'targetFrameRegisterArtist',
\r
3386 elmContainer = document.getElementById( 'register'),
\r
3387 elmProgress = document.getElementById( 'artist-console-progress'),
\r
3392 isUploading = false,
\r
3395 * upload ボタンが押されたらまず iframe をつくる.
\r
3397 function clickOK(){
\r
3398 if( !elmForm || !elmIframe || isUploading === true ) return false;
\r
3399 elmProgress.innerHTML = 'uploading.';
\r
3400 isUploading = true;
\r
3405 * form の target に iframe を指定したのち submit();
\r
3407 function submit(){
\r
3411 elmProgress.innerHTML = 'submit() err..';
\r
3412 isUploading = false;
\r
3413 setTimeout( clickCancel , 3000);
\r
3417 if( pettanr.ua.isIE){
\r
3418 elmIframe.onreadystatechange = detectIframe;
\r
3420 elmIframe.onload = onLoad;
\r
3422 elmProgress.innerHTML = 'uploading..';
\r
3425 * ie の 場合、readyState をチェック.
\r
3427 function detectIframe(){
\r
3428 if ( elmIframe.readyState === 'complete') {
\r
3429 elmIframe.onreadystatechange = new Function();
\r
3430 elmIframe.onreadystatechange = null;
\r
3434 function onLoad(){
\r
3435 elmIframe.onload = null;
\r
3436 ( elmIframe.contentWindow || elmIframe.contentDocument.parentWindow ).close();
\r
3437 elmProgress.innerHTML = 'success!';
\r
3438 setTimeout( clickCancel , 1000);
\r
3439 isUploading = false;
\r
3442 function detectForm(){
\r
3443 elmForm = elmContainer.getElementsByTagName( 'form' )[ 0 ];
\r
3445 var _inputList = elmForm.getElementsByTagName( 'input' ),
\r
3447 for( var i=0, l= _inputList.length; i<l; ++i){
\r
3448 _input = _inputList[ i ];
\r
3449 if( _input.type === 'submit'){
\r
3450 _input.style.display = 'none';
\r
3453 window.clearInterval( timer);
\r
3455 pettanr.util.createIframe( TARGET_FRAME_NAME, onCreateIframe);
\r
3456 elmProgress.innerHTML = 'create iframe';
\r
3459 function onCreateIframe( _iframe ){
\r
3460 elmContainer.appendChild( _iframe );
\r
3461 elmIframe = _iframe;
\r
3462 elmForm.target = _iframe.name;
\r
3463 elmProgress.innerHTML = '';
\r
3464 instance.onPaneResize( windowW, windowH );
\r
3469 function clickCancel(){
\r
3470 if( isUploading === true) return false;
\r
3471 pettanr.artistConsole.shutdown();
\r
3475 /* grobal method */
\r
3476 this.rootElement = document.getElementById( 'artist-console-wrapper' );
\r
3477 this.displayName = ID;
\r
3479 this.MIN_WIDTH = 320;
\r
3480 this.MIN_HEIGHT = 320;
\r
3481 this.init = function(){
\r
3482 jqWrap = $( '#artist-console-wrapper').hide();
\r
3483 $( '#artist-console-post-button').click( clickOK );
\r
3484 $( '#artist-console-cancel-button').click( clickCancel );
\r
3486 delete instance.init;
\r
3488 this.onOpen = function( w, h ){
\r
3489 instance.init && instance.init();
\r
3491 * ie 6, 7 で fadeIn 中の要素に appendChild すると クラッシュするので、document.body に追加.
\r
3493 elmScript = document.createElement( 'script' );
\r
3494 elmScript.type = 'text\/javascript';
\r
3495 elmScript.src = pettanr.CONST.REGISTER_ARTIST_JS;
\r
3496 document.body.appendChild( elmScript );
\r
3500 if( timer === null){
\r
3501 timer = window.setInterval( detectForm, 250 );
\r
3504 elmProgress.innerHTML = 'loading form.';
\r
3506 instance.onPaneResize( w, h );
\r
3508 this.onPaneResize = function( _windowW, _windowH ){
\r
3509 windowW = _windowW;
\r
3510 windowH = _windowH;
\r
3513 left: Math.floor( ( _windowW -jqWrap.width()) /2),
\r
3514 top: Math.floor( ( _windowH -jqWrap.height()) /2)
\r
3518 this.onClose = function(){
\r
3519 elmForm !== null && $( elmContainer.children ).remove();
\r
3520 elmForm = elmIframe = null;
\r
3521 isUploading = false;
\r
3523 if( elmScript !== null ){
\r
3524 document.body.removeChild( elmScript);
\r
3525 elmScript = null;
\r
3527 if( timer !== null){
\r
3528 window.clearInterval( timer);
\r
3535 pettanr.outputConsole = pettanr.view.registerApplication( function(){
\r
3536 var jqWrap, jqOutputArea,
\r
3537 ID = 'outputConsole',
\r
3540 //pettanr.key.addKeyDownEvent( ID, 69, false, false, clickOK);
\r
3542 function clickOK(){
\r
3543 pettanr.outputConsole.shutdown();
\r
3546 function getPanelElementByTiming( PANEL_ELEMENT_ARRAY, l ){
\r
3547 while( timing < l * 2){
\r
3548 for(var i=0; i<l; ++i){
\r
3549 if( timing === PANEL_ELEMENT_ARRAY[ i ].timing ){
\r
3551 return PANEL_ELEMENT_ARRAY[ i ];
\r
3559 function getAsHtmlString( isAbsoluteUrl, isXHTML, panelW, panelH, border, PANEL_ELEMENT_ARRAY ){
\r
3562 var HTML_ARRAY = [],
\r
3563 l = PANEL_ELEMENT_ARRAY.length,
\r
3566 while( HTML_ARRAY.length < l ){
\r
3567 _panelElement = getPanelElementByTiming( PANEL_ELEMENT_ARRAY, l );
\r
3568 if( _panelElement === null) break;
\r
3569 HTML_ARRAY.push( panelElementToHtml( _panelElement, isAbsoluteUrl, isXHTML ));
\r
3572 HTML_ARRAY.unshift(
\r
3574 '<div class="panel" ',
\r
3576 'height:', panelH, 'px;',
\r
3577 'background-color:', ';',
\r
3582 HTML_ARRAY.push( '</div>');
\r
3584 return HTML_ARRAY.join( pettanr.LINE_FEED_CODE_TEXTAREA);
\r
3587 function panelElementToHtml( _panelElement, isAbsoluteUrl, isXHTML ){
\r
3589 if( _panelElement.type === 0 ){
\r
3590 url = [ pettanr.CONST.RESOURCE_PICTURE_PATH, _panelElement.resourcePicture().id, '.', _panelElement.resourcePicture().ext ].join( '' );
\r
3593 'src="', isAbsoluteUrl !== true ? url : pettanr.util.getAbsolutePath( url ), '" ',
\r
3594 'width="', _panelElement.w, '" ',
\r
3595 'height="', _panelElement.h, '" ',
\r
3597 'left:', _panelElement.x, 'px;',
\r
3598 'top:', _panelElement.y, 'px;',
\r
3599 'z-index:', _panelElement.z, ';',
\r
3601 isXHTML !== true ? '>' : ' \/>'
\r
3604 url = _panelElement.getBalloonURL();
\r
3607 'src="', isAbsoluteUrl !== true ? url : pettanr.util.getAbsolutePath( url ), '" ',
\r
3608 'width="', _panelElement.w, '" ',
\r
3609 'height="', _panelElement.h, '" ',
\r
3611 'left:', _panelElement.x, 'px;',
\r
3612 'top:', _panelElement.y, 'px;',
\r
3613 'z-index:', _panelElement.z, ';',
\r
3615 isXHTML !== true ? '>' : ' \/>',
\r
3616 pettanr.LINE_FEED_CODE_TEXTAREA,
\r
3617 '<div class="balloon" style="',
\r
3618 'left:', _panelElement.x, 'px;',
\r
3619 'top:', _panelElement.y, 'px;',
\r
3620 'width:', _panelElement.w, 'px;',
\r
3621 'height:', _panelElement.h, 'px;',
\r
3622 'z-index:', _panelElement.z,
\r
3623 '"><span>', _panelElement.text(), '<\/span>', '<\/div>'
\r
3629 function getAsJsonString( comicID, panelID, panelTimming, panelW, panelH, border, PANEL_ELEMENT_ARRAY ){
\r
3632 var JSON_STRING_ARRAY = [],
\r
3634 BALLOON_ARRAY = [],
\r
3635 l = PANEL_ELEMENT_ARRAY.length,
\r
3637 cr = pettanr.LINE_FEED_CODE_TEXTAREA;
\r
3639 while( IMAGE_ARRAY.length + BALLOON_ARRAY.length <= l){
\r
3640 _panelElement = getPanelElementByTiming( PANEL_ELEMENT_ARRAY, l );
\r
3641 if( _panelElement === null) break;
\r
3642 _panelElement.type === 0 ?
\r
3643 IMAGE_ARRAY.push( imageToJson( _panelElement )) :
\r
3644 BALLOON_ARRAY.push( balloonToJson( _panelElement ) );
\r
3649 '"id": ', panelID, ',', cr,
\r
3650 '"border": ', border, ',', cr,
\r
3651 '"comic_id": ', comicID, ',', cr,
\r
3652 '"resource_picture_id": 1,', cr,
\r
3653 '"x": ', 0, ',', cr,
\r
3654 '"y": ', 0, ',', cr,
\r
3655 '"z": ', 0, ',', cr,
\r
3656 panelTimming !== -1 ? ( '"t": ' + panelTimming + ',' + cr ) : '',
\r
3657 '"width": ', panelW, ',', cr,
\r
3658 '"height": ', panelH, ',', cr,
\r
3659 '"panel_pictures_attributes": {', cr,
\r
3660 IMAGE_ARRAY.join( ',' + cr ), cr,
\r
3662 '"balloons_attributes": {', cr,
\r
3663 BALLOON_ARRAY.join( ',' + cr ), cr,
\r
3669 function imageToJson( _imageElement ){
\r
3670 var cr = pettanr.LINE_FEED_CODE_TEXTAREA;
\r
3672 '"new', timing, '": {', cr,
\r
3673 '"resource_picture_id": ', _imageElement.resourcePicture().id, ',', cr,
\r
3674 '"x": ', _imageElement.x, ',', cr,
\r
3675 '"y": ', _imageElement.y, ',', cr,
\r
3676 '"z": ', _imageElement.z, ',', cr,
\r
3677 '"width": ', _imageElement.flipH() * _imageElement.w, ',', cr,
\r
3678 '"height": ', _imageElement.flipV() * _imageElement.h, ',', cr,
\r
3679 '"t": ', timing, cr,
\r
3684 function balloonToJson( _textElement ){
\r
3685 var cr = pettanr.LINE_FEED_CODE_TEXTAREA;
\r
3687 '"new', timing, '": {', cr,
\r
3688 '"balloon_template_id": ', 1, ',', cr,
\r
3689 '"system_picture_id": ', 1, ',', cr,
\r
3690 '"size": ', 1, ',', cr,
\r
3691 '"tail": ', _textElement.angle(), ',', cr,
\r
3692 '"x": ', _textElement.x, ',', cr,
\r
3693 '"y": ', _textElement.y, ',', cr,
\r
3694 '"z": ', _textElement.z, ',', cr,
\r
3695 '"t": ', timing, ',', cr,
\r
3696 '"width": ', _textElement.w, ',', cr,
\r
3697 '"height": ', _textElement.h, ',', cr,
\r
3698 '"speaches_attributes": {', cr,
\r
3699 '"newf', timing, '": {', cr,
\r
3700 '"content": "', _textElement.text(), '",', cr,
\r
3701 '"x": ', _textElement.x, ',', cr,
\r
3702 '"y": ', _textElement.y, ',', cr,
\r
3703 '"t": ', timing, ',', cr,
\r
3704 '"width": ', _textElement.w, ',', cr,
\r
3705 '"height": ', _textElement.h, cr,
\r
3713 /* grobal method */
\r
3714 this.rootElement = document.getElementById( 'output-console-wrapper' );
\r
3715 this.displayName = ID;
\r
3718 this.MIN_WIDTH = 320;
\r
3719 this.MIN_HEIGHT = 320;
\r
3720 this.init = function(){
\r
3721 jqWrap = $( '#output-console-wrapper').hide();
\r
3722 jqOutputArea = $( '#output-area');
\r
3723 delete instance.init;
\r
3725 this.onOpen = function( _w, _h, _dataType, _comicID, _panelID, _panelTimming, _panelW, _panelH, _borderSize, _panelElements ){
\r
3726 instance.init && instance.init();
\r
3729 instance.onPaneResize( _w, _h );
\r
3731 if( _dataType === pettanr.outputConsole.JSON ){
\r
3732 text = getAsJsonString( _comicID, _panelID, _panelTimming, _panelW, _panelH, _borderSize, _panelElements );
\r
3734 text = getAsHtmlString( false, false, _panelW, _panelH, _borderSize, _panelElements );
\r
3736 jqOutputArea.val( text ).focus();
\r
3738 this.onPaneResize = function( _w, _h){
\r
3741 left: Math.floor( ( _w -jqWrap.width()) /2),
\r
3742 top: Math.floor( ( _h -jqWrap.height()) /2)
\r
3746 this.onClose = function(){
\r
3748 jqOutputArea.val('');
\r
3751 pettanr.outputConsole.JSON = 0;
\r
3752 pettanr.outputConsole.HTML = 1;
\r
3753 pettanr.outputConsole.XML = 2;
\r
3754 pettanr.outputConsole.SHORT_URL = 3;
\r
3755 pettanr.outputConsole.MOVERBLE_TYPE = 4;
\r
3756 pettanr.outputConsole.BLOGGER = 5;
\r