11 ( function( pettanr, gOS, window, document, undefined ){
13 * PettanR service driver.
15 var MyAuthorID = 'current_author' in window ? current_author.id : ( pettanr.CONST.SERVER_SUPPORT === false ? 1 : -1 ),
16 MyArtistID = 'current_artist' in window ? current_artist.id : ( pettanr.CONST.SERVER_SUPPORT === false ? 1 : -1 ),
18 FileAPI = gOS.registerDriver( function(){
19 var self = Driver = this,
20 unregisteredFileDataJsonList = [];
22 function onLoadJson( file, json ){
23 var access = FileAPI.getFileDataAccess( file ),
24 data = access !== null ? access.DATA : null,
30 data.state = Const.FILE.STATE.OK;
31 if( Type.isArray( json ) === true ){
32 for( i = 0, l = json.length; i < l; ++i ){
33 registerFileData( json[ i ], data );
36 if( Type.isNumber( json.id ) === true ){
37 registerFileData( json, data );
39 while( 0 < unregisteredFileDataJsonList.length ){
40 args = unregisteredFileDataJsonList.shift();
41 registerFileData( args[ 0 ], args[ 1 ] );
42 //alert( unregisteredFileDataJsonList.length )
44 file.dispatchEvent( FileAPI.createFileEvent( Const.FILE.EVENT.GET_SEQENTIAL_FILES, file, 'children', null ) );
46 function onErrorJson( file ){
47 var data = FileAPI.getFileData( file );
49 data.state = Const.FILE.STATE.ERROR;
51 file.dispatchEvent( FileAPI.createFileEvent( Const.FILE.EVENT.GET_SEQENTIAL_FILES, file, 'children', null ) );
53 function registerFileData( json, parent ){
57 case FILE_DATA_COMICS_ROOT :
58 case FILE_DATA_MY_COMICS_ROOT :
60 json.type = FILE_TYPE.COMIC;
61 data = createFileData( json, COMIC_ARRAY, 'title' );
62 if( data.json !== null ) data.json = true;
64 addChildData( data.author, data );
65 data.author.id === MyAuthorID && addChildData( FILE_DATA_MY_COMICS_ROOT, data );
67 parent === FILE_DATA_COMICS_ROOT && addChildData( FILE_DATA_LATEST_COMICS, data );
71 json.type = FILE_TYPE.STORY;
72 data = createFileData( json, STORY_ARRAY, 'x,y,z,t' );
73 addChildData( FILE_DATA_STORY_ROOT, data );
77 case FILE_DATA_LISENCE :
79 json.type = FILE_TYPE.LICENSE;
80 data = createFileData( json, LICENSE_ARRAY, 'name,caption,url,system_picture_id,settings,credit_pictures' );
81 addChildData( FILE_DATA_LISENCE, data );
84 case FILE_DATA_LISENCE_GROUP :
85 case LICENSE_GROUP_ARRAY :
86 json.type = FILE_TYPE.LICENSE_GROUP;
87 data = createFileData( json, LICENSE_GROUP_ARRAY, 'name,caption,url,classname' );
88 addChildData( FILE_DATA_LISENCE_GROUP, data );
91 // Speech Balloon Templete
92 case FILE_DATA_BALLOON_ROOT :
93 case BALLOON_TEMPLETE_ARRAY :
94 json.type = FILE_TYPE.BALLOON_TEMPLETE;
95 // register pettanr.balloon
96 pettanr.newBalloon.register( json.settings );
97 data = createFileData( json, BALLOON_TEMPLETE_ARRAY, 'name,caption,classname,settings' );
98 addChildData( FILE_DATA_BALLOON_ROOT, data );
102 case FILE_DATA_AUTHOR_ROOT :
104 json.type = FILE_TYPE.AUTHOR;
105 data = createFileData( json, AUTHOR_ARRAY, 'name,email,homepage_url' );
106 addChildData( FILE_DATA_AUTHOR_ROOT, data );
110 case FILE_DATA_ARTIST_ROOT :
112 json.type = FILE_TYPE.ARTIST;
113 data = createFileData( json, ARTIST_ARRAY, 'name,email,homepage_url' );
114 addChildData( FILE_DATA_ARTIST_ROOT, data );
118 json.type = FILE_TYPE.PICTURE;
119 data = createFileData( json, PICTURE_ARRAY, 'ext,revision,credit,settings' );
123 case FILE_DATA_RESOURCE_PICTURES_ROOT :
124 case FILE_DATA_MY_RESOURCE_PICTURES_ROOT :
125 case RESOURCE_PICTURE_ARRAY :
126 json.type = FILE_TYPE.RESOURCE_PICTURE;
127 data = createFileData( json, RESOURCE_PICTURE_ARRAY, 'ext' );
129 addChildData( data.artist, data );
130 data.artist.id === MyArtistID && addChildData( FILE_DATA_MY_RESOURCE_PICTURES_ROOT, data );
135 case FILE_DATA_MY_ORIGINAL_PICTURES_ROOT :
136 case ORIGINAL_PICTURE_ARRAY :
137 json.type = FILE_TYPE.ORIGINAL_PICTURE;
138 data = createFileData( json, ORIGINAL_PICTURE_ARRAY, 'ext,filesize,width,height,md5' );
140 // addChildData( data.artist, data );
141 data.artist.id === MyArtistID && addChildData( FILE_DATA_MY_ORIGINAL_PICTURES_ROOT, data );
145 case FILE_DATA_PANELS_ROOT :
146 case FILE_DATA_MY_PANELS_ROOT :
148 json.type = FILE_TYPE.PANEL;
149 data = createFileData( json, PANEL_ARRAY, 'border,publish,width,height' );
150 addChildData( FILE_DATA_LATEST_PANELS, data );
151 data.author.id === MyAuthorID && addChildData( FILE_DATA_MY_PANELS_ROOT, data );
155 case PANEL_ELEMENT_ARRAY :
156 json.type = FILE_TYPE.PANEL_ELEMENT;
157 data = createFileData( json, PANEL_ELEMENT_ARRAY, 'caption,url,width,height,x,y,z,t' ); // 画像の分
163 if( parent.type === FILE_TYPE.COMIC ){
164 //alert( 'comicstory' )
165 data = registerFileData( json, STORY_ARRAY );
166 //addChildData( parent, data );
169 throw new Error( 'build file error!' );
174 * 1. すでに一度以上ファイルを取得している場合、そのオブジェクトを取得.または、新規に作成.
175 * 2. オブジェクトに値をコピー・上書き
178 function createFileData( json, array, copyProps ){
179 copyProps = copyProps + ',id,type';
181 var getIndex = Util.getIndex,
183 data = getResource( array, id ),
190 copyProps = copyProps.split( ',' );
192 if( getIndex( copyProps, p ) !== -1 ) data[ p ] = json[ p ];
196 data.driver = Driver;
197 if( Type.isString( json.created_at ) === true ) data.created_at = Math.floor( new Date( json.created_at ).getTime() / 1000 );
198 if( Type.isString( json.updated_at ) === true ) data.updated_at = Math.floor( new Date( json.updated_at ).getTime() / 1000 );
201 histories = json.pictures;
202 if( Type.isArray( histories ) === true ){
203 for( i = 0, l = histories.length; i < l; ++i ){
204 history = getResource( PICTURE_ARRAY, histories[ i ] );
205 addChildData( data, history );
207 data.picture = history;
211 stories = json.stories;
212 if( Type.isArray( stories ) === true ){
213 for( i = 0, l = stories.length; i < l; ++i ){
214 story = getResource( STORY_ARRAY, stories[ i ] );
218 addChildData( data, story );
223 elements = json.elements;
224 if( Type.isArray( elements ) === true ){
225 for( i = 0, l = elements.length; i<l; ++i ){
229 addChildData( data, getResource( PANEL_ELEMENT_ARRAY, elements[ i ] ) );
234 if( json.artist || json.artist_id ){
235 data.artist = getResource( ARTIST_ARRAY, json.artist || json.artist_id );
239 if( json.author || json.author_id ){
240 data.author = getResource( AUTHOR_ARRAY, json.author || json.author_id );
244 if( json.comic || json.comic_id ){
245 data.comic = getResource( COMIC_ARRAY, json.comic || json.comic_id );
249 if( json.panel || json.panel_id ){
250 data.panel = getResource( PANEL_ARRAY, json.panel || json.panel_id );
254 if( json.picture || json.picture_id ){
255 data.picture = getResource( PICTURE_ARRAY, json.picture || json.picture_id );
259 if( json.license || json.license_id ){
260 data.license = getResource( LICENSE_ARRAY, json.license || json.license_id );
264 if( json.license_group || json.license_group_id ){
265 data.license_group = getResource( LICENSE_GROUP_ARRAY, json.license_group || json.license_group_id );
269 if( json.original_picture || json.original_picture_id ){
270 data.original_picture = getResource( ORIGINAL_PICTURE_ARRAY, json.original_picture || {
271 id : json.original_picture_id,
273 filesize : json.filesize,
275 height : json.height,
277 artist : json.artist,
278 artist_id : json.artist_id
284 function addChildData( parent, child ){
285 if( Type.isArray( parent.children ) === false ){
286 parent.children = [ child ];
289 Util.getIndex( parent.children, child ) === -1 && parent.children.push( child );
291 function getResource( list, IDorOBJECT ){
293 if( Type.isNumber( IDorOBJECT ) === true ){
296 if( IDorOBJECT && Type.isNumber( IDorOBJECT.id ) === true ){
299 unregisteredFileDataJsonList.push( [ obj, list ] );
301 alert( 'getResource error' + IDorOBJECT.toString() );
305 if( !data ) data = list[ id ] = { id : id };
309 this.getSeqentialFiles = function( file ){
310 var data = FileAPI.getFileData( file ),
311 json = data.json || null;
312 if( data.type === FILE_TYPE.COMIC && json === true ){
313 if( pettanr.CONST.SERVER_SUPPORT === false ){
314 json = [ 'json\/comics_', data.id, '.json' ].join( '' );
316 json = [ pettanr.CONST.PETTANR_ROOT_PATH, 'stories\/', data.id, '\/comic.json' ].join( '' );
320 if( typeof json === 'string' ){
321 FileAPI.getJson( file, json, onLoadJson, onErrorJson );
322 data.state = Const.FILE.STATE.LOADING;
323 if( data.json !== null ) delete data.json;
327 this.getName = function( file ){
328 var data = FileAPI.getFileData( file ),
329 type = data !== null ? data.type : null;
331 case FILE_TYPE.BALLOON :
333 case FILE_TYPE.PANEL_ELEMENT :
335 case FILE_TYPE.RESOURCE_PICTURE :
336 return [ '素材 ' + data.id, '.', data.ext ].join( '' );
337 case FILE_TYPE.PICTURE :
338 return [ '実素材 ' + data.id, '.', data.ext ].join( '' );
339 case FILE_TYPE.ORIGINAL_PICTURE :
340 return [ '原画 ', data.id, '.', data.ext ].join( '' );
341 case FILE_TYPE.COMIC :
343 case FILE_TYPE.STORY :
344 return [ 'story id:', data.id, ' ', data.comic ? data.comic.title : 'no comic', ':', data.t ].join( '' );
345 case FILE_TYPE.PANEL :
346 return [ 'panel id:', data.id ].join( '' );
347 case FILE_TYPE.AUTHOR :
348 return [ data.name, '先生' ].join( '' );
349 case FILE_TYPE.ARTIST :
350 return [ data.name, '画伯' ].join( '' );
351 case FILE_TYPE.BALLOON_TEMPLETE :
352 return [ data.id, data.caption ].join( ':' );
353 case FILE_TYPE.FOLDER :
357 this.getThumbnail = function( file ){
358 var data = FileAPI.getFileData( file ),
359 type = data !== null ? data.type : null;
360 if( data === FILE_DATA_COMICS_ROOT ) return { className: 'file-type-cabinet' };
363 case FILE_TYPE.PANEL_ELEMENT :
364 return { className: 'file-type-charactor' };
365 case FILE_TYPE.RESOURCE_PICTURE :
366 return { image: [ pettanr.CONST.THUMBNAIL_PATH, data.id, '.', data.ext ].join( '' )};
367 case FILE_TYPE.PICTURE :
368 //data = data.original_picture;
369 return { image: [ pettanr.CONST.THUMBNAIL_PATH, data.id, '.', data.ext ].join( '' )};
370 case FILE_TYPE.ORIGINAL_PICTURE :
371 return { className: 'file-type-charactor' };
372 // return { image: [ pettanr.CONST.THUMBNAIL_PATH, data.id, '.', data.ext ].join( '' )};
373 case FILE_TYPE.BALLOON :
375 case FILE_TYPE.COMIC :
376 return { className: 'file-type-comic' };
377 case FILE_TYPE.STORY :
379 case FILE_TYPE.PANEL :
380 return { className: 'file-type-panel' };
381 case FILE_TYPE.AUTHOR :
382 return { className: 'file-type-author' };
383 case FILE_TYPE.ARTIST :
384 return { className: 'file-type-artist' };
385 case FILE_TYPE.BALLOON_TEMPLETE :
386 return { className: 'file-type-balloon' };
387 case FILE_TYPE.FOLDER :
388 return { className: 'file-type-folder' };
390 return { className: 'file-type-broken' };
392 this.getSummary = function( file ){
393 var data = FileAPI.getFileData( file ),
394 type = data !== null ? data.type : null;
395 if( data === FILE_DATA_COMICS_ROOT ) return 'cabinet file';
397 case FILE_TYPE.BALLOON :
399 case FILE_TYPE.PANEL_ELEMENT :
400 return 'caption:' + data.caption + ' url:' + data.url + ' ' + data.width + 'x' + data.height + ' x:' + data.x + ' y:' + data.y + ' z:' + data.z + ' t:' + data.t;
401 case FILE_TYPE.RESOURCE_PICTURE :
403 case FILE_TYPE.PICTURE :
404 return '実素材情報 revision:' + data.revision + ' ' + data.credit + ' ' + data.settings;
405 case FILE_TYPE.ORIGINAL_PICTURE :
406 return [ '原画情報 ', data.width, 'x', data.height, ', filesize:', data.filesize, ' md5', data.md5 ].join( '' );
407 case FILE_TYPE.COMIC :
408 return 'comic id:' + data.id;
409 case FILE_TYPE.STORY :
411 case FILE_TYPE.PANEL :
412 return [ 'panel id:', data.id, ', width:', data.width, ', height:', data.height, ', 枠線:', data.border, ', 公開:', data.publish ].join( '' );
413 case FILE_TYPE.AUTHOR :
414 return 'author id:' + data.id;
415 case FILE_TYPE.ARTIST :
416 return [ 'artist id:', data.id, ' Email:', data.email || 'empty' , ', HP:', data.homepage_url || 'empty' ].join( '' );
417 case FILE_TYPE.BALLOON_TEMPLETE :
418 return data.name + ', ' + data.settings;
419 case FILE_TYPE.FOLDER :
420 return 'pettanR folder';
422 return 'pettanR unknown file';
424 this.read = function( file ){
425 var data = FileAPI.getFileData( file ),
426 type = data !== null ? data.type : null,
429 case FILE_TYPE.COMIC :
430 ret = Util.copy( data );
431 ret.panels = ret.children;
432 if( Type.isArray( ret.panels ) === true ){
433 for( i = ret.panels.length; i; ){
434 elm = ret.panels[ --i ];
435 elm.elements = elm.children;
439 case FILE_TYPE.STORY :
440 ret = Util.copy( data );
441 ret.panel.elements = ret.panel.children;
443 case FILE_TYPE.PANEL :
444 ret = Util.copy( data );
445 ret.elements = ret.children;
447 case FILE_TYPE.PANEL_ELEMENT :
448 case FILE_TYPE.BALLOON :
449 case FILE_TYPE.ORIGINAL_PICTURE :
452 this.write = function( file, newData, onUpdate ){
453 var data = FileAPI.getFileData( file ),
454 type = data !== null ? data.type : null;
456 case FILE_TYPE.COMIC :
457 case FILE_TYPE.PANEL :
458 case FILE_TYPE.PANEL_ELEMENT :
459 case FILE_TYPE.BALLOON :
460 case FILE_TYPE.ORIGINAL_PICTURE :
463 this.viewerApplicationList = function( file ){
464 var data = FileAPI.getFileData( file ),
465 type = data !== null ? data.type : null;
466 if( data === FILE_DATA_MY_ORIGINAL_PICTURES_ROOT ) return [ PremiumSatge ];
468 case FILE_TYPE.COMIC :
469 case FILE_TYPE.PANEL :
470 case FILE_TYPE.STORY :
472 case FILE_TYPE.PANEL_ELEMENT :
473 case FILE_TYPE.BALLOON :
474 case FILE_TYPE.ORIGINAL_PICTURE :
476 case FILE_TYPE.ARTIST :
477 return [ PremiumSatge ];
482 this.editorApplicationList = function( file ){
483 var data = FileAPI.getFileData( file ),
484 type = data !== null ? data.type : null;
486 case FILE_TYPE.COMIC :
487 return [ Editor, ComicConsole ];
488 case FILE_TYPE.PANEL :
490 case FILE_TYPE.PANEL_ELEMENT :
491 case FILE_TYPE.BALLOON :
492 case FILE_TYPE.ORIGINAL_PICTURE :
493 case FILE_TYPE.ARTIST :
499 Const = FileAPI.getConst(),
500 FILE_TYPE = Util.extend(
503 COMIC : FileAPI.createFileTypeID(),
504 STORY : FileAPI.createFileTypeID(),
505 PANEL : FileAPI.createFileTypeID(),
506 PANEL_ELEMENT : FileAPI.createFileTypeID(),
507 BALLOON : FileAPI.createFileTypeID(),
508 BALLOON_TEMPLETE : FileAPI.createFileTypeID(),
509 ORIGINAL_PICTURE : FileAPI.createFileTypeID(),
510 RESOURCE_PICTURE : FileAPI.createFileTypeID(),
511 PICTURE : FileAPI.createFileTypeID(),
512 AUTHOR : FileAPI.createFileTypeID(),
513 ARTIST : FileAPI.createFileTypeID(),
514 LICENSE : FileAPI.createFileTypeID(),
515 LICENSE_GROUP : FileAPI.createFileTypeID(),
525 LICENSE_GROUP_ARRAY = [],
526 PANEL_ELEMENT_ARRAY = [],
527 ORIGINAL_PICTURE_ARRAY = [],
528 RESOURCE_PICTURE_ARRAY = [],
529 BALLOON_TEMPLETE_ARRAY = [],
530 BASIC_LICENSES = 'cc_by,cc_nc,cc_nd,cc_sa,keep_aspect_ratio,no_convert,no_flip,no_resize'.split( ','),
531 FILE_DATA_SERVICE_ROOT = {
532 name: 'PettanR root',
533 type: FILE_TYPE.FOLDER,
536 FILE_DATA_COMICS_ROOT = {
538 type: FILE_TYPE.FOLDER,
541 json: pettanr.CONST.URL_COMICS_JSON
543 FILE_DATA_PANELS_ROOT = {
545 type: FILE_TYPE.FOLDER,
548 json: pettanr.CONST.URL_PANELS_JSON
550 FILE_DATA_RESOURCE_PICTURES_ROOT = {
552 type: FILE_TYPE.FOLDER,
555 json: pettanr.CONST.URL_RESOURCE_PICTURES_JSON
557 FILE_DATA_ORIGINAL_PICTURES_ROOT = {
559 type: FILE_TYPE.FOLDER,
563 FILE_DATA_MY_COMICS_ROOT = {
565 type: FILE_TYPE.FOLDER,
569 json: pettanr.CONST.URL_MY_COMICS_JSON
571 FILE_DATA_LATEST_COMICS = {
572 name: 'Latest Comics',
573 type: FILE_TYPE.FOLDER,
576 FILE_DATA_STORY_ROOT = {
578 type: FILE_TYPE.FOLDER,
582 FILE_DATA_LATEST_PANELS = {
583 name: 'Latest Panels',
584 type: FILE_TYPE.FOLDER,
587 FILE_DATA_MY_PANELS_ROOT = {
589 type: FILE_TYPE.FOLDER,
592 json: pettanr.CONST.URL_MY_PANELS_JSON
594 FILE_DATA_MY_RESOURCE_PICTURES_ROOT = {
596 type: FILE_TYPE.FOLDER,
599 // json: pettanr.CONST.URL_RESOURCE_PICTURES_JSON,
602 FILE_DATA_MY_ORIGINAL_PICTURES_ROOT = {
604 type: FILE_TYPE.FOLDER,
607 json: pettanr.CONST.URL_MY_ORIGINAL_PICTURES_JSON,
610 FILE_DATA_AUTHOR_ROOT = {
612 type: FILE_TYPE.FOLDER,
615 FILE_DATA_ARTIST_ROOT = {
617 type: FILE_TYPE.FOLDER,
620 FILE_DATA_LISENCE_ROOT = {
621 name: 'Lisence Root',
622 type: FILE_TYPE.FOLDER,
625 FILE_DATA_LISENCE = {
627 type: FILE_TYPE.FOLDER,
630 FILE_DATA_LISENCE_GROUP = {
631 name: 'Lisence Group',
632 type: FILE_TYPE.FOLDER,
635 FILE_DATA_BALLOON_ROOT = {
636 name: 'Balloon Templetes',
637 type: FILE_TYPE.FOLDER,
640 json: pettanr.CONST.SPEECH_BALOON_TEMPLETE
642 FILE_DATA_SERVICE_ROOT.children.push( FILE_DATA_COMICS_ROOT, FILE_DATA_RESOURCE_PICTURES_ROOT, FILE_DATA_ORIGINAL_PICTURES_ROOT, FILE_DATA_LISENCE_ROOT, FILE_DATA_BALLOON_ROOT );
643 FILE_DATA_COMICS_ROOT.children.push( FILE_DATA_MY_COMICS_ROOT, FILE_DATA_LATEST_COMICS, FILE_DATA_AUTHOR_ROOT, FILE_DATA_STORY_ROOT, FILE_DATA_PANELS_ROOT );
644 FILE_DATA_PANELS_ROOT.children.push( FILE_DATA_LATEST_PANELS, FILE_DATA_MY_PANELS_ROOT );
645 FILE_DATA_RESOURCE_PICTURES_ROOT.children.push( FILE_DATA_MY_RESOURCE_PICTURES_ROOT, FILE_DATA_ARTIST_ROOT );
646 FILE_DATA_LISENCE_ROOT.children.push( FILE_DATA_LISENCE_GROUP, FILE_DATA_LISENCE );
647 FILE_DATA_ORIGINAL_PICTURES_ROOT.children.push( FILE_DATA_MY_ORIGINAL_PICTURES_ROOT );
649 FileAPI.createFolderUnderRoot( FILE_DATA_SERVICE_ROOT );
651 Driver.isPettanrFileInstance = function( file ){
652 if( FileAPI.isFileInstance( file ) === true ){
653 var _data = FileAPI.getFileData( file.getUID() );// file でなく file.getUID()
654 return _data !== null && _data.driver === Driver;
659 var Cabinet = gOS.registerApplication( function(){
669 this.bgColor = '#FFFFFF';
670 this.MIN_WIDTH = 500;
671 this.MIN_HEIGHT = 300;
672 this.onInit = function(){
673 self.rootElement.id = 'cabinet-root';
674 self.rootElement.innerHTML = [
675 '<div id="cabinet-header">',
676 '<div class="header-title">Cabinet</div>',
677 '<div id="cabinet-close-button">x</div>',
678 '<div id="cabinet-path" class="finder-path"></div>',
680 '<div id="cabinet-container" class="finder-container"></div>'
683 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
685 tree = FileAPI.createTree( FILE_DATA_SERVICE_ROOT );
686 eventRoot = self.getPointingDeviceEventTreeRoot();
690 this.onOpen = function( _w, _h ){
691 headerH = Util.getElementSize( document.getElementById( 'cabinet-header' ) ).height;
693 nodeClose = eventRoot.createNode( document.getElementById( 'cabinet-close-button' ), false, false, 'close-button-hover', 'pointer' );
694 nodeClose.addEventListener( 'click', Cabinet.shutdown );
695 nodePath = eventRoot.createNode( document.getElementById( 'cabinet-path' ), false, false );
696 nodeBody = eventRoot.createNode( document.getElementById( 'cabinet-container' ), false, true, null, '', true );
698 finder = self.createFinder( nodeBody, tree );
699 finder.createPath( nodePath );
700 self.onPaneResize( _w, _h );
702 this.onClose = function(){
705 finder = tree = null;
707 this.onPaneResize = function( w, h ){
709 nodeBody.update( 0, headerH, w, h - headerH );
710 finder.resize( w, h - headerH );
712 }, false, true, 'Cabinet', 'cabinet', null, '#1C1C1C' );
714 var Gallery = gOS.registerApplication( function(){
724 this.bgColor = '#FFFFFF';
725 this.MIN_WIDTH = 500;
726 this.MIN_HEIGHT = 300;
727 this.onInit = function(){
728 self.rootElement.id = 'gallery-root';
729 self.rootElement.innerHTML = [
730 '<div id="gallery-header">',
731 '<div class="header-title">Gallery</div>',
732 '<div id="gallery-close-button">x</div>',
733 '<div id="gallery-path" class="finder-path"></div>',
735 '<div id="gallery-container" class="finder-container"></div>'
738 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
740 tree = FileAPI.createTree( FILE_DATA_RESOURCE_PICTURES_ROOT );
741 var _root = tree.getRootFile(),
742 _myPic = _root.getChildFileAt( 0 ),
743 _pic = _root.getChildFileAt( 1 );
744 _myPic.getSeqentialFiles();
745 _pic.getSeqentialFiles();
749 eventRoot = self.getPointingDeviceEventTreeRoot();
751 this.onOpen = function( w, h ){
752 headerH = Util.getElementSize( document.getElementById( 'gallery-header' ) ).height;
754 nodeClose = eventRoot.createNode( document.getElementById( 'gallery-close-button' ), false, false, 'close-button-hover', 'pointer' );
755 nodeClose.addEventListener( 'click', Gallery.shutdown );
756 nodePath = eventRoot.createNode( document.getElementById( 'gallery-path' ), false, false );
757 nodeBody = eventRoot.createNode( document.getElementById( 'gallery-container' ), false, true, null, '', true );
759 finder = self.createFinder( nodeBody, tree );
760 finder.createPath( nodePath );
761 self.onPaneResize( w, h );
763 this.onClose = function(){
766 finder = tree = null;
768 this.onPaneResize = function( w, h ){
770 nodeBody.update( 0, headerH, w, h - headerH );
771 finder.resize( w, h - headerH );
773 }, false, true, 'Gallery', 'gallery', null, '#01A31C' );
775 var Backyard = gOS.registerApplication( function(){
778 this.bgColor = '#FFFFFF';
779 this.MIN_WIDTH = 500;
780 this.MIN_HEIGHT = 300;
781 this.onInit = function(){
783 this.onOpen = function( _w, _h, _option ){
785 this.onClose = function(){
787 this.onPaneResize = function( _w, _h){
789 }, false, false, 'Settings', 'settings', null, '#DDDDDD' );
791 if( pettanr.DEBUG === true){
792 var Debug = gOS.registerApplication( function(){
797 pettanR: pettanr.version,
798 ua: navigator.userAgent,
799 platform: navigator.platform,
800 appVersion: navigator.appVersion,
801 appCodeName: navigator.appCodeName,
802 appName: navigator.appName,
803 language: navigator.browserLanguage || navigator.language,
805 RenderingMode: UA.isStanderdMode === true ? 'Standerd' : 'Quirks'
808 data.version = UA.IE;
809 if( UA.ieVersion >= 8 ) data.RenderingVersion = UA.ieRenderingVersion;
810 data.browserType = UA.STANDALONE === true ? 'Standalone' : 'bundle';
811 if( UA.ieVersion < 9 ) {
820 this.bgColor = '#FFFFFF';
821 this.MIN_WIDTH = 500;
822 this.MIN_HEIGHT = 300;
823 this.onInit = function(){
824 self.rootElement.id = 'debug-root';
825 self.rootElement.innerHTML = '<dl id="useragent" class="dl-table clearfix"></dl>';
827 this.onOpen = function( _w, _h, _option ){
828 elmDl = document.getElementById( 'useragent' );
830 for( var key in data ){
831 elmDt = document.createElement( 'dt' );
832 elmDt.innerHTML = key;
833 elmDd = document.createElement( 'dd' );
834 elmDd.innerHTML = '' + data[ key];
835 if( !data[ key ] ) elmDd.style.color = 'red';
836 elmDl.appendChild( elmDt );
837 elmDl.appendChild( elmDd );
840 this.onClose = function(){
843 this.onPaneResize = function( _w, _h ){
846 }, false, true, 'Debug', 'debug', null, '#01A31C' );
849 /* ----------------------------------------
850 * Image Group Exproler
853 var PremiumSatge = gOS.registerApplication( function(){
854 var BASE_PATH = pettanr.CONST.RESOURCE_PICTURE_PATH,
855 THUMB_PATH = pettanr.CONST.THUMBNAIL_PATH,
856 LIMIT_FILESIZE = 1024 * 100,
862 elmContainer, elmIconOrigin, elmName, elmButton,
863 containerW, containerH,
864 itemW, itemH, buttonW,
867 onUpdateContext = null,
870 var ImageGroupIconClass = function( index, data ){
871 var elmIconWrap = elmIconOrigin.cloneNode( true ),
872 elmIconTitle = Util.getElementsByClassName( elmIconWrap, 'image-group-item-title' )[ 0 ],
873 originalPicture = data.original_picture || data,
874 SRC = [ BASE_PATH, data.id, '.', data.ext ].join( ''),
875 LOW_SRC = originalPicture.filesize && originalPicture.filesize > LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext ].join( '' ) : null,
876 reversibleImage = null,
880 elmContainer.appendChild( elmIconWrap );
881 elmIconWrap.style.left = ( index * itemW ) + 'px';
882 elmIconTitle.appendChild( document.createTextNode( originalPicture.filesize + 'bytes' ) );
884 function onImageLoad( url, _imgW, _imgH ){
885 data.width = _imgW = _imgW || originalPicture.width || 64;
886 data.height = _imgH = _imgH || originalPicture.height || 64;
887 elmIconTitle.firstChild.data = _imgW + 'x' + _imgH;
888 var zoom = 128 /( _imgW > _imgH ? _imgW : _imgH ),
889 MATH_FLOOR = Math.floor,
890 h = MATH_FLOOR( _imgH * zoom ),
891 w = MATH_FLOOR( _imgW * zoom );
892 reversibleImage.elm.style.cssText = [
895 'margin:', MATH_FLOOR( itemH / 2 - h / 2 ), 'px ', MATH_FLOOR( itemW / 2 - w / 2 ), 'px 0'
897 reversibleImage.resize( w, h );
898 self.addEventListener( elmIconWrap, 'click', onClick );
903 PremiumSatge.shutdown();
906 function asyncDraw(){
907 reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onImageLoad );
908 elmIconWrap.appendChild( reversibleImage.elm );
913 this.onEnter = function( delay ){
914 self.addTimer( asyncDraw, delay, true );
915 delete instance.onEnter;
917 this.destroy = function(){
918 delete instance.destroy;
919 // timer && window.clearTimeout( timer );
920 self.removeTimer( asyncDraw );
921 self.removeEventListener( elmIconWrap );
922 reversibleImage !== null && reversibleImage.destroy();
923 // Util.removeAllChildren( elmIconWrap );
924 // elmContainer.removeChild( elmIconWrap );
925 reversibleImage = elmIconWrap = elmIconTitle = data = timer = null;
929 function onEnterShowImage(){
930 var l = ICON_ARRAY.length,
931 _start = -wrapX /itemW -1,
932 _end = _start + winW /itemW +1,
934 for( var i=0, c = 0; i<l; ++i){
935 _icon = ICON_ARRAY[ i ];
936 if( _start < i && i < _end && _icon.onEnter ){
937 _icon.onEnter( c * 100 );
941 //onEnterInterval !== null && window.clearTimeout( onEnterInterval );
942 //onEnterInterval = null;
943 self.removeTimer( onEnterShowImage );
945 function clickClose(){
946 PremiumSatge.shutdown();
948 function onMouseWheel( e ){
949 if( winW < containerW ){
950 wrapX += e.wheelDelta / 2;
951 wrapX = wrapX > 0 ? 0 : wrapX < winW -containerW ? winW -containerW : wrapX;
952 elmContainer.style.left = wrapX + 'px';
954 self.removeTimer( onEnterShowImage );
955 self.addTimer( onEnterShowImage, 500 );
960 function drawIcons(){
961 while( ICON_ARRAY.length > 0 ){
962 ICON_ARRAY.shift().destroy();
964 var _index = rootFile.search( {
966 type : FILE_TYPE.ARTIST
968 _artistFile = rootFile.getChildFileAt( _index ),
970 if( _artistFile !== null ){
971 for( var i=0, l=_artistFile.getChildFileLength(); i<l; ++i ){
972 file = _artistFile.getChildFileAt( i );
973 ICON_ARRAY.push( new ImageGroupIconClass( i, FileAPI.getFileData( file ) ));
976 elmName.firstChild.data = _artistFile.getName();
977 _artistFile.destroy();
981 function onFadeout(){
982 while( ICON_ARRAY.length > 0 ){
983 ICON_ARRAY.shift().destroy();
985 onUpdate !== null && onUpdateData !== null && onUpdate.call( onUpdateContext, onUpdateData );
986 onUpdate = onUpdateData = onUpdateContext = null;
987 PremiumSatge.shutdown();
991 this.MIN_WIDTH = 320;
992 this.MIN_HEIGHT = 320;
993 this.onInit = function(){
994 self.rootElement.id = 'image-group-wrapper';
996 self.rootElement.innerHTML = [
997 '<div id="image-group-icon-container"></div>',
998 '<div id="image-group-name">NO DATA...</div>',
999 '<div id="image-group-button" class="button">close</div>'
1002 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
1004 tree = FileAPI.createTree( FILE_DATA_ARTIST_ROOT );
1005 rootFile = tree.getRootFile();
1007 this.onOpen = function( _windowW, _windowH, _ARTISTIDorFILE, _onUpdate, opt_thisObj ){
1008 elmContainer = document.getElementById( 'image-group-icon-container' );
1009 containerH = Util.getElementSize( elmContainer ).height;
1011 elmIconOrigin = ( function(){
1012 var ret = document.createElement( 'div' ),
1013 data = document.createElement( 'div' );
1014 ret.appendChild( data );
1015 ret.className = 'image-group-item';
1016 data.className = 'image-group-item-title';
1020 var size = Util.getElementSize( elmIconOrigin );
1022 itemH = size.height;
1024 elmName = document.getElementById( 'image-group-name' );
1025 elmButton = document.getElementById( 'image-group-button' );
1027 buttonW = Util.getElementSize( elmButton ).width;
1029 self.addEventListener( elmContainer, 'mousewheel', onMouseWheel );
1030 self.addEventListener( elmButton, 'click', clickClose );
1031 tree.addTreeEventListener( Const.TREE.EVENT.UPDATE, drawIcons );
1033 var data = FileAPI.getFileData( _ARTISTIDorFILE );
1035 artistID = MyArtistID || -1;
1037 if( data.type === FILE_TYPE.ARTIST || FILE_DATA_MY_ORIGINAL_PICTURES_ROOT === data ){
1038 artistID = data.id || -1;
1040 if( Type.isNumber( _ARTISTIDorFILE ) === true ){
1041 artistID = _ARTISTIDorFILE;
1044 onUpdate = _onUpdate || null;
1045 onUpdateContext = opt_thisObj || null;
1046 onUpdateData = null;
1051 containerW = ICON_ARRAY.length * itemW;
1055 var w = winW > containerW ? winW : containerW,
1056 h = _windowH > containerH ? containerH : _windowH,
1057 MATH_FLOOR = Math.floor;
1059 $( elmContainer ).css( {
1063 top: MATH_FLOOR( _windowH /2 )
1064 }).stop().animate( {
1066 top: MATH_FLOOR( _windowH /2 - h /2 )
1067 }, onEnterShowImage );
1069 elmButton.style.cssText = [
1070 'left:', MATH_FLOOR( _windowW /2 - buttonW /2 ), 'px;',
1071 'top:', MATH_FLOOR( _windowH /2 + containerH /2 +10 ), 'px'
1074 this.onPaneResize = function( _windowW, _windowH ){
1075 var w = _windowW > containerW ? _windowW : containerW,
1076 h = _windowH > containerH ? containerH : _windowH,
1077 MATH_FLOOR = Math.floor,
1078 offsetW = MATH_FLOOR( _windowW /2 -winW /2 );
1082 if( offsetW <= 0 ){ // smaller
1083 $( elmContainer ).stop().css( {
1088 top: MATH_FLOOR( _windowH /2 -h /2 )
1091 $( elmContainer ).stop().css( { // bigger
1094 borderLeftWidth: offsetW
1096 top: MATH_FLOOR( _windowH /2 -h /2 ),
1100 elmButton.style.cssText = [
1101 'left:', MATH_FLOOR( _windowW /2 -buttonW /2 ), 'px;',
1102 'top:', MATH_FLOOR( _windowH /2 +containerH /2 + 10 ), 'px'
1106 this.onClose = function(){
1107 if( tree === null ) return true;
1108 $( elmContainer ).stop().animate( {
1110 top: Math.floor( winH / 2 )
1112 // onEnterInterval !== null && window.clearTimeout( onEnterInterval );
1113 // onEnterInterval = null;
1116 tree.removeTreeEventListener( Const.TREE.EVENT.UPDATE, drawIcons );
1118 tree = rootFile = null;
1122 }, true, true, 'Premium Stage', 'premiumStage', null, '#C3325F' );
1125 /* ----------------------------------------
1129 var TextEditor = gOS.registerApplication( function(){
1130 var elmTextarea, elmButton,
1131 textElement, onUpdate,
1137 textElement && textElement.text( elmTextarea.value );
1138 self.addAsyncCall( asyncCallback );
1141 function asyncCallback(){
1142 onUpdate && onUpdate( textElement );
1143 onUpdate = textElement = null;
1144 TextEditor.shutdown();
1148 function textareaFitHeight(){
1150 while( elmTextarea.offsetHeight < textElement.h ){
1152 elmTextarea.rows = rows;
1154 if( rows > 1 ) elmTextarea.rows = --rows;
1159 this.MIN_WIDTH = 320;
1160 this.MIN_HEIGHT = 320;
1161 this.onInit = function(){
1162 self.rootElement.id = 'speach-editor-wrapper';
1163 self.rootElement.innerHTML = '<textarea id="speach-editor"></textarea><div id="speach-edit-complete-button" class="button">OK</div>';
1165 this.onOpen = function( _w, _h, _panelX, _panelY, _textElement, _onUpdate ){
1166 elmTextarea = document.getElementById( 'speach-editor' );
1167 elmButton = document.getElementById( 'speach-edit-complete-button' );
1169 self.addKeyEventListener( 'keydown', new Function( 'return false' ), 69, false, true );
1170 self.addEventListener( elmButton, 'click', clickOK );
1174 textElement = _textElement;
1175 onUpdate = _onUpdate || null;
1177 self.onPaneResize( _w, _h );
1178 elmTextarea.value = _textElement.content;
1179 elmTextarea.focus();
1182 * ie6,7は、textarea { width:100%}でも高さが変わらない。rowsを設定。
1184 UA.isIE === true && UA.ieVersion <= 7 && self.addAsyncCall( textareaFitHeight );
1186 this.onPaneResize = function( _w, _h ){
1187 self.rootElement.style.cssText = [
1188 'left:', textElement.x + panelX, 'px;',
1189 'top:', textElement.y + panelY, 'px;',
1190 'width:', textElement.w, 'px;',
1191 'height:', textElement.h, 'px;'
1194 this.onClose = function(){
1195 self.removeKeyEventListener();
1196 self.removeEventListener( elmButton );
1198 elmTextarea = elmButton = onUpdate = textElement = self = null;
1200 }, true, false, 'Tetxt Editor', 'texteditor', null, '#DDDDDD' );
1203 var Reader = gOS.registerApplication( function(){
1204 var windowW, windowH,
1208 elmContainer, elmTitle, elmAuthor, elmBackButton, elmNextButton,
1212 currentPanel = null,
1217 function onBackClick(){
1218 currentIndex -= ( currentIndex > 0 ? 1 : 0 );
1222 function onNextClick(){
1223 currentIndex += ( currentIndex < numPanel - 1 ? 1 : 0 );
1228 var elm = elmContainer.childNodes[ currentIndex ],
1229 h = windowH - headerH - consoleH,
1232 top = headerH - elm.offsetTop + Math.floor( ( h - elm.offsetHeight ) / 2 );
1235 $( elmContainer ).stop().animate( {
1239 function getCurrentTopPosition(){
1243 var fileData, title, author, story;
1245 if( Driver.isPettanrFileInstance( currentFile ) === true ){
1246 switch( currentFile.getType() ){
1247 case FILE_TYPE.COMIC :
1248 fileData = currentFile.read();
1249 title = fileData.title;
1250 author = fileData.author.name;
1251 comicData = fileData;
1252 numPanel = currentFile.getChildFileLength();
1254 case FILE_TYPE.STORY :
1255 story = currentFile.read();
1256 fileData = story.panel;
1257 title = story.comic.title;
1258 author = fileData.author.name;
1259 comicData = fileData;
1262 case FILE_TYPE.PANEL :
1263 fileData = currentFile.read();
1265 author = fileData.author.name;
1266 comicData = fileData;
1273 if( comicData !== null ){
1274 elmTitle.data = title;
1275 elmAuthor.data = author;
1276 // bindWorker.json( comicData );
1277 bindWorker.file( currentFile );
1278 self.addAsyncCall( asyncResize );
1281 function asyncResize(){
1282 self.onPaneResize( windowW, windowH );
1287 this.MIN_WIDTH = 320;
1288 this.MIN_HEIGHT = 320;
1289 this.onInit = function(){
1290 self.rootElement.id = 'comic-reader-wrapper';
1291 self.rootElement.innerHTML = [
1292 '<div id="comic-reader-panel-container"></div>',
1293 '<div class="comic-reader-shadow" style="top:0;height:40px;"></div>',
1294 '<div id="comic-reader-header">',
1295 '<div id="comic-reader-header-content">',
1296 '<span id="comic-reader-title">NO DATA...</span>',
1297 '<span id="comic-reader-author">NO DATA...</span>',
1300 '<div class="comic-reader-shadow" style="bottom:0;height:100px;"></div>',
1301 '<div id="comic-reader-console">',
1302 '<div id="comic-reader-button-centering">',
1303 '<a href="#" id="comic-reader-back-button">▲</da>',
1304 '<a href="#" id="comic-reader-forward-button">▼</a>',
1309 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
1312 this.onOpen = function( _w, _h, file ){
1313 headerH = Util.getElementSize( document.getElementById( 'comic-reader-header' ) ).height;
1314 consoleH = Util.getElementSize( document.getElementById( 'comic-reader-console' ) ).height;
1315 elmContainer = document.getElementById( 'comic-reader-panel-container' );
1316 elmTitle = document.getElementById( 'comic-reader-title' ).firstChild;
1317 elmAuthor = document.getElementById( 'comic-reader-author' ).firstChild;
1318 elmBackButton = document.getElementById( 'comic-reader-back-button' );
1319 elmNextButton = document.getElementById( 'comic-reader-forward-button' );
1321 bindWorker = pettanr.bind.createBindWorker( elmContainer, null, false, false );
1323 self.addEventListener( elmBackButton, 'click', onBackClick );
1324 self.addEventListener( elmNextButton, 'click', onNextClick );
1326 numPanel = currentIndex = 0;
1328 elmContainer.style.cssText = 'left:' + ( _w / 2 ) + 'px;' + 'top:' + _h + 'px;';
1332 if( FileAPI.isFileInstance( file ) === true ){
1334 file.addEventListener( Const.FILE.EVENT.GET_SEQENTIAL_FILES, draw );
1335 file.getSeqentialFiles();
1339 this.onPaneResize = function( _windowW, _windowH ){
1342 var panelH = elmContainer.offsetHeight,
1343 panelW = elmContainer.offsetWidth,
1344 h = _windowH - headerH - consoleH;
1345 $( elmContainer ).stop().animate(
1347 left: Math.floor( ( _windowW - panelW ) / 2 ),
1348 top: headerH + ( panelH < h ? Math.floor( ( h - panelH ) / 2 ) : 0 )
1352 this.onClose = function(){
1353 self.removeEventListener( elmBackButton );
1354 self.removeEventListener( elmNextButton );
1356 bindWorker.destroy();
1359 currentFile && currentFile.removeEventListener( Const.FILE.EVENT.GET_SEQENTIAL_FILES, draw );
1360 currentFile = comicData = currentPanel = null;
1362 elmContainer = elmTitle = elmAuthor = elmBackButton = elmNextButton = null;
1364 }, true, true, 'Comic Reader', 'comicreader', null, '#01A31C' );
1367 var Editor = gOS.registerApplication( function(){
1369 var PANEL_ELEMENT_TYPE_IMAGE = 0,
1370 PANEL_ELEMENT_TYPE_TEXT = 1,
1372 PANEL_ELEMENT_ARRAY = [],
1373 MIN_PANEL_HEIGHT = 20,
1374 MIN_ELEMENT_SIZE = 19,
1375 MOUSE_HIT_AREA = 10,
1385 var kill = function(){
1388 if( o.hasOwnProperty && !o.hasOwnProperty( p ) ) continue;
1393 /* ----------------------------------------
1395 * - mouseEventListener
1406 var MENU_BAR_CONTROL = ( function(){
1407 var ELM_ITEM_CLASSNAME = 'menubar-item',
1410 nodeBar, nodeBox, layerBox,
1412 /** -----------------------------------------
1413 * PrivateOptionDataClass
1415 var PrivateOptionDataClass = function( menuData, option, title, shortcut, callback, visible, separateAfter, thisObject ){
1416 this.menuData = menuData;
1417 this.option = option;
1419 this.shortcut = shortcut || '';
1420 this.callback = callback;
1421 this.thisObject = thisObject;
1422 this.visible = visible;
1423 this.separateAfter = separateAfter;
1425 PrivateOptionDataClass.prototype = {
1430 visible : undefined,
1436 separateAfter : false,
1437 show : function( elm ){
1438 if( this.elm === elm ) return;
1440 elm = document.createElement( 'div' );
1441 elmBox.appendChild( elm );
1442 elm.appendChild( document.createElement( 'span' ) );
1443 elm.appendChild( document.createElement( 'kbd' ) );
1446 this.option.title( this.title );
1447 this.option.visible( !!this.visible );
1448 elm.lastChild.innerHTML = this.shortcut;
1449 elm.style.borderStyle = this.border === true ? 'solid' : 'none';
1451 this.node = nodeBox.createNode( elm, false, true, 'menubar-option-hover', 'pointer' );
1452 this.node.disabled( !this.visible );
1460 this.callback.call( this.thisObject || this.option, Util.getIndex( this.menuData.optionDataList, this ) );
1462 remove : function(){
1463 var list = PrivateOptionDataClass.list;
1464 list.splice( Util.getIndex( list, this ), 1 );
1467 PrivateOptionDataClass.list = [];
1468 PrivateOptionDataClass.get = function( OptionOrElm ){
1469 var list = PrivateOptionDataClass.list,
1474 if( data.option === OptionOrElm || data.elm === OptionOrElm ) return data;
1479 /** -----------------------------------------
1482 var OptionClass = function( menuData, title, shortcut, callback, visible, separateAfter, thisObject ){
1483 PrivateOptionDataClass.list.push( new PrivateOptionDataClass( menuData, this, title, shortcut, callback, visible, separateAfter, thisObject ) );
1485 OptionClass.prototype = {
1486 title: function( v ){
1487 var data = PrivateOptionDataClass.get( this );
1488 if( Type.isString( v ) === true ){
1490 if( data.elm ) data.elm.firstChild.innerHTML = v;
1494 visible : function( v ){
1495 var data = PrivateOptionDataClass.get( this );
1496 if( Type.isBoolean( v ) === true ){
1498 data.elm && Util.toggleClass( data.elm, 'menubar-option-disabled', !v );
1500 return data.visible;
1503 /** -----------------------------------------
1506 var AsyncOptionClass = function( menuData, callback, visible, separateAfter, thisObject ){
1507 var data = new PrivateOptionDataClass( menuData, this, null, null, callback, visible, separateAfter, thisObject );
1508 data.show = AsyncOptionClass.show;
1509 data.hide = AsyncOptionClass.hide;
1510 PrivateOptionDataClass.list.push( data );
1512 AsyncOptionClass.prototype = {
1513 title : function(){},
1514 visible : OptionClass.prototype.visible
1516 AsyncOptionClass.show = function( elm ){
1517 if( this.elm === elm ) return;
1519 elm = document.createElement( 'div' );
1520 elmBox.appendChild( elm );
1521 elm.appendChild( document.createElement( 'span' ) );
1522 elm.appendChild( document.createElement( 'kbd' ) );
1525 elm.className = 'loading';
1526 elm.style.height = '90px';
1527 elm.firstChild.innerHTML = this.elm.lastChild.innerHTML = '';
1528 elm.style.borderStyle = this.border === true ? 'solid' : 'none';
1532 AsyncOptionClass.hide = function(){
1533 this.elm.className = '';
1534 this.elm.style.height = '';
1538 /** -----------------------------------------
1539 * MenuPrivateDataClass
1541 var MenuPrivateDataClass = function( menu, title ){
1543 this.elm = document.createElement( 'div' );
1544 this.optionDataList = [];
1546 elmBar.appendChild( this.elm );
1547 this.elm.className = ELM_ITEM_CLASSNAME;
1548 this.elm.innerHTML = title;
1550 MenuPrivateDataClass.prototype = {
1557 optionDataList : null,
1559 this.elm.style.left = ( menuW * Util.getIndex( MenuPrivateDataClass.list, this ) ) + 'px';
1560 this.node = nodeBar.createNode( this.elm, false, false, ELM_ITEM_CLASSNAME + '-hover', 'pointer' );
1561 // this.node.addEventListener( 'click', this.onClick, this );
1562 this.node.addEventListener( 'click', this.onClick, this );
1566 while( o = this.optionDataList.shift() ) o.remove();
1570 onClick : function( e ){
1571 if( currentMenu !== this.menu ){
1572 currentMenu && currentMenu.hide();
1573 currentMenu = this.menu;
1577 onOptionClick : function( e ){
1578 var target = e.target,
1579 i = target.nodeIndex(),
1580 option = this.optionDataList[ i ];
1581 if( target === nodeBox ) return true;
1585 MenuPrivateDataClass.list = [];
1586 MenuPrivateDataClass.get = function( menu ){
1587 var list = MenuPrivateDataClass.list,
1590 if( list[ --i ].menu === menu ) return list[ i ];
1595 /** -----------------------------------------
1598 var MenuClass = function( title ){
1599 MenuPrivateDataClass.list.push( new MenuPrivateDataClass( this, title ) );
1601 MenuClass.prototype = {
1603 var data = MenuPrivateDataClass.get( this );
1604 if( data.visible === true ) return;
1606 data.elm.className = ELM_ITEM_CLASSNAME + '-focus';
1609 elmBox = document.createElement( 'div' );
1610 elmBar.appendChild( elmBox );
1611 elmBox.className = 'menubar-option-box';
1612 nodeBox = nodeBar.createNode( elmBox, false, false, 'menubar-option-box-hover' );
1614 nodeBox.disabled( false );
1615 elmBar.parentNode.insertBefore( elmBox, elmBar.nextSibling ); // ie6 では elmBar の 子にすると 選択肢が表示されない
1617 nodeBox.setPosition( data.node.x(), barH );
1620 children = elmBox.childNodes,
1621 list = data.optionDataList
1623 while( l < children.length ){
1624 elmBox.removeChild( elmBox.firstChild );
1626 for( i = 0; i < l; ++i ){
1627 list[ i ].show( children[ i ] );
1631 nodeBar.addEventListener( 'mouseout', this.hide, this );
1632 nodeBox.addEventListener( 'click', data.onOptionClick, data );
1633 data.visible = true;
1636 data = MenuPrivateDataClass.get( this );
1637 if( data.visible === false ) return;
1639 data.elm.className = ELM_ITEM_CLASSNAME;
1640 for( var i = data.optionDataList.length; i; ){
1641 data.optionDataList[ --i ].hide();
1643 elmBar.parentNode.removeChild( elmBox );
1644 nodeBox.disabled( true );
1646 nodeBar.removeEventListener( 'mouseout', this.hide );
1647 nodeBox.removeEventListener( 'click', data.onOptionClick );
1648 data.visible = false;
1651 createOption: function( title, shortcut, callback, visible, separateBefore, separateAfter, thisObject ){
1652 var data = MenuPrivateDataClass.get( this ),
1653 before = data.optionDataList[ data.optionDataList.length - 1 ],
1654 ret = new OptionClass( data, title, shortcut, callback, visible, separateAfter, thisObject ),
1655 dataOption = PrivateOptionDataClass.get( ret );
1656 if( before ) before.border = separateBefore === true || before.separateAfter === true;
1657 data.optionDataList.push( dataOption );
1658 if( data.visible === true ){
1664 createAsyncOption: function( onOpen, visible, separateBefore, separateAfter, thisObject ){
1665 var data = MenuPrivateDataClass.get( this ),
1666 before = data.optionDataList[ data.optionDataList.length -1 ],
1667 ret = new AsyncOptionClass( data, onOpen, visible, separateAfter, thisObject ),
1668 dataOption = PrivateOptionDataClass.get( ret );
1669 if( before ) before.border = separateBefore === true || before.separateAfter === true;
1670 data.optionDataList.push( dataOption );
1671 data.visible === true && dataOption.show();
1674 remove : function( option ){
1675 var data = MenuPrivateDataClass.get( this ),
1676 optionData = PrivateOptionDataClass.get( option ),
1677 i = Util.getIndex( data.optionDataList, optionData );
1678 if( i === -1 ) return;
1680 data.optionDataList.splice( i, 1 );
1682 data.visible === true && elmBox.removeChild( optionData.elm ) && optionData.hide();
1683 optionData.remove();
1685 !( option instanceof AsyncOptionClass ) && data.optionDataList.length === 0 && this.hide();
1690 id : 'MENU_BAR_CONTROL',
1693 elmBar = document.getElementById( 'menu-bar' );
1694 nodeBar = eventRoot.createNode( elmBar, false, false, 'menu-bar-hover' );
1696 MENU_BAR_CONTROL.QUIT = MENU_BAR_CONTROL.createItem( 'Quit' );
1697 MENU_BAR_CONTROL.EDIT = MENU_BAR_CONTROL.createItem( 'Edit' );
1698 MENU_BAR_CONTROL.WINDOW = MENU_BAR_CONTROL.createItem( 'Window' );
1699 MENU_BAR_CONTROL.HELP = MENU_BAR_CONTROL.createItem( 'Help' );
1701 var size = Util.getElementSize( MenuPrivateDataClass.list[ 0 ].elm );
1703 barH = MENU_BAR_CONTROL.h = size.height;
1705 elmBar.style.top = ( - barH ) + 'px';
1706 $( elmBar ).animate( { top: 0 } );
1708 delete MENU_BAR_CONTROL.init;
1711 for( var i = MenuPrivateDataClass.list.length; i; ) MenuPrivateDataClass.list[ --i ].open();
1712 delete MENU_BAR_CONTROL.open;
1716 while( data = MenuPrivateDataClass.list.shift() ) data.close();
1718 MenuPrivateDataClass.list = elmBar = layerBox = elmBox = null;
1719 MENU_BAR_CONTROL.kill = kill;
1720 MENU_BAR_CONTROL.kill();
1722 createItem : function( title ){
1723 return new MenuClass( title );
1725 busy : function( _busy ){
1728 onWindowResize: function( _windowW, _windowH ){
1739 /* ----------------------------------------
1743 var HISTORY_CONTROL = ( function() {
1751 * currentを控えてstackForward.push(current)
1752 * stackBack.pop()を実行してcurrentに
1754 if( stackBack.length === 0 ) return;
1756 var s = stackBack.pop();
1757 s.callback.apply( s.thisObj || {}, s.argBack );
1758 menubarBack.visible( stackBack.length !== 0 );
1759 SAVE_CONTROL.panelUpdated( stackBack.length !== 0 );
1761 stackForward.push( s );
1762 menubarForward.visible( true );
1765 if( stackForward.length === 0 ) return;
1767 var s = stackForward.pop();
1768 s.callback.apply( s.thisObj || {}, s.argForword );
1769 menubarForward.visible( stackForward.length !== 0 );
1771 stackBack.push( s );
1772 menubarBack.visible( true );
1773 SAVE_CONTROL.panelUpdated( true );
1775 var RecordClass = function( callback, argBack, argForword, destroy, opt_thisObject ){
1776 this.callback = callback;
1777 this.argBack = argBack;
1778 this.argForword = argForword;
1779 this.destroy = !!destroy;
1780 this.thisObj = opt_thisObject;
1782 RecordClass.prototype.kill = function( _callDestroy ){
1783 var _argBack = this.argBack,
1784 _argForword = this.argForword,
1789 if( _callDestroy !== true ) return;
1791 if( Type.isArray( _argBack ) === true ){ // isArray
1792 while( v = _argBack.shift() ){
1793 _callDestroy === true && Type.isFunction( v.destroy ) === true && v.destroy();
1796 if( Type.isArray( _argForword ) === true ){
1797 while( v = _argForword.shift() ){
1798 _callDestroy === true && Type.isFunction( v.destroy ) === true && v.destroy();
1804 app.addKeyEventListener( 'keydown', back, 90, false, true ); // ctrl + Z
1805 app.addKeyEventListener( 'keydown', forward, 90, true, true ); // ctrl + shift + Z
1806 app.addKeyEventListener( 'keydown', forward, 89, false, true ); // ctrl + Y
1808 delete HISTORY_CONTROL.init;
1811 menubarBack = MENU_BAR_CONTROL.EDIT.createOption( 'back', 'ctrl + z', back, false );
1812 menubarForward = MENU_BAR_CONTROL.EDIT.createOption( 'forward', 'ctrl + y', forward, false, false, true );
1814 delete HISTORY_CONTROL.open;
1818 while( s = stackBack.shift() ) s.kill( true );
1819 while( s = stackForward.shift() ) s.kill( true );
1820 menubarBack = menubarForward = stackBack = stackForward = null;
1822 saveState: function( _function, _argBack, _argForword, _onRecordDestroy, opt_thisObject ){
1823 stackBack.push( new RecordClass( _function, _argBack, _argForword, _onRecordDestroy, opt_thisObject ));
1824 menubarBack.visible( true );
1825 SAVE_CONTROL.panelUpdated( true );
1828 while( s = stackForward.shift() ) s.kill( s.destroy );
1829 menubarForward.visible( false );
1834 /* ----------------------------------------
1838 var SAVE_CONTROL = ( function(){
1839 var save, saveQuit, eXport, quit,
1846 PanelConsole.boot( Model.createPanel( {
1849 panelTimming : panelTimming,
1850 panelW : PANEL_CONTROL.w,
1851 panelH : PANEL_CONTROL.h,
1853 panelElementArray : PANEL_ELEMENT_ARRAY,
1857 function onSaveQuit(){
1858 // Editor.shutdown();
1861 function onExport(){
1863 comicID, panelID, panelTimming,
1864 PANEL_CONTROL.w, PANEL_CONTROL.h,
1865 2, // border, BackgroundImage
1871 delete SAVE_CONTROL.init;
1874 save = MENU_BAR_CONTROL.QUIT.createOption( 'save', 'ctrl + S', onSave, false );
1875 saveQuit = MENU_BAR_CONTROL.QUIT.createOption( 'save & quit', null, onSaveQuit, false, false, true );
1876 eXport = MENU_BAR_CONTROL.QUIT.createOption( 'export', null, onExport, true, false, true );
1877 quit = MENU_BAR_CONTROL.QUIT.createOption( 'quit', null, quit, true, true );
1879 delete SAVE_CONTROL.open;
1882 save = saveQuit = eXport = quit = null;
1883 SAVE_CONTROL.kill = kill;
1884 SAVE_CONTROL.kill();
1887 panelUpdated: function( _updated ){
1888 if( Type.isBoolean( _updated ) === true ){
1889 save.visible( _updated );
1890 saveQuit.visible( _updated );
1901 /* ----------------------------------------
1904 * - mouseEventListener
1906 var WINDOWS_CONTROL = ( function(){
1908 * 表示上手前にあるwindowは、WINDOW_DATA_LISTの先頭にあり、htmlでは後ろにある。
1910 var DEFAULT_MIN_WINDOW_WIDTH = 200,
1911 DEFAULT_MIN_WINDOW_HEIGHT = 200,
1912 WINDOW_DATA_LIST = [],
1913 WINDOW_BODY_BODER_SIZE = 1,
1922 var WindowPrivateData = function(){};
1923 WindowPrivateData.prototype = {
1925 menubarOption : null,
1953 init : function( win, bodyTempleteID, title, x, y, w, h, visible, closeEnabled, resizeEnabled, minWindowW, minWindowH ){
1955 this.bodyTempleteID = bodyTempleteID;
1961 this.visible = visible;
1962 this.closeEnabled = closeEnabled;
1963 this.resizeEnabled = resizeEnabled;
1964 this.minWindowW = minWindowW;
1965 this.minWindowH = minWindowH;
1967 WINDOW_DATA_LIST.push( this );
1969 create : function(){
1970 var win = this.window;
1971 this.elm = win.elm = elmWindowOrigin.cloneNode( true );
1972 this.menubarOption = MENU_BAR_CONTROL.WINDOW.createOption(
1973 ( this.visible !== true ? 'show ' : 'hide ' ) + this.title,
1974 null, this.onMenubarClick,
1983 onMenubarClick : function(){
1984 this.window[ this.visible === true ? 'close' : 'open' ]();
1986 update : function( x, y, w, h ){
1987 var win = this.window, bodyH;
1989 x = x !== undefined ? x : this.x;
1990 y = y !== undefined ? y : this.y;
1991 y = y > MENU_BAR_CONTROL.h ? y : MENU_BAR_CONTROL.h;
1992 w = w !== undefined ? w : this.w;
1993 h = h !== undefined ? h : this.h;
1995 this.nodeWindow.update( x, y, w, h );
1996 this.nodeHead && this.nodeHead.update( 0, 0, w, this.headerH );
1997 console.log( '************ hewader' + this.headerH )
1998 this.nodeBody.update( 0, this.headerH, w, this.bodyH = h - this.headerH - this.footerH );
1999 ( this.w !== w || this.h !== h ) && win.onResize && win.onResize( w, this.bodyH );
2006 firstOpen : function(){
2007 var win = this.window,
2008 elmHead = this.elmHead = Util.getElementsByClassName( this.elm, 'window-header' )[ 0 ],
2009 elmBody = this.elmBody = Util.getElementsByClassName( this.elm, 'window-body' )[ 0 ],
2010 elmClose = Util.getElementsByClassName( this.elm, 'window-close-button' )[ 0 ],
2011 elmFoot = Util.getElementsByClassName( this.elm, 'window-footer' )[ 0 ],
2012 elmResize = Util.getElementsByClassName( this.elm, 'window-resize-button' )[ 0 ],
2013 replaceID = this.bodyTempleteID;
2015 this.nodeWindow = nodeContainer.createNode( this.elm, false, true, 'window-wrapper-hover' );
2016 this.nodeWindow.addEventListener( 'mousemove', this.mousemove, this );
2017 this.nodeWindow.addEventListener( 'mousedown', this.mousedown, this );
2018 this.nodeWindow.addEventListener( 'mouseup', this.mouseup, this );
2019 this.nodeWindow.addEventListener( 'mouseout', this.mouseup, this );
2021 // this.nodeHead = this.nodeWindow.createNode( elmHead );
2022 win.title( this.title );
2024 this.nodeBody = this.nodeWindow.createNode( elmBody, false, true, null, '', true );
2025 replaceID && elmBody.appendChild( document.getElementById( replaceID ) );
2027 if( this.closeEnabled === true ){
2028 // this.nodeClose = this.nodeHead.createNode( elmClose );
2029 // this.nodeClose.addEventListener( 'mousedown', win.close, data );
2031 elmClose.parentNode.removeChild( elmClose );
2034 if( this.resizeEnabled === true ){
2035 // this.nodeFoot = this.nodeWindow.createNode( elmFoot );
2036 this.footerH = Util.getElementSize( elmFoot ).height; // this.nodeFoot.height();
2038 // this.nodeResize = this.nodeFoot.createNode( elmResize );
2039 // this.nodeResize.addEventListener( 'mousedrag', this.resizeDrag, data );
2041 elmFoot.parentNode.removeChild( elmFoot );
2044 this.update( this.x, this.y, this.w, this.h );
2045 if( win.onFirstOpen ){
2046 win.onFirstOpen( this.w, this.bodyH, this.nodeBody );
2047 delete win.onFirtOpen;
2050 this.firstOpen = null;
2052 onFadeIn : function(){
2053 var data = WindowPrivateData.get( this ),
2055 data.firstOpen && data.firstOpen();
2056 win.onOpen && win.onOpen( data.w, data.bodyH );
2057 data.nodeWindow.disabled( false );
2060 onFadeOut : function(){
2061 var data = WindowPrivateData.get( this ),
2063 elmRoot.removeChild( data.elm );
2064 win.onClose && app.addAsyncCall( win.onClose, null, win );
2066 mousedown : function( e ){
2067 currentWindowData !== this && this.goFront();
2071 if( this.resizeEnabled === true && this.w - 20 <= x && x < this.w && this.headerH + this.bodyH < y && y <= this.h ){
2072 this.isResizing = true;
2073 //this.startX = this.x;
2074 //this.startY = this.y;
2075 this.startW = this.w;
2076 this.startH = this.h;
2079 // app.updateCoursor( 'nw-resize' );
2080 this.nodeWindow.cursor( 'nw-resize' );
2084 // if( x < 0 || y < 0 || this.w < x || this.headerH < y ) return false;
2085 if( this.closeEnabled === true && this.w - closeButtonWidth < x && y < this.headerH ){
2086 this.window.close();
2090 if( y < this.headerH ){
2091 this.isDragging = true;
2092 this.startX = this.x;
2093 this.startY = this.y;
2094 this.startW = this.w;
2095 this.startH = this.h;
2099 // app.updateCoursor( 'move' );
2100 this.nodeWindow.cursor( 'move' );
2104 mouseup : function( e ){
2105 if( this.isResizing === true || this.isDragging === true ){
2106 this.isDragging = this.isResizing = false;
2109 this.nodeWindow.cursor( '' );
2111 mousemove : function( e ){
2112 currentWindowData !== this && this.goFront();
2117 if( this.isResizing === true ){
2118 w = this.startW + x - this.offsetX;
2119 h = this.startH + y - this.offsetY;
2120 this.w = w = w < this.minWindowW ? this.minWindowW : w;
2121 this.h = h = h < this.minWindowH ? this.minWindowH : h;
2122 this.elm.style.width = w + 'px';
2123 this.elm.style.height = h + 'px';
2126 if( this.isDragging === true ){
2127 this.x = x = this.startX + x - this.offsetX;
2128 this.y = y = this.startY + y - this.offsetY;
2129 this.elm.style.left = x + 'px';
2130 this.elm.style.top = y + 'px';
2133 // if( e.hit === false || ( this.headerH < layerY && layerY < this.headerH + this.bodyH ) ) return false;
2134 this.nodeWindow.cursor( ( /*0 < layerX && layerX < this.w && 0 <= layerY &&*/ y <= this.headerH ) ? 'pointer' : '' );
2136 goFront : function(){
2137 currentWindowData = this;
2138 var i = nodeContainer.numNode() - 1;
2139 // console.log( this.nodeWindow.nodeIndex() + ' , ' + this.nodeWindow.numNode() )
2140 if( this.nodeWindow.nodeIndex() !== i ){
2141 this.nodeWindow.nodeIndex( i );
2142 elmRoot.appendChild( this.elm );
2146 return this.isDragging === true || this.isResizing === true;
2148 destroy : function(){
2152 WindowPrivateData.get = function( windowOrElement ){
2153 if( windowOrElement instanceof WindowPrivateData ) return windowOrElement;
2154 var list = WINDOW_DATA_LIST,
2159 if( data.window === windowOrElement || data.elm === windowOrElement ) return data;
2167 var WindowClass = function( bodyTempleteID, title, x, y, w, h, visible, closeEnabled, resizeEnabled, minWindowW, minWindowH ){
2168 ( new WindowPrivateData() ).init( this, bodyTempleteID, title, x, y, w, h, visible, closeEnabled, resizeEnabled, minWindowW, minWindowH );
2170 WindowClass.prototype = {
2173 var data = WindowPrivateData.get( this );
2174 if( data.visible === true ) return;
2176 data.visible = true;
2178 data.menubarOption.title( 'hide ' + data.title );
2180 // WINDOW_DATA_LIST.splice( Util.getIndex( WINDOW_DATA_LIST, data ), 1 );
2181 // WINDOW_DATA_LIST.unshift( data );
2182 currentWindowData = null;
2185 var data = WindowPrivateData.get( this );
2186 if( data.visible === false ) return;
2188 data.visible = false;
2189 $( data.elm ).fadeOut( data.onFadeOut );
2190 data.menubarOption.title( 'show ' + data.title );
2191 data.nodeWindow.disabled( true );
2193 title : function( _title ){
2194 if( Type.isString( _title ) === true ){
2195 var data = WindowPrivateData.get( this );
2196 data.elmHead.firstChild.innerHTML = data.title = _title;
2197 // data.nodeHead.mesure();
2198 //data.headerH = data.nodeHead.height();
2199 data.headerH = Util.getElementSize( data.elmHead ).height;
2203 createHeaderItem : function(){
2204 var data = WindowPrivateData.get( this ),
2205 elm = document.createElement( 'div' ),
2207 if( !data.nodeHead ) data.nodeHead = data.nodeWindow.createNode( data.elmHead, true, false );
2208 data.elmHead.appendChild( elm );
2209 elm.className = 'header-item finder-path';
2210 node = data.nodeHead.createNode( elm, false, true, 'header-item-hover', '' )
2211 // data.nodeHead.mesure();
2212 // data.headerH = data.nodeHead.height();
2214 data.headerH = Util.getElementSize( data.elmHead ).height;
2221 function openWindow( data ){
2222 if( data.visible !== true ) return;
2223 elmRoot.appendChild( data.elm );// appendした後に fadeIn() しないと ie で filterが適用されない.
2224 $( data.elm ).fadeIn( data.onFadeIn );
2229 id : 'WINDOWS_CONTROL',
2231 elmRoot = document.getElementById( 'window-container' );
2232 nodeContainer = eventRoot.createNode( elmRoot, true, false );
2233 elmWindowOrigin = app.fetchHTMLElement( 'windowTemplete' );
2234 closeButtonWidth = Util.getElementSize( Util.getElementsByClassName( elmWindowOrigin, 'window-close-button' )[ 0 ] ).width;
2236 delete WINDOWS_CONTROL.init;
2239 for( var i = WINDOW_DATA_LIST.length, data; i; ){
2240 data = WINDOW_DATA_LIST[ --i ];
2244 delete WINDOWS_CONTROL.open;
2248 onWindowResize : function( _windowW, _windowH ){
2253 createWindow : function( EXTENDS, bodyTempleteID, title, x, y, w, h, opt_visible, opt_closeEnabled, opt_resizeEnabled, opt_minWindowW, opt_minWindowH ){
2254 opt_visible = opt_visible !== false;
2255 opt_closeEnabled = opt_closeEnabled === true;
2256 opt_resizeEnabled = opt_resizeEnabled === true;
2257 opt_minWindowW = opt_minWindowW || ( w < DEFAULT_MIN_WINDOW_WIDTH ) ? w : DEFAULT_MIN_WINDOW_WIDTH;
2258 opt_minWindowH = opt_minWindowH || ( h < DEFAULT_MIN_WINDOW_HEIGHT ) ? h : DEFAULT_MIN_WINDOW_HEIGHT;
2260 var win = new WindowClass( bodyTempleteID, title, x, y, w, h, opt_visible, opt_closeEnabled, opt_resizeEnabled, opt_minWindowW, opt_minWindowH ),
2262 for( var key in EXTENDS ){
2263 win[ key ] = EXTENDS[ key ];
2265 if( Type.isUndefined( WINDOWS_CONTROL.init ) === true ){
2266 data = WindowPrivateData.get( win );
2275 /* ----------------------------------------
2279 var TOOL_BOX_WINDOW = ( function(){
2281 app.addKeyEventListener( 'keydown', addImage, 73, false, true );
2282 app.addKeyEventListener( 'keydown', addText, 84, false, true );
2283 app.addKeyEventListener( 'keydown', switchGrid, 71, false, true );
2285 function addImage(){
2286 // IMAGE_EXPLORER_WINDOW.open();
2287 app.addAsyncCall( IMAGE_EXPLORER_WINDOW.open, null, IMAGE_EXPLORER_WINDOW );
2288 //TOOL_BOX_WINDOW.bodyBackOrForward( true );
2291 app.addAsyncCall( PANEL_ELEMENT_CONTROL.createTextElement );
2293 function switchGrid(){
2294 app.addAsyncCall( GRID_CONTROL.update, null, GRID_CONTROL );
2296 function popupHelp(){
2297 //.bodyBackOrForward( true );
2298 app.addAsyncCall( HELP_DOCUMENTS_WINDOW.open, null, HELP_DOCUMENTS_WINDOW );
2300 function editBG( e ){
2301 //TOOL_BOX_WINDOW.bodyBackOrForward( true );
2302 app.addAsyncCall( INFOMATION_WINDOW.open, null, INFOMATION_WINDOW );
2305 return WINDOWS_CONTROL.createWindow(
2308 MENU_BAR_CONTROL.EDIT.createOption( 'Add Image', 'ctrl + I', addImage, true, true, false );
2309 MENU_BAR_CONTROL.EDIT.createOption( 'Add Text', 'ctrl + T', addText, true, false, true );
2310 MENU_BAR_CONTROL.EDIT.createOption( 'show Grid', 'ctrl + G', switchGrid, true, true, true );
2312 onFirstOpen: function( x, y, nodeBody ){
2313 nodeBody.createNode( document.getElementById( 'toolbox-add-image-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', addImage );
2314 nodeBody.createNode( document.getElementById( 'toolbox-add-text-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', addText );
2315 nodeBody.createNode( document.getElementById( 'toolbox-edit-bg-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', editBG );
2316 nodeBody.createNode( document.getElementById( 'toolbox-switch-grid' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', switchGrid );
2317 nodeBody.createNode( document.getElementById( 'toolbox-popup-help-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', popupHelp );
2318 // nodeBody.createNode( document.getElementById( 'toolbox-add-text-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', addText );
2321 'toolbox-window', 'Tool box', 0, 215, 110, 290, true
2326 /* ----------------------------------------
2330 var IMAGE_EXPLORER_WINDOW = ( function(){
2333 function onFileSelect( file ){
2334 // 他の image ファイルも許可する?
2335 if( Driver.isPettanrFileInstance( file ) === true ){
2336 if( file.getType() === FILE_TYPE.RESOURCE_PICTURE ){
2337 PANEL_ELEMENT_CONTROL.onImageSelect( FileAPI.getFileData( file ) );
2342 return WINDOWS_CONTROL.createWindow(
2344 onInit: function(){},
2345 onFirstOpen: function( _w, _h, nodeBody ){
2346 tree = FileAPI.createTree( FILE_DATA_RESOURCE_PICTURES_ROOT );
2347 var _root = tree.getRootFile(),
2348 _myPic = _root.getChildFileAt( 0 ),
2349 _pic = _root.getChildFileAt( 1 );
2350 _myPic.getSeqentialFiles();
2351 _pic.getSeqentialFiles();
2355 finder = app.createFinder(
2360 finder.createPath( IMAGE_EXPLORER_WINDOW.createHeaderItem() );
2362 onOpen: function( _w, _h ){
2363 finder.resize( _w, _h );
2365 onResize: function( _w, _h ){
2366 finder.resize( _w, _h );
2369 null, 'Album', 0, 215, 600, 350, false, true, true, 300, 300
2374 /* ----------------------------------------
2378 var INFOMATION_WINDOW = ( function(){
2379 var backgroundInfomationElm;
2381 return WINDOWS_CONTROL.createWindow(
2383 onFirstOpen: function( _w, _h ){
2384 backgroundInfomationElm = $( '#panel-background-information');
2386 onResize: function( _w, _h ){
2388 update: function( currentElement ){
2392 'infomation-window', 'Infomation', 0, 30, 200, 180, true
2396 /* ----------------------------------------
2400 var HELP_DOCUMENTS_WINDOW = ( function(){
2405 currentPageIndex = 0,
2409 function onAjaxStart( _pageIndex ){
2410 delete asyncOption.callback;
2412 currentPageIndex = _pageIndex || currentPageIndex;
2413 if( onHelpLoad !== null ){
2423 var onHelpLoad = function( _xml ){
2424 var jqXML = $( _xml ),
2425 helpTitle = jqXML.find( 'pages' ).eq( 0 ).attr( 'title' ),
2426 elmRoot = document.createElement( 'div' ),
2427 elmNavi = document.createElement( 'div' ),
2428 elmItemOrigin = document.createElement( 'a' ),
2429 elmPages = document.createElement( 'div' ),
2430 elmPageOrigin = document.createElement( 'div' ),
2431 elmTitleOrigin = document.createElement( 'h2' ),
2433 elmRoot.className = 'multi-page-container clearfix';
2434 elmNavi.className = 'sidenavi';
2435 elmItemOrigin.className = 'sidenavi-item';
2436 elmItemOrigin.href = '#';
2437 elmPages.className = 'page-contents';
2438 elmPageOrigin.className = 'page-content main';
2439 elmPageOrigin.appendChild( elmTitleOrigin);
2441 MENU_BAR_CONTROL.HELP.remove( asyncOption );
2444 jqXML.find( 'page' ).each( function(){
2445 var xmlPage = $( this ),
2446 title = xmlPage.attr( 'title' ),
2447 content = xmlPage.text();
2449 elmItemOrigin.innerHTML = title;
2450 elmNavi.appendChild( elmItemOrigin.cloneNode( true ) );
2452 elmTitleOrigin.innerHTML = title;
2454 elmPage = elmPageOrigin.cloneNode( true );
2455 elmPage.innerHTML = content;
2457 Util.cleanElement( elmPage);
2459 if( elmPage.childNodes.length > 0 ){
2460 elmPage.insertBefore( elmTitleOrigin.cloneNode( true ), elmPage.childNodes[0]);
2462 elmPage.appendChild( elmTitleOrigin.cloneNode( true ));
2464 elmPages.appendChild( elmPage );
2466 MENU_BAR_CONTROL.HELP.createOption( title, null, onSelectionClick, true );
2469 elmRoot.appendChild( elmNavi );
2470 elmRoot.appendChild( elmPages );
2471 jqAjaxContents.removeClass( 'loading' ).append( elmRoot );
2473 jqNaviItems = jqAjaxContents.find( 'a.' + elmItemOrigin.className ).click( onNaviClick );
2474 jqPages = jqAjaxContents.find( '.page-content' );
2475 jqPages.find( 'a' ).click( onInnerLinkClick );
2477 app.addAsyncCall( jumpPage );
2479 function onSelectionClick( _pageIndex ){
2480 HELP_DOCUMENTS_WINDOW.open();
2481 jumpPage( _pageIndex );
2483 function jumpPage( _index ){
2484 if( Type.isNumber( _index ) === true && 0 <= _index && _index < numPage && currentPageIndex !== _index ){
2485 currentPageIndex = _index;
2487 jqNaviItems.removeClass( 'current' ).eq( currentPageIndex ).addClass( 'current' );
2488 jqPages.hide().eq( currentPageIndex ).show();
2490 function onNaviClick( e ){
2492 jumpPage( Util.getChildIndex( this.parentNode, this ) );
2495 function onInnerLinkClick( e ){
2496 var jump = ( this.href || '' ).split( '#jump' ),
2499 jumpPage( '' + parseFloat( n ) === n ? parseFloat( n ) : -1 );
2502 return WINDOWS_CONTROL.createWindow(
2505 asyncOption = MENU_BAR_CONTROL.HELP.createAsyncOption( onAjaxStart );
2506 jqAjaxContents = $( HELP_DOCUMENTS_WINDOW.elm ).find( '.window-body' ).addClass( 'loading' ).css( { overflow: 'auto' } );
2508 onFirstOpen: function( _w, _h ){
2509 jqAjaxContents.css( { height: _h } );
2510 onAjaxStart !== null && onAjaxStart();
2512 onResize: function( _w, _h ){
2513 jqAjaxContents && jqAjaxContents.css( { height: _h } );
2516 null, 'Help', 0, 215, 400, 350, false, true, true, 300, 300
2520 /* ----------------------------------------
2523 * - panelResizeListener
2525 var GRID_CONTROL = ( function(){
2527 urlBG = "url('images/grid.gif')",
2532 elmGrid = document.getElementById( 'grid' );
2533 delete GRID_CONTROL.init;
2536 delete GRID_CONTROL.open;
2541 onPanelResize: function( _panelX, _panelY ){
2542 elmGrid.style.backgroundPosition = [ _panelX % 10, 'px ', _panelY % 10, 'px' ].join( '' );
2543 elmGrid.style.height = windowH +'px';
2545 enabled: function(){
2549 $( elmGrid ).stop().css( {
2552 })[ visible === true ? 'fadeOut' : 'fadeIn' ]();
2556 if( visible === true && urlBG !== null ){
2557 elmGrid.style.backgroundImage = urlBG;
2565 /* ----------------------------------------
2566 * WHITE_GLASS_CONTROL
2567 * - panelResizeListener
2569 var WHITE_GLASS_CONTROL = ( function(){
2570 var styleTop, styleLeft, styleRight, styleBottom;
2574 styleTop = document.getElementById( 'whiteGlass-top' ).style;
2575 styleLeft = document.getElementById( 'whiteGlass-left' ).style;
2576 styleRight = document.getElementById( 'whiteGlass-right' ).style;
2577 styleBottom = document.getElementById( 'whiteGlass-bottom' ).style;
2578 delete WHITE_GLASS_CONTROL.init;
2580 onPanelResize: function( _panelX, _panelY, _panelW, _panelH ){
2583 marginTop = _panelY,
2584 marginBottom = windowH -_h -marginTop,
2586 rightWidth = windowW -_w -marginX;
2588 styleTop.height = ( marginTop < 0 ? 0 : marginTop ) + 'px';
2590 styleLeft.top = marginTop + 'px';
2591 styleLeft.width = ( marginX < 0 ? 0 : marginX ) + 'px';
2592 styleLeft.height = ( _h + marginBottom ) + 'px';
2594 styleRight.top = marginTop + 'px';
2595 styleRight.left = _w +marginX + 'px';
2596 styleRight.width = ( rightWidth < 0 ? 0 : rightWidth ) + 'px';
2597 styleRight.height = ( _h + marginBottom ) + 'px';
2599 styleBottom.top = ( _h +marginTop ) + 'px';
2600 styleBottom.left = marginX + 'px';
2601 styleBottom.width = _w + 'px';
2602 styleBottom.height = ( marginBottom < 0 ? 0 : marginBottom ) + 'px';
2608 /* --------------------------------------------------------------------------------------------
2610 * - mouseEventListener
2612 var PanelResizerClass = function( id, isTop ){
2616 PanelResizerClass.BORDER_SIZE = 2;
2617 PanelResizerClass.HEIGHT = 30;
2618 PanelResizerClass.prototype = {
2623 x : - PanelResizerClass.BORDER_SIZE / 2,
2626 h : PanelResizerClass.HEIGHT,
2636 this.node = PANEL_CONTROL.node.createNode( document.getElementById( this.id ), false, false, 'panel-resizer-hover', 'pointer' );
2637 this.node.addEventListener( 'mousedown', this.mousedown, this );
2638 this.style = document.getElementById( this.id ).style;
2639 this.y = this.isTop === true ? ( -5 - PanelResizerClass.HEIGHT - PanelResizerClass.BORDER_SIZE ) : 0;
2641 mousedown : function( e ){
2643 var x = e.layerX, // - this.panelX,
2644 y = e.layerY; // - this.panelY;
2646 this.startY = this.panelY;
2647 this.startH = this.panelH;
2648 this.isDragging = true;
2649 // app.updateCoursor( 'n-resize' );
2650 this.node.addEventListener( 'mousemove', this.mousemove, this );
2651 this.node.addEventListener( 'mouseup', this.mouseup, this );
2652 this.node.cursor( 'n-resize' );
2655 mousemove : function( e ){
2656 var move = e.layerY - this.offsetY,
2659 if( this.isTop === true ){
2660 if( this.panelH - move < MIN_PANEL_HEIGHT ){
2661 move = this.panelH - MIN_PANEL_HEIGHT;
2663 PANEL_CONTROL.resizeElement( true, this.panelX, this.panelY + move, this.panelW, this.panelH - move );
2665 h = this.startH + move;
2666 if( 0 < h && h < windowH - this.panelY - PanelResizerClass.HEIGHT - 5 - PanelResizerClass.BORDER_SIZE ){
2667 PANEL_CONTROL.resizeElement( false, this.panelX, this.panelY, this.panelW, h < MIN_PANEL_HEIGHT ? MIN_PANEL_HEIGHT : h );
2672 mouseup : function( e ){
2673 if( this.isDragging !== true ) return;
2674 ( this.startY !== this.panelY || this.startH !== this.panelH ) &&
2675 HISTORY_CONTROL.saveState(
2677 [ undefined, this.startY, undefined, this.startH ],
2678 [ undefined, this.panelY, undefined, this.panelH ],
2681 this.isDragging = false;
2682 var move = e.layerY - this.offsetY,
2685 if( this.isTop === true ){
2686 if( this.panelH - move < MIN_PANEL_HEIGHT ){
2687 move = this.panelH - MIN_PANEL_HEIGHT;
2689 PANEL_CONTROL.resize( true, this.panelX, this.panelY + move, this.panelW, this.panelH - move );
2691 h = this.startH + move;
2692 if( 0 < h && h < windowH - this.panelY - PanelResizerClass.HEIGHT - 5 - PanelResizerClass.BORDER_SIZE ){
2693 PANEL_CONTROL.resize( false, this.panelX, this.panelY, this.panelW, h < MIN_PANEL_HEIGHT ? MIN_PANEL_HEIGHT : h );
2696 // app.updateCoursor( '' );
2697 this.node.removeEventListener( 'mousemove', this.mousemove );
2698 this.node.removeEventListener( 'mouseup', this.mouseup );
2699 this.node.cursor( 'pointer' );
2701 restoreState : function( x, y, w, h ){
2702 PANEL_CONTROL.resize( this.isTop, x || this.panelX, y || this.panelY, w || this.panelW, h || this.panelH );
2705 return this.isDragging;
2707 onPanelResize : function( x, y, w, h ){
2710 if( this.panelW !== w ){
2711 this.style.width = ( w + 2 ) + 'px';
2715 this.y = this.isTop === true ? this.y : ( this.panelH + 5 + PanelResizerClass.BORDER_SIZE );
2716 this.w = this.panelW + 2;
2717 this.node.update( undefined, undefined, this.w );
2721 /* ----------------------------------------
2724 * - mouseEventListener
2726 * panel-border の表示と onPanelResize の通知.
2730 var PANEL_CONTROL = ( function(){
2731 var elmPanel, stylePanel,
2733 DEFAULT_PANEL_WIDTH = 400,
2734 DEFAULT_PANEL_HEIGHT = 300,
2736 offsetX, offsetY, startX, startY,
2738 isDraggable = false,
2739 resizerTop = new PanelResizerClass( 'panel-resizer-top', true ),
2740 resizerBottom = new PanelResizerClass( 'panel-resizer-bottom', false );
2742 app.addKeyEventListener( 'keychange', onSpaceUpdate, 32, false, false );
2744 function onSpaceUpdate( e ){
2745 if( e.type === 'keyup' ){
2746 app.isCurrentInteractiveEventListener( null ) === true && app.updateCoursor( '' );
2747 isDraggable = false;
2749 app.isCurrentInteractiveEventListener( null ) === true && app.updateCoursor( 'move' );
2756 id : 'PANEL_CONTROL',
2764 elmPanel = this.elm = document.getElementById( 'panel-tools-container' );
2765 nodePanel = this.node = eventRoot.createNode( elmPanel, true, false );
2768 resizerBottom.init();
2770 stylePanel = elmPanel.style;
2771 delete PANEL_CONTROL.init;
2773 open: function( _panelW, _panelH, _borderSize ){
2774 PANEL_CONTROL.w = Type.isFinite( _panelW ) === true ? _panelW : DEFAULT_PANEL_WIDTH;
2775 PANEL_CONTROL.h = Type.isFinite( _panelH ) === true ? _panelH : DEFAULT_PANEL_HEIGHT;
2776 borderSize = Type.isFinite( _borderSize ) === true ? _borderSize : borderSize;
2778 delete PANEL_CONTROL.open;
2783 resize: function( isResizerTopAction, x, y, w, h ){
2784 PANEL_CONTROL.x = x = x !== undefined ? x : PANEL_CONTROL.x;
2785 PANEL_CONTROL.y = y = y !== undefined ? y : PANEL_CONTROL.y;
2786 PANEL_CONTROL.w = w = w !== undefined ? w : PANEL_CONTROL.w;
2787 PANEL_CONTROL.h = h = h !== undefined ? h : PANEL_CONTROL.h;
2789 nodePanel.update( x - borderSize, y - borderSize, w, h );
2792 resizerTop.onPanelResize( x, y, w, h );
2793 resizerBottom.onPanelResize( x, y, w, h );
2794 GRID_CONTROL.onPanelResize( x, y );
2795 WHITE_GLASS_CONTROL.onPanelResize( x, y, w, h );
2796 PANEL_ELEMENT_CONTROL.onPanelResize( x, y, w, h, isResizerTopAction === true );
2798 resizeElement : function( isResizerTopAction, x, y, w, h ){
2799 stylePanel.cssText = [ 'left:', ( x - borderSize ), 'px;',
2800 'top:', ( y - borderSize ), 'px;',
2802 'height:', h, 'px' ].join( '' );
2803 // PANEL_RESIZER_TOP.onPanelResize( x, y, w, h );
2804 // PANEL_RESIZER_BOTTOM.onPanelResize( x, y, w, h );
2805 GRID_CONTROL.onPanelResize( x, y );
2806 WHITE_GLASS_CONTROL.onPanelResize( x, y, w, h );
2807 PANEL_ELEMENT_CONTROL.onPanelResize( x, y, w, h, isResizerTopAction );
2809 onWindowResize: function( _windowW, _windowH ){
2810 PANEL_CONTROL.x = Math.floor( ( _windowW - PANEL_CONTROL.w ) / 2 );
2811 PANEL_CONTROL.y = Math.floor( ( _windowH - PANEL_CONTROL.h ) / 2 );
2812 PANEL_CONTROL.resize();
2814 mousemove: function( _mouseX, _mouseY ){
2815 if( isDraggable === true && isDragging === true ){
2816 PANEL_CONTROL.resize( false, startX + _mouseX - offsetX, startY + _mouseY - offsetY );
2819 mouseup: function( _mouseX, _mouseY ){
2820 if( isDraggable === true ){
2822 app.updateCoursor( '' );
2825 mousedown: function( _mouseX, _mouseY ){
2826 if( isDraggable === true ){
2829 startX = PANEL_CONTROL.x;
2830 startY = PANEL_CONTROL.y;
2832 app.updateCoursor( 'move' );
2837 return isDragging === true;
2842 /* --------------------------------------------------------------------------------------------
2844 * - panelElementOperator
2846 var TailOperator = ( function(){
2853 DEG_TO_RAD = Math.PI / 180,
2854 RAD_TO_DEG = 1 / DEG_TO_RAD,
2858 balloonW, balloonH, balloonA, radA,
2864 var elm = document.getElementById( 'balloon-tail-mover' );
2865 SIZE = Util.getElementSize( elm ).width;
2866 styleMover = elm.style;
2867 delete TailOperator.init;
2869 update: function ( _w, _h, _a ){
2870 balloonW = _w !== undefined ? _w : balloonW;
2871 balloonH = _h !== undefined ? _h : balloonH;
2872 balloonA = _a !== undefined ? _a : balloonA;
2873 radA = ( balloonA - 90 ) * DEG_TO_RAD;
2874 tailX = FLOOR( ( ( COS( radA ) / 2 + 0.5 ) * ( balloonW + SIZE )) - SIZE / 2 );
2875 tailY = FLOOR( ( ( SIN( radA ) / 2 + 0.5 ) * ( balloonH + SIZE )) - SIZE / 2 );
2876 styleMover.left = tailX + 'px';
2877 styleMover.top = tailY + 'px';
2879 show: function( _currentText ){
2881 * visibilityのほうがいい, display:none だと ie で描画が狂う
2883 styleMover.visibility = '';
2884 currentText = _currentText;
2885 TailOperator.update( _currentText.w, _currentText.h, _currentText.a );
2888 styleMover.visibility = 'hidden';
2891 hitTest: function( _mouseX, _mouseY ){
2892 var _x = tailX -SIZE / 2,
2893 _y = tailY -SIZE / 2,
2894 ret = _x <= _mouseX && _y <= _mouseY && _x + SIZE >= _mouseX && _y + SIZE >= _mouseY;
2895 ret === true && app.updateCoursor( 'move' );
2898 onStart: function( _mouseX, _mouseY ){
2899 if( currentText.type !== PANEL_ELEMENT_TYPE_TEXT ) return false;
2900 if( TailOperator.hitTest( _mouseX, _mouseY ) === true ){
2903 startA = currentText.a;
2908 onDrag: function( _mouseX, _mouseY ){
2909 _mouseX = _mouseX - w / 2;
2910 _mouseY = _mouseY - h / 2; //Balloonの中心を0,0とする座標系に変換
2911 TailOperator.update( w, h,
2913 ATAN( _mouseY / _mouseX ) * RAD_TO_DEG + ( _mouseX > 0 ? 90 : 270 ) :
2914 _mouseY > 0 ? 180 : 0
2916 currentText && currentText.angle( FLOOR( balloonA + 0.5 ) );
2917 CONSOLE_CONTROLER.update( currentText );
2919 onFinish: function(){
2920 startA !== currentText.a && PanelElementOperatorManager.saveStatus( undefined, undefined, w, h, startA );
2921 startA !== currentText.a && PanelElementOperatorManager.resize( undefined, undefined, w, h, currentText.a );
2923 onCancel: function(){
2924 currentText.angle( startA );
2925 PanelElementOperatorManager.resize( undefined, undefined, w, h, startA );
2930 /* --------------------------------------------------------------------------------------------
2932 * - panelElementOperator
2934 var ResizeOperator = ( function(){
2935 var HIT_AREA = MOUSE_HIT_AREA,
2936 POSITION_ARRAY = [],
2939 { cursor: 'n-resize', v: 3 },
2940 { cursor: 'e-resize', h: 2 },
2941 { cursor: 'e-resize', h: 1 },
2942 { cursor: 'n-resize', v: 0 },
2943 { cursor: 'nw-resize', h: 5, v: 6, vh: 7 },
2944 { cursor: 'ne-resize', h: 4, v: 7, vh: 6 },
2945 { cursor: 'ne-resize', h: 7, v: 4, vh: 5 },
2946 { cursor: 'nw-resize', h: 6, v: 5, vh: 4 }
2959 var RESIZE_WORK_ARRAY = [
2960 { x: 0, w: 0, y: 1, h: -1}, //top
2961 { x: 1, w: -1, y: 0, h: 0}, //left
2962 { x: 0, w: 1, y: 0, h: 0}, //right
2963 { x: 0, w: 0, y: 0, h: 1}, //bottom
2964 { x: 1, w: -1, y: 1, h: -1}, //top-left
2965 { x: 0, w: 1, y: 1, h: -1}, //top-right
2966 { x: 1, w: -1, y: 0, h: 1}, //bottom-left
2967 { x: 0, w: 1, y: 0, h: 1} //bottom-right
2969 startX, startY, startW, startH,
2970 flipV, flipH, startFilpV, startFilpH, startAspect,
2971 baseX, baseY, baseW, baseH,
2972 currentX, currentY, currentW, currentH,
2976 function update( _x, _y, _w, _h ){
2978 _x = _x !== undefined ? _x : currentX;
2979 _y = _y !== undefined ? _y : currentY;
2980 _w = _w !== undefined ? _w : currentW;
2981 _h = _h !== undefined ? _h : currentH;
2983 if( isSpeach === false && currentIndex > 3 && app.shiftEnabled() === true ){
2984 if( startAspect >= 1 ){
2986 _w = FLOOR( startAspect * _h );
2987 _x = _x + ( currentIndex % 2 === 0 ? __w - _w : 0 );
2990 _h = FLOOR( _w / startAspect );
2991 _y = _y + ( currentIndex <= 5 ? __h - _h : 0 );
2994 ResizeOperator.update( x = _x, y = _y, w = _w, h = _h );
2995 currentElement.resize( _x, _y, _w, _h );
2996 isSpeach === true && TailOperator.update( _w, _h );
2997 CONSOLE_CONTROLER.show( currentElement, _w, _h );
2998 // CONSOLE_CONTROLER.update( currentElement );
3001 function flip( _flipH, _flipV ){
3002 var p = CURSOR_AND_FLIP[ currentIndex ];
3003 currentIndex = _flipH === true || _flipV === true ? p[
3004 _flipH === true && _flipV === true ? 'vh' : ( _flipH === true ? 'h' : 'v' )
3006 app.updateCoursor( CURSOR_AND_FLIP[ currentIndex ].cursor );
3007 elmInner.className = 'current-resizer-is-' + currentIndex;
3008 currentElement.flip( _flipH, _flipV );
3012 elmInner = document.getElementById( 'comic-element-resizer-container-inner' );
3013 styleInner = elmInner.style;
3015 styleResizerTop = document.getElementById( 'comic-element-resizer-top' ).style;
3016 styleResizerLeft = document.getElementById( 'comic-element-resizer-left' ).style;
3017 styleResizerRight = document.getElementById( 'comic-element-resizer-right' ).style;
3018 styleResizerBottom = document.getElementById( 'comic-element-resizer-bottom' ).style;
3020 delete ResizeOperator.init;
3022 update: function( _x, _y, _w, _h ){
3023 x = _x = _x !== undefined ? _x : x;
3024 y = _y = _y !== undefined ? _y : y;
3025 w = _w = _w !== undefined ? _w : w;
3026 h = _h = _h !== undefined ? _h : h;
3028 PanelElementOperatorManager.resizeElement( _x, _y, _w, _h );
3030 styleInner.width = _w + 'px';
3031 styleInner.height = _h + 'px';
3033 styleResizerTop.left = styleResizerBottom.left = FLOOR( _w / 2 - 5 ) + 'px';
3034 styleResizerLeft.top = styleResizerRight.top = FLOOR( _h / 2 - 5 ) + 'px';
3036 POSITION_ARRAY.length = 0;
3037 POSITION_ARRAY.push(
3038 {x: 5, y: -HIT_AREA, w: _w - 5, h: HIT_AREA * 2 }, // top
3039 {x: -HIT_AREA, y: 5, w: HIT_AREA * 2, h: _h - 5 }, // left
3040 {x: _w - 5, y: HIT_AREA + 5, w: HIT_AREA * 2, h: _h - 5 }, // right
3041 {x: 5, y: _h - 5, w: _w - 5, h: HIT_AREA * 2 }, // bottom
3042 {x: -HIT_AREA, y: -HIT_AREA, w: HIT_AREA + 5, h: HIT_AREA + 5}, // top left
3043 {x: _w - 5, y: -HIT_AREA, w: HIT_AREA + 5, h: HIT_AREA + 5}, // top right
3044 {x: -HIT_AREA, y: _h - 5, w: HIT_AREA + 5, h: HIT_AREA + 5}, // bottom left
3045 {x: _w - 5, y: _h - 5, w: HIT_AREA + 5, h: HIT_AREA + 5} // bottom right
3048 index: function( _mouseX, _mouseY ){
3050 for( i = 4; i < 8; ++i ){
3051 p = POSITION_ARRAY[ i ];
3052 if( p.x <= _mouseX && p.y <= _mouseY && p.x + p.w >= _mouseX && p.y + p.h >= _mouseY ){
3053 app.updateCoursor( CURSOR_AND_FLIP[ i ].cursor );
3054 elmInner.className = 'current-resizer-is-' + i;
3055 return currentIndex = i;
3058 for( i = 0; i < 4; ++i ){
3059 p = POSITION_ARRAY[ i ];
3060 if( p.x <= _mouseX && _mouseX <= p.x + p.w && p.y <= _mouseY && _mouseY <= p.y + p.h ){
3061 app.updateCoursor( CURSOR_AND_FLIP[ i ].cursor );
3062 elmInner.className = 'current-resizer-is-' + i;
3063 return currentIndex = i;
3066 app.updateCoursor( '' );
3067 elmInner.className = '';
3070 show: function( _currentElement ){
3071 currentElement = _currentElement;
3072 isSpeach = _currentElement.type === PANEL_ELEMENT_TYPE_TEXT;
3073 ResizeOperator.update( _currentElement.x, _currentElement.y, _currentElement.w, _currentElement.h );
3076 currentElement = null;
3078 onStart: function( _mouseX, _mouseY ){
3079 isSpeach = currentElement.type === PANEL_ELEMENT_TYPE_TEXT;
3080 if( currentElement.keepSize === true ) return false;
3081 currentIndex = this.index( _mouseX, _mouseY );
3082 if( currentIndex === -1 ) return false;
3085 startX = baseX = currentElement.x;
3086 startY = baseY = currentElement.y;
3087 startW = baseW = currentElement.w;
3088 startH = baseH = currentElement.h;
3089 startFilpV = currentElement.flipV;
3090 startFilpH = currentElement.flipH;
3091 startAspect = startW / startH;
3094 onDrag: function( _mouseX, _mouseY ){
3095 var com = RESIZE_WORK_ARRAY[ currentIndex ],
3096 moveX = _mouseX - offsetX,
3097 moveY = _mouseY - offsetY,
3098 _updated = moveX !== 0 || moveY !== 0,
3105 * Opera 11+ often forget values, why ??
3107 while( _x === undefined || _y === undefined || _w === undefined || _h === undefined ){
3108 _x = _x !== undefined ? _x : baseX + moveX * com.x;
3109 _y = _y !== undefined ? _y : baseY + moveY * com.y;
3110 _w = _w !== undefined ? _w : baseW + moveX * com.w;
3111 _h = _h !== undefined ? _h : baseH + moveY * com.h;
3112 error += _thisError === 0 ? 0 : 1;
3114 if( _thisError > 9999 ){
3116 //alert( 'opera error' +error);
3122 if( _w >= MIN_ELEMENT_SIZE && _h >= MIN_ELEMENT_SIZE ){
3125 if( _w >= -MIN_ELEMENT_SIZE && _h >= -MIN_ELEMENT_SIZE ){
3127 if( _w < MIN_ELEMENT_SIZE){
3128 //_x += Math.abs( MIN_ELEMENT_SIZE -_w);
3130 _w = MIN_ELEMENT_SIZE;
3132 if( _h < MIN_ELEMENT_SIZE){
3133 //_y += Math.abs( MIN_ELEMENT_SIZE -_h);
3135 _h = MIN_ELEMENT_SIZE;
3138 if( currentElement.type === PANEL_ELEMENT_TYPE_TEXT ){
3141 if( _w < -MIN_ELEMENT_SIZE || _h < -MIN_ELEMENT_SIZE ){
3143 if( _w < -MIN_ELEMENT_SIZE && _h > MIN_ELEMENT_SIZE ){
3146 baseX = _x = _x +_w;
3148 baseW = _w = _memoryX -_x;
3150 flip( true, false );
3151 flipV = currentElement.flipV;
3153 if( _w > MIN_ELEMENT_SIZE && _h < -MIN_ELEMENT_SIZE ){
3157 baseY = _y = _y +_h;
3159 baseH = _h = _memoryY -_y;
3161 flipH = currentElement.flipH;
3166 baseX = _x = _x + _w;
3167 baseY = _y = _y + _h;
3168 baseW = _w = _memoryX - _x;
3169 baseH = _h = _memoryY - _y;
3171 flipV = currentElement.flipV;
3172 flipH = currentElement.flipH;
3182 _updated === true && update( _x, _y, _w, _h );
3185 'currentIndex:', currentIndex,
3186 'baseW', baseW, 'baseH', baseH,'<br>',
3187 'mouse', _mouseX, _mouseY,'<br>',
3188 'move', moveX, moveY,'<br>',
3189 'xy', _x, _y, 'wh',_w, _h,'<br>',
3190 'com.w', com.w, 'com.h', com.h,'<br>',
3191 'current',currentW, currentH,'<br>',
3196 onFinish: function(){
3197 app.updateCoursor( '' );
3198 if( w === startW && h === startH && x === startX && y === startY ) return;
3199 PanelElementOperatorManager.resize( x, y, w, h );
3200 currentElement.resize( x, y, w, h );
3201 PanelElementOperatorManager.saveStatus( startX, startY, startW, startH, undefined, startFilpV, startFilpH );
3203 onCancel: function(){
3204 app.updateCoursor( '' );
3205 PanelElementOperatorManager.resize( startX, startY, startW, startH );
3206 currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
3207 currentElement.animate( startX, startY, startW, startH, startFilpV, startFilpH ) :
3208 currentElement.animate( startX, startY, startW, startH, angle );
3210 onShiftUpdate: update,
3211 onCtrlUpdate: update
3215 /* --------------------------------------------------------------------------------------------
3217 * - panelElementOperator
3219 var PositionOperator = ( function(){
3220 var HIT_AREA = MOUSE_HIT_AREA,
3226 function update( _x, _y ){
3227 x = _x !== undefined ? _x : x;
3228 y = _y !== undefined ? _y : y;
3229 // ResizeOperator.update( x, y );
3231 PanelElementOperatorManager.resizeElement( x, y );
3233 currentElement.resize( x, y );
3234 // CONSOLE_CONTROLER.update( currentElement );
3238 delete PositionOperator.init;
3240 show : function( _currentElement ){
3241 currentElement = _currentElement;
3244 currentElement = null;
3246 onStart: function( _mouseX, _mouseY ){
3249 startX = x = currentElement.x;
3250 startY = y = currentElement.y;
3251 app.updateCoursor( 'move' );
3253 onDrag: function( _mouseX, _mouseY ){
3254 var moveX = _mouseX - offsetX,
3255 moveY = _mouseY - offsetY,
3256 _x = startX + moveX,
3257 _y = startY + moveY;
3258 if( GRID_CONTROL.enabled() === true ){
3259 _x = Math.floor( _x / 10 ) * 10;
3260 _y = Math.floor( _y / 10 ) * 10;
3264 onFinish: function(){
3265 app.updateCoursor( '' );
3266 if( x === startX && y === startY ) return;
3267 PanelElementOperatorManager.resize( x, y );
3268 currentElement.resize( x, y );
3269 PanelElementOperatorManager.saveStatus( startX, startY );
3271 onCancel: function(){
3272 app.updateCoursor( '' );
3273 PanelElementOperatorManager.resize( startX, startY );
3274 currentElement.animate( startX, startY );
3276 onShiftUpdate: update,
3277 onCtrlUpdate: update
3282 /* --------------------------------------------------------------------------------------------
3283 * PanelElementOperatorManager
3285 var PanelElementOperatorManager = ( function(){
3286 var HIT_AREA = MOUSE_HIT_AREA,
3288 currentOperator = null,
3289 currentElement = null,
3291 styleContainer = null,
3292 currentX, currentY, currentW, currentH, angle, flipV, flipH;
3294 function mousedown( e ){
3295 var x = e.layerX - HIT_AREA / 2 - 5,
3296 y = e.layerY - HIT_AREA / 2 - 5;
3297 if( isSpeach === true && TailOperator.onStart( x, y ) === true ){
3298 currentOperator = TailOperator;
3300 if( ResizeOperator.onStart( x, y ) === true ){
3301 currentOperator = ResizeOperator;
3303 PositionOperator.onStart( x, y );
3304 currentOperator = PositionOperator;
3308 function mousemove( e ){
3309 var x = e.layerX - HIT_AREA / 2 - 5,
3310 y = e.layerY - HIT_AREA / 2 - 5;
3311 if( currentOperator !== null ){
3312 currentOperator.onDrag( x, y );
3315 if( currentElement !== null ){
3316 ( isSpeach === false || TailOperator.hitTest( x, y ) === false ) && ResizeOperator.index( x, y );
3319 function mouseup( e ){
3320 currentOperator !== null && currentOperator.onFinish();
3321 currentOperator = null;
3328 TailOperator.init();
3329 ResizeOperator.init();
3330 PositionOperator.init();
3331 CONSOLE_CONTROLER.init();
3333 app.addKeyEventListener( 'keychange', function( e ){
3334 currentOperator !== null && currentOperator.onShiftUpdate && currentOperator.onShiftUpdate();
3337 app.addKeyEventListener( 'keychange', function( e ){
3338 currentOperator !== null && currentOperator.onCtrlUpdate && currentOperator.onCtrlUpdate();
3341 app.addKeyEventListener( 'keydown', function( e ){
3342 currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel();
3343 currentOperator = null;
3345 }, 27, false, false );
3347 delete PanelElementOperatorManager.init;
3350 var elm = document.getElementById( 'comic-element-resizer-container' );
3351 PanelElementOperatorManager.elm = elm;
3352 PanelElementOperatorManager.node = eventRoot.createNode( elm, false, false );
3353 PanelElementOperatorManager.node.addEventListener( 'mouseout', PanelElementOperatorManager.hide, PanelElementOperatorManager );
3354 styleContainer = elm.style;
3355 PanelElementOperatorManager.node.disabled( true );
3356 PanelElementOperatorManager.node.addEventListener( 'mousemove', mousemove );
3357 PanelElementOperatorManager.node.addEventListener( 'mousedown', mousedown );
3358 PanelElementOperatorManager.node.addEventListener( 'mouseup', mouseup );
3360 CONSOLE_CONTROLER.open();
3361 PanelElementOperatorManager.hide();
3363 delete PanelElementOperatorManager.open;
3368 show : function( _currentElement ){
3369 if( currentElement === null ){
3370 styleContainer.display = '';
3371 PanelElementOperatorManager.node.disabled( false );
3373 if( currentElement !== _currentElement ){
3374 currentElement = _currentElement;
3376 ResizeOperator.show( _currentElement );
3377 PositionOperator.show( _currentElement );
3379 isSpeach = ( _currentElement.type === PANEL_ELEMENT_TYPE_TEXT );
3380 isSpeach === true ? TailOperator.show( _currentElement ) : TailOperator.hide();
3382 flipV = _currentElement.flipV;
3383 flipH = _currentElement.flipH;
3385 PanelElementOperatorManager.resize(
3386 _currentElement.x, _currentElement.y, _currentElement.w, _currentElement.h,
3387 isSpeach === true ? _currentElement.a : 0
3392 if( currentElement !== null ){
3393 styleContainer.display = 'none';
3394 PanelElementOperatorManager.node.disabled( true );
3396 currentElement = null;
3397 app.updateCoursor( '' );
3398 TailOperator.hide();
3399 ResizeOperator.hide();
3400 PositionOperator.hide();
3401 CONSOLE_CONTROLER.hide();
3403 resizeElement : function( _x, _y, _w, _h, _angle ){
3404 _x = _x !== undefined ? _x : currentX;
3405 _y = _y !== undefined ? _y : currentY;
3406 _w = _w !== undefined ? _w : currentW;
3407 _h = _h !== undefined ? _h : currentH;
3409 var style = PanelElementOperatorManager.elm.style;
3410 style.left = ( PANEL_CONTROL.x + _x - HIT_AREA / 2 - 5 ) + 'px';
3411 style.top = ( PANEL_CONTROL.y + _y - HIT_AREA / 2 - 5 ) + 'px';
3412 style.width = ( _w + HIT_AREA + 5 ) + 'px';
3413 style.heught = ( _h + HIT_AREA + 5 ) + 'px';
3415 // ResizeOperator.update( _x, _y, _w, _h );
3416 isSpeach === true && TailOperator.update( _w, _h, angle );
3417 CONSOLE_CONTROLER.show( currentElement, _w, _h );
3419 resize: function( _x, _y, _w, _h, _angle ){
3420 currentX = _x = _x !== undefined ? _x : currentX;
3421 currentY = _y = _y !== undefined ? _y : currentY;
3422 currentW = _w = _w !== undefined ? _w : currentW;
3423 currentH = _h = _h !== undefined ? _h : currentH;
3424 angle = _angle = _angle !== undefined ? _angle : angle;
3426 // ResizeOperator.update( _x, _y, _w, _h );
3427 isSpeach === true && TailOperator.update( _w, _h, angle );
3428 CONSOLE_CONTROLER.show( currentElement, _w, _h );
3429 //CONSOLE_CONTROLER.update( currentElement );
3430 PanelElementOperatorManager.node.update( PANEL_CONTROL.x + _x - HIT_AREA / 2 - 5, PANEL_CONTROL.y + _y - HIT_AREA / 2 - 5, _w + HIT_AREA + 5, _h + HIT_AREA + 5 );
3433 restoreState: function( _currentElement, _x, _y, _w, _h, _a, _flipV, _flipH ){
3434 if( arguments.length !== 8 ) return;
3435 if( !_currentElement && !currentOperator ) return;
3436 _currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
3437 _currentElement.animate( _x, _y, _w, _h, _flipV, _flipH ) :
3438 _currentElement.animate( _x, _y, _w, _h, _a );
3439 currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel();
3440 currentOperator = null;
3441 currentElement === _currentElement ? PanelElementOperatorManager.resize( _x, _y, _w, _h, _a ) : PanelElementOperatorManager.show( _currentElement );
3443 saveStatus: function( startX, startY, startW, startH, startA, startFilpV, startFilpH ){
3444 startX = startX !== undefined ? startX : currentX;
3445 startY = startY !== undefined ? startY : currentY;
3446 startW = startW !== undefined ? startW : currentW;
3447 startH = startH !== undefined ? startH : currentH;
3448 startA = startA !== undefined ? startA : angle;
3449 startFilpV = startFilpV !== undefined ? startFilpV : flipV;
3450 startFilpH = startFilpH !== undefined ? startFilpH : flipH;
3451 currentElement && HISTORY_CONTROL.saveState( PanelElementOperatorManager.restoreState,
3452 [ currentElement, startX, startY, startW, startH, startA, startFilpV, startFilpH ],
3453 [ currentElement, currentX, currentY, currentW, currentH, angle, flipV, flipH ]
3459 * // PanelElementOperatorManager
3462 /* --------------------------------------------------------------------------------------------
3465 var CONSOLE_CONTROLER = ( function(){
3466 var LAYER_BACK_BUTTON, LAYER_FORWARD_BUTTON, DELETE_BUTTON, EDIT_BUTTON, CHANGE_BUTTON,
3467 PUSH_OUT_RATIO = 0.5,
3469 elmRoot, elmContainer, elmPushout, elmTail,
3474 currentElement = null,
3477 ui, inputX, inputY, inputZ, inputA, inputW, inputH, inputPercentW, inputPercentH, inputAspectRatio,
3478 buttonBack, buttonForward, buttonDel, buttonEdit, butonChange;
3480 function layerBack(){
3481 if( currentElement === null ) return;
3482 if( PANEL_ELEMENT_CONTROL.replace( currentElement, false ) === false ) return;
3483 CONSOLE_CONTROLER.update( currentElement );
3484 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.replace, [ currentElement, true ], [ currentElement, false ] );
3485 var _z = currentElement.z;
3486 LAYER_BACK_BUTTON.visible( _z > 0 );
3487 LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length - 1 );
3489 function layerForward(){
3490 if( currentElement === null ) return;
3491 if( PANEL_ELEMENT_CONTROL.replace( currentElement, true ) === false ) return;
3492 CONSOLE_CONTROLER.update( currentElement );
3493 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.replace, [ currentElement, false ], [ currentElement, true ] );
3494 var _z = currentElement.z;
3495 LAYER_BACK_BUTTON.visible( _z > 0 );
3496 LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length - 1 );
3499 if( currentElement === null ) return;
3500 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ true, currentElement ], [ false, currentElement ], false ); // true
3501 PANEL_ELEMENT_CONTROL.remove( currentElement );
3502 PanelElementOperatorManager.hide();
3505 if( currentElement === null || currentElement.type !== PANEL_ELEMENT_TYPE_TEXT ) return;
3506 TextEditor.boot( PANEL_CONTROL.x, PANEL_CONTROL.y, currentElement );
3509 if( currentElement === null ) return;
3510 PremiumSatge.boot( currentElement.artistID, currentElement.realPicture, currentElement );
3519 app.addKeyEventListener( 'keydown', layerBack, 66, false, true );
3520 app.addKeyEventListener( 'keydown', layerForward, 70, false, true );
3521 app.addKeyEventListener( 'keydown', del, 68, false, true );
3522 app.addKeyEventListener( 'keydown', edit, 69, false, true );
3523 app.addKeyEventListener( 'keydown', change, 85, false, true );
3525 elmContainer = document.getElementById( 'comic-element-consol-container' );
3526 elmRoot = elmContainer.parentNode;
3527 elmPushout = document.getElementById( 'comic-element-consol-pushout-wrapper' );
3528 elmTail = document.getElementById( 'comic-element-consol-pushout-tail' );
3529 delete CONSOLE_CONTROLER.init;
3532 LAYER_BACK_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'layer back', 'ctrl + B', layerBack, false, true, false );
3533 LAYER_FORWARD_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'layer forward', 'ctrl + F', layerForward, false, false, false );
3534 DELETE_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'delete', 'ctrl + D', del, false, true, true );
3535 EDIT_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'Edit Text', 'ctrl + E', edit, false, true, false );
3536 CHANGE_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'change', 'ctrl + U', change, false, false, true );
3537 // inputAspectRatio = $( '#comic-element-keep-aspect' );
3539 delete CONSOLE_CONTROLER.open;
3541 onMouseover : function( e ){
3542 node.mesureChildren();
3545 show: function( _currentElement, w, h ){
3546 if( node === null ){
3547 node = CONSOLE_CONTROLER.node = PanelElementOperatorManager.node.createNode( elmContainer, false, false, 'comic-element-consol-container-hover' );
3548 node.addEventListener( 'mouseover', CONSOLE_CONTROLER.onMouseover, CONSOLE_CONTROLER );
3549 ui = app.createUIGroup( node );
3550 inputX = ui.createInputText( document.getElementById( 'comic-element-x' ), null );
3551 inputY = ui.createInputText( document.getElementById( 'comic-element-y' ), null );
3552 inputZ = ui.createInputText( document.getElementById( 'comic-element-z' ), null );
3553 inputA = ui.createInputText( document.getElementById( 'comic-element-a' ), null );
3554 inputW = ui.createInputText( document.getElementById( 'comic-element-w' ), null );
3555 inputH = ui.createInputText( document.getElementById( 'comic-element-h' ), null );
3556 inputPercentW = ui.createInputText( document.getElementById( 'comic-element-w-percent' ), null );
3557 inputPercentH = ui.createInputText( document.getElementById( 'comic-element-h-percent' ), null );
3558 butonChange = ui.createButton( document.getElementById( 'change-image-button' ), change ),
3559 buttonBack = ui.createButton( document.getElementById( 'layer-back-button' ), layerBack ),
3560 buttonDel = ui.createButton( document.getElementById( 'delete-button' ), del ),
3561 buttonForward = ui.createButton( document.getElementById( 'layer-forward-button' ), layerForward ),
3562 buttonEdit = ui.createButton( document.getElementById( 'edit-text-button' ), edit );
3565 currentElement = _currentElement;
3567 var type = currentElement.type,
3568 z = currentElement.z;
3570 LAYER_BACK_BUTTON.visible( z > 0 );
3571 buttonBack.enabled( z > 0 );
3572 LAYER_FORWARD_BUTTON.visible( z < PANEL_ELEMENT_ARRAY.length - 1 );
3573 buttonForward.enabled( z < PANEL_ELEMENT_ARRAY.length - 1 )
3574 DELETE_BUTTON.visible( true );
3575 EDIT_BUTTON.visible( type === PANEL_ELEMENT_TYPE_TEXT );
3576 CHANGE_BUTTON.visible( false );
3578 //CONSOLE_CONTROLER.x = Math.floor( ( _w - CONSOLE_CONTROLER.w ) / 2 );
3579 CONSOLE_CONTROLER.w = w;
3580 CONSOLE_CONTROLER.h = elmContainer.offsetHeight;
3581 CONSOLE_CONTROLER.y = h - CONSOLE_CONTROLER.h;
3583 if( h * PUSH_OUT_RATIO < CONSOLE_CONTROLER.h ){
3584 if( pushout === false ){
3586 elmPushout.lastChild.appendChild( elmContainer );
3587 elmPushout.style.display = 'block';
3588 pushoutW = elmPushout.offsetWidth;
3589 pushoutH = elmPushout.offsetHeight;
3590 elmTail.style.top = ( pushoutH / 2 - tailSize / 2 ) + 'px';
3592 elmPushout.style.left = ( -pushoutW ) + 'px';
3593 elmPushout.style.top = ( h / 2 - pushoutH / 2 ) + 'px';
3594 elmPushout.className = 'satellite-left';
3596 if( pushout === true ){
3598 elmRoot.insertBefore( elmContainer, elmRoot.firstChild );
3599 elmPushout.style.cssText = '';
3602 CONSOLE_CONTROLER.update( currentElement );
3606 update : function( _currentElement ){
3607 if( _currentElement === null ){
3611 currentElement = _currentElement;
3612 var type = currentElement.type,
3613 x = currentElement.x,
3614 y = currentElement.y,
3615 z = currentElement.z,
3616 a = type === PANEL_ELEMENT_TYPE_TEXT ? Math.floor( currentElement.a ) : 0,
3617 w = currentElement.w,
3618 h = currentElement.h,
3619 actualW = type === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualW : 1,
3620 actualH = type === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualH : 1,
3621 wPercent = type === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( w / actualW * 100 ) : 0,
3622 hPercent = type === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( h / actualH * 100 ) : 0,
3623 keepAspect = currentElement.keepAspect;
3625 if( currentType !== type ){
3626 if( type === PANEL_ELEMENT_TYPE_TEXT ){
3627 inputA.visible( true );
3628 inputPercentW.visible( false );
3629 inputPercentH.visible( false );
3630 buttonEdit.enabled( true );
3631 //inputAspectRatio.hide();
3633 inputA.visible( false );
3634 inputPercentW.visible( true );
3635 inputPercentH.visible( true );
3636 buttonEdit.enabled( false );
3637 //inputAspectRatio.show();
3645 type === 1 && inputA.value( a );
3648 type === 0 && inputPercentW.value( wPercent );
3649 type === 0 && inputPercentH.value( hPercent );
3652 // if( visible === true ) styleConsoleWrapper.display = 'none';
3653 ui && ui.visible( false );
3655 currentElement = null;
3656 LAYER_BACK_BUTTON.visible( false );
3657 LAYER_FORWARD_BUTTON.visible( false );
3658 DELETE_BUTTON.visible( false );
3659 EDIT_BUTTON.visible( false );
3660 CHANGE_BUTTON.visible( false );
3667 var AbstractPanelElement = function( COMIC_ELM_TYPE ){
3668 this.type = COMIC_ELM_TYPE;
3670 AbstractPanelElement.prototype = {
3684 shift : function( shiftX, shiftY ){
3685 this.resize( this.x + shiftX, this.y + shiftY );
3687 mouseover : function( e ){
3688 PanelElementOperatorManager.show( this );
3692 /* --------------------------------------------------------------------------------------------
3695 var jqImageElementOrigin;
3696 var ImageElementClass = function( data ){
3697 jqImageElementOrigin = jqImageElementOrigin || $( app.fetchHTMLElement( 'imgElementTemplete' ) );
3699 this.$ = jqImageElementOrigin.clone( true );
3702 this.timing = data.t || PANEL_ELEMENT_ARRAY.length;
3703 this.keepSize = false;
3704 this.flipV = data.height < 0 ? -1 : 1;
3705 this.flipH = data.width < 0 ? -1 : 1;
3706 this.rPicture = data.picture;
3709 function animeComplete(){
3711 self._flipReversibleImage();
3713 this.animeComplete = animeComplete;
3715 ImageElementClass.prototype = Util.extend(
3716 new AbstractPanelElement( PANEL_ELEMENT_TYPE_IMAGE ),
3718 reversibleImage : null,
3720 this._updateResourcePicture( this.rPicture );
3721 this.node = PANEL_ELEMENT_CONTROL.node.createNode( this.$.get( 0 ), false, true );
3722 this.node.addEventListener( 'mouseover', this.mouseover, this );
3723 this.resize( this.data.x, this.data.y, Math.abs( this.data.width ), Math.abs( this.data.height ) );
3726 flip : function( updateH, updateV ){
3727 if( updateH !== true && updateV !== true ) return;
3728 this.flipH = updateH === true ? -this.flipH : this.flipH;
3729 this.flipV = updateV === true ? -this.flipV : this.flipV;
3730 this.reversibleImage.resize( this.flipH * this.w, this.flipV * this.h );
3732 realPicture : function( _rPicture ){
3733 if( _rPicture && _rPicture !== this.rPicture ){
3734 HISTORY_CONTROL.saveState( this._updateResourcePicture, this.rPicture, _rPicture, this );
3735 this._updateResourcePicture( _rPicture );
3737 return this.rPicture;
3739 resize : function( x, y, w, h, animate ){
3740 this.x = x = Type.isFinite( x ) === true ? x : this.x;
3741 this.y = y = Type.isFinite( y ) === true ? y : this.y;
3742 this.w = w = Type.isFinite( w ) === true ? w : this.w;
3743 this.h = h = Type.isFinite( h ) === true ? h : this.h;
3744 if( animate === true ){
3750 }, 250 , this.animeComplete );
3752 this.node.update( x, y, w, h );
3753 this._flipReversibleImage();
3756 animate : function ( x, y, w, h, flipH, flipV ){
3757 this.flipH = flipH !== undefined ? flipH : this.flipH;
3758 this.flipV = flipV !== undefined ? flipV : this.flipV;
3759 this.resize( x, y, w, h, true );
3761 destroy : function(){
3762 this.reversibleImage.destroy();
3763 this.$.stop().remove();
3766 this.destroy = null;
3768 _updateResourcePicture : function( _rPicture ){
3769 this.rPicture = _rPicture;
3770 this.oPicture = this.rPicture.original_picture;
3771 this.artistID = this.oPicture.artist.id || -1;
3773 this.actualW = this.oPicture.width;
3774 this.actualH = this.oPicture.height;
3776 var _reversibleImage = pettanr.image.createReversibleImage(
3777 [ pettanr.CONST.PICTURE_PATH, this.rPicture.id, '.', this.rPicture.ext ].join( '' ),
3778 this.flipH * this.w, this.flipV * this.h
3780 if( this.reversibleImage !== null ){
3781 this.$.children( this.reversibleImage.elm ).replaceWith( _reversibleImage.elm );
3782 this.reversibleImage.destroy();
3784 this.$.append( _reversibleImage.elm );
3786 this.reversibleImage = _reversibleImage;
3788 _flipReversibleImage : function(){
3789 this.reversibleImage && this.reversibleImage.resize( this.flipH * this.w, this.flipV * this.h );
3796 * / ImageElementClass
3797 * --------------------------------------------------------------------------------------------
3801 /* --------------------------------------------------------------------------------------------
3809 * 4.black-box( dq style)
3810 * 5.blue-box( ff style)
3813 var jqTextElementOrigin;
3814 var TextElementClass = function( data ){
3815 jqTextElementOrigin = jqTextElementOrigin || ( function(){
3816 var _OLD_IE = $( app.fetchHTMLElement( 'textElementTempleteForOldIE' ) ),
3817 _MODERN = $( app.fetchHTMLElement( 'textElementTemplete' ) );
3818 return UA.isIE === true && UA.ieRenderingVersion < 8 ? _OLD_IE : _MODERN;
3821 this.$ = jqTextElementOrigin.clone( true );
3823 this.elmText = this.$.find( 'td,.speach-inner' ).get( 0 );
3824 this.type = data.balloon_template_id;
3825 this.content = ( function(){
3826 var _speachs = data.speeches_attributes;
3827 for( var k in _speachs ){
3828 return _speachs[ k ].content || '';
3832 this.balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail, this.type );
3834 this.timing = data.t || PANEL_ELEMENT_ARRAY.length;
3836 this.$.find( 'img' ).eq( 0 ).replaceWith( this.balloon.elm );
3839 function animeComplete(){
3841 self._resizeBalloon();
3843 this.animeComplete = animeComplete;
3845 TextElementClass.prototype = Util.extend(
3846 new AbstractPanelElement( PANEL_ELEMENT_TYPE_TEXT ),
3850 this.node = PANEL_ELEMENT_CONTROL.node.createNode( this.$.get( 0 ), false, true );
3851 this.node.addEventListener( 'mouseover', this.mouseover, this );
3852 this.resize( this.data.x, this.data.y, this.data.width, this.data.height, this.data.tail );
3855 _updateType : function( _type ){
3856 if( this.type !== _type ){
3857 this.type = _type || this.type;
3858 this.balloon.type( this.type );
3861 _updateAngle : function( _a ){
3862 if( _a !== undefined && a !== _a ){
3863 this.a = _a !== undefined ? _a : this.a;
3864 this.balloon.angle( this.a );
3868 _updateText : function( _text ){
3869 this.content = _text || this.content || '';
3870 this.elmText.firstChild.data = this.content;
3872 _resizeBalloon : function(){
3873 this.balloon && this.balloon.resize( this.a, this.w, this.h );
3875 angle : function( _a ){
3876 _a !== undefined && this.resize( this.x, this.y, this.w, this.h, _a );
3879 text : function( _text ){
3880 if( _text && this.content !== _text ){
3881 HISTORY_CONTROL.saveState( this._updateText, this.content || '', _text, this );
3882 this._updateText( _text );
3884 return this.content;
3886 resize : function( x, y, w, h, a, animate ){
3887 this.x = x = x !== undefined ? x : this.x;
3888 this.y = y = y !== undefined ? y : this.y;
3889 this.w = w = w !== undefined ? w : this.w;
3890 this.h = h = h !== undefined ? h : this.h;
3891 this.a = a !== undefined ? a : this.a;
3893 if( animate === true ){
3899 }, 250 , this.animeComplete );
3901 this.node.update( x, y, w, h );
3902 this._resizeBalloon();
3905 animate : function ( _x, _y, _w, _h, _a ){
3906 this.resize( _x, _y, _w, _h, _a, true );
3908 destroy : function(){
3909 this.$.stop().remove();
3910 this.balloon.destroy();
3913 this.destroy = null;
3918 /* --------------------------------------------------------------------------------------------
3919 * PANEL_ELEMENT_CONTROL
3920 * - mouseEventListener
3922 var PANEL_ELEMENT_CONTROL = ( function(){
3923 var elmContainer = null,
3924 currentElement = null,
3926 panelX, panelY, panelW, panelH,
3929 * append, remove, replace
3931 * panelElement には、z-position と dom-index がある。
3932 * z-position は 表示上の位置。大きいほど前に表示される( z-index)
3933 * dom-index は 意味上の順番。htmlタグの登場順で、検索結果や音声読み上げブラウザで正しく意味が取れる順番。
3935 * editerでは、実際には z-index は使わず、htmlの順序で前後を表現する。
3936 * dom-index は、数値のみ保持して、投稿時にpanelElementを適宜に並び替える。
3938 * append panelElement
3939 * 1. 新しい panelElement の z-position を得る
3940 * 2. z の同じ panelElementを見つけ、その前に加える。または一番先頭へ。(PANEL_ELEMENT_ARRAY)
3941 * zが大きいほど、PANEL_ELEMENT_ARRAYの先頭へ。
3942 * 3. dom位置は、PANEL_ELEMENT_ARRAY とは反対に、前のものほど後ろへ。
3945 * remove panelElement
3949 function onFadeOut(){
3950 this.parentNode.removeChild( this );
3953 * PANEL_ELEMENT_ARRAY の順番を基準に、zの再計算
3956 function renumber(){
3957 var _panelElement, jqElm, jqAfter,
3958 i = PANEL_ELEMENT_ARRAY.length;
3960 _panelElement = PANEL_ELEMENT_ARRAY[ --i ];
3961 jqElm = _panelElement.$;
3962 !jqAfter && elmContainer.appendChild( jqElm.get( 0 ) );
3963 jqAfter && jqAfter.before( jqElm );
3965 _panelElement.z = i;
3966 _panelElement.node.nodeIndex( i );
3971 function onTextInput( _panelElement ){
3972 PANEL_ELEMENT_CONTROL.add( _panelElement );
3973 _panelElement.animate( undefined, undefined, _panelElement.w, _panelElement.h );
3974 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ false, _panelElement ], [ true, _panelElement ], true, PANEL_ELEMENT_CONTROL );
3978 id : 'PANEL_ELEMENT_CONTROL',
3981 elmContainer = document.getElementById( 'comic-element-container' );
3982 node = PANEL_ELEMENT_CONTROL.node = eventRoot.createNode( elmContainer, true, false );
3983 node.nodeIndex( 0 );
3984 delete PANEL_ELEMENT_CONTROL.init;
3987 delete PANEL_ELEMENT_CONTROL.open;
3991 while( panelElm = PANEL_ELEMENT_ARRAY.shift() ){
3992 panelElm.destroy && panelElm.destroy();
3995 add : function( _panelElement ){
3996 var z = Type.isFinite( _panelElement.z ) === true ? _panelElement.z : -1,
3997 i = PANEL_ELEMENT_ARRAY.length,
3998 _jqElm = _panelElement.$.stop().css( {
4004 PANEL_ELEMENT_ARRAY.push( _panelElement );
4007 if( PANEL_ELEMENT_ARRAY[ --i ].z < z ){
4013 PANEL_ELEMENT_ARRAY.unshift( _panelElement );
4015 PANEL_ELEMENT_ARRAY.splice( i + 1, 0, _panelElement );
4020 _panelElement.node.disabled( false );
4022 remove : function( _panelElement ){
4023 for( var i = PANEL_ELEMENT_ARRAY.length; i; ){
4024 if( PANEL_ELEMENT_ARRAY[ --i ] === _panelElement ){
4025 console.log( PANEL_ELEMENT_ARRAY.length );
4026 PANEL_ELEMENT_ARRAY.splice( i, 1 );
4027 _panelElement.node.disabled( true );
4028 _panelElement.node.nodeIndex( PANEL_ELEMENT_ARRAY.length );
4030 _panelElement.$.stop().css( {
4033 }).fadeOut( onFadeOut );
4034 if( currentElement === _panelElement ) currentElement = null;
4040 restore : function( isAppend, panelElement ){
4041 PANEL_ELEMENT_CONTROL[ isAppend === true ? 'add' : 'remove' ]( panelElement );
4043 replace: function( _panelElement, goForward ){
4044 // PANEL_ELEMENT_ARRAYの再構築
4045 var l = PANEL_ELEMENT_ARRAY.length,
4049 if( PANEL_ELEMENT_ARRAY[ --j ] === _panelElement ){
4054 if( i !== j ) return false;
4055 if( goForward === true ){
4056 if( i === 0 ) return false;
4057 PANEL_ELEMENT_ARRAY.splice( i, 1 );
4058 PANEL_ELEMENT_ARRAY.splice( i + 1, 0, _panelElement );
4060 if( i === l - 1 ) return false;
4061 PANEL_ELEMENT_ARRAY.splice( i, 1 );
4062 PANEL_ELEMENT_ARRAY.splice( i - 1, 0, _panelElement );
4067 onPanelResize : function ( _panelX, _panelY, _panelW, _panelH, isResizerTopAction ){
4069 * リサイズが、ResizerTopによって行われた場合、panelElementのyを動かして見かけ上動かないようにする。
4071 if( isResizerTopAction === true ){
4072 var _shiftX = _panelW - panelW,
4073 _shiftY = _panelH - panelH;
4074 for( var i = PANEL_ELEMENT_ARRAY.length; i; ){
4075 PANEL_ELEMENT_ARRAY[ --i ].shift( _shiftX, _shiftY );
4078 node.update( panelX = _panelX, panelY = _panelY, panelW = _panelW, panelH = _panelH );
4080 createImageElement: function( data ){
4081 if( Type.isObject( data ) === false ){
4082 PremiumSatge.boot( 1, PANEL_ELEMENT_CONTROL.onImageSelect );
4084 PANEL_ELEMENT_CONTROL.onImageSelect( data, true );
4087 onImageSelect: function( data, isPanelPictureData ){
4089 if( isPanelPictureData !== true ){
4090 _panelElement = new ImageElementClass( {
4091 picture : data.picture,
4092 x : Math.floor( panelW / 2 - data.width / 2 ),
4093 y : Math.floor( panelH / 2 - data.height / 2 ),
4099 _panelElement.init();
4100 PANEL_ELEMENT_CONTROL.add( _panelElement );
4101 _panelElement.animate( undefined, undefined, Math.abs( data.picture.original_picture.width ), Math.abs( data.picture.original_picture.height ) );
4103 _panelElement = new ImageElementClass( data );
4104 _panelElement.init();
4105 PANEL_ELEMENT_CONTROL.add( _panelElement );
4107 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ false, _panelElement ], [ true, _panelElement ], true );
4109 createTextElement: function( data ){
4111 if( Type.isObject( data ) === false ){
4113 balloon_template_id:1,
4116 x: Math.floor( panelW / 2 - 100 + Math.random() * 10 ),
4117 y: Math.floor( panelH / 2 - 100 + Math.random() * 10 ),
4122 speeches_attributes: {
4128 _panelElement = new TextElementClass( data );
4129 _panelElement.init();
4130 TextEditor.boot( PANEL_CONTROL.x, PANEL_CONTROL.y, _panelElement, onTextInput );
4132 _panelElement = new TextElementClass( data );
4133 _panelElement.init();
4134 onTextInput( _panelElement );
4141 * end of PANEL_ELEMENT_CONTROL
4144 function centering(){
4145 app.onPaneResize( windowW, windowH );
4150 this.MIN_WIDTH = 320;
4151 this.MIN_HEIGHT = 320;
4152 this.onInit = function(){
4153 app.rootElement.id = 'editor';
4154 app.rootElement.innerHTML = [
4155 '<div id="grid" style="display:none;"></div>',
4156 '<div id="comic-element-container"></div>',
4157 '<div id="whiteGlass-container">',
4158 '<div id="whiteGlass-top"></div>',
4159 '<div id="whiteGlass-left"></div>',
4160 '<div id="whiteGlass-right"></div>',
4161 '<div id="whiteGlass-bottom"></div>',
4163 '<div id="panel-tools-container">',
4164 '<div id="panel-resizer-top">▲</div>',
4165 '<div id="panel-resizer-bottom">▼</div>',
4167 '<div id="window-container"></div>',
4168 '<div id="comic-element-resizer-container">',
4169 '<div id="comic-element-resizer-container-inner">',
4170 '<div id="comic-element-consol-wrapper">',
4171 '<div id="comic-element-consol-container" class="clearfix">',
4172 '<div class="comic-element-consol-item">',
4173 '<div id="comic-element-x">',
4174 '<span class="comic-element-attribute-label">x:</span>',
4175 '<span id="comic-element-x-value" class="comic-element-attribute-value editable-value">0</span>',
4177 '<div id="comic-element-y">',
4178 '<span class="comic-element-attribute-label">y:</span>',
4179 '<span id="comic-element-y-value" class="comic-element-attribute-value editable-value">0</span>',
4182 '<div class="comic-element-consol-item">',
4183 '<div id="comic-element-z">',
4184 '<span class="comic-element-attribute-label">z:</span>',
4185 '<span id="comic-element-z-value" class="comic-element-attribute-value editable-value">0</span>',
4187 '<div id="comic-element-a">',
4188 '<span id="comic-element-a-value" class="comic-element-attribute-value editable-value">0</span>',
4189 '<span class="comic-element-attribute-label">°</span>',
4192 '<div class="comic-element-consol-item">',
4193 '<div id="comic-element-w">',
4194 '<span class="comic-element-attribute-label">w:</span>',
4195 '<span id="comic-element-w-value" class="comic-element-attribute-value editable-value">0</span>',
4197 '<div id="comic-element-h">',
4198 '<span class="comic-element-attribute-label">h:</span>',
4199 '<span id="comic-element-h-value" class="comic-element-attribute-value editable-value">0</span>',
4202 '<div class="comic-element-consol-item">',
4203 '<!-- <div id="comic-element-keep-aspect"></div> -->',
4204 '<div id="comic-element-w-percent">',
4205 '<span id="comic-element-w-percent-value" class="comic-element-attribute-value editable-value">0</span>',
4206 '<span class="comic-element-attribute-label">%</span>',
4208 '<div class="comic-element-consol-item" id="comic-element-h-percent">',
4209 '<span id="comic-element-h-percent-value" class="comic-element-attribute-value editable-value">0</span>',
4210 '<span class="comic-element-attribute-label">%</span>',
4213 '<div class="comic-element-consol-item-small">',
4214 '<div class="button" id="change-image-button">change</div>',
4216 '<div class="comic-element-consol-item-small">',
4217 '<div class="button" id="layer-back-button">back</div>',
4219 '<div class="comic-element-consol-item-small">',
4220 '<div class="button" id="delete-button">delete</div>',
4222 '<div class="comic-element-consol-item-small">',
4223 '<div class="button" id="layer-forward-button">forward</div>',
4225 '<div class="comic-element-consol-item-small">',
4226 '<div class="button" id="edit-text-button">edit</div>',
4228 '<!-- <div class="comic-element-consol-item-small">',
4229 '<div class="button" id="hide-text-tail-button">tail</div>',
4233 '<div class="comic-element-resizer" id="comic-element-resizer-top"></div>',
4234 '<div class="comic-element-resizer" id="comic-element-resizer-left"></div>',
4235 '<div class="comic-element-resizer" id="comic-element-resizer-right"></div>',
4236 '<div class="comic-element-resizer" id="comic-element-resizer-bottom"></div>',
4237 '<div class="comic-element-resizer" id="comic-element-resizer-top-left"></div>',
4238 '<div class="comic-element-resizer" id="comic-element-resizer-top-right"></div>',
4239 '<div class="comic-element-resizer" id="comic-element-resizer-bottom-left"></div>',
4240 '<div class="comic-element-resizer" id="comic-element-resizer-bottom-right"></div>',
4241 '<div id="comic-element-consol-pushout-wrapper">',
4242 '<div id="comic-element-consol-pushout-tail"></div>',
4243 '<div id="comic-element-consol-pushout-inner"></div>',
4245 '<div id="balloon-tail-mover"></div>',
4248 '<div id="menu-bar"></div>',
4250 '<div id="templete-container" style="display: none;">',
4251 '<div id="imgElementTemplete" class="comic-element-wrapper image-element"></div>',
4253 '<div id="textElementTemplete" class="comic-element-wrapper text-element">',
4255 '<div class="speach">',
4256 '<div class="speach-inner"> </div>',
4260 '<div id="textElementTempleteForOldIE" class="comic-element-wrapper text-element">',
4262 '<div class="speach">',
4263 '<table><tr><td> </td></tr></table>',
4267 '<div id="imageGroupItemTemplete" class="image-group-item">',
4268 '<div class="image-group-item-title">img-title</div>',
4271 '<div id="windowTemplete" class="window-wrapper">',
4272 '<div class="window-header">',
4273 '<div class="window-header-title">window title</div>',
4274 '<div class="window-close-button">x</div>',
4276 '<div class="window-body"></div>',
4277 '<div class="window-footer">',
4278 '<div class="window-resize-button"></div>',
4282 '<div id="infomation-window">',
4283 '<div id="panel-background-information">',
4284 '<div id="bg-pattern"></div>',
4285 '<div id="select-bg-pattern-button">pattern</div>',
4286 '<div id="reset-bg-pattern-button">x</div>',
4287 '<div id="bg-color"></div>',
4288 '<div id="select-bg-color-button">color</div>',
4289 '<div id="reset-bg-color-button">x</div>',
4290 '<!-- <div id="bg-pattern-x"></div>',
4291 '<div id="bg-pattern-y"></div>',
4292 '<div id="bg-pattern-repeat-x"></div>',
4293 '<div id="bg-pattern-repeat-y"></div> -->',
4297 '<div id="toolbox-window">',
4298 '<div id="toolbox-add-image-button" class="button">add image</div>',
4299 '<div id="toolbox-add-text-button" class="button">add text</div>',
4300 '<div id="toolbox-edit-bg-button" class="button">edit bg</div>',
4301 '<div id="toolbox-switch-grid" class="button">grid</div>',
4302 '<div id="toolbox-popup-help-button" class="button">?</div>',
4303 '<div id="toolbox-post-button" class="button">post</div>',
4309 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4310 eventRoot = app.getPointingDeviceEventTreeRoot();
4314 this.onOpen = function( _w, _h, file ){
4315 // 表示奥の物から順に init() していく
4316 PANEL_ELEMENT_CONTROL.init();
4317 PANEL_CONTROL.init();
4318 // PANEL_RESIZER_BOTTOM.init();
4319 // PANEL_RESIZER_TOP.init();
4320 WINDOWS_CONTROL.init();
4321 MENU_BAR_CONTROL.init();
4323 // レイヤーにあまり関係ないモジュール
4324 HISTORY_CONTROL.init();
4325 SAVE_CONTROL.init();
4326 GRID_CONTROL.init();
4327 WHITE_GLASS_CONTROL.init();
4328 PanelElementOperatorManager.init();
4337 fileData, panelElements, panelElm;
4339 if( FileAPI.isFileInstance( file ) === true ){
4340 if( Driver.isPettanrFileInstance( file ) === true ){
4341 if( file.getType() === FILE_TYPE.COMIC ){
4342 fileData = file.read();
4343 panelW = fileData.width;
4344 panelH = fileData.height;
4345 comicID = fileData.id || -1;
4347 if( file.getType() === FILE_TYPE.PANEL ){
4348 fileData = file.read();
4349 panelW = fileData.width;
4350 panelH = fileData.height;
4351 borderSize = fileData.border;
4352 panelElements = fileData.elements;
4353 comicID = fileData.comic ? fileData.comic.id || -1 : -1;
4354 panelID = fileData.id || -1;
4355 panelTimming = fileData.t || -1;
4362 // open() は各モジュールの init() 後に実施可能になる.
4363 HISTORY_CONTROL.open();
4364 SAVE_CONTROL.open();
4365 WINDOWS_CONTROL.open();
4367 GRID_CONTROL.open();
4368 PANEL_CONTROL.open( panelW, panelH, borderSize );
4369 PanelElementOperatorManager.open();
4370 PANEL_ELEMENT_CONTROL.open();
4373 MENU_BAR_CONTROL.open();
4377 app.onPaneResize( _w, _h );
4380 if( Type.isArray( panelElements ) === true ){
4381 for( var i=0; i<panelElements.length; ++i ){
4382 panelElm = panelElements[ i ];
4383 if( panelElm.picture ){
4384 PANEL_ELEMENT_CONTROL.createImageElement( panelElm );
4386 if( panelElm.balloon_template_id ){
4387 PANEL_ELEMENT_CONTROL.createTextElement( panelElm );
4395 app.addKeyEventListener( 'keydown', centering, 96, false, true ); // ctrl + 0
4396 app.addKeyEventListener( 'krydown', centering, 48, false, true ); // ctrl + 0
4397 MENU_BAR_CONTROL.EDIT.createOption( 'centering', 'ctrl + 0', centering, true, true, true);
4403 this.onClose = function(){
4405 HISTORY_CONTROL.close();
4407 WINDOWS_CONTROL.close();
4409 GRID_CONTROL.close();
4410 PANEL_CONTROL.close();
4412 PanelElementOperatorManager.close();
4413 PANEL_ELEMENT_CONTROL.close();
4416 MENU_BAR_CONTROL.close();
4420 this.onPaneResize = function( _windowW, _windowH ){
4421 windowW = _windowW || windowW;
4422 windowH = _windowH || windowH;
4424 app.rootElement.style.height = _windowH + 'px';
4426 WINDOWS_CONTROL.onWindowResize( _windowW, _windowH );
4427 MENU_BAR_CONTROL.onWindowResize( _windowW, _windowH );
4428 PANEL_CONTROL.onWindowResize( _windowW, _windowH );
4430 }, false, true, 'Panel Editor', 'paneleditor', null, '#2D89F0' );
4432 var FormApplicationHelper = function( app ){
4433 app.isUploading = false;
4434 app.elmProgress = null;
4435 app.elmUploader = null;
4436 app.elmScript = null;
4437 app.elmIframeWrap = null;
4438 app.elmIframe = null;
4440 app.fetchScript = function(){
4441 app.elmProgress = document.getElementById( app.elmProgressID );
4443 if( !( app.elmUploader = document.getElementById( app.elmUploaderID ) ) ){
4444 app.elmUploader = document.createElement( 'div' );
4445 app.rootElement.appendChild( app.elmUploader );
4446 app.elmUploader.id = app.elmUploaderID;
4447 if( app.hideUploader === true ){
4448 app.elmUploader.style.cssText = 'height:1px;line-height:1px;visibility:hidden;overflow:hidden;';
4452 app.elmIframeWrap = document.getElementById( app.iframeWrapID );
4453 app.elmScript = document.createElement( 'script' );
4454 document.body.appendChild( app.elmScript );
4455 app.elmScript.type = 'text\/javascript';
4456 app.elmScript.src = app.scriptSrc;
4458 app.elmProgress.innerHTML = 'loading form.';
4460 app.addTimer( app.detectForm, 250 );
4462 delete app.fetchScript;
4464 app.detectForm = function(){
4465 app.elmForm = app.elmUploader.getElementsByTagName( 'form' )[ 0 ];
4466 if( !app.elmForm ) return;
4467 app.removeTimer( app.detectForm );
4469 Util.createIframe( 'targetFrame', app.onCreateIframe );
4470 app.elmProgress.innerHTML = 'create iframe';
4471 delete app.detectForm;
4473 app.onCreateIframe = function( _iframe ){
4474 app.elmIframeWrap.appendChild( _iframe );
4475 _iframe.className = 'form-iframe';
4476 app.elmIframe = _iframe;
4477 app.elmForm.target = _iframe.name;
4478 app.elmProgress.innerHTML = '';
4479 app.onFormReady && app.onFormReady();
4481 delete app.onCreateIframe;
4483 app.submit = function(){
4484 app.elmProgress.innerHTML = 'submit!';
4486 app.elmForm.submit();
4487 app.isUploading = true;
4489 app.elmProgress.innerHTML = 'submit err..';
4490 app.submitError && app.submitError();
4493 if( app.detectIframe ){
4494 app.elmIframe.onreadystatechange = app.detectIframe;
4496 app.elmIframe.onload = app.onIframeUpdate;
4498 app.elmProgress.innerHTML = 'uploading..';
4503 app.detectIframe = function(){
4504 if ( this.readyState !== 'complete' ) return;
4505 this.onreadystatechange = new Function();
4506 this.onreadystatechange = null;
4507 app.onIframeUpdate();
4508 delete app.detectIframe;
4511 app.onIframeUpdate = function(){
4512 app.elmIframe.onload = null;
4514 console.log( ( app.elmIframe.contentWindow || app.elmIframe.contentDocument.parentWindow ).document.body.innerHTML );
4515 console.log( ( app.elmIframe.contentWindow || app.elmIframe.contentDocument.parentWindow )[ 'current_author' ] );
4519 ( app.elmIframe.contentWindow || app.elmIframe.contentDocument.parentWindow ).close();
4520 app.elmIframe = null;
4521 app.elmProgress.innerHTML = 'success!';
4522 app.isUploading = false;
4523 // app.submitSuccess && app.submitSuccess();
4524 delete app.onIframeUpdate;
4526 app.destroyHelper = function(){
4527 app.elmUploader.parentNode.removeChild( app.elmUploader );
4532 var ComicConsole = gOS.registerApplication( function(){
4533 var elmHeader, elmProgress,
4535 inputTitle, inputW, inputH,
4537 comboboxVisible, // comboboxEditable,
4538 buttonSubmit, buttonCancel,
4542 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4545 var _inputList = app.elmForm.getElementsByTagName( 'input' ),
4547 for( var i = _inputList.length; i; ){
4548 _input = _inputList[ --i ];
4549 _name = _input.name;
4550 if( _name === 'comic[title]' ){
4551 _input.value = inputTitle.value();
4553 if( _name === 'comic[width]' ){
4554 _input.value = inputW.value();
4556 if( _name === 'comic[height]' ){
4557 _input.value = inputH.value();
4560 var _selectList = app.elmForm.getElementsByTagName( 'select' ),
4561 _select, _optionList;
4562 for( i = _selectList.length; i; ){
4563 _select = _selectList[ --i ];
4564 _name = _select.name;
4565 _optionList = _select.getElementsByTagName( 'option' )
4566 if( _name === 'comic[visible]' ){
4567 _select.selectedIndex = comboboxVisible.selectIndex();
4569 if( _name === 'comic[editable]' ){
4570 _select.selectedIndex = comboboxEditable.selectIndex();
4573 buttonSubmit.enabled( false );
4576 function clickCancel(){
4577 if( app.isUploading === true ) return false;
4578 ComicConsole.shutdown();
4582 this.MIN_WIDTH = 320;
4583 this.MIN_HEIGHT = 320;
4584 this.onInit = function(){
4585 app.rootElement.id = 'comic-console-wrapper';
4586 app.rootElement.className = 'console-wrapper';
4587 app.rootElement.innerHTML = [
4588 '<div id="comic-console-header" class="console-header">Create New Comic</div>',
4589 '<div id="comic-console" class="console-inner">',
4590 '<div id="comic-console-title" class="field">',
4591 '<span class="field-label">Title:</span>',
4592 '<span id="comic-console-title-value" class="comic-console-value editable-value">No Title</span>',
4594 '<div id="comic-console-width" class="field">',
4595 '<span class="field-label">Default Width:</span>',
4596 '<span id="comic-console-width-value" class="comic-console-value editable-value">300</span>',
4598 '<div id="comic-console-height" class="field">',
4599 '<span class="field-label">Default Height:</span>',
4600 '<span id="comic-console-height-value" class="comic-console-value editable-value">200</span>',
4602 '<div id="comic-console-visible" class="field">',
4603 '<span class="field-label">Visible:</span>',
4604 '<span id="comic-console-visible-value" class="comic-console-value combobox"></span>',
4606 //'<div id="comic-console-editable" class="field">',
4607 // '<span class="field-label">Editable:</span>',
4608 // '<span id="comic-console-editable-value" class="comic-console-value combobox"></span>',
4610 '<div class="console-button-container">',
4611 '<div id="comic-console-post-button" class="button console-submit-button">create</div>',
4612 '<div id="comic-console-cancel-button" class="button console-cancel-button">cancel</div>',
4614 '<div id="comic-console-progress" class="console-progress"> </div>',
4615 '<div id="comic-console-iframe-container"></div>',
4619 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4620 eventRoot = app.getPointingDeviceEventTreeRoot();
4624 this.elmProgressID = 'comic-console-progress';
4625 this.elmUploaderID = 'newcomic';
4626 this.iframeWrapID = 'comic-console-iframe-container';
4627 this.elmIframeName = 'targetFrameCreateComic'
4628 this.scriptSrc = pettanr.CONST.CREATE_COMIC_JS;
4629 this.hideUploader = true;
4631 FormApplicationHelper( this );
4633 this.onOpen = function( w, h ){
4634 node = eventRoot.createNode( app.rootElement, true, true );
4636 var ui = app.createUIGroup( node );
4638 inputTitle = ui.createInputText( document.getElementById( 'comic-console-title') );
4639 inputW = ui.createInputText( document.getElementById( 'comic-console-width') );
4640 inputH = ui.createInputText( document.getElementById( 'comic-console-height') );
4641 comboboxVisible = ui.createCombobox( document.getElementById( 'comic-console-visible') );
4642 // comboboxEditable = ui.createCombobox( document.getElementById( 'comic-console-editable') );
4643 buttonSubmit = ui.createButton( document.getElementById( 'comic-console-post-button'), clickOK );
4644 buttonCancel = ui.createButton( document.getElementById( 'comic-console-cancel-button'), clickCancel );
4646 app.onPaneResize( w, h );
4650 this.onPaneResize = function( w, h ){
4653 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
4655 this.onClose = function(){
4656 app.destroyHelper();
4657 app = inputTitle = inputW = inputH = comboboxVisible = buttonSubmit = buttonCancel = null;
4659 this.onFormReady = function(){
4660 var selectList = app.elmForm.getElementsByTagName( 'select' ),
4664 for( var i=0, l=selectList.length; i<l; ++i ){
4665 select = selectList[ i ];
4666 optionList = select.getElementsByTagName( 'option' );
4667 for( j=0, m=optionList.length; j<m; ++j ){
4668 option = optionList[ j ];
4669 if( select.name === 'comic[visible]' ){
4670 comboboxVisible.createOption( option.innerHTML, option.value, option.selected );
4672 if( select.name === 'comic[editable]' ){
4673 comboboxEditable.createOption( option.innerHTML, option.value, option.selected );
4680 app.onPaneResize( windowW, windowH );
4682 delete app.onFormReady;
4684 this.submitError = function(){
4685 app.addTimer( clickCancel , 5000, true );
4687 this.submitSuccess = function(){
4688 app.addTimer( clickCancel , 5000, true );
4690 }, true, true, 'Comic Console', 'comicConsole', null, '#D44A26' );
4692 var UploadConsole = gOS.registerApplication( function(){
4693 var windowW, windowH,
4694 eventRoot, node, nodeForm,
4695 buttonSubmit, buttonCancel,
4700 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4701 if( elmFile.value.length === 0 ) return false;
4703 buttonSubmit.enabled( false );
4706 function clickCancel(){
4707 if( app.isUploading === true ) return false;
4708 UploadConsole.shutdown();
4713 this.MIN_WIDTH = 320;
4714 this.MIN_HEIGHT = 320;
4715 this.onInit = function(){
4716 app.rootElement.id = 'upload-console-wrapper';
4717 app.rootElement.className = 'console-wrapper';
4718 app.rootElement.innerHTML = [
4719 '<div id="upload-console-header" class="console-header">Upload Picture</div>',
4720 '<div id="upload-console" class="console-inner">',
4721 '<div id="upload-console-uiform"></div>',
4722 '<div class="console-button-container">',
4723 '<div id="upload-console-post-button" class="button console-submit-button">upload</div>',
4724 '<div id="upload-console-cancel-button" class="button console-cancel-button">cancel</div>',
4726 '<div id="upload-console-progress" class="console-progress"> </div>',
4727 '<div id="upload-console-iframe-container"></div>',
4731 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4733 eventRoot = app.getPointingDeviceEventTreeRoot();
4734 document.body.appendChild( Util.pullHtmlAsTemplete( '<div id="uploader"></div>' ) );
4737 this.elmProgressID = 'upload-console-progress';
4738 this.elmUploaderID = 'uploader';
4739 this.iframeWrapID = 'upload-console-iframe-container';
4740 this.elmIframeName = 'targetFrameUpload';
4741 this.scriptSrc = pettanr.CONST.UPLOAD_PICTURE_JS;
4742 this.hideUploader = false;
4743 FormApplicationHelper( this );
4744 this.onOpen = function( w, h ){
4745 node = eventRoot.createNode( app.rootElement, true, true );
4746 nodeForm = node.createNode( document.getElementById( 'upload-console-uiform' ), false, true );
4747 var ui = app.createUIGroup( node );
4749 buttonSubmit = ui.createButton( document.getElementById( 'upload-console-post-button' ), clickOK );
4750 buttonCancel = ui.createButton( document.getElementById( 'upload-console-cancel-button' ), clickCancel );
4752 app.onPaneResize( w, h );
4755 this.onPaneResize = function( w, h ){
4758 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
4760 this.onClose = function(){
4761 app.destroyHelper();
4762 app = elmFile = buttonSubmit = buttonCancel = null;
4764 this.onFormReady = function(){
4765 var elmForm = app.elmForm,
4766 _inputList = elmForm.getElementsByTagName( 'input' ),
4768 for( var i = _inputList.length; i; ){
4769 _input = _inputList[ --i ];
4770 if( _input.type === 'file' ){
4773 if( _input.type === 'submit' ){
4774 _input.style.display = 'none';
4778 app.createUIForm( nodeForm, elmForm );
4780 node.mesureChildren();
4781 app.onPaneResize( windowW, windowH );
4782 delete app.onFormReady;
4784 this.submitError = function(){
4785 app.addTimer( clickCancel , 5000, true );
4787 this.submitSuccess = function(){
4788 app.addTimer( clickCancel , 5000, true );
4790 }, true, true, 'Upload Console', 'uploadConsole', null, '#01A31C' );
4792 var ArtistConsole = gOS.registerApplication( function(){
4793 var windowW, windowH,
4795 elmName, elmLicense,
4796 inputName, inputLicense,
4797 buttonSubmit, buttonCancel,
4801 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4804 buttonSubmit.enabled( false );
4807 function clickCancel(){
4808 if( app.isUploading === true) return false;
4809 ArtistConsole.shutdown();
4812 function inputUpdate( v ){
4813 elmName.value = inputName.value();
4814 elmLicense.value = inputLicense.value();
4818 this.MIN_WIDTH = 320;
4819 this.MIN_HEIGHT = 320;
4820 this.onInit = function(){
4821 app.rootElement.id = 'artist-console-wrapper';
4822 app.rootElement.className = 'console-wrapper';
4823 app.rootElement.innerHTML = [
4824 '<div id="artist-console-header" class="console-header">Register Artist</div>',
4825 '<div id="artist-console" class="console-inner">',
4826 '<div id="artist-console-name" class="field">',
4827 '<span class="field-label">Name:</span>',
4828 '<span id="artist-console-name-value" class="comic-console-value editable-value">artist name here.</span>',
4830 '<div id="artist-console-license" class="field">',
4831 '<span class="field-label">License:</span>',
4832 '<span id="artist-console-license-value" class="comic-console-value editable-value">license here.</span>',
4834 '<div class="console-button-container">',
4835 '<div id="artist-console-post-button" class="button console-submit-button">register</div>',
4836 '<div id="artist-console-cancel-button" class="button console-cancel-button">cancel</div>',
4838 '<div id="artist-console-progress" class="console-progress"> </div>',
4839 '<div id="register" style="display:none;"></div>',
4840 '<div id="artist-console-iframe-container"></div>',
4844 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4845 eventRoot = app.getPointingDeviceEventTreeRoot();
4849 this.elmProgressID = 'artist-console-progress';
4850 this.elmUploaderID = 'register';
4851 this.iframeWrapID = 'artist-console-iframe-container';
4852 this.elmIframeName = 'targetFrameArtistRegister'
4853 this.scriptSrc = pettanr.CONST.REGISTER_ARTIST_JS;
4854 this.hideUploader = false;
4855 FormApplicationHelper( this );
4856 this.onFormReady = function(){
4857 var _inputList = app.elmForm.getElementsByTagName( 'input' ),
4859 for( var i = _inputList.length; i; ){
4860 _input = _inputList[ --i ];
4861 if( _input.type === 'submit' ){
4862 _input.style.display = 'none';
4864 if( _input.name === 'artist[name]' ){
4867 if( _input.name === 'artist[default_license_id]' ){
4868 elmLicense = _input;
4873 app.onPaneResize( windowW, windowH );
4874 node.mesureChildren();
4876 delete app.onFormReady;
4878 this.submitError = function(){
4879 app.addTimer( clickCancel , 5000, true );
4881 this.submitSuccess = function(){
4882 app.addTimer( clickCancel , 5000, true );
4884 this.onOpen = function( w, h ){
4885 node = eventRoot.createNode( app.rootElement, true, true );
4886 var ui = app.createUIGroup( node );
4888 inputName = ui.createInputText( document.getElementById( 'artist-console-name' ), inputUpdate );
4889 inputLicense = ui.createInputText( document.getElementById( 'artist-console-license' ), inputUpdate );
4890 buttonSubmit = ui.createButton( document.getElementById( 'artist-console-post-button' ), clickOK );
4891 buttonCancel = ui.createButton( document.getElementById( 'artist-console-cancel-button' ), clickCancel );
4893 app.onPaneResize( w, h );
4896 this.onPaneResize = function( w, h ){
4899 //app.rootElement.style.cssText = [
4900 // 'left:', Math.floor( ( _w - app.rootElement.offsetWidth ) /2 ), 'px;',
4901 // 'top:', Math.floor( ( _h- app.rootElement.offsetHeight ) /2 ), 'px;'
4903 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
4905 this.onClose = function(){
4906 app.destroyHelper();
4907 app = buttonSubmit = buttonCancel = null;
4909 }, true, true, 'Artist Console', 'artistConsole', null, '#FFC40D' );
4911 var PanelConsole = gOS.registerApplication( function(){
4912 var windowW, windowH,
4913 eventRoot, node, inputData,
4914 comboboxPublish, buttonSubmit, buttonClose,
4920 * upload ボタンが押されたらまず iframe をつくる.
4923 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4926 buttonSubmit.enabled( false );
4930 function clickCancel(){
4931 if( app.isUploading === true ) return false;
4932 PanelConsole.shutdown();
4935 function publishUpdate(){
4937 model.publish( comboboxPublish.selectIndex() === 1 );
4938 elmInput.value = model.getJsonPostString().replace( /\n/g, '' );
4939 inputData.value( elmInput.value );
4941 elmInput.value = inputData.value();
4946 this.MIN_WIDTH = 320;
4947 this.MIN_HEIGHT = 320;
4948 this.onInit = function(){
4949 app.rootElement.id = 'panel-console-wrapper';
4950 app.rootElement.className = 'console-wrapper';
4951 app.rootElement.innerHTML = [
4952 '<div id="panel-console-header" class="console-header">Create New Panel (dev)</div>',
4953 '<div id="panel-console" class="console-inner">',
4954 '<div id="panel-console-data" class="field">',
4955 '<span class="field-label">POST DATA:</span>',
4956 '<span id="panel-console-data-value" class="comic-console-value editable-value">panel json here.</span>',
4958 '<div id="panel-console-publish" class="field">',
4959 '<span class="field-label">Publish:</span>',
4960 '<span id="panel-console-publish-value" class="combobox"></span>',
4962 '<div class="console-button-container">',
4963 '<div id="panel-console-post-button" class="button console-submit-button">post</div>',
4964 '<div id="panel-console-cancel-button" class="button console-cancel-button">cancel</div>',
4966 '<div id="panel-console-progress" class="console-progress"> </div>',
4967 '<div id="newpanel" style="display:none;"></div>',
4968 '<div id="panel-console-iframe-container"></div>',
4972 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4973 eventRoot = app.getPointingDeviceEventTreeRoot();
4977 this.elmProgressID = 'panel-console-progress';
4978 this.elmUploaderID = 'newpanel';
4979 this.iframeWrapID = 'panel-console-iframe-container';
4980 this.elmIframeName = 'targetFrameNewPanel';
4981 this.scriptSrc = pettanr.CONST.CREATE_PANEL_JS;
4982 this.hideUploader = false;
4983 FormApplicationHelper( this );
4985 this.onOpen = function( w, h, _model ){
4986 node = eventRoot.createNode( app.rootElement, true, true );
4987 var ui = app.createUIGroup( node ),
4988 elm = document.getElementById( 'panel-console-publish' );
4990 inputData = ui.createInputText( document.getElementById( 'panel-console-data' ), publishUpdate );
4993 comboboxPublish = ui.createCombobox( elm, publishUpdate );
4994 comboboxPublish.createOption( 'only me', '0', _model.publish() === false );
4995 comboboxPublish.createOption( 'publish', '1', _model.publish() === true );
4998 elm.parentNode.removeChild( elm );
5001 buttonSubmit = ui.createButton( document.getElementById( 'panel-console-post-button' ), clickOK );
5002 buttonClose = ui.createButton( document.getElementById( 'panel-console-cancel-button' ), clickCancel );
5004 app.onPaneResize( w, h );
5007 this.onPaneResize = function( w, h ){
5010 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
5012 this.onClose = function(){
5013 app.destroyHelper();
5014 model && model.destroy();
5015 app = model = comboboxPublish = buttonSubmit = buttonClose = elmInput = null;
5017 this.onFormReady = function(){
5018 var _inputList = app.elmForm.getElementsByTagName( 'input' ),
5020 for( var i = _inputList.length; i; ){
5021 _input = _inputList[ --i ];
5022 if( _input.type === 'submit' ){
5023 _input.style.display = 'none';
5025 if( _input.name === 'json' ){
5032 node.mesureChildren();
5033 app.onPaneResize( windowW, windowH );
5035 delete app.onFormReady;
5037 this.submitError = function(){
5038 app.addTimer( clickCancel , 5000, true );
5040 this.submitSuccess = function(){
5041 app.addTimer( clickCancel , 5000, true );
5043 }, true, true, 'Panel Console', 'panelConsole', null, '#603CBA' );
5045 var Model = ( function(){
5047 var PanelModelClass = function( panel ){
5048 var comicID = panel.comicID || -1,
5049 panelID = panel.panelID || -1,
5050 panelTimming = panel.panelTimming || -1,
5051 panelW = panel.panelW,
5052 panelH = panel.panelH,
5053 borderSize = panel.borderSize,
5054 panelElementArray = panel.panelElementArray,
5055 publish = panel.publish,
5058 function getPanelElementByTiming(){
5059 var i, l = panelElementArray.length;
5060 while( timing < l * 2 ){
5061 for( i = 0; i < l; ++i ){
5062 if( timing === panelElementArray[ i ].timing ){
5063 // console.log( timing + ' , ' + panelElementArray[ i ].timing );
5065 return panelElementArray[ i ];
5072 function panelElementToHtml( _panelElement, isAbsoluteUrl, isXHTML ){
5074 if( _panelElement.type === 0 ){
5075 rPic = _panelElement.realPicture();
5076 url = [ pettanr.CONST.RESOURCE_PICTURE_PATH, rPic.id, '.', rPic.ext ].join( '' );
5079 'src="', isAbsoluteUrl !== true ? url : Util.getAbsolutePath( url ), '" ',
5080 'width="', _panelElement.w, '" ',
5081 'height="', _panelElement.h, '" ',
5083 'left:', _panelElement.x, 'px;',
5084 'top:', _panelElement.y, 'px;',
5085 'z-index:', _panelElement.z, ';',
5087 isXHTML !== true ? '>' : ' \/>'
5090 url = pettanr.balloon.getBalloonUrl( _panelElement.w, _panelElement.h, _panelElement.a );
5093 'src="', isAbsoluteUrl !== true ? url : Util.getAbsolutePath( url ), '" ',
5094 'width="', _panelElement.w, '" ',
5095 'height="', _panelElement.h, '" ',
5097 'left:', _panelElement.x, 'px;',
5098 'top:', _panelElement.y, 'px;',
5099 'z-index:', _panelElement.z, ';',
5101 isXHTML !== true ? '>' : ' \/>',
5102 pettanr.LINE_FEED_CODE_TEXTAREA,
5103 '<div class="balloon" style="',
5104 'left:', _panelElement.x, 'px;',
5105 'top:', _panelElement.y, 'px;',
5106 'width:', _panelElement.w, 'px;',
5107 'height:', _panelElement.h, 'px;',
5108 'z-index:', _panelElement.z,
5109 '"><span>', _panelElement.content, '<\/span>', '<\/div>'
5114 function getImageJsonGET( _imageElement ){
5115 var cr = pettanr.LINE_FEED_CODE_TEXTAREA,
5116 rPic = _imageElement.realPicture();
5119 '"resource_picture": {', cr,
5120 '"id": ', rPic.id, ',', cr,
5121 '"ext": ', '"', rPic.ext, '"', cr,
5123 '"x": ', _imageElement.x, ',', cr,
5124 '"y": ', _imageElement.y, ',', cr,
5125 '"z": ', _imageElement.z, ',', cr,
5126 '"width": ', _imageElement.flipH * _imageElement.w, ',', cr,
5127 '"height": ', _imageElement.flipV * _imageElement.h, ',', cr,
5128 '"t": ', timing, cr,
5132 function imageToJson( _imageElement, t ){
5133 var cr = pettanr.LINE_FEED_CODE_TEXTAREA;
5136 '"picture_id": ', _imageElement.realPicture().id, ',', cr,
5137 '"x": ', _imageElement.x, ',', cr,
5138 '"y": ', _imageElement.y, ',', cr,
5139 '"z": ', _imageElement.z + 1, ',', cr,
5140 '"t": ', t, ',', cr,
5141 '"width": ', _imageElement.flipH * _imageElement.w, ',', cr,
5142 '"height": ', _imageElement.flipV * _imageElement.h, cr,
5147 function balloonToJson( _textElement, t ){
5148 var cr = pettanr.LINE_FEED_CODE_TEXTAREA;
5151 '"speech_balloon_template_id": ', 1, ',', cr,
5152 '"classname": "Square",',
5153 '"z": ', _textElement.z + 1, ',', cr,
5154 '"t": ', t, ',', cr,
5155 '"settings": "{\'tail\':' + _textElement.a + '}",',
5156 '"balloons_attributes": {', cr,
5157 '"newb', t, '": {', cr,
5158 '"system_picture_id": ', 2, ',', cr,
5159 '"caption": "alt text",', cr,
5160 '"x": ', _textElement.x, ',', cr,
5161 '"y": ', _textElement.y, ',', cr,
5162 '"width": ', _textElement.w, ',', cr,
5163 '"height": ', _textElement.h, cr,
5166 '"speeches_attributes": {', cr,
5167 '"news', t, '": {', cr,
5168 '"content": "', _textElement.content, '",', cr,
5169 '"x": ', Math.floor( _textElement.w * 0.16 ), ',', cr,
5170 '"y": ', Math.floor( _textElement.w * 0.16 ), ',', cr,
5171 '"width": ', Math.floor( _textElement.w * 0.66 ), ',', cr,
5172 '"height": ', Math.floor( _textElement.h * 0.66 ), cr,
5179 this.getJsonPostString = function(){
5182 var JSON_STRING_ARRAY = [],
5185 l = panelElementArray.length,
5187 cr = pettanr.LINE_FEED_CODE_TEXTAREA;
5189 while( IMAGE_ARRAY.length + BALLOON_ARRAY.length <= l ){
5190 _panelElement = getPanelElementByTiming();
5191 if( _panelElement === null) break;
5192 n = IMAGE_ARRAY.length + BALLOON_ARRAY.length;
5193 _panelElement.type === 0 ?
5194 IMAGE_ARRAY.push( [ '"new', n, '": ', imageToJson( _panelElement, n ) ].join( '' ) ) :
5195 BALLOON_ARRAY.push( [ '"new', n, '": ', balloonToJson( _panelElement, n ) ].join( '' ) );
5199 panelID !== -1 ? ( '"id": ' + panelID + ',' + cr ) : '',
5200 // comicID !== -1 ? ( '"comic_id": ' + comicID + ',' + cr ) : '',
5201 '"width": ', panelW, ',', cr,
5202 '"height": ', panelH, ',', cr,
5203 '"border": ', borderSize, ',', cr,
5205 // '"picture_id": 1,', cr,
5206 '"x": ', 0, ',', cr,
5207 '"y": ', 0, ',', cr,
5208 '"z": ', 1, ',', cr,
5209 panelTimming !== -1 ? ( '"t": ' + panelTimming + ',' + cr ) : '',
5210 '"panel_pictures_attributes": {', cr,
5211 IMAGE_ARRAY.join( ',' + cr ), cr,
5213 '"speech_balloons_attributes": {', cr,
5214 BALLOON_ARRAY.join( ',' + cr ), cr,
5216 '"publish": ', ( publish === true ? 1 : 0 ), cr,
5220 this.getJsonGetString = function(){
5223 var JSON_STRING_ARRAY = [],
5225 l = panelElementArray.length,
5226 cr = pettanr.LINE_FEED_CODE_TEXTAREA,
5229 while( ELEMENT_ARRAY.length <= l){
5230 _panelElement = getPanelElementByTiming();
5231 if( _panelElement === null ) break;
5233 ELEMENT_ARRAY.push( _panelElement.type === 0 ? getImageJsonGET( _panelElement ) : balloonToJson( _panelElement ));
5238 //'"id": ', panelID, ',', cr,
5239 '"border": ', borderSize, ',', cr,
5240 // '"comic_id": ', comicID, ',', cr,
5241 // '"picture_id": 1,', cr,
5242 '"x": ', 0, ',', cr,
5243 '"y": ', 0, ',', cr,
5244 '"z": ', 1, ',', cr,
5245 // panelTimming !== -1 ? ( '"t": ' + panelTimming + ',' + cr ) : '',
5246 '"width": ', panelW, ',', cr,
5247 '"height": ', panelH, ',', cr,
5248 '"elements": [', cr,
5249 ELEMENT_ARRAY.join( ',' + cr ), cr,
5255 this.getAsHtmlString = function( isAbsoluteUrl, isXHTML ){
5258 var HTML_ARRAY = [],
5259 l = panelElementArray.length,
5262 while( HTML_ARRAY.length < l ){
5263 _panelElement = getPanelElementByTiming();
5264 if( _panelElement === null) break;
5265 HTML_ARRAY.push( panelElementToHtml( _panelElement, isAbsoluteUrl, isXHTML ));
5270 '<div class="panel" ',
5272 'height:', panelH, 'px;',
5273 'background-color:', ';',
5278 HTML_ARRAY.push( '</div>');
5280 return HTML_ARRAY.join( pettanr.LINE_FEED_CODE_TEXTAREA );
5282 this.publish = function( v ){
5283 return publish = Type.isBoolean( v ) === true ? v : publish;
5285 this.destroy = function(){
5286 panel = panelElementArray = null;
5291 createPanel: function( panelData ){
5292 return new PanelModelClass( panelData );
5298 var OutputConsole = gOS.registerApplication( function(){
5299 var FORMAT_LIST = [ 'json[POST]', 'json[GET]', 'XML', 'HTML', 'XHTML', 'MT export', 'Blogger ATOM' ];
5302 comboboxFormat, inputOption,
5303 buttonSubmit, buttonClose,
5305 comicID, panelID, panelTimming, panelW, panelH, borderSize, panelElementArray,
5310 OutputConsole.shutdown();
5313 function formatUpdate(){
5314 var i = comboboxFormat.selectIndex(),
5316 // buttonSubmit.enabled( false );
5318 text = model.getJsonPostString();
5319 // buttonSubmit.enabled( true );
5322 text = model.getJsonGetString();
5325 text = model.getAsHtmlString( false, false );
5329 elmOutputArea.value = text;
5331 function clickClose(){
5332 OutputConsole.shutdown();
5336 function clickPost(){
5337 // PanelConsole.boot( elmOutputArea.value );
5342 this.MIN_WIDTH = 320;
5343 this.MIN_HEIGHT = 320;
5344 this.onInit = function(){
5345 app.rootElement.id = 'output-console-wrapper';
5346 app.rootElement.className = 'console-wrapper';
5347 app.rootElement.innerHTML = [
5348 '<div id="output-console-header" class="console-header">Output Console</div>',
5349 '<div id="output-console" class="console-inner">',
5350 '<div id="output-console-format" class="field">',
5351 '<span class="field-label">Format:</span>',
5352 '<span id="output-console-format-value" class="output-console-value combobox"></span>',
5354 '<div id="output-console-option" class="field">',
5355 '<span class="field-label">Options:</span>',
5356 '<span id="output-console-option-value" class="output-console-value editable-value">absolute-path</span>',
5358 '<textarea id="output-area" readonly></textarea>',
5359 '<div id="output-console-close-button" class="button">close</div>',
5363 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
5364 eventRoot = app.getPointingDeviceEventTreeRoot();
5368 this.onOpen = function( _w, _h, _comicID, _panelID, _panelTimming, _panelW, _panelH, _borderSize, _panelElementArray ){
5369 elmOutputArea = document.getElementById( 'output-area' );
5371 node = eventRoot.createNode( app.rootElement, true, true );
5372 var ui = app.createUIGroup( node );
5373 comboboxFormat = ui.createCombobox( document.getElementById( 'output-console-format' ), formatUpdate );
5375 for( var i=0; FORMAT_LIST[ 0 ]; ++i ){
5376 comboboxFormat.createOption( FORMAT_LIST.shift(), null, i === 0 );
5378 inputOption = ui.createInputText( document.getElementById( 'output-console-option' ), null );
5379 // buttonSubmit = ui.createButton( document.getElementById( 'output-console-post-button' ), clickPost );
5380 buttonClose = ui.createButton( document.getElementById( 'output-console-close-button' ), clickClose );
5382 app.onPaneResize( _w, _h );
5384 comboboxFormat.focus( true );
5386 model = Model.createPanel( {
5389 panelTimming : _panelTimming,
5392 borderSize : _borderSize,
5393 panelElementArray : _panelElementArray,
5399 this.onPaneResize = function( w, h ){
5402 //app.rootElement.style.cssText = [
5403 // 'left:', Math.floor( ( _windowW - app.rootElement.offsetWidth ) /2 ), 'px;',
5404 // 'top:', Math.floor( ( _windowH - app.rootElement.offsetHeight ) /2 ), 'px;'
5406 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
5408 this.onClose = function(){
5409 elmOutputArea.value = '';
5411 elmOutputArea = comboboxFormat = inputOption = buttonSubmit = buttonClose = panelElementArray = model = null;
5413 }, true, false, 'Output Console', 'outputConsole', null, '#2D89F0' );
5415 })( pettanr, gOS, window, document );