/*
* pettanR system.js
- * version 0.5.37
+ * version 0.5.38
*
* gadgetOS
* author:
}
};
+/**
+ * Class を定義し システムの管理下に置く.
+ * 全てのクラスと pool が有効の場合インスタンスへの参照が保持される.
+ * 1. Class.create( def, opt_final, opt_pool, opt_abstract ) でクラスを登録.
+ * 2. コンストラクタ となるメソッドは、Constructor : function( arg ){ ... }, に書く.
+ * 3. 通常通り new で インスタンス生成
+ * 4. kill() でオブジェクトをクリーンして削除、pool が有効の場合は pool される.
+ * 5. pool が有効の場合、new で pool されたインスタンスが返される.
+ * 6.
+ *
+ */
var Class = ( function(){
- var CLASS_LIST = [];
+ var CLASS_LIST = [],
+ DEF_LIST = [],
+ PRIVATE_LIST = [];
function getClass( instance ){
var list = CLASS_LIST,
i = list.length,
getIndex = Util.getIndex,
- klass;
+ klass, def, live, pool;
for( ; i; ){
klass = list[ --i ];
- if( klass.live && getIndex( klass.live, instance ) !== -1 ) return klass;
- if( klass.pool && getIndex( klass.pool, instance ) !== -1 ) return klass;
+ def = getDef( klass );
+ if( def.live && getIndex( def.live, instance ) !== -1 ) return klass;
+ if( def.pool && getIndex( def.pool, instance ) !== -1 ) return klass;
if( instance instanceof klass ) return klass;
};
- return null;
+ throw new Error( 'Class not found!' );
};
- function clone( src ){
- var ret, key;
- if( Type.isArray( src ) === true ){
- ret = [];
- } else
- if( Type.isObject( src ) === true ){
- ret = {};
- } else
- if( Type.isNumber( src ) === true || Type.isString( src ) === true || Type.isBoolean( src ) === true ){
- return src;
- } else {
- return null;
- };
- for( key in src ){
- ret[ key ] = clone( src[ key ]);
- };
- return ret;
+ function getDef( klass ){
+ var i = Util.getIndex( CLASS_LIST, klass );
+ if( i !== -1 ) return DEF_LIST[ i ];
};
- function copy( base, extend ){
- for( var key in extend ){
- base[ key ] = extend[ key ];
+ /* over のプロパティを target にコピーする.ただし target の プロパティが優先, force で解除 */
+ function override( target, over, force ){
+ for( var p in over ){
+ if( force === true || typeof target[ p ] === 'undefined' ){
+ target[ p ] = over[ p ];
+ };
};
- return base;
+ return target;
};
- function extend(){
-
+ /* サブクラスを作るメソッド
+ * var subClass = superClass.inherits( ... )
+ * http://d.hatena.ne.jp/m-hiyama/20051018/1129605002
+ */
+ function inherits( def, opt_pool, opt_abstract, opt_final, opt_super, opt_PrivateClass ){
+ var Super = this,
+ def = getDef( Super ),
+ Traits, klass;
+ abstractFlag = false;
+ Traits = new Super;
+ abstractFlag = true;
+ klass = Class.create( override( Traits, def, true ), opt_pool, opt_abstract, opt_final, opt_PrivateClass );
+ if( opt_super === true ){
+ def.Super = Super.prototype;
+ };
+ return klass;
};
+ /* Class.create で作られたクラスのインスタンスが共通で備えるメソッド */
var basic = {
- clear : function(){
- var o = this,
+ kill : function(){
+ var instance = this,
p, v,
- klass = getClass( o );
- for( p in o ){
- if( o.hasOwnProperty && !o.hasOwnProperty( p ) ) continue;
- v = o[ p ];
- delete o[ p ];
+ klass = getClass( instance ),
+ def = getDef( klass ),
+ privateData, i;
+ Type.isFunction( o.onKill ) === true && o.onKill();
+
+ for( p in instance ){
+ if( instance.hasOwnProperty && !instance.hasOwnProperty( p ) ) continue;
+ v = instance[ p ];
+ delete instance[ p ];
+ };
+ if( def.pool ){
+ klass.live.splice( Util.getIndex( klass.live, instance ), 1 );
+ klass.pool.push( instance );
};
- if( klass && klass.pool ){
- klass.live.splice( Util.getIndex( klass.live, o ), 1 );
- klass.pool.push( o );
+ if( def.privateClass ){
+ privateData = instance.getPrivateData();
+ privateData && privateData.kill();
+ };
+ if( def.isPrivate === true ){
+ i = Util.getIndex( def.dataList, instance );
+ def.dataList.splice( i, 1 );
+ def.userList.splice( i, 1 );
};
}
};
+ /* privateDataclass をもつクラスに追加されるメソッド */
+ function newPrivateData( instance /*, args */ ){
+ var klass = getDef( getClass( instance ) ).privateClass,
+ def = getDef( klass ),
+ i = Util.getIndex( def.userList, instance ),
+ args = c( arguments ),
+ data;
+ if( i === -1 ){
+ throw new Error( 'Private already exist!' );
+ };
+ privateFlag = false;
+ args.unshift();
+ data = I.apply( klass, args );
+ privateFlag = false;
+ def.dataList.push( data );
+ def.userList.push( instance );
+ return data;
+ };
+ function getPrivateData( instance ){
+ var klass = getDef( getClass( instance ) ).privateClass,
+ def = getDef( klass ),
+ i = Util.getIndex( def.userList, instance );
+ if( i !== -1 ) return def.userList[ i ];
+ };
- var f = true;
- var c = Util.copyArray;
- var a;
+ /*
+ * new の実体.コンストラクタの機能は instance.Constructor に書く.
+ * これにより pool された オブジェクト(破棄されたインスタンス) を再利用できる
+ */
+ var abstractFlag = true,
+ privateFlag = true,
+ f = true,
+ c = Util.copyArray,
+ a, dataUser;
function I(){
var klass = this,
+ def = getDef( klass ),
instance;
- if( klass.Abstract === true ){
- throw new Error( 'AbstractClass!' );
+ if( def.abstract === true ){
+ if( abstractFlag === true ){
+ throw new Error( 'AbstractClass!' );
+ };
+ f = false;
+ instance = new klass();
+ f = true;
+ return instance;
};
- if( klass.pool && klass.pool.length > 0 ){
- instance = klass.pool.shift();
+ if( def.isPrivate === true && privateFlag === true ){
+ throw new Error( 'use class.newPrivateData( instance, args )!' );
+ };
+ if( def.pool && def.pool.length > 0 ){
+ instance = def.pool.shift();
} else {
f = false;
instance = new klass();
f = true;
};
- if( klass._super ){
- instance._super = klass._super.prototype;
+ if( def.Super ){
+ instance.Super = def.Super;
};
- instance.init && instance.init.apply( instance, c( arguments ) );
- klass.live && klass.live.push( instance );
+ instance.Constructor && instance.Constructor.apply( instance, c( arguments ) );
+ def.live && def.live.push( instance );
return instance;
};
return {
- create : function( def, opt_final, pool, opt_abstract ){
+ create : function( def, opt_pool, opt_abstract, opt_final, opt_PrivateClass ){
var klass = function(){
- a = arguments;
- if( f ) return I.apply( a.callee, c( a ) );
+ a = arguments;
+ if( f ) return I.apply( a.callee, c( a ) );
+ },
+ def = {},
+ _def;
+ klass.prototype = override( def, basic, false );
+ if( opt_final === true && opt_abstract === true ){
+ throw new Error( 'final & Abstract!' );
};
- klass.prototype = copy( copy( {}, basic ), def );
if( opt_final !== true ){
- klass.extend = extend;
- };
- if( pool === true ){
- klass.pool = [];
- klass.live = [];
+ klass.inherits = inherits;
};
if( opt_abstract === true ){
- klass.Abstract = true;
+ def.abstract = true;
+ } else
+ if( opt_pool === true ){
+ def.pool = [];
+ def.live = [];
+ };
+ if( opt_PrivateClass ){
+ _def = getDef( opt_PrivateClass );
+ if( !_def || _def.isPrivate !== true ){
+ throw new Error( 'PrivateClass not found! please, Class.createPrivateData().' );
+ };
+ def.privateClass = opt_PrivateClass;
+ klass.newPrivateData = newPrivateData;
+ klass.getPrivateData = getPrivateData;
};
CLASS_LIST.push( klass );
+ DEF_LIST.push( def );
+ return klass;
+ },
+ createPrivateData : function( def, opt_abstract, opt_final ){
+ var klass = Class.create( def, true, opt_abstract, opt_final ),
+ def = getDef( klass );
+ def.isPrivate = true;
+ def.userList = [];
+ def.dataList = [];
return klass;
+ },
+ onShutdown : function(){
+
}
};
})();
};
update();
}
- }
+ };
})();
/* --------------------------------------------------------------
};
/**
- * clip : true の場合、子ノードの変更によってヒットエリアを変化させない.elm には overflow:hidden としておくのが通常.
+ * clip : true の場合、子ノードの変更によってヒットエリアを変化させない.elm には overflow:hidden としておくのが通常.
*/
var NodePrivateData = function(){};
NodePrivateData.prototype = {
list = NodePrivateData.dataList,
node;
this.removeEventListener();
+ ScrollBarManager.remove( this );
if( nodes ){
while( node = nodes.shift() ) node._destroy();
delete this.childData;
smoothList.length === 0 && SystemTimer.add( SUPER_USER_KEY, tick, 16 );
smoothList.push( data );
};
+ },
+ remove : function( data ){
+ var list = smoothList,
+ i = Util.getIndex( list, data );
+ data === currentNodeData && scrollRelease();
+ i !== -1 && list.splice( i, 1 );
}
};
})();
function asyncBoot(){
application = Application.boot( appClass, displayName, self.getUID(), isOverlay, Util.copyArray( arguments ) );
};
-
this.getUID = function(){
return Util.getIndex( API_USER_LIST, appClass );
};
+ this.getDisplayName = function(){
+ return this.displayName;
+ };
this.boot = function( /* _option */ ){
AsyncCall.add( this, asyncBoot, Util.copyArray( arguments ) );
};
var list = UIItemPrivateData.list;
list.splice( Util.getIndex( list, this ), 1 );
+ list = this.groupData.itemList;
+ var i = Util.getIndex( list, this.item );
+ i !== -1 && list.splice( i, 1 );
+
this.node && this.node.remove();
}
};
wrap.appendChild( form );
data.init( this, this.ui.createFileInput( el, data.onUpdate, null, form ) );
this.itemList.push( data );
- // alert( i )
break;
case 'button':
break;
var Finder = ( function(){
var FINDER_LIST = [],
ELM_ORIGIN_LOCATION_ITEM = Util.pullHtmlAsTemplete( '<div class="finder-location-item"></div>' ),
- ICON_CLASSNAME = 'finder-icon-thumbnail';
-
- var HTML_FINDER_ICON = ( function(){
+ HTML_FINDER_ICON = ( function(){
return ( UA.isIE === true && UA.ieVersion < 8 ?
[
'<div class="finder-icon fnder-icon-ie7">',
- '<span class="finder-icon-handle"></span>',
- '<span class="' + ICON_CLASSNAME + '"></span>',
+ '<div class="finder-icon-handle"></div>',
+ '<div class="file-icon"><div></div></div>',
'<span class="finder-icon-cell finder-icon-ie-filename">',
'<span class="finder-icon-vertical-middle-outer">',
'<span class="finder-icon-vertical-middle-inner">',
'</span>',
'</span>',
'</span>',
- '<span class="finder-icon-down"></span>',
+ '<div class="finder-icon-down"></div>',
'</div>'
] :
[
'<div class="finder-icon fnder-icon-modern">',
- '<span class="finder-icon-handle"></span>',
- '<span class="' + ICON_CLASSNAME + '"></span>',
- '<span class="finder-icon-filename break-word">file name</span>',
- '<span class="finder-icon-summary break-word">file descriptiion</span>',
- '<span class="finder-icon-down">></span>',
+ '<div class="finder-icon-handle"></div>',
+ '<div class="file-icon"><div></div></div>',
+ '<div class="finder-icon-filename break-word">file name</div>',
+ '<div class="finder-icon-summary break-word">file descriptiion</div>',
+ '<div class="finder-icon-down">></div>',
'</div>'
] ).join( '' );
})(),
var file = this.file,
elm = this.elm,
thumb = file.getThumbnail(),
- elmThumb = Util.getElementsByClassName( elm, ICON_CLASSNAME )[ 0 ],
+ elmThumb = Util.getElementsByClassName( elm, 'file-icon' )[ 0 ].firstChild,
elmName = Util.getElementsByClassName( elm, 'finder-icon-filename' )[ 0 ],
elmDesc = Util.getElementsByClassName( elm, 'finder-icon-summary' )[ 0 ];
if( thumb.image ){
- elmThumb.className = ICON_CLASSNAME + ' has-thumbnail';
+ elmThumb.className = 'has-thumbnail';
elmThumb.style.backgroundImage = [ 'url(', thumb.image, ')' ].join( '' );
} else {
- elmThumb.className = ICON_CLASSNAME + ' ' + thumb.className;
+ elmThumb.className = thumb.className;
elmThumb.style.backgroundImage = '';
};
}
};
+ var ApplicationButton = function(){};
+ ApplicationButton.prototype = {
+ elm : null,
+ button : null,
+ app : null,
+ fileUID : -1,
+ init : function( ui, elmParent, app, file ){
+ if( this.elm === null ){
+ this.elm = document.createElement( 'div' );
+ };
+ elmParent.appendChild( this.elm );
+ this.elm.className = 'button';
+ this.elm.innerHTML = app.getDisplayName();
+
+ var that = this;
+ this.button = ui.createButton( this.elm, function(){
+ that.onClick();
+ } );
+
+ this.app = app;
+ this.fileUID = file.getUID();
+ },
+ onClick : function(){
+ this.app.boot( this.fileUID );
+ return false;
+ },
+ destroy : function(){
+ var elm = this.elm;
+ elm.parentNode.removeChild( elm );
+
+ this.button.destroy();
+ //this.kill()
+ //this.elm = elm;
+ }
+ };
+
var DetailPageClass = function(){};
DetailPageClass.prototype = Util.extend( new PageClass(), {
+ appButtons : null,
init : function( finderData ){
this.finderData = finderData;
this.apiuser = finderData.apiuser;
if( this.elm === null ){
this.elm = Util.pullHtmlAsTemplete( [
'<div class="finder-detail">',
- '<div class="finder-icon"><div class="finder-detail-thumbnail"></div></div>',
+ '<div class="file-icon"><div></div></div>',
'<div class="finder-detail-filename break-word">file name</div>',
'<div class="finder-detail-summary break-word">file descriptiion</div>',
+ '<div>View this file</div>',
+ '<div class="viewer-apps"></div>',
+ '<div>Edit this file</div>',
+ '<div class="editor-apps"></div>',
'</div>'
].join( '' ) );
};
this.elm.style.display = 'none';
this.elmScroll.appendChild( this.elm );
this.node = this.nodeRoot.createNode( this.elm, true, false );
+
+ this.ui = this.apiuser.createUIGroup( this.node );
+ this.appButtons = [];
},
- draw : function( file ){
+ draw : function( file ){
var elm = this.elm,
thumb = file.getThumbnail(),
- elmThumb = Util.getElementsByClassName( elm, 'finder-detail-thumbnail' )[ 0 ],
+ elmThumb = Util.getElementsByClassName( elm, 'file-icon' )[ 0 ].firstChild,
elmName = Util.getElementsByClassName( elm, 'finder-detail-filename' )[ 0 ],
- elmDesc = Util.getElementsByClassName( elm, 'finder-detail-summary' )[ 0 ];
+ elmDesc = Util.getElementsByClassName( elm, 'finder-detail-summary' )[ 0 ],
+ tmpButtons = Util.copyArray( this.appButtons ),
+ apps, app, elmContainer;
if( thumb.image ){
- elmThumb.className = 'finder-detail-thumbnail has-thumbnail';
+ elmThumb.className = 'has-thumbnail';
elmThumb.style.backgroundImage = [ 'url(', thumb.image, ')' ].join( '' );
} else {
- elmThumb.className = 'finder-detail-thumbnail ' + thumb.className;
+ elmThumb.className = thumb.className;
elmThumb.style.backgroundImage = '';
};
this.node.width( this.nodeRoot.width() );
this.node.height( this.nodeRoot.height() );
- this.elmScroll.style.height = this.nodeRoot.height() + 'px';
+ this.appButtons.length = 0;
+
+ apps = file.viewerApplicationList();
+ elmContainer = Util.getElementsByClassName( elm, 'viewer-apps' )[ 0 ];
+ for( i = 0; i < apps.length; ++i ){
+ button = 0 < tmpButtons.length ? tmpButtons.shift() : new ApplicationButton();
+ button.init( this.ui, elmContainer, apps[ i ], file );
+ this.appButtons.push( button );
+ };
+ apps = file.editorApplicationList();
+ elmContainer = Util.getElementsByClassName( elm, 'editor-apps' )[ 0 ];
+ for( i = 0; i < apps.length; ++i ){
+ button = 0 < tmpButtons.length ? tmpButtons.shift() : new ApplicationButton();
+ button.init( this.ui, elmContainer, apps[ i ], file );
+ this.appButtons.push( button );
+ };
+
+ while( button = tmpButtons.shift() ) button.destroy();
+
+ this.resize();
},
pan : function(){
var page = this,
},
resize : function(){
-
+ this.elmScroll.style.height = this.nodeRoot.height() + 'px';
},
destroy : function(){
-
+ var button;
+ while( button = this.appButtons.shift() ) button.destroy();
+ this.ui.destroy();
+ this.node.remove();
}
});
FinderPrivateData.LIST.push( this );
},
onIconClick : function( e ){
+ if( this.panInPage === this.pageDetail ) return;
+
var target = e.target,
list = this.panInPage.iconList,
i, icon,
if( icon.node === target ){
i = icon._index;
file = this.currentFile.getChildFileAt( i );
+ if( target.width() - 30 < e.layerX ){
+ this.tree.down( i );
+ this.draw( this.w, this.h, 1, true );
+ } else
if( file.getChildFileLength() !== -1 || file.getType() === Const.FILE.TYPE.FOLDER ){
this.tree.down( i );
this.draw( this.w, this.h, 1 );
this.tree.up( i );
this.draw( this.w, this.h, -1 );
},
- draw : function( w, h, way ){
+ draw : function( w, h, way, showDetail ){
var data = this, page;
data.w = w = Type.isFinite( w ) === true ? w : data.w;
data.h = h = Type.isFinite( h ) === true ? h : data.h;
var file = this.currentFile = this.tree.getCurrentFile(),
- isFolder = file.getChildFileLength() !== -1 || file.getType() === Const.FILE.TYPE.FOLDER;
+ isFolder = showDetail !== true && ( file.getChildFileLength() !== -1 || file.getType() === Const.FILE.TYPE.FOLDER );
data.elmPath && data.drawPath( w );
page = this.panInPage;