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 );
92 case FILE_DATA_AUTHOR_ROOT :
94 json.type = FILE_TYPE.AUTHOR;
95 data = createFileData( json, AUTHOR_ARRAY, 'name,email,homepage_url' );
96 addChildData( FILE_DATA_AUTHOR_ROOT, data );
100 case FILE_DATA_ARTIST_ROOT :
102 json.type = FILE_TYPE.ARTIST;
103 data = createFileData( json, ARTIST_ARRAY, 'name,email,homepage_url' );
104 addChildData( FILE_DATA_ARTIST_ROOT, data );
108 json.type = FILE_TYPE.PICTURE;
109 data = createFileData( json, PICTURE_ARRAY, 'ext,revision,credit,settings' );
113 case FILE_DATA_RESOURCE_PICTURES_ROOT :
114 case FILE_DATA_MY_RESOURCE_PICTURES_ROOT :
115 case RESOURCE_PICTURE_ARRAY :
116 json.type = FILE_TYPE.RESOURCE_PICTURE;
117 data = createFileData( json, RESOURCE_PICTURE_ARRAY, 'ext' );
119 addChildData( data.artist, data );
120 data.artist.id === MyArtistID && addChildData( FILE_DATA_MY_RESOURCE_PICTURES_ROOT, data );
125 case FILE_DATA_MY_ORIGINAL_PICTURES_ROOT :
126 case ORIGINAL_PICTURE_ARRAY :
127 json.type = FILE_TYPE.ORIGINAL_PICTURE;
128 data = createFileData( json, ORIGINAL_PICTURE_ARRAY, 'ext,filesize,width,height,md5' );
130 // addChildData( data.artist, data );
131 data.artist.id === MyArtistID && addChildData( FILE_DATA_MY_ORIGINAL_PICTURES_ROOT, data );
135 case FILE_DATA_PANELS_ROOT :
136 case FILE_DATA_MY_PANELS_ROOT :
138 json.type = FILE_TYPE.PANEL;
139 data = createFileData( json, PANEL_ARRAY, 'border,publish,width,height' );
140 addChildData( FILE_DATA_LATEST_PANELS, data );
141 data.author.id === MyAuthorID && addChildData( FILE_DATA_MY_PANELS_ROOT, data );
145 case PANEL_ELEMENT_ARRAY :
146 json.type = FILE_TYPE.PANEL_ELEMENT;
147 data = createFileData( json, PANEL_ELEMENT_ARRAY, 'caption,url,width,height,x,y,z,t' ); // 画像の分
153 if( parent.type === FILE_TYPE.COMIC ){
154 //alert( 'comicstory' )
155 data = registerFileData( json, STORY_ARRAY );
156 //addChildData( parent, data );
159 throw new Error( 'build file error!' );
164 * 1. すでに一度以上ファイルを取得している場合、そのオブジェクトを取得.または、新規に作成.
165 * 2. オブジェクトに値をコピー・上書き
168 function createFileData( json, array, copyProps ){
169 copyProps = copyProps + ',id,type';
171 var getIndex = Util.getIndex,
173 data = getResource( array, id ),
180 copyProps = copyProps.split( ',' );
182 if( getIndex( copyProps, p ) !== -1 ) data[ p ] = json[ p ];
186 data.driver = Driver;
187 if( Type.isString( json.created_at ) === true ) data.created_at = Math.floor( new Date( json.created_at ).getTime() / 1000 );
188 if( Type.isString( json.updated_at ) === true ) data.updated_at = Math.floor( new Date( json.updated_at ).getTime() / 1000 );
191 histories = json.pictures;
192 if( Type.isArray( histories ) === true ){
193 for( i = 0, l = histories.length; i < l; ++i ){
194 history = getResource( PICTURE_ARRAY, histories[ i ] );
195 addChildData( data, history );
197 data.picture = history;
201 stories = json.stories;
202 if( Type.isArray( stories ) === true ){
203 for( i = 0, l = stories.length; i < l; ++i ){
204 story = getResource( STORY_ARRAY, stories[ i ] );
208 addChildData( data, story );
213 elements = json.elements;
214 if( Type.isArray( elements ) === true ){
215 for( i = 0, l = elements.length; i<l; ++i ){
219 addChildData( data, getResource( PANEL_ELEMENT_ARRAY, elements[ i ] ) );
224 if( json.artist || json.artist_id ){
225 data.artist = getResource( ARTIST_ARRAY, json.artist || json.artist_id );
229 if( json.author || json.author_id ){
230 data.author = getResource( AUTHOR_ARRAY, json.author || json.author_id );
234 if( json.comic || json.comic_id ){
235 data.comic = getResource( COMIC_ARRAY, json.comic || json.comic_id );
239 if( json.panel || json.panel_id ){
240 data.panel = getResource( PANEL_ARRAY, json.panel || json.panel_id );
244 if( json.picture || json.picture_id ){
245 data.picture = getResource( PICTURE_ARRAY, json.picture || json.picture_id );
249 if( json.license || json.license_id ){
250 data.license = getResource( LICENSE_ARRAY, json.license || json.license_id );
254 if( json.license_group || json.license_group_id ){
255 data.license_group = getResource( LICENSE_GROUP_ARRAY, json.license_group || json.license_group_id );
259 if( json.original_picture || json.original_picture_id ){
260 data.original_picture = getResource( ORIGINAL_PICTURE_ARRAY, json.original_picture || {
261 id : json.original_picture_id,
263 filesize : json.filesize,
265 height : json.height,
267 artist : json.artist,
268 artist_id : json.artist_id
274 function addChildData( parent, child ){
275 if( Type.isArray( parent.children ) === false ){
276 parent.children = [ child ];
279 Util.getIndex( parent.children, child ) === -1 && parent.children.push( child );
281 function getResource( list, IDorOBJECT ){
283 if( Type.isNumber( IDorOBJECT ) === true ){
286 if( IDorOBJECT && Type.isNumber( IDorOBJECT.id ) === true ){
289 unregisteredFileDataJsonList.push( [ obj, list ] );
291 alert( 'getResource error' + IDorOBJECT.toString() );
295 if( !data ) data = list[ id ] = { id : id };
299 this.getSeqentialFiles = function( file ){
300 var data = FileAPI.getFileData( file ),
301 json = data.json || null;
302 if( data.type === FILE_TYPE.COMIC && json === true ){
303 if( pettanr.CONST.SERVER_SUPPORT === false ){
304 json = [ 'json\/comics_', data.id, '.json' ].join( '' );
306 json = [ pettanr.CONST.PETTANR_ROOT_PATH, 'stories\/', data.id, '\/comic.json' ].join( '' );
310 if( typeof json === 'string' ){
311 FileAPI.getJson( file, json, onLoadJson, onErrorJson );
312 data.state = Const.FILE.STATE.LOADING;
313 if( data.json !== null ) delete data.json;
317 this.getName = function( file ){
318 var data = FileAPI.getFileData( file ),
319 type = data !== null ? data.type : null;
321 case FILE_TYPE.BALLOON :
323 case FILE_TYPE.PANEL_ELEMENT :
325 case FILE_TYPE.RESOURCE_PICTURE :
326 return [ '素材 ' + data.id, '.', data.ext ].join( '' );
327 case FILE_TYPE.PICTURE :
328 return [ '実素材 ' + data.id, '.', data.ext ].join( '' );
329 case FILE_TYPE.ORIGINAL_PICTURE :
330 return [ '原画 ', data.id, '.', data.ext ].join( '' );
331 case FILE_TYPE.COMIC :
333 case FILE_TYPE.STORY :
334 return [ 'story id:', data.id, ' ', data.comic ? data.comic.title : 'no comic', ':', data.t ].join( '' );
335 case FILE_TYPE.PANEL :
336 return [ 'panel id:', data.id ].join( '' );
337 case FILE_TYPE.AUTHOR :
338 return [ data.name, '先生' ].join( '' );
339 case FILE_TYPE.ARTIST :
340 return [ data.name, '画伯' ].join( '' );
341 case FILE_TYPE.FOLDER :
345 this.getThumbnail = function( file ){
346 var data = FileAPI.getFileData( file ),
347 type = data !== null ? data.type : null;
348 if( data === FILE_DATA_COMICS_ROOT ) return { className: 'file-type-cabinet' };
351 case FILE_TYPE.PANEL_ELEMENT :
352 return { className: 'file-type-charactor' };
353 case FILE_TYPE.RESOURCE_PICTURE :
354 return { image: [ pettanr.CONST.THUMBNAIL_PATH, data.id, '.', data.ext ].join( '' )};
355 case FILE_TYPE.PICTURE :
356 //data = data.original_picture;
357 return { image: [ pettanr.CONST.THUMBNAIL_PATH, data.id, '.', data.ext ].join( '' )};
358 case FILE_TYPE.ORIGINAL_PICTURE :
359 return { className: 'file-type-charactor' };
360 // return { image: [ pettanr.CONST.THUMBNAIL_PATH, data.id, '.', data.ext ].join( '' )};
361 case FILE_TYPE.BALLOON :
363 case FILE_TYPE.COMIC :
364 return { className: 'file-type-comic' };
365 case FILE_TYPE.STORY :
367 case FILE_TYPE.PANEL :
368 return { className: 'file-type-panel' };
369 case FILE_TYPE.AUTHOR :
370 return { className: 'file-type-author' };
371 case FILE_TYPE.ARTIST :
372 return { className: 'file-type-artist' };
373 case FILE_TYPE.FOLDER :
374 return { className: 'file-type-folder' };
376 return { className: 'file-type-broken' };
378 this.getSummary = function( file ){
379 var data = FileAPI.getFileData( file ),
380 type = data !== null ? data.type : null;
381 if( data === FILE_DATA_COMICS_ROOT ) return 'cabinet file';
383 case FILE_TYPE.BALLOON :
385 case FILE_TYPE.PANEL_ELEMENT :
386 return 'caption:' + data.caption + ' url:' + data.url + ' ' + data.width + 'x' + data.height + ' x:' + data.x + ' y:' + data.y + ' z:' + data.z + ' t:' + data.t;
387 case FILE_TYPE.RESOURCE_PICTURE :
389 case FILE_TYPE.PICTURE :
390 return '実素材情報 revision:' + data.revision + ' ' + data.credit + ' ' + data.settings;
391 case FILE_TYPE.ORIGINAL_PICTURE :
392 return [ '原画情報 ', data.width, 'x', data.height, ', filesize:', data.filesize, ' md5', data.md5 ].join( '' );
393 case FILE_TYPE.COMIC :
394 return 'comic id:' + data.id;
395 case FILE_TYPE.STORY :
397 case FILE_TYPE.PANEL :
398 return [ 'panel id:', data.id, ', width:', data.width, ', height:', data.height, ', 枠線:', data.border, ', 公開:', data.publish ].join( '' );
399 case FILE_TYPE.AUTHOR :
400 return 'author id:' + data.id;
401 case FILE_TYPE.ARTIST :
402 return [ 'artist id:', data.id, ' Email:', data.email || 'empty' , ', HP:', data.homepage_url || 'empty' ].join( '' );
403 case FILE_TYPE.FOLDER :
404 return 'pettanR folder';
406 return 'pettanR unknown file';
408 this.read = function( file ){
409 var data = FileAPI.getFileData( file ),
410 type = data !== null ? data.type : null,
413 case FILE_TYPE.COMIC :
414 ret = Util.copy( data );
415 ret.panels = ret.children;
416 if( Type.isArray( ret.panels ) === true ){
417 for( i = ret.panels.length; i; ){
418 elm = ret.panels[ --i ];
419 elm.elements = elm.children;
423 case FILE_TYPE.STORY :
424 ret = Util.copy( data );
425 ret.panel.elements = ret.panel.children;
427 case FILE_TYPE.PANEL :
428 ret = Util.copy( data );
429 ret.elements = ret.children;
431 case FILE_TYPE.PANEL_ELEMENT :
432 case FILE_TYPE.BALLOON :
433 case FILE_TYPE.ORIGINAL_PICTURE :
436 this.write = function( file, newData, onUpdate ){
437 var data = FileAPI.getFileData( file ),
438 type = data !== null ? data.type : null;
440 case FILE_TYPE.COMIC :
441 case FILE_TYPE.PANEL :
442 case FILE_TYPE.PANEL_ELEMENT :
443 case FILE_TYPE.BALLOON :
444 case FILE_TYPE.ORIGINAL_PICTURE :
447 this.viewerApplicationList = function( file ){
448 var data = FileAPI.getFileData( file ),
449 type = data !== null ? data.type : null;
450 if( data === FILE_DATA_MY_ORIGINAL_PICTURES_ROOT ) return [ PremiumSatge ];
452 case FILE_TYPE.COMIC :
453 case FILE_TYPE.PANEL :
454 case FILE_TYPE.STORY :
456 case FILE_TYPE.PANEL_ELEMENT :
457 case FILE_TYPE.BALLOON :
458 case FILE_TYPE.ORIGINAL_PICTURE :
460 case FILE_TYPE.ARTIST :
461 return [ PremiumSatge ];
466 this.editorApplicationList = function( file ){
467 var data = FileAPI.getFileData( file ),
468 type = data !== null ? data.type : null;
470 case FILE_TYPE.COMIC :
471 return [ Editor, ComicConsole ];
472 case FILE_TYPE.PANEL :
474 case FILE_TYPE.PANEL_ELEMENT :
475 case FILE_TYPE.BALLOON :
476 case FILE_TYPE.ORIGINAL_PICTURE :
477 case FILE_TYPE.ARTIST :
483 Const = FileAPI.getConst(),
484 FILE_TYPE = Util.extend(
487 COMIC : FileAPI.createFileTypeID(),
488 STORY : FileAPI.createFileTypeID(),
489 PANEL : FileAPI.createFileTypeID(),
490 PANEL_ELEMENT : FileAPI.createFileTypeID(),
491 BALLOON : FileAPI.createFileTypeID(),
492 ORIGINAL_PICTURE : FileAPI.createFileTypeID(),
493 RESOURCE_PICTURE : FileAPI.createFileTypeID(),
494 PICTURE : FileAPI.createFileTypeID(),
495 AUTHOR : FileAPI.createFileTypeID(),
496 ARTIST : FileAPI.createFileTypeID(),
497 LICENSE : FileAPI.createFileTypeID(),
498 LICENSE_GROUP : FileAPI.createFileTypeID()
508 LICENSE_GROUP_ARRAY = [],
509 PANEL_ELEMENT_ARRAY = [],
510 ORIGINAL_PICTURE_ARRAY = [],
511 RESOURCE_PICTURE_ARRAY = [],
512 BALLOON_TEMPLETE_ARRAY = [],
513 BASIC_LICENSES = 'cc_by,cc_nc,cc_nd,cc_sa,keep_aspect_ratio,no_convert,no_flip,no_resize'.split( ','),
514 FILE_DATA_SERVICE_ROOT = {
515 name: 'PettanR root',
516 type: FILE_TYPE.FOLDER,
519 FILE_DATA_COMICS_ROOT = {
521 type: FILE_TYPE.FOLDER,
524 json: pettanr.CONST.URL_COMICS_JSON
526 FILE_DATA_PANELS_ROOT = {
528 type: FILE_TYPE.FOLDER,
531 json: pettanr.CONST.URL_PANELS_JSON
533 FILE_DATA_RESOURCE_PICTURES_ROOT = {
535 type: FILE_TYPE.FOLDER,
538 json: pettanr.CONST.URL_RESOURCE_PICTURES_JSON
540 FILE_DATA_ORIGINAL_PICTURES_ROOT = {
542 type: FILE_TYPE.FOLDER,
546 FILE_DATA_MY_COMICS_ROOT = {
548 type: FILE_TYPE.FOLDER,
552 json: pettanr.CONST.URL_MY_COMICS_JSON
554 FILE_DATA_LATEST_COMICS = {
555 name: 'Latest Comics',
556 type: FILE_TYPE.FOLDER,
559 FILE_DATA_STORY_ROOT = {
561 type: FILE_TYPE.FOLDER,
565 FILE_DATA_LATEST_PANELS = {
566 name: 'Latest Panels',
567 type: FILE_TYPE.FOLDER,
570 FILE_DATA_MY_PANELS_ROOT = {
572 type: FILE_TYPE.FOLDER,
575 json: pettanr.CONST.URL_MY_PANELS_JSON
577 FILE_DATA_MY_RESOURCE_PICTURES_ROOT = {
579 type: FILE_TYPE.FOLDER,
582 // json: pettanr.CONST.URL_RESOURCE_PICTURES_JSON,
585 FILE_DATA_MY_ORIGINAL_PICTURES_ROOT = {
587 type: FILE_TYPE.FOLDER,
590 json: pettanr.CONST.URL_MY_ORIGINAL_PICTURES_JSON,
593 FILE_DATA_AUTHOR_ROOT = {
595 type: FILE_TYPE.FOLDER,
598 FILE_DATA_ARTIST_ROOT = {
600 type: FILE_TYPE.FOLDER,
603 FILE_DATA_LISENCE_ROOT = {
604 name: 'Lisence Root',
605 type: FILE_TYPE.FOLDER,
608 FILE_DATA_LISENCE = {
610 type: FILE_TYPE.FOLDER,
613 FILE_DATA_LISENCE_GROUP = {
614 name: 'Lisence Group',
615 type: FILE_TYPE.FOLDER,
618 FILE_DATA_BALLOON_ROOT = {
619 name: 'Balloon templetes',
620 type: FILE_TYPE.FOLDER,
623 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 );
624 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 );
625 FILE_DATA_PANELS_ROOT.children.push( FILE_DATA_LATEST_PANELS, FILE_DATA_MY_PANELS_ROOT );
626 FILE_DATA_RESOURCE_PICTURES_ROOT.children.push( FILE_DATA_MY_RESOURCE_PICTURES_ROOT, FILE_DATA_ARTIST_ROOT );
627 FILE_DATA_LISENCE_ROOT.children.push( FILE_DATA_LISENCE_GROUP, FILE_DATA_LISENCE );
628 FILE_DATA_ORIGINAL_PICTURES_ROOT.children.push( FILE_DATA_MY_ORIGINAL_PICTURES_ROOT );
630 FileAPI.createFolderUnderRoot( FILE_DATA_SERVICE_ROOT );
632 Driver.isPettanrFileInstance = function( file ){
633 if( FileAPI.isFileInstance( file ) === true ){
634 var _data = FileAPI.getFileData( file.getUID() );// file でなく file.getUID()
635 return _data !== null && _data.driver === Driver;
640 var Cabinet = gOS.registerApplication( function(){
650 this.bgColor = '#FFFFFF';
651 this.MIN_WIDTH = 500;
652 this.MIN_HEIGHT = 300;
653 this.onInit = function(){
654 self.rootElement.id = 'cabinet-root';
655 self.rootElement.innerHTML = [
656 '<div id="cabinet-header">',
657 '<div class="header-title">Cabinet</div>',
658 '<div id="cabinet-close-button">x</div>',
659 '<div id="cabinet-path" class="finder-path"></div>',
661 '<div id="cabinet-container" class="finder-container"></div>'
664 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
666 tree = FileAPI.createTree( FILE_DATA_SERVICE_ROOT );
667 eventRoot = self.getPointingDeviceEventTreeRoot();
671 this.onOpen = function( _w, _h ){
672 headerH = Util.getElementSize( document.getElementById( 'cabinet-header' ) ).height;
674 nodeClose = eventRoot.createNode( document.getElementById( 'cabinet-close-button' ), false, false, 'close-button-hover', 'pointer' );
675 nodeClose.addEventListener( 'click', Cabinet.shutdown );
676 nodePath = eventRoot.createNode( document.getElementById( 'cabinet-path' ), false, false );
677 nodeBody = eventRoot.createNode( document.getElementById( 'cabinet-container' ), false, true, null, '', true );
679 finder = self.createFinder( nodeBody, tree );
680 finder.createPath( nodePath );
681 self.onPaneResize( _w, _h );
683 this.onClose = function(){
686 finder = tree = null;
688 this.onPaneResize = function( w, h ){
690 nodeBody.update( 0, headerH, w, h - headerH );
691 finder.resize( w, h - headerH );
693 }, false, true, 'Cabinet', 'cabinet', null, '#1C1C1C' );
695 var Gallery = gOS.registerApplication( function(){
705 this.bgColor = '#FFFFFF';
706 this.MIN_WIDTH = 500;
707 this.MIN_HEIGHT = 300;
708 this.onInit = function(){
709 self.rootElement.id = 'gallery-root';
710 self.rootElement.innerHTML = [
711 '<div id="gallery-header">',
712 '<div class="header-title">Gallery</div>',
713 '<div id="gallery-close-button">x</div>',
714 '<div id="gallery-path" class="finder-path"></div>',
716 '<div id="gallery-container" class="finder-container"></div>'
719 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
721 tree = FileAPI.createTree( FILE_DATA_RESOURCE_PICTURES_ROOT );
722 var _root = tree.getRootFile(),
723 _myPic = _root.getChildFileAt( 0 ),
724 _pic = _root.getChildFileAt( 1 );
725 _myPic.getSeqentialFiles();
726 _pic.getSeqentialFiles();
730 eventRoot = self.getPointingDeviceEventTreeRoot();
732 this.onOpen = function( w, h ){
733 headerH = Util.getElementSize( document.getElementById( 'gallery-header' ) ).height;
735 nodeClose = eventRoot.createNode( document.getElementById( 'gallery-close-button' ), false, false, 'close-button-hover', 'pointer' );
736 nodeClose.addEventListener( 'click', Gallery.shutdown );
737 nodePath = eventRoot.createNode( document.getElementById( 'gallery-path' ), false, false );
738 nodeBody = eventRoot.createNode( document.getElementById( 'gallery-container' ), false, true, null, '', true );
740 finder = self.createFinder( nodeBody, tree );
741 finder.createPath( nodePath );
742 self.onPaneResize( w, h );
744 this.onClose = function(){
747 finder = tree = null;
749 this.onPaneResize = function( w, h ){
751 nodeBody.update( 0, headerH, w, h - headerH );
752 finder.resize( w, h - headerH );
754 }, false, true, 'Gallery', 'gallery', null, '#01A31C' );
756 var Backyard = gOS.registerApplication( function(){
759 this.bgColor = '#FFFFFF';
760 this.MIN_WIDTH = 500;
761 this.MIN_HEIGHT = 300;
762 this.onInit = function(){
764 this.onOpen = function( _w, _h, _option ){
766 this.onClose = function(){
768 this.onPaneResize = function( _w, _h){
770 }, false, false, 'Settings', 'settings', null, '#DDDDDD' );
772 if( pettanr.DEBUG === true){
773 var Debug = gOS.registerApplication( function(){
778 pettanR: pettanr.version,
779 ua: navigator.userAgent,
780 platform: navigator.platform,
781 appVersion: navigator.appVersion,
782 appCodeName: navigator.appCodeName,
783 appName: navigator.appName,
784 language: navigator.browserLanguage || navigator.language,
786 RenderingMode: UA.isStanderdMode === true ? 'Standerd' : 'Quirks'
789 data.version = UA.IE;
790 if( UA.ieVersion >= 8 ) data.RenderingVersion = UA.ieRenderingVersion;
791 data.browserType = UA.STANDALONE === true ? 'Standalone' : 'bundle';
792 if( UA.ieVersion < 9 ) {
801 this.bgColor = '#FFFFFF';
802 this.MIN_WIDTH = 500;
803 this.MIN_HEIGHT = 300;
804 this.onInit = function(){
805 self.rootElement.id = 'debug-root';
806 self.rootElement.innerHTML = '<dl id="useragent" class="dl-table clearfix"></dl>';
808 this.onOpen = function( _w, _h, _option ){
809 elmDl = document.getElementById( 'useragent' );
811 for( var key in data ){
812 elmDt = document.createElement( 'dt' );
813 elmDt.innerHTML = key;
814 elmDd = document.createElement( 'dd' );
815 elmDd.innerHTML = '' + data[ key];
816 if( !data[ key ] ) elmDd.style.color = 'red';
817 elmDl.appendChild( elmDt );
818 elmDl.appendChild( elmDd );
821 this.onClose = function(){
824 this.onPaneResize = function( _w, _h ){
827 }, false, true, 'Debug', 'debug', null, '#01A31C' );
830 /* ----------------------------------------
831 * Image Group Exproler
834 var PremiumSatge = gOS.registerApplication( function(){
835 var BASE_PATH = pettanr.CONST.RESOURCE_PICTURE_PATH,
836 THUMB_PATH = pettanr.CONST.THUMBNAIL_PATH,
837 LIMIT_FILESIZE = 1024 * 100,
843 elmContainer, elmIconOrigin, elmName, elmButton,
844 containerW, containerH,
845 itemW, itemH, buttonW,
848 onUpdateContext = null,
851 var ImageGroupIconClass = function( index, data ){
852 var elmIconWrap = elmIconOrigin.cloneNode( true ),
853 elmIconTitle = Util.getElementsByClassName( elmIconWrap, 'image-group-item-title' )[ 0 ],
854 originalPicture = data.original_picture || data,
855 SRC = [ BASE_PATH, data.id, '.', data.ext ].join( ''),
856 LOW_SRC = originalPicture.filesize && originalPicture.filesize > LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext ].join( '' ) : null,
857 reversibleImage = null,
861 elmContainer.appendChild( elmIconWrap );
862 elmIconWrap.style.left = ( index * itemW ) + 'px';
863 elmIconTitle.appendChild( document.createTextNode( originalPicture.filesize + 'bytes' ) );
865 function onImageLoad( url, _imgW, _imgH ){
866 data.width = _imgW = _imgW || originalPicture.width || 64;
867 data.height = _imgH = _imgH || originalPicture.height || 64;
868 elmIconTitle.firstChild.data = _imgW + 'x' + _imgH;
869 var zoom = 128 /( _imgW > _imgH ? _imgW : _imgH ),
870 MATH_FLOOR = Math.floor,
871 h = MATH_FLOOR( _imgH * zoom ),
872 w = MATH_FLOOR( _imgW * zoom );
873 reversibleImage.elm.style.cssText = [
876 'margin:', MATH_FLOOR( itemH / 2 - h / 2 ), 'px ', MATH_FLOOR( itemW / 2 - w / 2 ), 'px 0'
878 reversibleImage.resize( w, h );
879 self.addEventListener( elmIconWrap, 'click', onClick );
884 PremiumSatge.shutdown();
887 function asyncDraw(){
888 reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onImageLoad );
889 elmIconWrap.appendChild( reversibleImage.elm );
894 this.onEnter = function( delay ){
895 self.addTimer( asyncDraw, delay, true );
896 delete instance.onEnter;
898 this.destroy = function(){
899 delete instance.destroy;
900 // timer && window.clearTimeout( timer );
901 self.removeTimer( asyncDraw );
902 self.removeEventListener( elmIconWrap );
903 reversibleImage !== null && reversibleImage.destroy();
904 // Util.removeAllChildren( elmIconWrap );
905 // elmContainer.removeChild( elmIconWrap );
906 reversibleImage = elmIconWrap = elmIconTitle = data = timer = null;
910 function onEnterShowImage(){
911 var l = ICON_ARRAY.length,
912 _start = -wrapX /itemW -1,
913 _end = _start + winW /itemW +1,
915 for( var i=0, c = 0; i<l; ++i){
916 _icon = ICON_ARRAY[ i ];
917 if( _start < i && i < _end && _icon.onEnter ){
918 _icon.onEnter( c * 100 );
922 //onEnterInterval !== null && window.clearTimeout( onEnterInterval );
923 //onEnterInterval = null;
924 self.removeTimer( onEnterShowImage );
926 function clickClose(){
927 PremiumSatge.shutdown();
929 function onMouseWheel( e ){
930 if( winW < containerW ){
931 wrapX += e.wheelDelta / 2;
932 wrapX = wrapX > 0 ? 0 : wrapX < winW -containerW ? winW -containerW : wrapX;
933 elmContainer.style.left = wrapX + 'px';
935 self.removeTimer( onEnterShowImage );
936 self.addTimer( onEnterShowImage, 500 );
941 function drawIcons(){
942 while( ICON_ARRAY.length > 0 ){
943 ICON_ARRAY.shift().destroy();
945 var _index = rootFile.search( {
947 type : FILE_TYPE.ARTIST
949 _artistFile = rootFile.getChildFileAt( _index ),
951 if( _artistFile !== null ){
952 for( var i=0, l=_artistFile.getChildFileLength(); i<l; ++i ){
953 file = _artistFile.getChildFileAt( i );
954 ICON_ARRAY.push( new ImageGroupIconClass( i, FileAPI.getFileData( file ) ));
957 elmName.firstChild.data = _artistFile.getName();
958 _artistFile.destroy();
962 function onFadeout(){
963 while( ICON_ARRAY.length > 0 ){
964 ICON_ARRAY.shift().destroy();
966 onUpdate !== null && onUpdateData !== null && onUpdate.call( onUpdateContext, onUpdateData );
967 onUpdate = onUpdateData = onUpdateContext = null;
968 PremiumSatge.shutdown();
972 this.MIN_WIDTH = 320;
973 this.MIN_HEIGHT = 320;
974 this.onInit = function(){
975 self.rootElement.id = 'image-group-wrapper';
977 self.rootElement.innerHTML = [
978 '<div id="image-group-icon-container"></div>',
979 '<div id="image-group-name">NO DATA...</div>',
980 '<div id="image-group-button" class="button">close</div>'
983 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
985 tree = FileAPI.createTree( FILE_DATA_ARTIST_ROOT );
986 rootFile = tree.getRootFile();
988 this.onOpen = function( _windowW, _windowH, _ARTISTIDorFILE, _onUpdate, opt_thisObj ){
989 elmContainer = document.getElementById( 'image-group-icon-container' );
990 containerH = Util.getElementSize( elmContainer ).height;
992 elmIconOrigin = ( function(){
993 var ret = document.createElement( 'div' ),
994 data = document.createElement( 'div' );
995 ret.appendChild( data );
996 ret.className = 'image-group-item';
997 data.className = 'image-group-item-title';
1001 var size = Util.getElementSize( elmIconOrigin );
1003 itemH = size.height;
1005 elmName = document.getElementById( 'image-group-name' );
1006 elmButton = document.getElementById( 'image-group-button' );
1008 buttonW = Util.getElementSize( elmButton ).width;
1010 self.addEventListener( elmContainer, 'mousewheel', onMouseWheel );
1011 self.addEventListener( elmButton, 'click', clickClose );
1012 tree.addTreeEventListener( Const.TREE.EVENT.UPDATE, drawIcons );
1014 var data = FileAPI.getFileData( _ARTISTIDorFILE );
1016 artistID = MyArtistID || -1;
1018 if( data.type === FILE_TYPE.ARTIST || FILE_DATA_MY_ORIGINAL_PICTURES_ROOT === data ){
1019 artistID = data.id || -1;
1021 if( Type.isNumber( _ARTISTIDorFILE ) === true ){
1022 artistID = _ARTISTIDorFILE;
1025 onUpdate = _onUpdate || null;
1026 onUpdateContext = opt_thisObj || null;
1027 onUpdateData = null;
1032 containerW = ICON_ARRAY.length * itemW;
1036 var w = winW > containerW ? winW : containerW,
1037 h = _windowH > containerH ? containerH : _windowH,
1038 MATH_FLOOR = Math.floor;
1040 $( elmContainer ).css( {
1044 top: MATH_FLOOR( _windowH /2 )
1045 }).stop().animate( {
1047 top: MATH_FLOOR( _windowH /2 - h /2 )
1048 }, onEnterShowImage );
1050 elmButton.style.cssText = [
1051 'left:', MATH_FLOOR( _windowW /2 - buttonW /2 ), 'px;',
1052 'top:', MATH_FLOOR( _windowH /2 + containerH /2 +10 ), 'px'
1055 this.onPaneResize = function( _windowW, _windowH ){
1056 var w = _windowW > containerW ? _windowW : containerW,
1057 h = _windowH > containerH ? containerH : _windowH,
1058 MATH_FLOOR = Math.floor,
1059 offsetW = MATH_FLOOR( _windowW /2 -winW /2 );
1063 if( offsetW <= 0 ){ // smaller
1064 $( elmContainer ).stop().css( {
1069 top: MATH_FLOOR( _windowH /2 -h /2 )
1072 $( elmContainer ).stop().css( { // bigger
1075 borderLeftWidth: offsetW
1077 top: MATH_FLOOR( _windowH /2 -h /2 ),
1081 elmButton.style.cssText = [
1082 'left:', MATH_FLOOR( _windowW /2 -buttonW /2 ), 'px;',
1083 'top:', MATH_FLOOR( _windowH /2 +containerH /2 + 10 ), 'px'
1087 this.onClose = function(){
1088 if( tree === null ) return true;
1089 $( elmContainer ).stop().animate( {
1091 top: Math.floor( winH / 2 )
1093 // onEnterInterval !== null && window.clearTimeout( onEnterInterval );
1094 // onEnterInterval = null;
1097 tree.removeTreeEventListener( Const.TREE.EVENT.UPDATE, drawIcons );
1099 tree = rootFile = null;
1103 }, true, true, 'Premium Stage', 'premiumStage', null, '#C3325F' );
1106 /* ----------------------------------------
1110 var TextEditor = gOS.registerApplication( function(){
1111 var elmTextarea, elmButton,
1112 textElement, onUpdate,
1118 textElement && textElement.text( elmTextarea.value );
1119 self.addAsyncCall( asyncCallback );
1122 function asyncCallback(){
1123 onUpdate && onUpdate( textElement );
1124 onUpdate = textElement = null;
1125 TextEditor.shutdown();
1129 function textareaFitHeight(){
1131 while( elmTextarea.offsetHeight < textElement.h ){
1133 elmTextarea.rows = rows;
1135 if( rows > 1 ) elmTextarea.rows = --rows;
1140 this.MIN_WIDTH = 320;
1141 this.MIN_HEIGHT = 320;
1142 this.onInit = function(){
1143 self.rootElement.id = 'speach-editor-wrapper';
1144 self.rootElement.innerHTML = '<textarea id="speach-editor"></textarea><div id="speach-edit-complete-button" class="button">OK</div>';
1146 this.onOpen = function( _w, _h, _panelX, _panelY, _textElement, _onUpdate ){
1147 elmTextarea = document.getElementById( 'speach-editor' );
1148 elmButton = document.getElementById( 'speach-edit-complete-button' );
1150 self.addKeyEventListener( 'keydown', new Function( 'return false' ), 69, false, true );
1151 self.addEventListener( elmButton, 'click', clickOK );
1155 textElement = _textElement;
1156 onUpdate = _onUpdate || null;
1158 self.onPaneResize( _w, _h );
1159 elmTextarea.value = _textElement.content;
1160 elmTextarea.focus();
1163 * ie6,7は、textarea { width:100%}でも高さが変わらない。rowsを設定。
1165 UA.isIE === true && UA.ieVersion <= 7 && self.addAsyncCall( textareaFitHeight );
1167 this.onPaneResize = function( _w, _h ){
1168 self.rootElement.style.cssText = [
1169 'left:', textElement.x + panelX, 'px;',
1170 'top:', textElement.y + panelY, 'px;',
1171 'width:', textElement.w, 'px;',
1172 'height:', textElement.h, 'px;'
1175 this.onClose = function(){
1176 self.removeKeyEventListener();
1177 self.removeEventListener( elmButton );
1179 elmTextarea = elmButton = onUpdate = textElement = self = null;
1181 }, true, false, 'Tetxt Editor', 'texteditor', null, '#DDDDDD' );
1184 var Reader = gOS.registerApplication( function(){
1185 var windowW, windowH,
1189 elmContainer, elmTitle, elmAuthor, elmBackButton, elmNextButton,
1193 currentPanel = null,
1198 function onBackClick(){
1199 currentIndex -= ( currentIndex > 0 ? 1 : 0 );
1203 function onNextClick(){
1204 currentIndex += ( currentIndex < numPanel - 1 ? 1 : 0 );
1209 var elm = elmContainer.childNodes[ currentIndex ],
1210 h = windowH - headerH - consoleH,
1213 top = headerH - elm.offsetTop + Math.floor( ( h - elm.offsetHeight ) / 2 );
1216 $( elmContainer ).stop().animate( {
1220 function getCurrentTopPosition(){
1224 var fileData, title, author, story;
1226 if( Driver.isPettanrFileInstance( currentFile ) === true ){
1227 switch( currentFile.getType() ){
1228 case FILE_TYPE.COMIC :
1229 fileData = currentFile.read();
1230 title = fileData.title;
1231 author = fileData.author.name;
1232 comicData = fileData;
1233 numPanel = currentFile.getChildFileLength();
1235 case FILE_TYPE.STORY :
1236 story = currentFile.read();
1237 fileData = story.panel;
1238 title = story.comic.title;
1239 author = fileData.author.name;
1240 comicData = fileData;
1243 case FILE_TYPE.PANEL :
1244 fileData = currentFile.read();
1246 author = fileData.author.name;
1247 comicData = fileData;
1254 if( comicData !== null ){
1255 elmTitle.data = title;
1256 elmAuthor.data = author;
1257 // bindWorker.json( comicData );
1258 bindWorker.file( currentFile );
1259 self.addAsyncCall( asyncResize );
1262 function asyncResize(){
1263 self.onPaneResize( windowW, windowH );
1268 this.MIN_WIDTH = 320;
1269 this.MIN_HEIGHT = 320;
1270 this.onInit = function(){
1271 self.rootElement.id = 'comic-reader-wrapper';
1272 self.rootElement.innerHTML = [
1273 '<div id="comic-reader-panel-container"></div>',
1274 '<div class="comic-reader-shadow" style="top:0;height:40px;"></div>',
1275 '<div id="comic-reader-header">',
1276 '<div id="comic-reader-header-content">',
1277 '<span id="comic-reader-title">NO DATA...</span>',
1278 '<span id="comic-reader-author">NO DATA...</span>',
1281 '<div class="comic-reader-shadow" style="bottom:0;height:100px;"></div>',
1282 '<div id="comic-reader-console">',
1283 '<div id="comic-reader-button-centering">',
1284 '<a href="#" id="comic-reader-back-button">▲</da>',
1285 '<a href="#" id="comic-reader-forward-button">▼</a>',
1290 self.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
1293 this.onOpen = function( _w, _h, file ){
1294 headerH = Util.getElementSize( document.getElementById( 'comic-reader-header' ) ).height;
1295 consoleH = Util.getElementSize( document.getElementById( 'comic-reader-console' ) ).height;
1296 elmContainer = document.getElementById( 'comic-reader-panel-container' );
1297 elmTitle = document.getElementById( 'comic-reader-title' ).firstChild;
1298 elmAuthor = document.getElementById( 'comic-reader-author' ).firstChild;
1299 elmBackButton = document.getElementById( 'comic-reader-back-button' );
1300 elmNextButton = document.getElementById( 'comic-reader-forward-button' );
1302 bindWorker = pettanr.bind.createBindWorker( elmContainer, null, false, false );
1304 self.addEventListener( elmBackButton, 'click', onBackClick );
1305 self.addEventListener( elmNextButton, 'click', onNextClick );
1307 numPanel = currentIndex = 0;
1309 elmContainer.style.cssText = 'left:' + ( _w / 2 ) + 'px;' + 'top:' + _h + 'px;';
1313 if( FileAPI.isFileInstance( file ) === true ){
1315 file.addEventListener( Const.FILE.EVENT.GET_SEQENTIAL_FILES, draw );
1316 file.getSeqentialFiles();
1320 this.onPaneResize = function( _windowW, _windowH ){
1323 var panelH = elmContainer.offsetHeight,
1324 panelW = elmContainer.offsetWidth,
1325 h = _windowH - headerH - consoleH;
1326 $( elmContainer ).stop().animate(
1328 left: Math.floor( ( _windowW - panelW ) / 2 ),
1329 top: headerH + ( panelH < h ? Math.floor( ( h - panelH ) / 2 ) : 0 )
1333 this.onClose = function(){
1334 self.removeEventListener( elmBackButton );
1335 self.removeEventListener( elmNextButton );
1337 bindWorker.destroy();
1340 currentFile && currentFile.removeEventListener( Const.FILE.EVENT.GET_SEQENTIAL_FILES, draw );
1341 currentFile = comicData = currentPanel = null;
1343 elmContainer = elmTitle = elmAuthor = elmBackButton = elmNextButton = null;
1345 }, true, true, 'Comic Reader', 'comicreader', null, '#01A31C' );
1348 var Editor = gOS.registerApplication( function(){
1350 var PANEL_ELEMENT_TYPE_IMAGE = 0,
1351 PANEL_ELEMENT_TYPE_TEXT = 1,
1353 PANEL_ELEMENT_ARRAY = [],
1354 MIN_PANEL_HEIGHT = 20,
1355 MIN_ELEMENT_SIZE = 19,
1356 MOUSE_HIT_AREA = 10,
1366 var kill = function(){
1369 if( o.hasOwnProperty && !o.hasOwnProperty( p ) ) continue;
1374 /* ----------------------------------------
1376 * - mouseEventListener
1387 var MENU_BAR_CONTROL = ( function(){
1388 var ELM_ITEM_CLASSNAME = 'menubar-item',
1391 nodeBar, nodeBox, layerBox,
1393 /** -----------------------------------------
1394 * PrivateOptionDataClass
1396 var PrivateOptionDataClass = function( menuData, option, title, shortcut, callback, visible, separateAfter, thisObject ){
1397 this.menuData = menuData;
1398 this.option = option;
1400 this.shortcut = shortcut || '';
1401 this.callback = callback;
1402 this.thisObject = thisObject;
1403 this.visible = visible;
1404 this.separateAfter = separateAfter;
1406 PrivateOptionDataClass.prototype = {
1411 visible : undefined,
1417 separateAfter : false,
1418 show : function( elm ){
1419 if( this.elm === elm ) return;
1421 elm = document.createElement( 'div' );
1422 elmBox.appendChild( elm );
1423 elm.appendChild( document.createElement( 'span' ) );
1424 elm.appendChild( document.createElement( 'kbd' ) );
1427 this.option.title( this.title );
1428 this.option.visible( !!this.visible );
1429 elm.lastChild.innerHTML = this.shortcut;
1430 elm.style.borderStyle = this.border === true ? 'solid' : 'none';
1432 this.node = nodeBox.createNode( elm, false, true, 'menubar-option-hover', 'pointer' );
1433 this.node.disabled( !this.visible );
1441 this.callback.call( this.thisObject || this.option, Util.getIndex( this.menuData.optionDataList, this ) );
1443 remove : function(){
1444 var list = PrivateOptionDataClass.list;
1445 list.splice( Util.getIndex( list, this ), 1 );
1448 PrivateOptionDataClass.list = [];
1449 PrivateOptionDataClass.get = function( OptionOrElm ){
1450 var list = PrivateOptionDataClass.list,
1455 if( data.option === OptionOrElm || data.elm === OptionOrElm ) return data;
1460 /** -----------------------------------------
1463 var OptionClass = function( menuData, title, shortcut, callback, visible, separateAfter, thisObject ){
1464 PrivateOptionDataClass.list.push( new PrivateOptionDataClass( menuData, this, title, shortcut, callback, visible, separateAfter, thisObject ) );
1466 OptionClass.prototype = {
1467 title: function( v ){
1468 var data = PrivateOptionDataClass.get( this );
1469 if( Type.isString( v ) === true ){
1471 if( data.elm ) data.elm.firstChild.innerHTML = v;
1475 visible : function( v ){
1476 var data = PrivateOptionDataClass.get( this );
1477 if( Type.isBoolean( v ) === true ){
1479 data.elm && Util.toggleClass( data.elm, 'menubar-option-disabled', !v );
1481 return data.visible;
1484 /** -----------------------------------------
1487 var AsyncOptionClass = function( menuData, callback, visible, separateAfter, thisObject ){
1488 var data = new PrivateOptionDataClass( menuData, this, null, null, callback, visible, separateAfter, thisObject );
1489 data.show = AsyncOptionClass.show;
1490 data.hide = AsyncOptionClass.hide;
1491 PrivateOptionDataClass.list.push( data );
1493 AsyncOptionClass.prototype = {
1494 title : function(){},
1495 visible : OptionClass.prototype.visible
1497 AsyncOptionClass.show = function( elm ){
1498 if( this.elm === elm ) return;
1500 elm = document.createElement( 'div' );
1501 elmBox.appendChild( elm );
1502 elm.appendChild( document.createElement( 'span' ) );
1503 elm.appendChild( document.createElement( 'kbd' ) );
1506 elm.className = 'loading';
1507 elm.style.height = '90px';
1508 elm.firstChild.innerHTML = this.elm.lastChild.innerHTML = '';
1509 elm.style.borderStyle = this.border === true ? 'solid' : 'none';
1513 AsyncOptionClass.hide = function(){
1514 this.elm.className = '';
1515 this.elm.style.height = '';
1519 /** -----------------------------------------
1520 * MenuPrivateDataClass
1522 var MenuPrivateDataClass = function( menu, title ){
1524 this.elm = document.createElement( 'div' );
1525 this.optionDataList = [];
1527 elmBar.appendChild( this.elm );
1528 this.elm.className = ELM_ITEM_CLASSNAME;
1529 this.elm.innerHTML = title;
1531 MenuPrivateDataClass.prototype = {
1538 optionDataList : null,
1540 this.elm.style.left = ( menuW * Util.getIndex( MenuPrivateDataClass.list, this ) ) + 'px';
1541 this.node = nodeBar.createNode( this.elm, false, false, ELM_ITEM_CLASSNAME + '-hover', 'pointer' );
1542 // this.node.addEventListener( 'click', this.onClick, this );
1543 this.node.addEventListener( 'click', this.onClick, this );
1547 while( o = this.optionDataList.shift() ) o.remove();
1551 onClick : function( e ){
1552 if( currentMenu !== this.menu ){
1553 currentMenu && currentMenu.hide();
1554 currentMenu = this.menu;
1558 onOptionClick : function( e ){
1559 var target = e.target,
1560 i = target.nodeIndex(),
1561 option = this.optionDataList[ i ];
1562 if( target === nodeBox ) return true;
1566 MenuPrivateDataClass.list = [];
1567 MenuPrivateDataClass.get = function( menu ){
1568 var list = MenuPrivateDataClass.list,
1571 if( list[ --i ].menu === menu ) return list[ i ];
1576 /** -----------------------------------------
1579 var MenuClass = function( title ){
1580 MenuPrivateDataClass.list.push( new MenuPrivateDataClass( this, title ) );
1582 MenuClass.prototype = {
1584 var data = MenuPrivateDataClass.get( this );
1585 if( data.visible === true ) return;
1587 data.elm.className = ELM_ITEM_CLASSNAME + '-focus';
1590 elmBox = document.createElement( 'div' );
1591 elmBar.appendChild( elmBox );
1592 elmBox.className = 'menubar-option-box';
1593 nodeBox = nodeBar.createNode( elmBox, false, false, 'menubar-option-box-hover' );
1595 nodeBox.disabled( false );
1596 elmBar.parentNode.insertBefore( elmBox, elmBar.nextSibling ); // ie6 では elmBar の 子にすると 選択肢が表示されない
1598 nodeBox.setPosition( data.node.x(), barH );
1601 children = elmBox.childNodes,
1602 list = data.optionDataList
1604 while( l < children.length ){
1605 elmBox.removeChild( elmBox.firstChild );
1607 for( i = 0; i < l; ++i ){
1608 list[ i ].show( children[ i ] );
1612 nodeBar.addEventListener( 'mouseout', this.hide, this );
1613 nodeBox.addEventListener( 'click', data.onOptionClick, data );
1614 data.visible = true;
1617 data = MenuPrivateDataClass.get( this );
1618 if( data.visible === false ) return;
1620 data.elm.className = ELM_ITEM_CLASSNAME;
1621 for( var i = data.optionDataList.length; i; ){
1622 data.optionDataList[ --i ].hide();
1624 elmBar.parentNode.removeChild( elmBox );
1625 nodeBox.disabled( true );
1627 nodeBar.removeEventListener( 'mouseout', this.hide );
1628 nodeBox.removeEventListener( 'click', data.onOptionClick );
1629 data.visible = false;
1632 createOption: function( title, shortcut, callback, visible, separateBefore, separateAfter, thisObject ){
1633 var data = MenuPrivateDataClass.get( this ),
1634 before = data.optionDataList[ data.optionDataList.length - 1 ],
1635 ret = new OptionClass( data, title, shortcut, callback, visible, separateAfter, thisObject ),
1636 dataOption = PrivateOptionDataClass.get( ret );
1637 if( before ) before.border = separateBefore === true || before.separateAfter === true;
1638 data.optionDataList.push( dataOption );
1639 if( data.visible === true ){
1645 createAsyncOption: function( onOpen, visible, separateBefore, separateAfter, thisObject ){
1646 var data = MenuPrivateDataClass.get( this ),
1647 before = data.optionDataList[ data.optionDataList.length -1 ],
1648 ret = new AsyncOptionClass( data, onOpen, visible, separateAfter, thisObject ),
1649 dataOption = PrivateOptionDataClass.get( ret );
1650 if( before ) before.border = separateBefore === true || before.separateAfter === true;
1651 data.optionDataList.push( dataOption );
1652 data.visible === true && dataOption.show();
1655 remove : function( option ){
1656 var data = MenuPrivateDataClass.get( this ),
1657 optionData = PrivateOptionDataClass.get( option ),
1658 i = Util.getIndex( data.optionDataList, optionData );
1659 if( i === -1 ) return;
1661 data.optionDataList.splice( i, 1 );
1663 data.visible === true && elmBox.removeChild( optionData.elm ) && optionData.hide();
1664 optionData.remove();
1666 !( option instanceof AsyncOptionClass ) && data.optionDataList.length === 0 && this.hide();
1671 id : 'MENU_BAR_CONTROL',
1674 elmBar = document.getElementById( 'menu-bar' );
1675 nodeBar = eventRoot.createNode( elmBar, false, false, 'menu-bar-hover' );
1677 MENU_BAR_CONTROL.QUIT = MENU_BAR_CONTROL.createItem( 'Quit' );
1678 MENU_BAR_CONTROL.EDIT = MENU_BAR_CONTROL.createItem( 'Edit' );
1679 MENU_BAR_CONTROL.WINDOW = MENU_BAR_CONTROL.createItem( 'Window' );
1680 MENU_BAR_CONTROL.HELP = MENU_BAR_CONTROL.createItem( 'Help' );
1682 var size = Util.getElementSize( MenuPrivateDataClass.list[ 0 ].elm );
1684 barH = MENU_BAR_CONTROL.h = size.height;
1686 elmBar.style.top = ( - barH ) + 'px';
1687 $( elmBar ).animate( { top: 0 } );
1689 delete MENU_BAR_CONTROL.init;
1692 for( var i = MenuPrivateDataClass.list.length; i; ) MenuPrivateDataClass.list[ --i ].open();
1693 delete MENU_BAR_CONTROL.open;
1697 while( data = MenuPrivateDataClass.list.shift() ) data.close();
1699 MenuPrivateDataClass.list = elmBar = layerBox = elmBox = null;
1700 MENU_BAR_CONTROL.kill = kill;
1701 MENU_BAR_CONTROL.kill();
1703 createItem : function( title ){
1704 return new MenuClass( title );
1706 busy : function( _busy ){
1709 onWindowResize: function( _windowW, _windowH ){
1720 /* ----------------------------------------
1724 var HISTORY_CONTROL = ( function() {
1732 * currentを控えてstackForward.push(current)
1733 * stackBack.pop()を実行してcurrentに
1735 if( stackBack.length === 0 ) return;
1737 var s = stackBack.pop();
1738 s.callback.apply( s.thisObj || {}, s.argBack );
1739 menubarBack.visible( stackBack.length !== 0 );
1740 SAVE_CONTROL.panelUpdated( stackBack.length !== 0 );
1742 stackForward.push( s );
1743 menubarForward.visible( true );
1746 if( stackForward.length === 0 ) return;
1748 var s = stackForward.pop();
1749 s.callback.apply( s.thisObj || {}, s.argForword );
1750 menubarForward.visible( stackForward.length !== 0 );
1752 stackBack.push( s );
1753 menubarBack.visible( true );
1754 SAVE_CONTROL.panelUpdated( true );
1756 var RecordClass = function( callback, argBack, argForword, destroy, opt_thisObject ){
1757 this.callback = callback;
1758 this.argBack = argBack;
1759 this.argForword = argForword;
1760 this.destroy = !!destroy;
1761 this.thisObj = opt_thisObject;
1763 RecordClass.prototype.kill = function( _callDestroy ){
1764 var _argBack = this.argBack,
1765 _argForword = this.argForword,
1770 if( _callDestroy !== true ) return;
1772 if( Type.isArray( _argBack ) === true ){ // isArray
1773 while( v = _argBack.shift() ){
1774 _callDestroy === true && Type.isFunction( v.destroy ) === true && v.destroy();
1777 if( Type.isArray( _argForword ) === true ){
1778 while( v = _argForword.shift() ){
1779 _callDestroy === true && Type.isFunction( v.destroy ) === true && v.destroy();
1785 app.addKeyEventListener( 'keydown', back, 90, false, true ); // ctrl + Z
1786 app.addKeyEventListener( 'keydown', forward, 90, true, true ); // ctrl + shift + Z
1787 app.addKeyEventListener( 'keydown', forward, 89, false, true ); // ctrl + Y
1789 delete HISTORY_CONTROL.init;
1792 menubarBack = MENU_BAR_CONTROL.EDIT.createOption( 'back', 'ctrl + z', back, false );
1793 menubarForward = MENU_BAR_CONTROL.EDIT.createOption( 'forward', 'ctrl + y', forward, false, false, true );
1795 delete HISTORY_CONTROL.open;
1799 while( s = stackBack.shift() ) s.kill( true );
1800 while( s = stackForward.shift() ) s.kill( true );
1801 menubarBack = menubarForward = stackBack = stackForward = null;
1803 saveState: function( _function, _argBack, _argForword, _onRecordDestroy, opt_thisObject ){
1804 stackBack.push( new RecordClass( _function, _argBack, _argForword, _onRecordDestroy, opt_thisObject ));
1805 menubarBack.visible( true );
1806 SAVE_CONTROL.panelUpdated( true );
1809 while( s = stackForward.shift() ) s.kill( s.destroy );
1810 menubarForward.visible( false );
1815 /* ----------------------------------------
1819 var SAVE_CONTROL = ( function(){
1820 var save, saveQuit, eXport, quit,
1827 PanelConsole.boot( Model.createPanel( {
1830 panelTimming : panelTimming,
1831 panelW : PANEL_CONTROL.w,
1832 panelH : PANEL_CONTROL.h,
1834 panelElementArray : PANEL_ELEMENT_ARRAY,
1838 function onSaveQuit(){
1839 // Editor.shutdown();
1842 function onExport(){
1844 comicID, panelID, panelTimming,
1845 PANEL_CONTROL.w, PANEL_CONTROL.h,
1846 2, // border, BackgroundImage
1852 delete SAVE_CONTROL.init;
1855 save = MENU_BAR_CONTROL.QUIT.createOption( 'save', 'ctrl + S', onSave, false );
1856 saveQuit = MENU_BAR_CONTROL.QUIT.createOption( 'save & quit', null, onSaveQuit, false, false, true );
1857 eXport = MENU_BAR_CONTROL.QUIT.createOption( 'export', null, onExport, true, false, true );
1858 quit = MENU_BAR_CONTROL.QUIT.createOption( 'quit', null, quit, true, true );
1860 delete SAVE_CONTROL.open;
1863 save = saveQuit = eXport = quit = null;
1864 SAVE_CONTROL.kill = kill;
1865 SAVE_CONTROL.kill();
1868 panelUpdated: function( _updated ){
1869 if( Type.isBoolean( _updated ) === true ){
1870 save.visible( _updated );
1871 saveQuit.visible( _updated );
1882 /* ----------------------------------------
1885 * - mouseEventListener
1887 var WINDOWS_CONTROL = ( function(){
1889 * 表示上手前にあるwindowは、WINDOW_DATA_LISTの先頭にあり、htmlでは後ろにある。
1891 var DEFAULT_MIN_WINDOW_WIDTH = 200,
1892 DEFAULT_MIN_WINDOW_HEIGHT = 200,
1893 WINDOW_DATA_LIST = [],
1894 WINDOW_BODY_BODER_SIZE = 1,
1903 var WindowPrivateData = function(){};
1904 WindowPrivateData.prototype = {
1906 menubarOption : null,
1934 init : function( win, bodyTempleteID, title, x, y, w, h, visible, closeEnabled, resizeEnabled, minWindowW, minWindowH ){
1936 this.bodyTempleteID = bodyTempleteID;
1942 this.visible = visible;
1943 this.closeEnabled = closeEnabled;
1944 this.resizeEnabled = resizeEnabled;
1945 this.minWindowW = minWindowW;
1946 this.minWindowH = minWindowH;
1948 WINDOW_DATA_LIST.push( this );
1950 create : function(){
1951 var win = this.window;
1952 this.elm = win.elm = elmWindowOrigin.cloneNode( true );
1953 this.menubarOption = MENU_BAR_CONTROL.WINDOW.createOption(
1954 ( this.visible !== true ? 'show ' : 'hide ' ) + this.title,
1955 null, this.onMenubarClick,
1964 onMenubarClick : function(){
1965 this.window[ this.visible === true ? 'close' : 'open' ]();
1967 update : function( x, y, w, h ){
1968 var win = this.window, bodyH;
1970 x = x !== undefined ? x : this.x;
1971 y = y !== undefined ? y : this.y;
1972 y = y > MENU_BAR_CONTROL.h ? y : MENU_BAR_CONTROL.h;
1973 w = w !== undefined ? w : this.w;
1974 h = h !== undefined ? h : this.h;
1976 this.nodeWindow.update( x, y, w, h );
1977 this.nodeHead && this.nodeHead.update( 0, 0, w, this.headerH );
1978 console.log( '************ hewader' + this.headerH )
1979 this.nodeBody.update( 0, this.headerH, w, this.bodyH = h - this.headerH - this.footerH );
1980 ( this.w !== w || this.h !== h ) && win.onResize && win.onResize( w, this.bodyH );
1987 firstOpen : function(){
1988 var win = this.window,
1989 elmHead = this.elmHead = Util.getElementsByClassName( this.elm, 'window-header' )[ 0 ],
1990 elmBody = this.elmBody = Util.getElementsByClassName( this.elm, 'window-body' )[ 0 ],
1991 elmClose = Util.getElementsByClassName( this.elm, 'window-close-button' )[ 0 ],
1992 elmFoot = Util.getElementsByClassName( this.elm, 'window-footer' )[ 0 ],
1993 elmResize = Util.getElementsByClassName( this.elm, 'window-resize-button' )[ 0 ],
1994 replaceID = this.bodyTempleteID;
1996 this.nodeWindow = nodeContainer.createNode( this.elm, false, true, 'window-wrapper-hover' );
1997 this.nodeWindow.addEventListener( 'mousemove', this.mousemove, this );
1998 this.nodeWindow.addEventListener( 'mousedown', this.mousedown, this );
1999 this.nodeWindow.addEventListener( 'mouseup', this.mouseup, this );
2000 this.nodeWindow.addEventListener( 'mouseout', this.mouseup, this );
2002 // this.nodeHead = this.nodeWindow.createNode( elmHead );
2003 win.title( this.title );
2005 this.nodeBody = this.nodeWindow.createNode( elmBody, false, true, null, '', true );
2006 replaceID && elmBody.appendChild( document.getElementById( replaceID ) );
2008 if( this.closeEnabled === true ){
2009 // this.nodeClose = this.nodeHead.createNode( elmClose );
2010 // this.nodeClose.addEventListener( 'mousedown', win.close, data );
2012 elmClose.parentNode.removeChild( elmClose );
2015 if( this.resizeEnabled === true ){
2016 // this.nodeFoot = this.nodeWindow.createNode( elmFoot );
2017 this.footerH = Util.getElementSize( elmFoot ).height; // this.nodeFoot.height();
2019 // this.nodeResize = this.nodeFoot.createNode( elmResize );
2020 // this.nodeResize.addEventListener( 'mousedrag', this.resizeDrag, data );
2022 elmFoot.parentNode.removeChild( elmFoot );
2025 this.update( this.x, this.y, this.w, this.h );
2026 if( win.onFirstOpen ){
2027 win.onFirstOpen( this.w, this.bodyH, this.nodeBody );
2028 delete win.onFirtOpen;
2031 this.firstOpen = null;
2033 onFadeIn : function(){
2034 var data = WindowPrivateData.get( this ),
2036 data.firstOpen && data.firstOpen();
2037 win.onOpen && win.onOpen( data.w, data.bodyH );
2038 data.nodeWindow.disabled( false );
2041 onFadeOut : function(){
2042 var data = WindowPrivateData.get( this ),
2044 elmRoot.removeChild( data.elm );
2045 win.onClose && app.addAsyncCall( win.onClose, null, win );
2047 mousedown : function( e ){
2048 currentWindowData !== this && this.goFront();
2052 if( this.resizeEnabled === true && this.w - 20 <= x && x < this.w && this.headerH + this.bodyH < y && y <= this.h ){
2053 this.isResizing = true;
2054 //this.startX = this.x;
2055 //this.startY = this.y;
2056 this.startW = this.w;
2057 this.startH = this.h;
2060 // app.updateCoursor( 'nw-resize' );
2061 this.nodeWindow.cursor( 'nw-resize' );
2065 // if( x < 0 || y < 0 || this.w < x || this.headerH < y ) return false;
2066 if( this.closeEnabled === true && this.w - closeButtonWidth < x && y < this.headerH ){
2067 this.window.close();
2071 if( y < this.headerH ){
2072 this.isDragging = true;
2073 this.startX = this.x;
2074 this.startY = this.y;
2075 this.startW = this.w;
2076 this.startH = this.h;
2080 // app.updateCoursor( 'move' );
2081 this.nodeWindow.cursor( 'move' );
2085 mouseup : function( e ){
2086 if( this.isResizing === true || this.isDragging === true ){
2087 this.isDragging = this.isResizing = false;
2090 this.nodeWindow.cursor( '' );
2092 mousemove : function( e ){
2093 currentWindowData !== this && this.goFront();
2098 if( this.isResizing === true ){
2099 w = this.startW + x - this.offsetX;
2100 h = this.startH + y - this.offsetY;
2101 this.w = w = w < this.minWindowW ? this.minWindowW : w;
2102 this.h = h = h < this.minWindowH ? this.minWindowH : h;
2103 this.elm.style.width = w + 'px';
2104 this.elm.style.height = h + 'px';
2107 if( this.isDragging === true ){
2108 this.x = x = this.startX + x - this.offsetX;
2109 this.y = y = this.startY + y - this.offsetY;
2110 this.elm.style.left = x + 'px';
2111 this.elm.style.top = y + 'px';
2114 // if( e.hit === false || ( this.headerH < layerY && layerY < this.headerH + this.bodyH ) ) return false;
2115 this.nodeWindow.cursor( ( /*0 < layerX && layerX < this.w && 0 <= layerY &&*/ y <= this.headerH ) ? 'pointer' : '' );
2117 goFront : function(){
2118 currentWindowData = this;
2119 var i = nodeContainer.numNode() - 1;
2120 // console.log( this.nodeWindow.nodeIndex() + ' , ' + this.nodeWindow.numNode() )
2121 if( this.nodeWindow.nodeIndex() !== i ){
2122 this.nodeWindow.nodeIndex( i );
2123 elmRoot.appendChild( this.elm );
2127 return this.isDragging === true || this.isResizing === true;
2129 destroy : function(){
2133 WindowPrivateData.get = function( windowOrElement ){
2134 if( windowOrElement instanceof WindowPrivateData ) return windowOrElement;
2135 var list = WINDOW_DATA_LIST,
2140 if( data.window === windowOrElement || data.elm === windowOrElement ) return data;
2148 var WindowClass = function( bodyTempleteID, title, x, y, w, h, visible, closeEnabled, resizeEnabled, minWindowW, minWindowH ){
2149 ( new WindowPrivateData() ).init( this, bodyTempleteID, title, x, y, w, h, visible, closeEnabled, resizeEnabled, minWindowW, minWindowH );
2151 WindowClass.prototype = {
2154 var data = WindowPrivateData.get( this );
2155 if( data.visible === true ) return;
2157 data.visible = true;
2159 data.menubarOption.title( 'hide ' + data.title );
2161 // WINDOW_DATA_LIST.splice( Util.getIndex( WINDOW_DATA_LIST, data ), 1 );
2162 // WINDOW_DATA_LIST.unshift( data );
2163 currentWindowData = null;
2166 var data = WindowPrivateData.get( this );
2167 if( data.visible === false ) return;
2169 data.visible = false;
2170 $( data.elm ).fadeOut( data.onFadeOut );
2171 data.menubarOption.title( 'show ' + data.title );
2172 data.nodeWindow.disabled( true );
2174 title : function( _title ){
2175 if( Type.isString( _title ) === true ){
2176 var data = WindowPrivateData.get( this );
2177 data.elmHead.firstChild.innerHTML = data.title = _title;
2178 // data.nodeHead.mesure();
2179 //data.headerH = data.nodeHead.height();
2180 data.headerH = Util.getElementSize( data.elmHead ).height;
2184 createHeaderItem : function(){
2185 var data = WindowPrivateData.get( this ),
2186 elm = document.createElement( 'div' ),
2188 if( !data.nodeHead ) data.nodeHead = data.nodeWindow.createNode( data.elmHead, true, false );
2189 data.elmHead.appendChild( elm );
2190 elm.className = 'header-item finder-path';
2191 node = data.nodeHead.createNode( elm, false, true, 'header-item-hover', '' )
2192 // data.nodeHead.mesure();
2193 // data.headerH = data.nodeHead.height();
2195 data.headerH = Util.getElementSize( data.elmHead ).height;
2202 function openWindow( data ){
2203 if( data.visible !== true ) return;
2204 elmRoot.appendChild( data.elm );// appendした後に fadeIn() しないと ie で filterが適用されない.
2205 $( data.elm ).fadeIn( data.onFadeIn );
2210 id : 'WINDOWS_CONTROL',
2212 elmRoot = document.getElementById( 'window-container' );
2213 nodeContainer = eventRoot.createNode( elmRoot, true, false );
2214 elmWindowOrigin = app.fetchHTMLElement( 'windowTemplete' );
2215 closeButtonWidth = Util.getElementSize( Util.getElementsByClassName( elmWindowOrigin, 'window-close-button' )[ 0 ] ).width;
2217 delete WINDOWS_CONTROL.init;
2220 for( var i = WINDOW_DATA_LIST.length, data; i; ){
2221 data = WINDOW_DATA_LIST[ --i ];
2225 delete WINDOWS_CONTROL.open;
2229 onWindowResize : function( _windowW, _windowH ){
2234 createWindow : function( EXTENDS, bodyTempleteID, title, x, y, w, h, opt_visible, opt_closeEnabled, opt_resizeEnabled, opt_minWindowW, opt_minWindowH ){
2235 opt_visible = opt_visible !== false;
2236 opt_closeEnabled = opt_closeEnabled === true;
2237 opt_resizeEnabled = opt_resizeEnabled === true;
2238 opt_minWindowW = opt_minWindowW || ( w < DEFAULT_MIN_WINDOW_WIDTH ) ? w : DEFAULT_MIN_WINDOW_WIDTH;
2239 opt_minWindowH = opt_minWindowH || ( h < DEFAULT_MIN_WINDOW_HEIGHT ) ? h : DEFAULT_MIN_WINDOW_HEIGHT;
2241 var win = new WindowClass( bodyTempleteID, title, x, y, w, h, opt_visible, opt_closeEnabled, opt_resizeEnabled, opt_minWindowW, opt_minWindowH ),
2243 for( var key in EXTENDS ){
2244 win[ key ] = EXTENDS[ key ];
2246 if( Type.isUndefined( WINDOWS_CONTROL.init ) === true ){
2247 data = WindowPrivateData.get( win );
2256 /* ----------------------------------------
2260 var TOOL_BOX_WINDOW = ( function(){
2262 app.addKeyEventListener( 'keydown', addImage, 73, false, true );
2263 app.addKeyEventListener( 'keydown', addText, 84, false, true );
2264 app.addKeyEventListener( 'keydown', switchGrid, 71, false, true );
2266 function addImage(){
2267 // IMAGE_EXPLORER_WINDOW.open();
2268 app.addAsyncCall( IMAGE_EXPLORER_WINDOW.open, null, IMAGE_EXPLORER_WINDOW );
2269 //TOOL_BOX_WINDOW.bodyBackOrForward( true );
2272 app.addAsyncCall( PANEL_ELEMENT_CONTROL.createTextElement );
2274 function switchGrid(){
2275 app.addAsyncCall( GRID_CONTROL.update, null, GRID_CONTROL );
2277 function popupHelp(){
2278 //.bodyBackOrForward( true );
2279 app.addAsyncCall( HELP_DOCUMENTS_WINDOW.open, null, HELP_DOCUMENTS_WINDOW );
2281 function editBG( e ){
2282 //TOOL_BOX_WINDOW.bodyBackOrForward( true );
2283 app.addAsyncCall( INFOMATION_WINDOW.open, null, INFOMATION_WINDOW );
2286 return WINDOWS_CONTROL.createWindow(
2289 MENU_BAR_CONTROL.EDIT.createOption( 'Add Image', 'ctrl + I', addImage, true, true, false );
2290 MENU_BAR_CONTROL.EDIT.createOption( 'Add Text', 'ctrl + T', addText, true, false, true );
2291 MENU_BAR_CONTROL.EDIT.createOption( 'show Grid', 'ctrl + G', switchGrid, true, true, true );
2293 onFirstOpen: function( x, y, nodeBody ){
2294 nodeBody.createNode( document.getElementById( 'toolbox-add-image-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', addImage );
2295 nodeBody.createNode( document.getElementById( 'toolbox-add-text-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', addText );
2296 nodeBody.createNode( document.getElementById( 'toolbox-edit-bg-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', editBG );
2297 nodeBody.createNode( document.getElementById( 'toolbox-switch-grid' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', switchGrid );
2298 nodeBody.createNode( document.getElementById( 'toolbox-popup-help-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', popupHelp );
2299 // nodeBody.createNode( document.getElementById( 'toolbox-add-text-button' ), false, true, 'button-hover', 'pointer' ).addEventListener( 'click', addText );
2302 'toolbox-window', 'Tool box', 0, 215, 110, 290, true
2307 /* ----------------------------------------
2311 var IMAGE_EXPLORER_WINDOW = ( function(){
2314 function onFileSelect( file ){
2315 // 他の image ファイルも許可する?
2316 if( Driver.isPettanrFileInstance( file ) === true ){
2317 if( file.getType() === FILE_TYPE.RESOURCE_PICTURE ){
2318 PANEL_ELEMENT_CONTROL.onImageSelect( FileAPI.getFileData( file ) );
2323 return WINDOWS_CONTROL.createWindow(
2325 onInit: function(){},
2326 onFirstOpen: function( _w, _h, nodeBody ){
2327 tree = FileAPI.createTree( FILE_DATA_RESOURCE_PICTURES_ROOT );
2328 var _root = tree.getRootFile(),
2329 _myPic = _root.getChildFileAt( 0 ),
2330 _pic = _root.getChildFileAt( 1 );
2331 _myPic.getSeqentialFiles();
2332 _pic.getSeqentialFiles();
2336 finder = app.createFinder(
2341 finder.createPath( IMAGE_EXPLORER_WINDOW.createHeaderItem() );
2343 onOpen: function( _w, _h ){
2344 finder.resize( _w, _h );
2346 onResize: function( _w, _h ){
2347 finder.resize( _w, _h );
2350 null, 'Album', 0, 215, 600, 350, false, true, true, 300, 300
2355 /* ----------------------------------------
2359 var INFOMATION_WINDOW = ( function(){
2360 var backgroundInfomationElm;
2362 return WINDOWS_CONTROL.createWindow(
2364 onFirstOpen: function( _w, _h ){
2365 backgroundInfomationElm = $( '#panel-background-information');
2367 onResize: function( _w, _h ){
2369 update: function( currentElement ){
2373 'infomation-window', 'Infomation', 0, 30, 200, 180, true
2377 /* ----------------------------------------
2381 var HELP_DOCUMENTS_WINDOW = ( function(){
2386 currentPageIndex = 0,
2390 function onAjaxStart( _pageIndex ){
2391 delete asyncOption.callback;
2393 currentPageIndex = _pageIndex || currentPageIndex;
2394 if( onHelpLoad !== null ){
2404 var onHelpLoad = function( _xml ){
2405 var jqXML = $( _xml ),
2406 helpTitle = jqXML.find( 'pages' ).eq( 0 ).attr( 'title' ),
2407 elmRoot = document.createElement( 'div' ),
2408 elmNavi = document.createElement( 'div' ),
2409 elmItemOrigin = document.createElement( 'a' ),
2410 elmPages = document.createElement( 'div' ),
2411 elmPageOrigin = document.createElement( 'div' ),
2412 elmTitleOrigin = document.createElement( 'h2' ),
2414 elmRoot.className = 'multi-page-container clearfix';
2415 elmNavi.className = 'sidenavi';
2416 elmItemOrigin.className = 'sidenavi-item';
2417 elmItemOrigin.href = '#';
2418 elmPages.className = 'page-contents';
2419 elmPageOrigin.className = 'page-content main';
2420 elmPageOrigin.appendChild( elmTitleOrigin);
2422 MENU_BAR_CONTROL.HELP.remove( asyncOption );
2425 jqXML.find( 'page' ).each( function(){
2426 var xmlPage = $( this ),
2427 title = xmlPage.attr( 'title' ),
2428 content = xmlPage.text();
2430 elmItemOrigin.innerHTML = title;
2431 elmNavi.appendChild( elmItemOrigin.cloneNode( true ) );
2433 elmTitleOrigin.innerHTML = title;
2435 elmPage = elmPageOrigin.cloneNode( true );
2436 elmPage.innerHTML = content;
2438 Util.cleanElement( elmPage);
2440 if( elmPage.childNodes.length > 0 ){
2441 elmPage.insertBefore( elmTitleOrigin.cloneNode( true ), elmPage.childNodes[0]);
2443 elmPage.appendChild( elmTitleOrigin.cloneNode( true ));
2445 elmPages.appendChild( elmPage );
2447 MENU_BAR_CONTROL.HELP.createOption( title, null, onSelectionClick, true );
2450 elmRoot.appendChild( elmNavi );
2451 elmRoot.appendChild( elmPages );
2452 jqAjaxContents.removeClass( 'loading' ).append( elmRoot );
2454 jqNaviItems = jqAjaxContents.find( 'a.' + elmItemOrigin.className ).click( onNaviClick );
2455 jqPages = jqAjaxContents.find( '.page-content' );
2456 jqPages.find( 'a' ).click( onInnerLinkClick );
2458 app.addAsyncCall( jumpPage );
2460 function onSelectionClick( _pageIndex ){
2461 HELP_DOCUMENTS_WINDOW.open();
2462 jumpPage( _pageIndex );
2464 function jumpPage( _index ){
2465 if( Type.isNumber( _index ) === true && 0 <= _index && _index < numPage && currentPageIndex !== _index ){
2466 currentPageIndex = _index;
2468 jqNaviItems.removeClass( 'current' ).eq( currentPageIndex ).addClass( 'current' );
2469 jqPages.hide().eq( currentPageIndex ).show();
2471 function onNaviClick( e ){
2473 jumpPage( Util.getChildIndex( this.parentNode, this ) );
2476 function onInnerLinkClick( e ){
2477 var jump = ( this.href || '' ).split( '#jump' ),
2480 jumpPage( '' + parseFloat( n ) === n ? parseFloat( n ) : -1 );
2483 return WINDOWS_CONTROL.createWindow(
2486 asyncOption = MENU_BAR_CONTROL.HELP.createAsyncOption( onAjaxStart );
2487 jqAjaxContents = $( HELP_DOCUMENTS_WINDOW.elm ).find( '.window-body' ).addClass( 'loading' ).css( { overflow: 'auto' } );
2489 onFirstOpen: function( _w, _h ){
2490 jqAjaxContents.css( { height: _h } );
2491 onAjaxStart !== null && onAjaxStart();
2493 onResize: function( _w, _h ){
2494 jqAjaxContents && jqAjaxContents.css( { height: _h } );
2497 null, 'Help', 0, 215, 400, 350, false, true, true, 300, 300
2501 /* ----------------------------------------
2504 * - panelResizeListener
2506 var GRID_CONTROL = ( function(){
2508 urlBG = "url('images/grid.gif')",
2513 elmGrid = document.getElementById( 'grid' );
2514 delete GRID_CONTROL.init;
2517 delete GRID_CONTROL.open;
2522 onPanelResize: function( _panelX, _panelY ){
2523 elmGrid.style.backgroundPosition = [ _panelX % 10, 'px ', _panelY % 10, 'px' ].join( '' );
2524 elmGrid.style.height = windowH +'px';
2526 enabled: function(){
2530 $( elmGrid ).stop().css( {
2533 })[ visible === true ? 'fadeOut' : 'fadeIn' ]();
2537 if( visible === true && urlBG !== null ){
2538 elmGrid.style.backgroundImage = urlBG;
2546 /* ----------------------------------------
2547 * WHITE_GLASS_CONTROL
2548 * - panelResizeListener
2550 var WHITE_GLASS_CONTROL = ( function(){
2551 var styleTop, styleLeft, styleRight, styleBottom;
2555 styleTop = document.getElementById( 'whiteGlass-top' ).style;
2556 styleLeft = document.getElementById( 'whiteGlass-left' ).style;
2557 styleRight = document.getElementById( 'whiteGlass-right' ).style;
2558 styleBottom = document.getElementById( 'whiteGlass-bottom' ).style;
2559 delete WHITE_GLASS_CONTROL.init;
2561 onPanelResize: function( _panelX, _panelY, _panelW, _panelH ){
2564 marginTop = _panelY,
2565 marginBottom = windowH -_h -marginTop,
2567 rightWidth = windowW -_w -marginX;
2569 styleTop.height = ( marginTop < 0 ? 0 : marginTop ) + 'px';
2571 styleLeft.top = marginTop + 'px';
2572 styleLeft.width = ( marginX < 0 ? 0 : marginX ) + 'px';
2573 styleLeft.height = ( _h + marginBottom ) + 'px';
2575 styleRight.top = marginTop + 'px';
2576 styleRight.left = _w +marginX + 'px';
2577 styleRight.width = ( rightWidth < 0 ? 0 : rightWidth ) + 'px';
2578 styleRight.height = ( _h + marginBottom ) + 'px';
2580 styleBottom.top = ( _h +marginTop ) + 'px';
2581 styleBottom.left = marginX + 'px';
2582 styleBottom.width = _w + 'px';
2583 styleBottom.height = ( marginBottom < 0 ? 0 : marginBottom ) + 'px';
2589 /* --------------------------------------------------------------------------------------------
2591 * - mouseEventListener
2593 var PanelResizerClass = function( id, isTop ){
2597 PanelResizerClass.BORDER_SIZE = 2;
2598 PanelResizerClass.HEIGHT = 30;
2599 PanelResizerClass.prototype = {
2604 x : - PanelResizerClass.BORDER_SIZE / 2,
2607 h : PanelResizerClass.HEIGHT,
2617 this.node = PANEL_CONTROL.node.createNode( document.getElementById( this.id ), false, false, 'panel-resizer-hover', 'pointer' );
2618 this.node.addEventListener( 'mousedown', this.mousedown, this );
2619 this.style = document.getElementById( this.id ).style;
2620 this.y = this.isTop === true ? ( -5 - PanelResizerClass.HEIGHT - PanelResizerClass.BORDER_SIZE ) : 0;
2622 mousedown : function( e ){
2624 var x = e.layerX, // - this.panelX,
2625 y = e.layerY; // - this.panelY;
2627 this.startY = this.panelY;
2628 this.startH = this.panelH;
2629 this.isDragging = true;
2630 // app.updateCoursor( 'n-resize' );
2631 this.node.addEventListener( 'mousemove', this.mousemove, this );
2632 this.node.addEventListener( 'mouseup', this.mouseup, this );
2633 this.node.cursor( 'n-resize' );
2636 mousemove : function( e ){
2637 var move = e.layerY - this.offsetY,
2640 if( this.isTop === true ){
2641 if( this.panelH - move < MIN_PANEL_HEIGHT ){
2642 move = this.panelH - MIN_PANEL_HEIGHT;
2644 PANEL_CONTROL.resizeElement( true, this.panelX, this.panelY + move, this.panelW, this.panelH - move );
2646 h = this.startH + move;
2647 if( 0 < h && h < windowH - this.panelY - PanelResizerClass.HEIGHT - 5 - PanelResizerClass.BORDER_SIZE ){
2648 PANEL_CONTROL.resizeElement( false, this.panelX, this.panelY, this.panelW, h < MIN_PANEL_HEIGHT ? MIN_PANEL_HEIGHT : h );
2653 mouseup : function( e ){
2654 if( this.isDragging !== true ) return;
2655 ( this.startY !== this.panelY || this.startH !== this.panelH ) &&
2656 HISTORY_CONTROL.saveState(
2658 [ undefined, this.startY, undefined, this.startH ],
2659 [ undefined, this.panelY, undefined, this.panelH ],
2662 this.isDragging = false;
2663 var move = e.layerY - this.offsetY,
2666 if( this.isTop === true ){
2667 if( this.panelH - move < MIN_PANEL_HEIGHT ){
2668 move = this.panelH - MIN_PANEL_HEIGHT;
2670 PANEL_CONTROL.resize( true, this.panelX, this.panelY + move, this.panelW, this.panelH - move );
2672 h = this.startH + move;
2673 if( 0 < h && h < windowH - this.panelY - PanelResizerClass.HEIGHT - 5 - PanelResizerClass.BORDER_SIZE ){
2674 PANEL_CONTROL.resize( false, this.panelX, this.panelY, this.panelW, h < MIN_PANEL_HEIGHT ? MIN_PANEL_HEIGHT : h );
2677 // app.updateCoursor( '' );
2678 this.node.removeEventListener( 'mousemove', this.mousemove );
2679 this.node.removeEventListener( 'mouseup', this.mouseup );
2680 this.node.cursor( 'pointer' );
2682 restoreState : function( x, y, w, h ){
2683 PANEL_CONTROL.resize( this.isTop, x || this.panelX, y || this.panelY, w || this.panelW, h || this.panelH );
2686 return this.isDragging;
2688 onPanelResize : function( x, y, w, h ){
2691 if( this.panelW !== w ){
2692 this.style.width = ( w + 2 ) + 'px';
2696 this.y = this.isTop === true ? this.y : ( this.panelH + 5 + PanelResizerClass.BORDER_SIZE );
2697 this.w = this.panelW + 2;
2698 this.node.update( undefined, undefined, this.w );
2702 /* ----------------------------------------
2705 * - mouseEventListener
2707 * panel-border の表示と onPanelResize の通知.
2711 var PANEL_CONTROL = ( function(){
2712 var elmPanel, stylePanel,
2714 DEFAULT_PANEL_WIDTH = 400,
2715 DEFAULT_PANEL_HEIGHT = 300,
2717 offsetX, offsetY, startX, startY,
2719 isDraggable = false,
2720 resizerTop = new PanelResizerClass( 'panel-resizer-top', true ),
2721 resizerBottom = new PanelResizerClass( 'panel-resizer-bottom', false );
2723 app.addKeyEventListener( 'keychange', onSpaceUpdate, 32, false, false );
2725 function onSpaceUpdate( e ){
2726 if( e.type === 'keyup' ){
2727 app.isCurrentInteractiveEventListener( null ) === true && app.updateCoursor( '' );
2728 isDraggable = false;
2730 app.isCurrentInteractiveEventListener( null ) === true && app.updateCoursor( 'move' );
2737 id : 'PANEL_CONTROL',
2745 elmPanel = this.elm = document.getElementById( 'panel-tools-container' );
2746 nodePanel = this.node = eventRoot.createNode( elmPanel, true, false );
2749 resizerBottom.init();
2751 stylePanel = elmPanel.style;
2752 delete PANEL_CONTROL.init;
2754 open: function( _panelW, _panelH, _borderSize ){
2755 PANEL_CONTROL.w = Type.isFinite( _panelW ) === true ? _panelW : DEFAULT_PANEL_WIDTH;
2756 PANEL_CONTROL.h = Type.isFinite( _panelH ) === true ? _panelH : DEFAULT_PANEL_HEIGHT;
2757 borderSize = Type.isFinite( _borderSize ) === true ? _borderSize : borderSize;
2759 delete PANEL_CONTROL.open;
2764 resize: function( isResizerTopAction, x, y, w, h ){
2765 PANEL_CONTROL.x = x = x !== undefined ? x : PANEL_CONTROL.x;
2766 PANEL_CONTROL.y = y = y !== undefined ? y : PANEL_CONTROL.y;
2767 PANEL_CONTROL.w = w = w !== undefined ? w : PANEL_CONTROL.w;
2768 PANEL_CONTROL.h = h = h !== undefined ? h : PANEL_CONTROL.h;
2770 nodePanel.update( x - borderSize, y - borderSize, w, h );
2773 resizerTop.onPanelResize( x, y, w, h );
2774 resizerBottom.onPanelResize( x, y, w, h );
2775 GRID_CONTROL.onPanelResize( x, y );
2776 WHITE_GLASS_CONTROL.onPanelResize( x, y, w, h );
2777 PANEL_ELEMENT_CONTROL.onPanelResize( x, y, w, h, isResizerTopAction === true );
2779 resizeElement : function( isResizerTopAction, x, y, w, h ){
2780 stylePanel.cssText = [ 'left:', ( x - borderSize ), 'px;',
2781 'top:', ( y - borderSize ), 'px;',
2783 'height:', h, 'px' ].join( '' );
2784 // PANEL_RESIZER_TOP.onPanelResize( x, y, w, h );
2785 // PANEL_RESIZER_BOTTOM.onPanelResize( x, y, w, h );
2786 GRID_CONTROL.onPanelResize( x, y );
2787 WHITE_GLASS_CONTROL.onPanelResize( x, y, w, h );
2788 PANEL_ELEMENT_CONTROL.onPanelResize( x, y, w, h, isResizerTopAction );
2790 onWindowResize: function( _windowW, _windowH ){
2791 PANEL_CONTROL.x = Math.floor( ( _windowW - PANEL_CONTROL.w ) / 2 );
2792 PANEL_CONTROL.y = Math.floor( ( _windowH - PANEL_CONTROL.h ) / 2 );
2793 PANEL_CONTROL.resize();
2795 mousemove: function( _mouseX, _mouseY ){
2796 if( isDraggable === true && isDragging === true ){
2797 PANEL_CONTROL.resize( false, startX + _mouseX - offsetX, startY + _mouseY - offsetY );
2800 mouseup: function( _mouseX, _mouseY ){
2801 if( isDraggable === true ){
2803 app.updateCoursor( '' );
2806 mousedown: function( _mouseX, _mouseY ){
2807 if( isDraggable === true ){
2810 startX = PANEL_CONTROL.x;
2811 startY = PANEL_CONTROL.y;
2813 app.updateCoursor( 'move' );
2818 return isDragging === true;
2823 /* --------------------------------------------------------------------------------------------
2825 * - panelElementOperator
2827 var TailOperator = ( function(){
2834 DEG_TO_RAD = Math.PI / 180,
2835 RAD_TO_DEG = 1 / DEG_TO_RAD,
2839 balloonW, balloonH, balloonA, radA,
2845 var elm = document.getElementById( 'balloon-tail-mover' );
2846 SIZE = Util.getElementSize( elm ).width;
2847 styleMover = elm.style;
2848 delete TailOperator.init;
2850 update: function ( _w, _h, _a ){
2851 balloonW = _w !== undefined ? _w : balloonW;
2852 balloonH = _h !== undefined ? _h : balloonH;
2853 balloonA = _a !== undefined ? _a : balloonA;
2854 radA = ( balloonA - 90 ) * DEG_TO_RAD;
2855 tailX = FLOOR( ( ( COS( radA ) / 2 + 0.5 ) * ( balloonW + SIZE )) - SIZE / 2 );
2856 tailY = FLOOR( ( ( SIN( radA ) / 2 + 0.5 ) * ( balloonH + SIZE )) - SIZE / 2 );
2857 styleMover.left = tailX + 'px';
2858 styleMover.top = tailY + 'px';
2860 show: function( _currentText ){
2862 * visibilityのほうがいい, display:none だと ie で描画が狂う
2864 styleMover.visibility = '';
2865 currentText = _currentText;
2866 TailOperator.update( _currentText.w, _currentText.h, _currentText.a );
2869 styleMover.visibility = 'hidden';
2872 hitTest: function( _mouseX, _mouseY ){
2873 var _x = tailX -SIZE / 2,
2874 _y = tailY -SIZE / 2,
2875 ret = _x <= _mouseX && _y <= _mouseY && _x + SIZE >= _mouseX && _y + SIZE >= _mouseY;
2876 ret === true && app.updateCoursor( 'move' );
2879 onStart: function( _mouseX, _mouseY ){
2880 if( currentText.type !== PANEL_ELEMENT_TYPE_TEXT ) return false;
2881 if( TailOperator.hitTest( _mouseX, _mouseY ) === true ){
2884 startA = currentText.a;
2889 onDrag: function( _mouseX, _mouseY ){
2890 _mouseX = _mouseX - w / 2;
2891 _mouseY = _mouseY - h / 2; //Balloonの中心を0,0とする座標系に変換
2892 TailOperator.update( w, h,
2894 ATAN( _mouseY / _mouseX ) * RAD_TO_DEG + ( _mouseX > 0 ? 90 : 270 ) :
2895 _mouseY > 0 ? 180 : 0
2897 currentText && currentText.angle( FLOOR( balloonA + 0.5 ) );
2898 CONSOLE_CONTROLER.update( currentText );
2900 onFinish: function(){
2901 startA !== currentText.a && PanelElementOperatorManager.saveStatus( undefined, undefined, w, h, startA );
2902 startA !== currentText.a && PanelElementOperatorManager.resize( undefined, undefined, w, h, currentText.a );
2904 onCancel: function(){
2905 currentText.angle( startA );
2906 PanelElementOperatorManager.resize( undefined, undefined, w, h, startA );
2911 /* --------------------------------------------------------------------------------------------
2913 * - panelElementOperator
2915 var ResizeOperator = ( function(){
2916 var HIT_AREA = MOUSE_HIT_AREA,
2917 POSITION_ARRAY = [],
2920 { cursor: 'n-resize', v: 3 },
2921 { cursor: 'e-resize', h: 2 },
2922 { cursor: 'e-resize', h: 1 },
2923 { cursor: 'n-resize', v: 0 },
2924 { cursor: 'nw-resize', h: 5, v: 6, vh: 7 },
2925 { cursor: 'ne-resize', h: 4, v: 7, vh: 6 },
2926 { cursor: 'ne-resize', h: 7, v: 4, vh: 5 },
2927 { cursor: 'nw-resize', h: 6, v: 5, vh: 4 }
2940 var RESIZE_WORK_ARRAY = [
2941 { x: 0, w: 0, y: 1, h: -1}, //top
2942 { x: 1, w: -1, y: 0, h: 0}, //left
2943 { x: 0, w: 1, y: 0, h: 0}, //right
2944 { x: 0, w: 0, y: 0, h: 1}, //bottom
2945 { x: 1, w: -1, y: 1, h: -1}, //top-left
2946 { x: 0, w: 1, y: 1, h: -1}, //top-right
2947 { x: 1, w: -1, y: 0, h: 1}, //bottom-left
2948 { x: 0, w: 1, y: 0, h: 1} //bottom-right
2950 startX, startY, startW, startH,
2951 flipV, flipH, startFilpV, startFilpH, startAspect,
2952 baseX, baseY, baseW, baseH,
2953 currentX, currentY, currentW, currentH,
2957 function update( _x, _y, _w, _h ){
2959 _x = _x !== undefined ? _x : currentX;
2960 _y = _y !== undefined ? _y : currentY;
2961 _w = _w !== undefined ? _w : currentW;
2962 _h = _h !== undefined ? _h : currentH;
2964 if( isSpeach === false && currentIndex > 3 && app.shiftEnabled() === true ){
2965 if( startAspect >= 1 ){
2967 _w = FLOOR( startAspect * _h );
2968 _x = _x + ( currentIndex % 2 === 0 ? __w - _w : 0 );
2971 _h = FLOOR( _w / startAspect );
2972 _y = _y + ( currentIndex <= 5 ? __h - _h : 0 );
2975 ResizeOperator.update( x = _x, y = _y, w = _w, h = _h );
2976 currentElement.resize( _x, _y, _w, _h );
2977 isSpeach === true && TailOperator.update( _w, _h );
2978 CONSOLE_CONTROLER.show( currentElement, _w, _h );
2979 // CONSOLE_CONTROLER.update( currentElement );
2982 function flip( _flipH, _flipV ){
2983 var p = CURSOR_AND_FLIP[ currentIndex ];
2984 currentIndex = _flipH === true || _flipV === true ? p[
2985 _flipH === true && _flipV === true ? 'vh' : ( _flipH === true ? 'h' : 'v' )
2987 app.updateCoursor( CURSOR_AND_FLIP[ currentIndex ].cursor );
2988 elmInner.className = 'current-resizer-is-' + currentIndex;
2989 currentElement.flip( _flipH, _flipV );
2993 elmInner = document.getElementById( 'comic-element-resizer-container-inner' );
2994 styleInner = elmInner.style;
2996 styleResizerTop = document.getElementById( 'comic-element-resizer-top' ).style;
2997 styleResizerLeft = document.getElementById( 'comic-element-resizer-left' ).style;
2998 styleResizerRight = document.getElementById( 'comic-element-resizer-right' ).style;
2999 styleResizerBottom = document.getElementById( 'comic-element-resizer-bottom' ).style;
3001 delete ResizeOperator.init;
3003 update: function( _x, _y, _w, _h ){
3004 x = _x = _x !== undefined ? _x : x;
3005 y = _y = _y !== undefined ? _y : y;
3006 w = _w = _w !== undefined ? _w : w;
3007 h = _h = _h !== undefined ? _h : h;
3009 PanelElementOperatorManager.resizeElement( _x, _y, _w, _h );
3011 styleInner.width = _w + 'px';
3012 styleInner.height = _h + 'px';
3014 styleResizerTop.left = styleResizerBottom.left = FLOOR( _w / 2 - 5 ) + 'px';
3015 styleResizerLeft.top = styleResizerRight.top = FLOOR( _h / 2 - 5 ) + 'px';
3017 POSITION_ARRAY.length = 0;
3018 POSITION_ARRAY.push(
3019 {x: 5, y: -HIT_AREA, w: _w - 5, h: HIT_AREA * 2 }, // top
3020 {x: -HIT_AREA, y: 5, w: HIT_AREA * 2, h: _h - 5 }, // left
3021 {x: _w - 5, y: HIT_AREA + 5, w: HIT_AREA * 2, h: _h - 5 }, // right
3022 {x: 5, y: _h - 5, w: _w - 5, h: HIT_AREA * 2 }, // bottom
3023 {x: -HIT_AREA, y: -HIT_AREA, w: HIT_AREA + 5, h: HIT_AREA + 5}, // top left
3024 {x: _w - 5, y: -HIT_AREA, w: HIT_AREA + 5, h: HIT_AREA + 5}, // top right
3025 {x: -HIT_AREA, y: _h - 5, w: HIT_AREA + 5, h: HIT_AREA + 5}, // bottom left
3026 {x: _w - 5, y: _h - 5, w: HIT_AREA + 5, h: HIT_AREA + 5} // bottom right
3029 index: function( _mouseX, _mouseY ){
3031 for( i = 4; i < 8; ++i ){
3032 p = POSITION_ARRAY[ i ];
3033 if( p.x <= _mouseX && p.y <= _mouseY && p.x + p.w >= _mouseX && p.y + p.h >= _mouseY ){
3034 app.updateCoursor( CURSOR_AND_FLIP[ i ].cursor );
3035 elmInner.className = 'current-resizer-is-' + i;
3036 return currentIndex = i;
3039 for( i = 0; i < 4; ++i ){
3040 p = POSITION_ARRAY[ i ];
3041 if( p.x <= _mouseX && _mouseX <= p.x + p.w && p.y <= _mouseY && _mouseY <= p.y + p.h ){
3042 app.updateCoursor( CURSOR_AND_FLIP[ i ].cursor );
3043 elmInner.className = 'current-resizer-is-' + i;
3044 return currentIndex = i;
3047 app.updateCoursor( '' );
3048 elmInner.className = '';
3051 show: function( _currentElement ){
3052 currentElement = _currentElement;
3053 isSpeach = _currentElement.type === PANEL_ELEMENT_TYPE_TEXT;
3054 ResizeOperator.update( _currentElement.x, _currentElement.y, _currentElement.w, _currentElement.h );
3057 currentElement = null;
3059 onStart: function( _mouseX, _mouseY ){
3060 isSpeach = currentElement.type === PANEL_ELEMENT_TYPE_TEXT;
3061 if( currentElement.keepSize === true ) return false;
3062 currentIndex = this.index( _mouseX, _mouseY );
3063 if( currentIndex === -1 ) return false;
3066 startX = baseX = currentElement.x;
3067 startY = baseY = currentElement.y;
3068 startW = baseW = currentElement.w;
3069 startH = baseH = currentElement.h;
3070 startFilpV = currentElement.flipV;
3071 startFilpH = currentElement.flipH;
3072 startAspect = startW / startH;
3075 onDrag: function( _mouseX, _mouseY ){
3076 var com = RESIZE_WORK_ARRAY[ currentIndex ],
3077 moveX = _mouseX - offsetX,
3078 moveY = _mouseY - offsetY,
3079 _updated = moveX !== 0 || moveY !== 0,
3086 * Opera 11+ often forget values, why ??
3088 while( _x === undefined || _y === undefined || _w === undefined || _h === undefined ){
3089 _x = _x !== undefined ? _x : baseX + moveX * com.x;
3090 _y = _y !== undefined ? _y : baseY + moveY * com.y;
3091 _w = _w !== undefined ? _w : baseW + moveX * com.w;
3092 _h = _h !== undefined ? _h : baseH + moveY * com.h;
3093 error += _thisError === 0 ? 0 : 1;
3095 if( _thisError > 9999 ){
3097 //alert( 'opera error' +error);
3103 if( _w >= MIN_ELEMENT_SIZE && _h >= MIN_ELEMENT_SIZE ){
3106 if( _w >= -MIN_ELEMENT_SIZE && _h >= -MIN_ELEMENT_SIZE ){
3108 if( _w < MIN_ELEMENT_SIZE){
3109 //_x += Math.abs( MIN_ELEMENT_SIZE -_w);
3111 _w = MIN_ELEMENT_SIZE;
3113 if( _h < MIN_ELEMENT_SIZE){
3114 //_y += Math.abs( MIN_ELEMENT_SIZE -_h);
3116 _h = MIN_ELEMENT_SIZE;
3119 if( currentElement.type === PANEL_ELEMENT_TYPE_TEXT ){
3122 if( _w < -MIN_ELEMENT_SIZE || _h < -MIN_ELEMENT_SIZE ){
3124 if( _w < -MIN_ELEMENT_SIZE && _h > MIN_ELEMENT_SIZE ){
3127 baseX = _x = _x +_w;
3129 baseW = _w = _memoryX -_x;
3131 flip( true, false );
3132 flipV = currentElement.flipV;
3134 if( _w > MIN_ELEMENT_SIZE && _h < -MIN_ELEMENT_SIZE ){
3138 baseY = _y = _y +_h;
3140 baseH = _h = _memoryY -_y;
3142 flipH = currentElement.flipH;
3147 baseX = _x = _x + _w;
3148 baseY = _y = _y + _h;
3149 baseW = _w = _memoryX - _x;
3150 baseH = _h = _memoryY - _y;
3152 flipV = currentElement.flipV;
3153 flipH = currentElement.flipH;
3163 _updated === true && update( _x, _y, _w, _h );
3166 'currentIndex:', currentIndex,
3167 'baseW', baseW, 'baseH', baseH,'<br>',
3168 'mouse', _mouseX, _mouseY,'<br>',
3169 'move', moveX, moveY,'<br>',
3170 'xy', _x, _y, 'wh',_w, _h,'<br>',
3171 'com.w', com.w, 'com.h', com.h,'<br>',
3172 'current',currentW, currentH,'<br>',
3177 onFinish: function(){
3178 app.updateCoursor( '' );
3179 if( w === startW && h === startH && x === startX && y === startY ) return;
3180 PanelElementOperatorManager.resize( x, y, w, h );
3181 currentElement.resize( x, y, w, h );
3182 PanelElementOperatorManager.saveStatus( startX, startY, startW, startH, undefined, startFilpV, startFilpH );
3184 onCancel: function(){
3185 app.updateCoursor( '' );
3186 PanelElementOperatorManager.resize( startX, startY, startW, startH );
3187 currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
3188 currentElement.animate( startX, startY, startW, startH, startFilpV, startFilpH ) :
3189 currentElement.animate( startX, startY, startW, startH, angle );
3191 onShiftUpdate: update,
3192 onCtrlUpdate: update
3196 /* --------------------------------------------------------------------------------------------
3198 * - panelElementOperator
3200 var PositionOperator = ( function(){
3201 var HIT_AREA = MOUSE_HIT_AREA,
3207 function update( _x, _y ){
3208 x = _x !== undefined ? _x : x;
3209 y = _y !== undefined ? _y : y;
3210 // ResizeOperator.update( x, y );
3212 PanelElementOperatorManager.resizeElement( x, y );
3214 currentElement.resize( x, y );
3215 // CONSOLE_CONTROLER.update( currentElement );
3219 delete PositionOperator.init;
3221 show : function( _currentElement ){
3222 currentElement = _currentElement;
3225 currentElement = null;
3227 onStart: function( _mouseX, _mouseY ){
3230 startX = x = currentElement.x;
3231 startY = y = currentElement.y;
3232 app.updateCoursor( 'move' );
3234 onDrag: function( _mouseX, _mouseY ){
3235 var moveX = _mouseX - offsetX,
3236 moveY = _mouseY - offsetY,
3237 _x = startX + moveX,
3238 _y = startY + moveY;
3239 if( GRID_CONTROL.enabled() === true ){
3240 _x = Math.floor( _x / 10 ) * 10;
3241 _y = Math.floor( _y / 10 ) * 10;
3245 onFinish: function(){
3246 app.updateCoursor( '' );
3247 if( x === startX && y === startY ) return;
3248 PanelElementOperatorManager.resize( x, y );
3249 currentElement.resize( x, y );
3250 PanelElementOperatorManager.saveStatus( startX, startY );
3252 onCancel: function(){
3253 app.updateCoursor( '' );
3254 PanelElementOperatorManager.resize( startX, startY );
3255 currentElement.animate( startX, startY );
3257 onShiftUpdate: update,
3258 onCtrlUpdate: update
3263 /* --------------------------------------------------------------------------------------------
3264 * PanelElementOperatorManager
3266 var PanelElementOperatorManager = ( function(){
3267 var HIT_AREA = MOUSE_HIT_AREA,
3269 currentOperator = null,
3270 currentElement = null,
3272 styleContainer = null,
3273 currentX, currentY, currentW, currentH, angle, flipV, flipH;
3275 function mousedown( e ){
3276 var x = e.layerX - HIT_AREA / 2 - 5,
3277 y = e.layerY - HIT_AREA / 2 - 5;
3278 if( isSpeach === true && TailOperator.onStart( x, y ) === true ){
3279 currentOperator = TailOperator;
3281 if( ResizeOperator.onStart( x, y ) === true ){
3282 currentOperator = ResizeOperator;
3284 PositionOperator.onStart( x, y );
3285 currentOperator = PositionOperator;
3289 function mousemove( e ){
3290 var x = e.layerX - HIT_AREA / 2 - 5,
3291 y = e.layerY - HIT_AREA / 2 - 5;
3292 if( currentOperator !== null ){
3293 currentOperator.onDrag( x, y );
3296 if( currentElement !== null ){
3297 ( isSpeach === false || TailOperator.hitTest( x, y ) === false ) && ResizeOperator.index( x, y );
3300 function mouseup( e ){
3301 currentOperator !== null && currentOperator.onFinish();
3302 currentOperator = null;
3309 TailOperator.init();
3310 ResizeOperator.init();
3311 PositionOperator.init();
3312 CONSOLE_CONTROLER.init();
3314 app.addKeyEventListener( 'keychange', function( e ){
3315 currentOperator !== null && currentOperator.onShiftUpdate && currentOperator.onShiftUpdate();
3318 app.addKeyEventListener( 'keychange', function( e ){
3319 currentOperator !== null && currentOperator.onCtrlUpdate && currentOperator.onCtrlUpdate();
3322 app.addKeyEventListener( 'keydown', function( e ){
3323 currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel();
3324 currentOperator = null;
3326 }, 27, false, false );
3328 delete PanelElementOperatorManager.init;
3331 var elm = document.getElementById( 'comic-element-resizer-container' );
3332 PanelElementOperatorManager.elm = elm;
3333 PanelElementOperatorManager.node = eventRoot.createNode( elm, false, false );
3334 PanelElementOperatorManager.node.addEventListener( 'mouseout', PanelElementOperatorManager.hide, PanelElementOperatorManager );
3335 styleContainer = elm.style;
3336 PanelElementOperatorManager.node.disabled( true );
3337 PanelElementOperatorManager.node.addEventListener( 'mousemove', mousemove );
3338 PanelElementOperatorManager.node.addEventListener( 'mousedown', mousedown );
3339 PanelElementOperatorManager.node.addEventListener( 'mouseup', mouseup );
3341 CONSOLE_CONTROLER.open();
3342 PanelElementOperatorManager.hide();
3344 delete PanelElementOperatorManager.open;
3349 show : function( _currentElement ){
3350 if( currentElement === null ){
3351 styleContainer.display = '';
3352 PanelElementOperatorManager.node.disabled( false );
3354 if( currentElement !== _currentElement ){
3355 currentElement = _currentElement;
3357 ResizeOperator.show( _currentElement );
3358 PositionOperator.show( _currentElement );
3360 isSpeach = ( _currentElement.type === PANEL_ELEMENT_TYPE_TEXT );
3361 isSpeach === true ? TailOperator.show( _currentElement ) : TailOperator.hide();
3363 flipV = _currentElement.flipV;
3364 flipH = _currentElement.flipH;
3366 PanelElementOperatorManager.resize(
3367 _currentElement.x, _currentElement.y, _currentElement.w, _currentElement.h,
3368 isSpeach === true ? _currentElement.a : 0
3373 if( currentElement !== null ){
3374 styleContainer.display = 'none';
3375 PanelElementOperatorManager.node.disabled( true );
3377 currentElement = null;
3378 app.updateCoursor( '' );
3379 TailOperator.hide();
3380 ResizeOperator.hide();
3381 PositionOperator.hide();
3382 CONSOLE_CONTROLER.hide();
3384 resizeElement : function( _x, _y, _w, _h, _angle ){
3385 _x = _x !== undefined ? _x : currentX;
3386 _y = _y !== undefined ? _y : currentY;
3387 _w = _w !== undefined ? _w : currentW;
3388 _h = _h !== undefined ? _h : currentH;
3390 var style = PanelElementOperatorManager.elm.style;
3391 style.left = ( PANEL_CONTROL.x + _x - HIT_AREA / 2 - 5 ) + 'px';
3392 style.top = ( PANEL_CONTROL.y + _y - HIT_AREA / 2 - 5 ) + 'px';
3393 style.width = ( _w + HIT_AREA + 5 ) + 'px';
3394 style.heught = ( _h + HIT_AREA + 5 ) + 'px';
3396 // ResizeOperator.update( _x, _y, _w, _h );
3397 isSpeach === true && TailOperator.update( _w, _h, angle );
3398 CONSOLE_CONTROLER.show( currentElement, _w, _h );
3400 resize: function( _x, _y, _w, _h, _angle ){
3401 currentX = _x = _x !== undefined ? _x : currentX;
3402 currentY = _y = _y !== undefined ? _y : currentY;
3403 currentW = _w = _w !== undefined ? _w : currentW;
3404 currentH = _h = _h !== undefined ? _h : currentH;
3405 angle = _angle = _angle !== undefined ? _angle : angle;
3407 // ResizeOperator.update( _x, _y, _w, _h );
3408 isSpeach === true && TailOperator.update( _w, _h, angle );
3409 CONSOLE_CONTROLER.show( currentElement, _w, _h );
3410 //CONSOLE_CONTROLER.update( currentElement );
3411 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 );
3414 restoreState: function( _currentElement, _x, _y, _w, _h, _a, _flipV, _flipH ){
3415 if( arguments.length !== 8 ) return;
3416 if( !_currentElement && !currentOperator ) return;
3417 _currentElement.type === PANEL_ELEMENT_TYPE_IMAGE ?
3418 _currentElement.animate( _x, _y, _w, _h, _flipV, _flipH ) :
3419 _currentElement.animate( _x, _y, _w, _h, _a );
3420 currentOperator !== null && currentOperator.onCancel && currentOperator.onCancel();
3421 currentOperator = null;
3422 currentElement === _currentElement ? PanelElementOperatorManager.resize( _x, _y, _w, _h, _a ) : PanelElementOperatorManager.show( _currentElement );
3424 saveStatus: function( startX, startY, startW, startH, startA, startFilpV, startFilpH ){
3425 startX = startX !== undefined ? startX : currentX;
3426 startY = startY !== undefined ? startY : currentY;
3427 startW = startW !== undefined ? startW : currentW;
3428 startH = startH !== undefined ? startH : currentH;
3429 startA = startA !== undefined ? startA : angle;
3430 startFilpV = startFilpV !== undefined ? startFilpV : flipV;
3431 startFilpH = startFilpH !== undefined ? startFilpH : flipH;
3432 currentElement && HISTORY_CONTROL.saveState( PanelElementOperatorManager.restoreState,
3433 [ currentElement, startX, startY, startW, startH, startA, startFilpV, startFilpH ],
3434 [ currentElement, currentX, currentY, currentW, currentH, angle, flipV, flipH ]
3440 * // PanelElementOperatorManager
3443 /* --------------------------------------------------------------------------------------------
3446 var CONSOLE_CONTROLER = ( function(){
3447 var LAYER_BACK_BUTTON, LAYER_FORWARD_BUTTON, DELETE_BUTTON, EDIT_BUTTON, CHANGE_BUTTON,
3448 PUSH_OUT_RATIO = 0.5,
3450 elmRoot, elmContainer, elmPushout, elmTail,
3455 currentElement = null,
3458 ui, inputX, inputY, inputZ, inputA, inputW, inputH, inputPercentW, inputPercentH, inputAspectRatio,
3459 buttonBack, buttonForward, buttonDel, buttonEdit, butonChange;
3461 function layerBack(){
3462 if( currentElement === null ) return;
3463 if( PANEL_ELEMENT_CONTROL.replace( currentElement, false ) === false ) return;
3464 CONSOLE_CONTROLER.update( currentElement );
3465 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.replace, [ currentElement, true ], [ currentElement, false ] );
3466 var _z = currentElement.z;
3467 LAYER_BACK_BUTTON.visible( _z > 0 );
3468 LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length - 1 );
3470 function layerForward(){
3471 if( currentElement === null ) return;
3472 if( PANEL_ELEMENT_CONTROL.replace( currentElement, true ) === false ) return;
3473 CONSOLE_CONTROLER.update( currentElement );
3474 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.replace, [ currentElement, false ], [ currentElement, true ] );
3475 var _z = currentElement.z;
3476 LAYER_BACK_BUTTON.visible( _z > 0 );
3477 LAYER_FORWARD_BUTTON.visible( _z < PANEL_ELEMENT_ARRAY.length - 1 );
3480 if( currentElement === null ) return;
3481 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ true, currentElement ], [ false, currentElement ], false ); // true
3482 PANEL_ELEMENT_CONTROL.remove( currentElement );
3483 PanelElementOperatorManager.hide();
3486 if( currentElement === null || currentElement.type !== PANEL_ELEMENT_TYPE_TEXT ) return;
3487 TextEditor.boot( PANEL_CONTROL.x, PANEL_CONTROL.y, currentElement );
3490 if( currentElement === null ) return;
3491 PremiumSatge.boot( currentElement.artistID, currentElement.realPicture, currentElement );
3500 app.addKeyEventListener( 'keydown', layerBack, 66, false, true );
3501 app.addKeyEventListener( 'keydown', layerForward, 70, false, true );
3502 app.addKeyEventListener( 'keydown', del, 68, false, true );
3503 app.addKeyEventListener( 'keydown', edit, 69, false, true );
3504 app.addKeyEventListener( 'keydown', change, 85, false, true );
3506 elmContainer = document.getElementById( 'comic-element-consol-container' );
3507 elmRoot = elmContainer.parentNode;
3508 elmPushout = document.getElementById( 'comic-element-consol-pushout-wrapper' );
3509 elmTail = document.getElementById( 'comic-element-consol-pushout-tail' );
3510 delete CONSOLE_CONTROLER.init;
3513 LAYER_BACK_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'layer back', 'ctrl + B', layerBack, false, true, false );
3514 LAYER_FORWARD_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'layer forward', 'ctrl + F', layerForward, false, false, false );
3515 DELETE_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'delete', 'ctrl + D', del, false, true, true );
3516 EDIT_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'Edit Text', 'ctrl + E', edit, false, true, false );
3517 CHANGE_BUTTON = MENU_BAR_CONTROL.EDIT.createOption( 'change', 'ctrl + U', change, false, false, true );
3518 // inputAspectRatio = $( '#comic-element-keep-aspect' );
3520 delete CONSOLE_CONTROLER.open;
3522 onMouseover : function( e ){
3523 node.mesureChildren();
3526 show: function( _currentElement, w, h ){
3527 if( node === null ){
3528 node = CONSOLE_CONTROLER.node = PanelElementOperatorManager.node.createNode( elmContainer, false, false, 'comic-element-consol-container-hover' );
3529 node.addEventListener( 'mouseover', CONSOLE_CONTROLER.onMouseover, CONSOLE_CONTROLER );
3530 ui = app.createUIGroup( node );
3531 inputX = ui.createInputText( document.getElementById( 'comic-element-x' ), null );
3532 inputY = ui.createInputText( document.getElementById( 'comic-element-y' ), null );
3533 inputZ = ui.createInputText( document.getElementById( 'comic-element-z' ), null );
3534 inputA = ui.createInputText( document.getElementById( 'comic-element-a' ), null );
3535 inputW = ui.createInputText( document.getElementById( 'comic-element-w' ), null );
3536 inputH = ui.createInputText( document.getElementById( 'comic-element-h' ), null );
3537 inputPercentW = ui.createInputText( document.getElementById( 'comic-element-w-percent' ), null );
3538 inputPercentH = ui.createInputText( document.getElementById( 'comic-element-h-percent' ), null );
3539 butonChange = ui.createButton( document.getElementById( 'change-image-button' ), change ),
3540 buttonBack = ui.createButton( document.getElementById( 'layer-back-button' ), layerBack ),
3541 buttonDel = ui.createButton( document.getElementById( 'delete-button' ), del ),
3542 buttonForward = ui.createButton( document.getElementById( 'layer-forward-button' ), layerForward ),
3543 buttonEdit = ui.createButton( document.getElementById( 'edit-text-button' ), edit );
3546 currentElement = _currentElement;
3548 var type = currentElement.type,
3549 z = currentElement.z;
3551 LAYER_BACK_BUTTON.visible( z > 0 );
3552 buttonBack.enabled( z > 0 );
3553 LAYER_FORWARD_BUTTON.visible( z < PANEL_ELEMENT_ARRAY.length - 1 );
3554 buttonForward.enabled( z < PANEL_ELEMENT_ARRAY.length - 1 )
3555 DELETE_BUTTON.visible( true );
3556 EDIT_BUTTON.visible( type === PANEL_ELEMENT_TYPE_TEXT );
3557 CHANGE_BUTTON.visible( false );
3559 //CONSOLE_CONTROLER.x = Math.floor( ( _w - CONSOLE_CONTROLER.w ) / 2 );
3560 CONSOLE_CONTROLER.w = w;
3561 CONSOLE_CONTROLER.h = elmContainer.offsetHeight;
3562 CONSOLE_CONTROLER.y = h - CONSOLE_CONTROLER.h;
3564 if( h * PUSH_OUT_RATIO < CONSOLE_CONTROLER.h ){
3565 if( pushout === false ){
3567 elmPushout.lastChild.appendChild( elmContainer );
3568 elmPushout.style.display = 'block';
3569 pushoutW = elmPushout.offsetWidth;
3570 pushoutH = elmPushout.offsetHeight;
3571 elmTail.style.top = ( pushoutH / 2 - tailSize / 2 ) + 'px';
3573 elmPushout.style.left = ( -pushoutW ) + 'px';
3574 elmPushout.style.top = ( h / 2 - pushoutH / 2 ) + 'px';
3575 elmPushout.className = 'satellite-left';
3577 if( pushout === true ){
3579 elmRoot.insertBefore( elmContainer, elmRoot.firstChild );
3580 elmPushout.style.cssText = '';
3583 CONSOLE_CONTROLER.update( currentElement );
3587 update : function( _currentElement ){
3588 if( _currentElement === null ){
3592 currentElement = _currentElement;
3593 var type = currentElement.type,
3594 x = currentElement.x,
3595 y = currentElement.y,
3596 z = currentElement.z,
3597 a = type === PANEL_ELEMENT_TYPE_TEXT ? Math.floor( currentElement.a ) : 0,
3598 w = currentElement.w,
3599 h = currentElement.h,
3600 actualW = type === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualW : 1,
3601 actualH = type === PANEL_ELEMENT_TYPE_IMAGE ? currentElement.actualH : 1,
3602 wPercent = type === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( w / actualW * 100 ) : 0,
3603 hPercent = type === PANEL_ELEMENT_TYPE_IMAGE ? Math.floor( h / actualH * 100 ) : 0,
3604 keepAspect = currentElement.keepAspect;
3606 if( currentType !== type ){
3607 if( type === PANEL_ELEMENT_TYPE_TEXT ){
3608 inputA.visible( true );
3609 inputPercentW.visible( false );
3610 inputPercentH.visible( false );
3611 buttonEdit.enabled( true );
3612 //inputAspectRatio.hide();
3614 inputA.visible( false );
3615 inputPercentW.visible( true );
3616 inputPercentH.visible( true );
3617 buttonEdit.enabled( false );
3618 //inputAspectRatio.show();
3626 type === 1 && inputA.value( a );
3629 type === 0 && inputPercentW.value( wPercent );
3630 type === 0 && inputPercentH.value( hPercent );
3633 // if( visible === true ) styleConsoleWrapper.display = 'none';
3634 ui && ui.visible( false );
3636 currentElement = null;
3637 LAYER_BACK_BUTTON.visible( false );
3638 LAYER_FORWARD_BUTTON.visible( false );
3639 DELETE_BUTTON.visible( false );
3640 EDIT_BUTTON.visible( false );
3641 CHANGE_BUTTON.visible( false );
3648 var AbstractPanelElement = function( COMIC_ELM_TYPE ){
3649 this.type = COMIC_ELM_TYPE;
3651 AbstractPanelElement.prototype = {
3665 shift : function( shiftX, shiftY ){
3666 this.resize( this.x + shiftX, this.y + shiftY );
3668 mouseover : function( e ){
3669 PanelElementOperatorManager.show( this );
3673 /* --------------------------------------------------------------------------------------------
3676 var jqImageElementOrigin;
3677 var ImageElementClass = function( data ){
3678 jqImageElementOrigin = jqImageElementOrigin || $( app.fetchHTMLElement( 'imgElementTemplete' ) );
3680 this.$ = jqImageElementOrigin.clone( true );
3683 this.timing = data.t || PANEL_ELEMENT_ARRAY.length + 1;
3684 this.keepSize = false;
3685 this.flipV = data.height < 0 ? -1 : 1;
3686 this.flipH = data.width < 0 ? -1 : 1;
3687 this.rPicture = data.picture;
3690 function animeComplete(){
3692 self._flipReversibleImage();
3694 this.animeComplete = animeComplete;
3696 ImageElementClass.prototype = Util.extend(
3697 new AbstractPanelElement( PANEL_ELEMENT_TYPE_IMAGE ),
3699 reversibleImage : null,
3701 this._updateResourcePicture( this.rPicture );
3702 this.node = PANEL_ELEMENT_CONTROL.node.createNode( this.$.get( 0 ), false, true );
3703 this.node.addEventListener( 'mouseover', this.mouseover, this );
3704 this.resize( this.data.x, this.data.y, Math.abs( this.data.width ), Math.abs( this.data.height ) );
3707 flip : function( updateH, updateV ){
3708 if( updateH !== true && updateV !== true ) return;
3709 this.flipH = updateH === true ? -this.flipH : this.flipH;
3710 this.flipV = updateV === true ? -this.flipV : this.flipV;
3711 this.reversibleImage.resize( this.flipH * this.w, this.flipV * this.h );
3713 realPicture : function( _rPicture ){
3714 if( _rPicture && _rPicture !== this.rPicture ){
3715 HISTORY_CONTROL.saveState( this._updateResourcePicture, this.rPicture, _rPicture, this );
3716 this._updateResourcePicture( _rPicture );
3718 return this.rPicture;
3720 resize : function( x, y, w, h, animate ){
3721 this.x = x = Type.isFinite( x ) === true ? x : this.x;
3722 this.y = y = Type.isFinite( y ) === true ? y : this.y;
3723 this.w = w = Type.isFinite( w ) === true ? w : this.w;
3724 this.h = h = Type.isFinite( h ) === true ? h : this.h;
3725 if( animate === true ){
3731 }, 250 , this.animeComplete );
3733 this.node.update( x, y, w, h );
3734 this._flipReversibleImage();
3737 animate : function ( x, y, w, h, flipH, flipV ){
3738 this.flipH = flipH !== undefined ? flipH : this.flipH;
3739 this.flipV = flipV !== undefined ? flipV : this.flipV;
3740 this.resize( x, y, w, h, true );
3742 destroy : function(){
3743 this.reversibleImage.destroy();
3744 this.$.stop().remove();
3747 this.destroy = null;
3749 _updateResourcePicture : function( _rPicture ){
3750 this.rPicture = _rPicture;
3751 this.oPicture = this.rPicture.original_picture;
3752 this.artistID = this.oPicture.artist.id || -1;
3754 this.actualW = this.oPicture.width;
3755 this.actualH = this.oPicture.height;
3757 var _reversibleImage = pettanr.image.createReversibleImage(
3758 [ pettanr.CONST.PICTURE_PATH, this.rPicture.id, '.', this.rPicture.ext ].join( '' ),
3759 this.flipH * this.w, this.flipV * this.h
3761 if( this.reversibleImage !== null ){
3762 this.$.children( this.reversibleImage.elm ).replaceWith( _reversibleImage.elm );
3763 this.reversibleImage.destroy();
3765 this.$.append( _reversibleImage.elm );
3767 this.reversibleImage = _reversibleImage;
3769 _flipReversibleImage : function(){
3770 this.reversibleImage && this.reversibleImage.resize( this.flipH * this.w, this.flipV * this.h );
3777 * / ImageElementClass
3778 * --------------------------------------------------------------------------------------------
3782 /* --------------------------------------------------------------------------------------------
3790 * 4.black-box( dq style)
3791 * 5.blue-box( ff style)
3794 var jqTextElementOrigin;
3795 var TextElementClass = function( data ){
3796 jqTextElementOrigin = jqTextElementOrigin || ( function(){
3797 var _OLD_IE = $( app.fetchHTMLElement( 'textElementTempleteForOldIE' ) ),
3798 _MODERN = $( app.fetchHTMLElement( 'textElementTemplete' ) );
3799 return UA.isIE === true && UA.ieRenderingVersion < 8 ? _OLD_IE : _MODERN;
3802 this.$ = jqTextElementOrigin.clone( true );
3804 this.elmText = this.$.find( 'td,.speach-inner' ).get( 0 );
3805 this.type = data.balloon_template_id;
3806 this.content = ( function(){
3807 var _speachs = data.speeches_attributes;
3808 for( var k in _speachs ){
3809 return _speachs[ k ].content || '';
3813 this.balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail, this.type );
3815 this.timing = data.t || PANEL_ELEMENT_ARRAY.length + 1;
3817 this.$.find( 'img' ).eq( 0 ).replaceWith( this.balloon.elm );
3820 function animeComplete(){
3822 self._resizeBalloon();
3824 this.animeComplete = animeComplete;
3826 TextElementClass.prototype = Util.extend(
3827 new AbstractPanelElement( PANEL_ELEMENT_TYPE_TEXT ),
3831 this.node = PANEL_ELEMENT_CONTROL.node.createNode( this.$.get( 0 ), false, true );
3832 this.node.addEventListener( 'mouseover', this.mouseover, this );
3833 this.resize( this.data.x, this.data.y, this.data.width, this.data.height, this.data.tail );
3836 _updateType : function( _type ){
3837 if( this.type !== _type ){
3838 this.type = _type || this.type;
3839 this.balloon.type( this.type );
3842 _updateAngle : function( _a ){
3843 if( _a !== undefined && a !== _a ){
3844 this.a = _a !== undefined ? _a : this.a;
3845 this.balloon.angle( this.a );
3849 _updateText : function( _text ){
3850 this.content = _text || this.content || '';
3851 this.elmText.firstChild.data = this.content;
3853 _resizeBalloon : function(){
3854 this.balloon && this.balloon.resize( this.a, this.w, this.h );
3856 angle : function( _a ){
3857 _a !== undefined && this.resize( this.x, this.y, this.w, this.h, _a );
3860 text : function( _text ){
3861 if( _text && this.content !== _text ){
3862 HISTORY_CONTROL.saveState( this._updateText, this.content || '', _text, this );
3863 this._updateText( _text );
3865 return this.content;
3867 resize : function( x, y, w, h, a, animate ){
3868 this.x = x = x !== undefined ? x : this.x;
3869 this.y = y = y !== undefined ? y : this.y;
3870 this.w = w = w !== undefined ? w : this.w;
3871 this.h = h = h !== undefined ? h : this.h;
3872 this.a = a !== undefined ? a : this.a;
3874 if( animate === true ){
3880 }, 250 , this.animeComplete );
3882 this.node.update( x, y, w, h );
3883 this._resizeBalloon();
3886 animate : function ( _x, _y, _w, _h, _a ){
3887 this.resize( _x, _y, _w, _h, _a, true );
3889 destroy : function(){
3890 this.$.stop().remove();
3891 this.balloon.destroy();
3894 this.destroy = null;
3899 /* --------------------------------------------------------------------------------------------
3900 * PANEL_ELEMENT_CONTROL
3901 * - mouseEventListener
3903 var PANEL_ELEMENT_CONTROL = ( function(){
3904 var elmContainer = null,
3905 currentElement = null,
3907 panelX, panelY, panelW, panelH,
3910 * append, remove, replace
3912 * panelElement には、z-position と dom-index がある。
3913 * z-position は 表示上の位置。大きいほど前に表示される( z-index)
3914 * dom-index は 意味上の順番。htmlタグの登場順で、検索結果や音声読み上げブラウザで正しく意味が取れる順番。
3916 * editerでは、実際には z-index は使わず、htmlの順序で前後を表現する。
3917 * dom-index は、数値のみ保持して、投稿時にpanelElementを適宜に並び替える。
3919 * append panelElement
3920 * 1. 新しい panelElement の z-position を得る
3921 * 2. z の同じ panelElementを見つけ、その前に加える。または一番先頭へ。(PANEL_ELEMENT_ARRAY)
3922 * zが大きいほど、PANEL_ELEMENT_ARRAYの先頭へ。
3923 * 3. dom位置は、PANEL_ELEMENT_ARRAY とは反対に、前のものほど後ろへ。
3926 * remove panelElement
3930 function onFadeOut(){
3931 this.parentNode.removeChild( this );
3934 * PANEL_ELEMENT_ARRAY の順番を基準に、zの再計算
3937 function renumber(){
3938 var _panelElement, jqElm, jqAfter,
3939 i = PANEL_ELEMENT_ARRAY.length;
3941 _panelElement = PANEL_ELEMENT_ARRAY[ --i ];
3942 jqElm = _panelElement.$;
3943 !jqAfter && elmContainer.appendChild( jqElm.get( 0 ) );
3944 jqAfter && jqAfter.before( jqElm );
3946 _panelElement.z = i;
3947 _panelElement.node.nodeIndex( i );
3952 function onTextInput( _panelElement ){
3953 PANEL_ELEMENT_CONTROL.add( _panelElement );
3954 _panelElement.animate( undefined, undefined, _panelElement.w, _panelElement.h );
3955 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ false, _panelElement ], [ true, _panelElement ], true, PANEL_ELEMENT_CONTROL );
3959 id : 'PANEL_ELEMENT_CONTROL',
3962 elmContainer = document.getElementById( 'comic-element-container' );
3963 node = PANEL_ELEMENT_CONTROL.node = eventRoot.createNode( elmContainer, true, false );
3964 node.nodeIndex( 0 );
3965 delete PANEL_ELEMENT_CONTROL.init;
3968 delete PANEL_ELEMENT_CONTROL.open;
3972 while( panelElm = PANEL_ELEMENT_ARRAY.shift() ){
3973 panelElm.destroy && panelElm.destroy();
3976 add : function( _panelElement ){
3977 var z = Type.isFinite( _panelElement.z ) === true ? _panelElement.z : -1,
3978 i = PANEL_ELEMENT_ARRAY.length,
3979 _jqElm = _panelElement.$.stop().css( {
3985 PANEL_ELEMENT_ARRAY.push( _panelElement );
3988 if( PANEL_ELEMENT_ARRAY[ --i ].z < z ){
3994 PANEL_ELEMENT_ARRAY.unshift( _panelElement );
3996 PANEL_ELEMENT_ARRAY.splice( i + 1, 0, _panelElement );
4001 _panelElement.node.disabled( false );
4003 remove : function( _panelElement ){
4004 for( var i = PANEL_ELEMENT_ARRAY.length; i; ){
4005 if( PANEL_ELEMENT_ARRAY[ --i ] === _panelElement ){
4006 console.log( PANEL_ELEMENT_ARRAY.length );
4007 PANEL_ELEMENT_ARRAY.splice( i, 1 );
4008 _panelElement.node.disabled( true );
4009 _panelElement.node.nodeIndex( PANEL_ELEMENT_ARRAY.length );
4011 _panelElement.$.stop().css( {
4014 }).fadeOut( onFadeOut );
4015 if( currentElement === _panelElement ) currentElement = null;
4021 restore : function( isAppend, panelElement ){
4022 PANEL_ELEMENT_CONTROL[ isAppend === true ? 'add' : 'remove' ]( panelElement );
4024 replace: function( _panelElement, goForward ){
4025 // PANEL_ELEMENT_ARRAYの再構築
4026 var l = PANEL_ELEMENT_ARRAY.length,
4030 if( PANEL_ELEMENT_ARRAY[ --j ] === _panelElement ){
4035 if( i !== j ) return false;
4036 if( goForward === true ){
4037 if( i === 0 ) return false;
4038 PANEL_ELEMENT_ARRAY.splice( i, 1 );
4039 PANEL_ELEMENT_ARRAY.splice( i + 1, 0, _panelElement );
4041 if( i === l - 1 ) return false;
4042 PANEL_ELEMENT_ARRAY.splice( i, 1 );
4043 PANEL_ELEMENT_ARRAY.splice( i - 1, 0, _panelElement );
4048 onPanelResize : function ( _panelX, _panelY, _panelW, _panelH, isResizerTopAction ){
4050 * リサイズが、ResizerTopによって行われた場合、panelElementのyを動かして見かけ上動かないようにする。
4052 if( isResizerTopAction === true ){
4053 var _shiftX = _panelW - panelW,
4054 _shiftY = _panelH - panelH;
4055 for( var i = PANEL_ELEMENT_ARRAY.length; i; ){
4056 PANEL_ELEMENT_ARRAY[ --i ].shift( _shiftX, _shiftY );
4059 node.update( panelX = _panelX, panelY = _panelY, panelW = _panelW, panelH = _panelH );
4061 createImageElement: function( data ){
4062 if( Type.isObject( data ) === false ){
4063 PremiumSatge.boot( 1, PANEL_ELEMENT_CONTROL.onImageSelect );
4065 PANEL_ELEMENT_CONTROL.onImageSelect( data, true );
4068 onImageSelect: function( data, isPanelPictureData ){
4070 if( isPanelPictureData !== true ){
4071 _panelElement = new ImageElementClass( {
4072 picture : data.picture,
4073 x : Math.floor( panelW / 2 - data.width / 2 ),
4074 y : Math.floor( panelH / 2 - data.height / 2 ),
4076 t : PANEL_ELEMENT_ARRAY.length + 1,
4080 _panelElement.init();
4081 PANEL_ELEMENT_CONTROL.add( _panelElement );
4082 _panelElement.animate( undefined, undefined, Math.abs( data.picture.original_picture.width ), Math.abs( data.picture.original_picture.height ) );
4084 _panelElement = new ImageElementClass( data );
4085 _panelElement.init();
4086 PANEL_ELEMENT_CONTROL.add( _panelElement );
4088 HISTORY_CONTROL.saveState( PANEL_ELEMENT_CONTROL.restore, [ false, _panelElement ], [ true, _panelElement ], true );
4090 createTextElement: function( data ){
4092 if( Type.isObject( data ) === false ){
4094 balloon_template_id:1,
4097 x: Math.floor( panelW / 2 - 100 + Math.random() * 10 ),
4098 y: Math.floor( panelH / 2 - 100 + Math.random() * 10 ),
4100 t: PANEL_ELEMENT_ARRAY.length + 1,
4103 speeches_attributes: {
4109 _panelElement = new TextElementClass( data );
4110 _panelElement.init();
4111 TextEditor.boot( PANEL_CONTROL.x, PANEL_CONTROL.y, _panelElement, onTextInput );
4113 _panelElement = new TextElementClass( data );
4114 _panelElement.init();
4115 onTextInput( _panelElement );
4122 * end of PANEL_ELEMENT_CONTROL
4125 function centering(){
4126 app.onPaneResize( windowW, windowH );
4131 this.MIN_WIDTH = 320;
4132 this.MIN_HEIGHT = 320;
4133 this.onInit = function(){
4134 app.rootElement.id = 'editor';
4135 app.rootElement.innerHTML = [
4136 '<div id="grid" style="display:none;"></div>',
4137 '<div id="comic-element-container"></div>',
4138 '<div id="whiteGlass-container">',
4139 '<div id="whiteGlass-top"></div>',
4140 '<div id="whiteGlass-left"></div>',
4141 '<div id="whiteGlass-right"></div>',
4142 '<div id="whiteGlass-bottom"></div>',
4144 '<div id="panel-tools-container">',
4145 '<div id="panel-resizer-top">▲</div>',
4146 '<div id="panel-resizer-bottom">▼</div>',
4148 '<div id="window-container"></div>',
4149 '<div id="comic-element-resizer-container">',
4150 '<div id="comic-element-resizer-container-inner">',
4151 '<div id="comic-element-consol-wrapper">',
4152 '<div id="comic-element-consol-container" class="clearfix">',
4153 '<div class="comic-element-consol-item">',
4154 '<div id="comic-element-x">',
4155 '<span class="comic-element-attribute-label">x:</span>',
4156 '<span id="comic-element-x-value" class="comic-element-attribute-value editable-value">0</span>',
4158 '<div id="comic-element-y">',
4159 '<span class="comic-element-attribute-label">y:</span>',
4160 '<span id="comic-element-y-value" class="comic-element-attribute-value editable-value">0</span>',
4163 '<div class="comic-element-consol-item">',
4164 '<div id="comic-element-z">',
4165 '<span class="comic-element-attribute-label">z:</span>',
4166 '<span id="comic-element-z-value" class="comic-element-attribute-value editable-value">0</span>',
4168 '<div id="comic-element-a">',
4169 '<span id="comic-element-a-value" class="comic-element-attribute-value editable-value">0</span>',
4170 '<span class="comic-element-attribute-label">°</span>',
4173 '<div class="comic-element-consol-item">',
4174 '<div id="comic-element-w">',
4175 '<span class="comic-element-attribute-label">w:</span>',
4176 '<span id="comic-element-w-value" class="comic-element-attribute-value editable-value">0</span>',
4178 '<div id="comic-element-h">',
4179 '<span class="comic-element-attribute-label">h:</span>',
4180 '<span id="comic-element-h-value" class="comic-element-attribute-value editable-value">0</span>',
4183 '<div class="comic-element-consol-item">',
4184 '<!-- <div id="comic-element-keep-aspect"></div> -->',
4185 '<div id="comic-element-w-percent">',
4186 '<span id="comic-element-w-percent-value" class="comic-element-attribute-value editable-value">0</span>',
4187 '<span class="comic-element-attribute-label">%</span>',
4189 '<div class="comic-element-consol-item" id="comic-element-h-percent">',
4190 '<span id="comic-element-h-percent-value" class="comic-element-attribute-value editable-value">0</span>',
4191 '<span class="comic-element-attribute-label">%</span>',
4194 '<div class="comic-element-consol-item-small">',
4195 '<div class="button" id="change-image-button">change</div>',
4197 '<div class="comic-element-consol-item-small">',
4198 '<div class="button" id="layer-back-button">back</div>',
4200 '<div class="comic-element-consol-item-small">',
4201 '<div class="button" id="delete-button">delete</div>',
4203 '<div class="comic-element-consol-item-small">',
4204 '<div class="button" id="layer-forward-button">forward</div>',
4206 '<div class="comic-element-consol-item-small">',
4207 '<div class="button" id="edit-text-button">edit</div>',
4209 '<!-- <div class="comic-element-consol-item-small">',
4210 '<div class="button" id="hide-text-tail-button">tail</div>',
4214 '<div class="comic-element-resizer" id="comic-element-resizer-top"></div>',
4215 '<div class="comic-element-resizer" id="comic-element-resizer-left"></div>',
4216 '<div class="comic-element-resizer" id="comic-element-resizer-right"></div>',
4217 '<div class="comic-element-resizer" id="comic-element-resizer-bottom"></div>',
4218 '<div class="comic-element-resizer" id="comic-element-resizer-top-left"></div>',
4219 '<div class="comic-element-resizer" id="comic-element-resizer-top-right"></div>',
4220 '<div class="comic-element-resizer" id="comic-element-resizer-bottom-left"></div>',
4221 '<div class="comic-element-resizer" id="comic-element-resizer-bottom-right"></div>',
4222 '<div id="comic-element-consol-pushout-wrapper">',
4223 '<div id="comic-element-consol-pushout-tail"></div>',
4224 '<div id="comic-element-consol-pushout-inner"></div>',
4226 '<div id="balloon-tail-mover"></div>',
4229 '<div id="menu-bar"></div>',
4231 '<div id="templete-container" style="display: none;">',
4232 '<div id="imgElementTemplete" class="comic-element-wrapper image-element"></div>',
4234 '<div id="textElementTemplete" class="comic-element-wrapper text-element">',
4236 '<div class="speach">',
4237 '<div class="speach-inner"> </div>',
4241 '<div id="textElementTempleteForOldIE" class="comic-element-wrapper text-element">',
4243 '<div class="speach">',
4244 '<table><tr><td> </td></tr></table>',
4248 '<div id="imageGroupItemTemplete" class="image-group-item">',
4249 '<div class="image-group-item-title">img-title</div>',
4252 '<div id="windowTemplete" class="window-wrapper">',
4253 '<div class="window-header">',
4254 '<div class="window-header-title">window title</div>',
4255 '<div class="window-close-button">x</div>',
4257 '<div class="window-body"></div>',
4258 '<div class="window-footer">',
4259 '<div class="window-resize-button"></div>',
4263 '<div id="infomation-window">',
4264 '<div id="panel-background-information">',
4265 '<div id="bg-pattern"></div>',
4266 '<div id="select-bg-pattern-button">pattern</div>',
4267 '<div id="reset-bg-pattern-button">x</div>',
4268 '<div id="bg-color"></div>',
4269 '<div id="select-bg-color-button">color</div>',
4270 '<div id="reset-bg-color-button">x</div>',
4271 '<!-- <div id="bg-pattern-x"></div>',
4272 '<div id="bg-pattern-y"></div>',
4273 '<div id="bg-pattern-repeat-x"></div>',
4274 '<div id="bg-pattern-repeat-y"></div> -->',
4278 '<div id="toolbox-window">',
4279 '<div id="toolbox-add-image-button" class="button">add image</div>',
4280 '<div id="toolbox-add-text-button" class="button">add text</div>',
4281 '<div id="toolbox-edit-bg-button" class="button">edit bg</div>',
4282 '<div id="toolbox-switch-grid" class="button">grid</div>',
4283 '<div id="toolbox-popup-help-button" class="button">?</div>',
4284 '<div id="toolbox-post-button" class="button">post</div>',
4290 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4291 eventRoot = app.getPointingDeviceEventTreeRoot();
4295 this.onOpen = function( _w, _h, file ){
4296 // 表示奥の物から順に init() していく
4297 PANEL_ELEMENT_CONTROL.init();
4298 PANEL_CONTROL.init();
4299 // PANEL_RESIZER_BOTTOM.init();
4300 // PANEL_RESIZER_TOP.init();
4301 WINDOWS_CONTROL.init();
4302 MENU_BAR_CONTROL.init();
4304 // レイヤーにあまり関係ないモジュール
4305 HISTORY_CONTROL.init();
4306 SAVE_CONTROL.init();
4307 GRID_CONTROL.init();
4308 WHITE_GLASS_CONTROL.init();
4309 PanelElementOperatorManager.init();
4318 fileData, panelElements, panelElm;
4320 if( FileAPI.isFileInstance( file ) === true ){
4321 if( Driver.isPettanrFileInstance( file ) === true ){
4322 if( file.getType() === FILE_TYPE.COMIC ){
4323 fileData = file.read();
4324 panelW = fileData.width;
4325 panelH = fileData.height;
4326 comicID = fileData.id || -1;
4328 if( file.getType() === FILE_TYPE.PANEL ){
4329 fileData = file.read();
4330 panelW = fileData.width;
4331 panelH = fileData.height;
4332 borderSize = fileData.border;
4333 panelElements = fileData.elements;
4334 comicID = fileData.comic ? fileData.comic.id || -1 : -1;
4335 panelID = fileData.id || -1;
4336 panelTimming = fileData.t || -1;
4343 // open() は各モジュールの init() 後に実施可能になる.
4344 HISTORY_CONTROL.open();
4345 SAVE_CONTROL.open();
4346 WINDOWS_CONTROL.open();
4348 GRID_CONTROL.open();
4349 PANEL_CONTROL.open( panelW, panelH, borderSize );
4350 PanelElementOperatorManager.open();
4351 PANEL_ELEMENT_CONTROL.open();
4354 MENU_BAR_CONTROL.open();
4358 app.onPaneResize( _w, _h );
4361 if( Type.isArray( panelElements ) === true ){
4362 for( var i=0; i<panelElements.length; ++i ){
4363 panelElm = panelElements[ i ];
4364 if( panelElm.picture ){
4365 PANEL_ELEMENT_CONTROL.createImageElement( panelElm );
4367 if( panelElm.balloon_template_id ){
4368 PANEL_ELEMENT_CONTROL.createTextElement( panelElm );
4376 app.addKeyEventListener( 'keydown', centering, 96, false, true ); // ctrl + 0
4377 app.addKeyEventListener( 'krydown', centering, 48, false, true ); // ctrl + 0
4378 MENU_BAR_CONTROL.EDIT.createOption( 'centering', 'ctrl + 0', centering, true, true, true);
4384 this.onClose = function(){
4386 HISTORY_CONTROL.close();
4388 WINDOWS_CONTROL.close();
4390 GRID_CONTROL.close();
4391 PANEL_CONTROL.close();
4393 PanelElementOperatorManager.close();
4394 PANEL_ELEMENT_CONTROL.close();
4397 MENU_BAR_CONTROL.close();
4401 this.onPaneResize = function( _windowW, _windowH ){
4402 windowW = _windowW || windowW;
4403 windowH = _windowH || windowH;
4405 app.rootElement.style.height = _windowH + 'px';
4407 WINDOWS_CONTROL.onWindowResize( _windowW, _windowH );
4408 MENU_BAR_CONTROL.onWindowResize( _windowW, _windowH );
4409 PANEL_CONTROL.onWindowResize( _windowW, _windowH );
4411 }, false, true, 'Panel Editor', 'paneleditor', null, '#2D89F0' );
4413 var FormApplicationHelper = function( app ){
4414 app.isUploading = false;
4415 app.elmProgress = null;
4416 app.elmUploader = null;
4417 app.elmScript = null;
4418 app.elmIframeWrap = null;
4419 app.elmIframe = null;
4421 app.fetchScript = function(){
4422 app.elmProgress = document.getElementById( app.elmProgressID );
4424 if( !( app.elmUploader = document.getElementById( app.elmUploaderID ) ) ){
4425 app.elmUploader = document.createElement( 'div' );
4426 app.rootElement.appendChild( app.elmUploader );
4427 app.elmUploader.id = app.elmUploaderID;
4428 if( app.hideUploader === true ){
4429 app.elmUploader.style.cssText = 'height:1px;line-height:1px;visibility:hidden;overflow:hidden;';
4433 app.elmIframeWrap = document.getElementById( app.iframeWrapID );
4434 app.elmScript = document.createElement( 'script' );
4435 document.body.appendChild( app.elmScript );
4436 app.elmScript.type = 'text\/javascript';
4437 app.elmScript.src = app.scriptSrc;
4439 app.elmProgress.innerHTML = 'loading form.';
4441 app.addTimer( app.detectForm, 250 );
4443 delete app.fetchScript;
4445 app.detectForm = function(){
4446 app.elmForm = app.elmUploader.getElementsByTagName( 'form' )[ 0 ];
4447 if( !app.elmForm ) return;
4448 app.removeTimer( app.detectForm );
4450 Util.createIframe( 'targetFrame', app.onCreateIframe );
4451 app.elmProgress.innerHTML = 'create iframe';
4452 delete app.detectForm;
4454 app.onCreateIframe = function( _iframe ){
4455 app.elmIframeWrap.appendChild( _iframe );
4456 _iframe.className = 'form-iframe';
4457 app.elmIframe = _iframe;
4458 app.elmForm.target = _iframe.name;
4459 app.elmProgress.innerHTML = '';
4460 app.onFormReady && app.onFormReady();
4462 delete app.onCreateIframe;
4464 app.submit = function(){
4465 app.elmProgress.innerHTML = 'submit!';
4467 app.elmForm.submit();
4468 app.isUploading = true;
4470 app.elmProgress.innerHTML = 'submit err..';
4471 app.submitError && app.submitError();
4474 if( app.detectIframe ){
4475 app.elmIframe.onreadystatechange = app.detectIframe;
4477 app.elmIframe.onload = app.onIframeUpdate;
4479 app.elmProgress.innerHTML = 'uploading..';
4484 app.detectIframe = function(){
4485 if ( this.readyState !== 'complete' ) return;
4486 this.onreadystatechange = new Function();
4487 this.onreadystatechange = null;
4488 app.onIframeUpdate();
4489 delete app.detectIframe;
4492 app.onIframeUpdate = function(){
4493 app.elmIframe.onload = null;
4495 console.log( ( app.elmIframe.contentWindow || app.elmIframe.contentDocument.parentWindow ).document.body.innerHTML );
4496 console.log( ( app.elmIframe.contentWindow || app.elmIframe.contentDocument.parentWindow )[ 'current_author' ] );
4500 ( app.elmIframe.contentWindow || app.elmIframe.contentDocument.parentWindow ).close();
4501 app.elmIframe = null;
4502 app.elmProgress.innerHTML = 'success!';
4503 app.isUploading = false;
4504 // app.submitSuccess && app.submitSuccess();
4505 delete app.onIframeUpdate;
4507 app.destroyHelper = function(){
4508 app.elmUploader.parentNode.removeChild( app.elmUploader );
4513 var ComicConsole = gOS.registerApplication( function(){
4514 var elmHeader, elmProgress,
4516 inputTitle, inputW, inputH,
4518 comboboxVisible, // comboboxEditable,
4519 buttonSubmit, buttonCancel,
4523 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4526 var _inputList = app.elmForm.getElementsByTagName( 'input' ),
4528 for( var i = _inputList.length; i; ){
4529 _input = _inputList[ --i ];
4530 _name = _input.name;
4531 if( _name === 'comic[title]' ){
4532 _input.value = inputTitle.value();
4534 if( _name === 'comic[width]' ){
4535 _input.value = inputW.value();
4537 if( _name === 'comic[height]' ){
4538 _input.value = inputH.value();
4541 var _selectList = app.elmForm.getElementsByTagName( 'select' ),
4542 _select, _optionList;
4543 for( i = _selectList.length; i; ){
4544 _select = _selectList[ --i ];
4545 _name = _select.name;
4546 _optionList = _select.getElementsByTagName( 'option' )
4547 if( _name === 'comic[visible]' ){
4548 _select.selectedIndex = comboboxVisible.selectIndex();
4550 if( _name === 'comic[editable]' ){
4551 _select.selectedIndex = comboboxEditable.selectIndex();
4554 buttonSubmit.enabled( false );
4557 function clickCancel(){
4558 if( app.isUploading === true ) return false;
4559 ComicConsole.shutdown();
4563 this.MIN_WIDTH = 320;
4564 this.MIN_HEIGHT = 320;
4565 this.onInit = function(){
4566 app.rootElement.id = 'comic-console-wrapper';
4567 app.rootElement.className = 'console-wrapper';
4568 app.rootElement.innerHTML = [
4569 '<div id="comic-console-header" class="console-header">Create New Comic</div>',
4570 '<div id="comic-console" class="console-inner">',
4571 '<div id="comic-console-title" class="field">',
4572 '<span class="field-label">Title:</span>',
4573 '<span id="comic-console-title-value" class="comic-console-value editable-value">No Title</span>',
4575 '<div id="comic-console-width" class="field">',
4576 '<span class="field-label">Default Width:</span>',
4577 '<span id="comic-console-width-value" class="comic-console-value editable-value">300</span>',
4579 '<div id="comic-console-height" class="field">',
4580 '<span class="field-label">Default Height:</span>',
4581 '<span id="comic-console-height-value" class="comic-console-value editable-value">200</span>',
4583 '<div id="comic-console-visible" class="field">',
4584 '<span class="field-label">Visible:</span>',
4585 '<span id="comic-console-visible-value" class="comic-console-value combobox"></span>',
4587 //'<div id="comic-console-editable" class="field">',
4588 // '<span class="field-label">Editable:</span>',
4589 // '<span id="comic-console-editable-value" class="comic-console-value combobox"></span>',
4591 '<div class="console-button-container">',
4592 '<div id="comic-console-post-button" class="button console-submit-button">create</div>',
4593 '<div id="comic-console-cancel-button" class="button console-cancel-button">cancel</div>',
4595 '<div id="comic-console-progress" class="console-progress"> </div>',
4596 '<div id="comic-console-iframe-container"></div>',
4600 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4601 eventRoot = app.getPointingDeviceEventTreeRoot();
4605 this.elmProgressID = 'comic-console-progress';
4606 this.elmUploaderID = 'newcomic';
4607 this.iframeWrapID = 'comic-console-iframe-container';
4608 this.elmIframeName = 'targetFrameCreateComic'
4609 this.scriptSrc = pettanr.CONST.CREATE_COMIC_JS;
4610 this.hideUploader = true;
4612 FormApplicationHelper( this );
4614 this.onOpen = function( w, h ){
4615 node = eventRoot.createNode( app.rootElement, true, true );
4617 var ui = app.createUIGroup( node );
4619 inputTitle = ui.createInputText( document.getElementById( 'comic-console-title') );
4620 inputW = ui.createInputText( document.getElementById( 'comic-console-width') );
4621 inputH = ui.createInputText( document.getElementById( 'comic-console-height') );
4622 comboboxVisible = ui.createCombobox( document.getElementById( 'comic-console-visible') );
4623 // comboboxEditable = ui.createCombobox( document.getElementById( 'comic-console-editable') );
4624 buttonSubmit = ui.createButton( document.getElementById( 'comic-console-post-button'), clickOK );
4625 buttonCancel = ui.createButton( document.getElementById( 'comic-console-cancel-button'), clickCancel );
4627 app.onPaneResize( w, h );
4631 this.onPaneResize = function( w, h ){
4634 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
4636 this.onClose = function(){
4637 app.destroyHelper();
4638 app = inputTitle = inputW = inputH = comboboxVisible = buttonSubmit = buttonCancel = null;
4640 this.onFormReady = function(){
4641 var selectList = app.elmForm.getElementsByTagName( 'select' ),
4645 for( var i=0, l=selectList.length; i<l; ++i ){
4646 select = selectList[ i ];
4647 optionList = select.getElementsByTagName( 'option' );
4648 for( j=0, m=optionList.length; j<m; ++j ){
4649 option = optionList[ j ];
4650 if( select.name === 'comic[visible]' ){
4651 comboboxVisible.createOption( option.innerHTML, option.value, option.selected );
4653 if( select.name === 'comic[editable]' ){
4654 comboboxEditable.createOption( option.innerHTML, option.value, option.selected );
4661 app.onPaneResize( windowW, windowH );
4663 delete app.onFormReady;
4665 this.submitError = function(){
4666 app.addTimer( clickCancel , 5000, true );
4668 this.submitSuccess = function(){
4669 app.addTimer( clickCancel , 5000, true );
4671 }, true, true, 'Comic Console', 'comicConsole', null, '#D44A26' );
4673 var UploadConsole = gOS.registerApplication( function(){
4674 var windowW, windowH,
4675 eventRoot, node, nodeForm,
4676 buttonSubmit, buttonCancel,
4681 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4682 if( elmFile.value.length === 0 ) return false;
4684 buttonSubmit.enabled( false );
4687 function clickCancel(){
4688 if( app.isUploading === true ) return false;
4689 UploadConsole.shutdown();
4694 this.MIN_WIDTH = 320;
4695 this.MIN_HEIGHT = 320;
4696 this.onInit = function(){
4697 app.rootElement.id = 'upload-console-wrapper';
4698 app.rootElement.className = 'console-wrapper';
4699 app.rootElement.innerHTML = [
4700 '<div id="upload-console-header" class="console-header">Upload Picture</div>',
4701 '<div id="upload-console" class="console-inner">',
4702 '<div id="upload-console-uiform"></div>',
4703 '<div class="console-button-container">',
4704 '<div id="upload-console-post-button" class="button console-submit-button">upload</div>',
4705 '<div id="upload-console-cancel-button" class="button console-cancel-button">cancel</div>',
4707 '<div id="upload-console-progress" class="console-progress"> </div>',
4708 '<div id="upload-console-iframe-container"></div>',
4712 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4714 eventRoot = app.getPointingDeviceEventTreeRoot();
4715 document.body.appendChild( Util.pullHtmlAsTemplete( '<div id="uploader"></div>' ) );
4718 this.elmProgressID = 'upload-console-progress';
4719 this.elmUploaderID = 'uploader';
4720 this.iframeWrapID = 'upload-console-iframe-container';
4721 this.elmIframeName = 'targetFrameUpload';
4722 this.scriptSrc = pettanr.CONST.UPLOAD_PICTURE_JS;
4723 this.hideUploader = false;
4724 FormApplicationHelper( this );
4725 this.onOpen = function( w, h ){
4726 node = eventRoot.createNode( app.rootElement, true, true );
4727 nodeForm = node.createNode( document.getElementById( 'upload-console-uiform' ), false, true );
4728 var ui = app.createUIGroup( node );
4730 buttonSubmit = ui.createButton( document.getElementById( 'upload-console-post-button' ), clickOK );
4731 buttonCancel = ui.createButton( document.getElementById( 'upload-console-cancel-button' ), clickCancel );
4733 app.onPaneResize( w, h );
4736 this.onPaneResize = function( w, h ){
4739 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
4741 this.onClose = function(){
4742 app.destroyHelper();
4743 app = elmFile = buttonSubmit = buttonCancel = null;
4745 this.onFormReady = function(){
4746 var elmForm = app.elmForm,
4747 _inputList = elmForm.getElementsByTagName( 'input' ),
4749 for( var i = _inputList.length; i; ){
4750 _input = _inputList[ --i ];
4751 if( _input.type === 'file' ){
4754 if( _input.type === 'submit' ){
4755 _input.style.display = 'none';
4759 app.createUIForm( nodeForm, elmForm );
4761 node.mesureChildren();
4762 app.onPaneResize( windowW, windowH );
4763 delete app.onFormReady;
4765 this.submitError = function(){
4766 app.addTimer( clickCancel , 5000, true );
4768 this.submitSuccess = function(){
4769 app.addTimer( clickCancel , 5000, true );
4771 }, true, true, 'Upload Console', 'uploadConsole', null, '#01A31C' );
4773 var ArtistConsole = gOS.registerApplication( function(){
4774 var windowW, windowH,
4776 elmName, elmLicense,
4777 inputName, inputLicense,
4778 buttonSubmit, buttonCancel,
4782 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4785 buttonSubmit.enabled( false );
4788 function clickCancel(){
4789 if( app.isUploading === true) return false;
4790 ArtistConsole.shutdown();
4793 function inputUpdate( v ){
4794 elmName.value = inputName.value();
4795 elmLicense.value = inputLicense.value();
4799 this.MIN_WIDTH = 320;
4800 this.MIN_HEIGHT = 320;
4801 this.onInit = function(){
4802 app.rootElement.id = 'artist-console-wrapper';
4803 app.rootElement.className = 'console-wrapper';
4804 app.rootElement.innerHTML = [
4805 '<div id="artist-console-header" class="console-header">Register Artist</div>',
4806 '<div id="artist-console" class="console-inner">',
4807 '<div id="artist-console-name" class="field">',
4808 '<span class="field-label">Name:</span>',
4809 '<span id="artist-console-name-value" class="comic-console-value editable-value">artist name here.</span>',
4811 '<div id="artist-console-license" class="field">',
4812 '<span class="field-label">License:</span>',
4813 '<span id="artist-console-license-value" class="comic-console-value editable-value">license here.</span>',
4815 '<div class="console-button-container">',
4816 '<div id="artist-console-post-button" class="button console-submit-button">register</div>',
4817 '<div id="artist-console-cancel-button" class="button console-cancel-button">cancel</div>',
4819 '<div id="artist-console-progress" class="console-progress"> </div>',
4820 '<div id="register" style="display:none;"></div>',
4821 '<div id="artist-console-iframe-container"></div>',
4825 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4826 eventRoot = app.getPointingDeviceEventTreeRoot();
4830 this.elmProgressID = 'artist-console-progress';
4831 this.elmUploaderID = 'register';
4832 this.iframeWrapID = 'artist-console-iframe-container';
4833 this.elmIframeName = 'targetFrameArtistRegister'
4834 this.scriptSrc = pettanr.CONST.REGISTER_ARTIST_JS;
4835 this.hideUploader = false;
4836 FormApplicationHelper( this );
4837 this.onFormReady = function(){
4838 var _inputList = app.elmForm.getElementsByTagName( 'input' ),
4840 for( var i = _inputList.length; i; ){
4841 _input = _inputList[ --i ];
4842 if( _input.type === 'submit' ){
4843 _input.style.display = 'none';
4845 if( _input.name === 'artist[name]' ){
4848 if( _input.name === 'artist[default_license_id]' ){
4849 elmLicense = _input;
4854 app.onPaneResize( windowW, windowH );
4855 node.mesureChildren();
4857 delete app.onFormReady;
4859 this.submitError = function(){
4860 app.addTimer( clickCancel , 5000, true );
4862 this.submitSuccess = function(){
4863 app.addTimer( clickCancel , 5000, true );
4865 this.onOpen = function( w, h ){
4866 node = eventRoot.createNode( app.rootElement, true, true );
4867 var ui = app.createUIGroup( node );
4869 inputName = ui.createInputText( document.getElementById( 'artist-console-name' ), inputUpdate );
4870 inputLicense = ui.createInputText( document.getElementById( 'artist-console-license' ), inputUpdate );
4871 buttonSubmit = ui.createButton( document.getElementById( 'artist-console-post-button' ), clickOK );
4872 buttonCancel = ui.createButton( document.getElementById( 'artist-console-cancel-button' ), clickCancel );
4874 app.onPaneResize( w, h );
4877 this.onPaneResize = function( w, h ){
4880 //app.rootElement.style.cssText = [
4881 // 'left:', Math.floor( ( _w - app.rootElement.offsetWidth ) /2 ), 'px;',
4882 // 'top:', Math.floor( ( _h- app.rootElement.offsetHeight ) /2 ), 'px;'
4884 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
4886 this.onClose = function(){
4887 app.destroyHelper();
4888 app = buttonSubmit = buttonCancel = null;
4890 }, true, true, 'Artist Console', 'artistConsole', null, '#FFC40D' );
4892 var PanelConsole = gOS.registerApplication( function(){
4893 var windowW, windowH,
4894 eventRoot, node, inputData,
4895 comboboxPublish, buttonSubmit, buttonClose,
4901 * upload ボタンが押されたらまず iframe をつくる.
4904 if( !app.elmForm || !app.elmIframe || app.isUploading === true ) return false;
4907 buttonSubmit.enabled( false );
4911 function clickCancel(){
4912 if( app.isUploading === true ) return false;
4913 PanelConsole.shutdown();
4916 function publishUpdate(){
4918 model.publish( comboboxPublish.selectIndex() === 1 );
4919 elmInput.value = model.getJsonPostString().replace( /\n/g, '' );
4920 inputData.value( elmInput.value );
4922 elmInput.value = inputData.value();
4927 this.MIN_WIDTH = 320;
4928 this.MIN_HEIGHT = 320;
4929 this.onInit = function(){
4930 app.rootElement.id = 'panel-console-wrapper';
4931 app.rootElement.className = 'console-wrapper';
4932 app.rootElement.innerHTML = [
4933 '<div id="panel-console-header" class="console-header">Create New Panel (dev)</div>',
4934 '<div id="panel-console" class="console-inner">',
4935 '<div id="panel-console-data" class="field">',
4936 '<span class="field-label">POST DATA:</span>',
4937 '<span id="panel-console-data-value" class="comic-console-value editable-value">panel json here.</span>',
4939 '<div id="panel-console-publish" class="field">',
4940 '<span class="field-label">Publish:</span>',
4941 '<span id="panel-console-publish-value" class="combobox"></span>',
4943 '<div class="console-button-container">',
4944 '<div id="panel-console-post-button" class="button console-submit-button">post</div>',
4945 '<div id="panel-console-cancel-button" class="button console-cancel-button">cancel</div>',
4947 '<div id="panel-console-progress" class="console-progress"> </div>',
4948 '<div id="newpanel" style="display:none;"></div>',
4949 '<div id="panel-console-iframe-container"></div>',
4953 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
4954 eventRoot = app.getPointingDeviceEventTreeRoot();
4958 this.elmProgressID = 'panel-console-progress';
4959 this.elmUploaderID = 'newpanel';
4960 this.iframeWrapID = 'panel-console-iframe-container';
4961 this.elmIframeName = 'targetFrameNewPanel';
4962 this.scriptSrc = pettanr.CONST.CREATE_PANEL_JS;
4963 this.hideUploader = false;
4964 FormApplicationHelper( this );
4966 this.onOpen = function( w, h, _model ){
4967 node = eventRoot.createNode( app.rootElement, true, true );
4968 var ui = app.createUIGroup( node ),
4969 elm = document.getElementById( 'panel-console-publish' );
4971 inputData = ui.createInputText( document.getElementById( 'panel-console-data' ), publishUpdate );
4974 comboboxPublish = ui.createCombobox( elm, publishUpdate );
4975 comboboxPublish.createOption( 'only me', '0', _model.publish() === false );
4976 comboboxPublish.createOption( 'publish', '1', _model.publish() === true );
4979 elm.parentNode.removeChild( elm );
4982 buttonSubmit = ui.createButton( document.getElementById( 'panel-console-post-button' ), clickOK );
4983 buttonClose = ui.createButton( document.getElementById( 'panel-console-cancel-button' ), clickCancel );
4985 app.onPaneResize( w, h );
4988 this.onPaneResize = function( w, h ){
4991 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
4993 this.onClose = function(){
4994 app.destroyHelper();
4995 model && model.destroy();
4996 app = model = comboboxPublish = buttonSubmit = buttonClose = elmInput = null;
4998 this.onFormReady = function(){
4999 var _inputList = app.elmForm.getElementsByTagName( 'input' ),
5001 for( var i = _inputList.length; i; ){
5002 _input = _inputList[ --i ];
5003 if( _input.type === 'submit' ){
5004 _input.style.display = 'none';
5006 if( _input.name === 'json' ){
5013 node.mesureChildren();
5014 app.onPaneResize( windowW, windowH );
5016 delete app.onFormReady;
5018 this.submitError = function(){
5019 app.addTimer( clickCancel , 5000, true );
5021 this.submitSuccess = function(){
5022 app.addTimer( clickCancel , 5000, true );
5024 }, true, true, 'Panel Console', 'panelConsole', null, '#603CBA' );
5026 var Model = ( function(){
5028 var PanelModelClass = function( panel ){
5029 var comicID = panel.comicID || -1,
5030 panelID = panel.panelID || -1,
5031 panelTimming = panel.panelTimming || -1,
5032 panelW = panel.panelW,
5033 panelH = panel.panelH,
5034 borderSize = panel.borderSize,
5035 panelElementArray = panel.panelElementArray,
5036 publish = panel.publish,
5039 function getPanelElementByTiming(){
5040 var i, l = panelElementArray.length;
5041 while( timing < l * 2 ){
5042 for( i = 0; i < l; ++i ){
5043 if( timing === panelElementArray[ i ].timing ){
5044 // console.log( timing + ' , ' + panelElementArray[ i ].timing );
5046 return panelElementArray[ i ];
5053 function panelElementToHtml( _panelElement, isAbsoluteUrl, isXHTML ){
5055 if( _panelElement.type === 0 ){
5056 rPic = _panelElement.realPicture();
5057 url = [ pettanr.CONST.RESOURCE_PICTURE_PATH, rPic.id, '.', rPic.ext ].join( '' );
5060 'src="', isAbsoluteUrl !== true ? url : Util.getAbsolutePath( url ), '" ',
5061 'width="', _panelElement.w, '" ',
5062 'height="', _panelElement.h, '" ',
5064 'left:', _panelElement.x, 'px;',
5065 'top:', _panelElement.y, 'px;',
5066 'z-index:', _panelElement.z, ';',
5068 isXHTML !== true ? '>' : ' \/>'
5071 url = pettanr.balloon.getBalloonUrl( _panelElement.w, _panelElement.h, _panelElement.a );
5074 'src="', isAbsoluteUrl !== true ? url : Util.getAbsolutePath( url ), '" ',
5075 'width="', _panelElement.w, '" ',
5076 'height="', _panelElement.h, '" ',
5078 'left:', _panelElement.x, 'px;',
5079 'top:', _panelElement.y, 'px;',
5080 'z-index:', _panelElement.z, ';',
5082 isXHTML !== true ? '>' : ' \/>',
5083 pettanr.LINE_FEED_CODE_TEXTAREA,
5084 '<div class="balloon" style="',
5085 'left:', _panelElement.x, 'px;',
5086 'top:', _panelElement.y, 'px;',
5087 'width:', _panelElement.w, 'px;',
5088 'height:', _panelElement.h, 'px;',
5089 'z-index:', _panelElement.z,
5090 '"><span>', _panelElement.content, '<\/span>', '<\/div>'
5095 function getImageJsonGET( _imageElement ){
5096 var cr = pettanr.LINE_FEED_CODE_TEXTAREA,
5097 rPic = _imageElement.realPicture();
5100 '"resource_picture": {', cr,
5101 '"id": ', rPic.id, ',', cr,
5102 '"ext": ', '"', rPic.ext, '"', cr,
5104 '"x": ', _imageElement.x, ',', cr,
5105 '"y": ', _imageElement.y, ',', cr,
5106 '"z": ', _imageElement.z, ',', cr,
5107 '"width": ', _imageElement.flipH * _imageElement.w, ',', cr,
5108 '"height": ', _imageElement.flipV * _imageElement.h, ',', cr,
5109 '"t": ', timing, cr,
5113 function imageToJson( _imageElement, _timing ){
5114 var cr = pettanr.LINE_FEED_CODE_TEXTAREA;
5117 '"picture_id": ', _imageElement.realPicture().id, ',', cr,
5118 '"x": ', _imageElement.x, ',', cr,
5119 '"y": ', _imageElement.y, ',', cr,
5120 '"z": ', _imageElement.z + 1, ',', cr,
5121 '"t": ', _timing, ',', cr,
5122 '"width": ', _imageElement.flipH * _imageElement.w, ',', cr,
5123 '"height": ', _imageElement.flipV * _imageElement.h, cr,
5128 function balloonToJson( _textElement, _timing ){
5129 var cr = pettanr.LINE_FEED_CODE_TEXTAREA;
5132 '"balloon_template_id": ', 1, ',', cr,
5133 '"system_picture_id": ', 1, ',', cr,
5134 '"size": ', 1, ',', cr,
5135 '"tail": ', _textElement.a, ',', cr,
5136 '"x": ', _textElement.x, ',', cr,
5137 '"y": ', _textElement.y, ',', cr,
5138 '"z": ', _textElement.z + 1, ',', cr,
5139 '"t": ', timing, ',', cr,
5140 '"width": ', _textElement.w, ',', cr,
5141 '"height": ', _textElement.h, ',', cr,
5142 '"speeches_attributes": {', cr,
5143 '"newf', timing, '": {', cr,
5144 '"content": "', _textElement.content, '",', cr,
5145 '"x": ', _textElement.x, ',', cr,
5146 '"y": ', _textElement.y, ',', cr,
5147 '"t": ', timing, ',', cr,
5148 '"width": ', _textElement.w, ',', cr,
5149 '"height": ', _textElement.h, cr,
5156 this.getJsonPostString = function(){
5159 var JSON_STRING_ARRAY = [],
5162 l = panelElementArray.length,
5164 cr = pettanr.LINE_FEED_CODE_TEXTAREA;
5166 while( IMAGE_ARRAY.length + BALLOON_ARRAY.length <= l ){
5167 _panelElement = getPanelElementByTiming();
5168 if( _panelElement === null) break;
5169 n = IMAGE_ARRAY.length + BALLOON_ARRAY.length;
5170 _panelElement.type === 0 ?
5171 IMAGE_ARRAY.push( [ '"new', n, '": ', imageToJson( _panelElement, n ) ].join( '' ) ) :
5172 BALLOON_ARRAY.push( [ '"new', n, '": ', balloonToJson( _panelElement, n ) ].join( '' ) );
5176 panelID !== -1 ? ( '"id": ' + panelID + ',' + cr ) : '',
5177 // comicID !== -1 ? ( '"comic_id": ' + comicID + ',' + cr ) : '',
5178 '"width": ', panelW, ',', cr,
5179 '"height": ', panelH, ',', cr,
5180 '"border": ', borderSize, ',', cr,
5182 // '"picture_id": 1,', cr,
5183 '"x": ', 0, ',', cr,
5184 '"y": ', 0, ',', cr,
5185 '"z": ', 1, ',', cr,
5186 panelTimming !== -1 ? ( '"t": ' + panelTimming + ',' + cr ) : '',
5187 '"panel_pictures_attributes": {', cr,
5188 IMAGE_ARRAY.join( ',' + cr ), cr,
5190 '"speech_balloons_attributes": {', cr,
5191 BALLOON_ARRAY.join( ',' + cr ), cr,
5193 '"publish": ', ( publish === true ? 1 : 0 ), cr,
5197 this.getJsonGetString = function(){
5200 var JSON_STRING_ARRAY = [],
5202 l = panelElementArray.length,
5203 cr = pettanr.LINE_FEED_CODE_TEXTAREA,
5206 while( ELEMENT_ARRAY.length <= l){
5207 _panelElement = getPanelElementByTiming();
5208 if( _panelElement === null ) break;
5210 ELEMENT_ARRAY.push( _panelElement.type === 0 ? getImageJsonGET( _panelElement ) : balloonToJson( _panelElement ));
5215 //'"id": ', panelID, ',', cr,
5216 '"border": ', borderSize, ',', cr,
5217 // '"comic_id": ', comicID, ',', cr,
5218 // '"picture_id": 1,', cr,
5219 '"x": ', 0, ',', cr,
5220 '"y": ', 0, ',', cr,
5221 '"z": ', 1, ',', cr,
5222 // panelTimming !== -1 ? ( '"t": ' + panelTimming + ',' + cr ) : '',
5223 '"width": ', panelW, ',', cr,
5224 '"height": ', panelH, ',', cr,
5225 '"elements": [', cr,
5226 ELEMENT_ARRAY.join( ',' + cr ), cr,
5232 this.getAsHtmlString = function( isAbsoluteUrl, isXHTML ){
5235 var HTML_ARRAY = [],
5236 l = panelElementArray.length,
5239 while( HTML_ARRAY.length < l ){
5240 _panelElement = getPanelElementByTiming();
5241 if( _panelElement === null) break;
5242 HTML_ARRAY.push( panelElementToHtml( _panelElement, isAbsoluteUrl, isXHTML ));
5247 '<div class="panel" ',
5249 'height:', panelH, 'px;',
5250 'background-color:', ';',
5255 HTML_ARRAY.push( '</div>');
5257 return HTML_ARRAY.join( pettanr.LINE_FEED_CODE_TEXTAREA );
5259 this.publish = function( v ){
5260 return publish = Type.isBoolean( v ) === true ? v : publish;
5262 this.destroy = function(){
5263 panel = panelElementArray = null;
5268 createPanel: function( panelData ){
5269 return new PanelModelClass( panelData );
5275 var OutputConsole = gOS.registerApplication( function(){
5276 var FORMAT_LIST = [ 'json[POST]', 'json[GET]', 'XML', 'HTML', 'XHTML', 'MT export', 'Blogger ATOM' ];
5279 comboboxFormat, inputOption,
5280 buttonSubmit, buttonClose,
5283 comicID, panelID, panelTimming, panelW, panelH, borderSize, panelElementArray,
5288 OutputConsole.shutdown();
5291 function formatUpdate(){
5292 var i = comboboxFormat.selectIndex(),
5294 // buttonSubmit.enabled( false );
5296 text = model.getJsonPostString();
5297 // buttonSubmit.enabled( true );
5300 text = model.getJsonGetString();
5303 text = model.getAsHtmlString( false, false );
5307 elmOutputArea.value = text;
5309 function clickClose(){
5310 OutputConsole.shutdown();
5314 function clickPost(){
5315 // PanelConsole.boot( elmOutputArea.value );
5320 this.MIN_WIDTH = 320;
5321 this.MIN_HEIGHT = 320;
5322 this.onInit = function(){
5323 app.rootElement.id = 'output-console-wrapper';
5324 app.rootElement.className = 'console-wrapper';
5325 app.rootElement.innerHTML = [
5326 '<div id="output-console-header" class="console-header">Output Console</div>',
5327 '<div id="output-console" class="console-inner">',
5328 '<div id="output-console-format" class="field">',
5329 '<span class="field-label">Format:</span>',
5330 '<span id="output-console-format-value" class="output-console-value combobox"></span>',
5332 '<div id="output-console-option" class="field">',
5333 '<span class="field-label">Options:</span>',
5334 '<span id="output-console-option-value" class="output-console-value editable-value">absolute-path</span>',
5336 '<textarea id="output-area" readonly></textarea>',
5337 '<div id="output-console-close-button" class="button">close</div>',
5341 app.fetchCSS( pettanr.CONST.URL_PETA_APPS_CSS );
5342 eventRoot = app.getPointingDeviceEventTreeRoot();
5346 this.onOpen = function( _w, _h, _comicID, _panelID, _panelTimming, _panelW, _panelH, _borderSize, _panelElementArray ){
5347 elmOutputArea = document.getElementById( 'output-area' );
5349 node = eventRoot.createNode( app.rootElement, true, true );
5350 var ui = app.createUIGroup( node );
5351 comboboxFormat = ui.createCombobox( document.getElementById( 'output-console-format' ), formatUpdate );
5353 for( var i=0; FORMAT_LIST[ 0 ]; ++i ){
5354 comboboxFormat.createOption( FORMAT_LIST.shift(), null, i === 0 );
5356 inputOption = ui.createInputText( document.getElementById( 'output-console-option' ), null );
5357 // buttonSubmit = ui.createButton( document.getElementById( 'output-console-post-button' ), clickPost );
5358 buttonClose = ui.createButton( document.getElementById( 'output-console-close-button' ), clickClose );
5360 app.onPaneResize( _w, _h );
5362 comboboxFormat.focus( true );
5364 model = Model.createPanel( {
5367 panelTimming : _panelTimming,
5370 borderSize : _borderSize,
5371 panelElementArray : _panelElementArray,
5377 this.onPaneResize = function( w, h ){
5380 //app.rootElement.style.cssText = [
5381 // 'left:', Math.floor( ( _windowW - app.rootElement.offsetWidth ) /2 ), 'px;',
5382 // 'top:', Math.floor( ( _windowH - app.rootElement.offsetHeight ) /2 ), 'px;'
5384 node.update( w / 2 - node.width() / 2, h / 2 - node.height() / 2 );
5386 this.onClose = function(){
5387 elmOutputArea.value = '';
5389 elmOutputArea = comboboxFormat = inputOption = buttonSubmit = buttonClose = panelElementArray = model = null;
5391 }, true, false, 'Output Console', 'outputConsole', null, '#2D89F0' );
5393 })( pettanr, gOS, window, document );