MONOPOLY : 16, // move event を独占する\r
SYS_CANCEL : 32,\r
\r
- _LIVE_LIST : [],\r
- _POOL_LIST : [],\r
+ _LIVE_LIST : [],\r
+ _POOL_LIST : [],\r
+ \r
create : function( arg0, arg1, arg2 /* [ listener || ( context + function ) || function ][ args... ] */ ){\r
var self = X.Callback,\r
live = self._LIVE_LIST,\r
} else\r
if( typeof arg0 === 'function' ){\r
callback = arg0;\r
- arg2 = arg1;\r
+ if( !( arg2 = arg1 ) ) return callback; // function のみの場合 callback オブジェクトを作らない\r
} else\r
if( arg0 && typeof arg0.handleEvent === 'function' ){\r
listener = arg0;\r
};\r
return f;\r
},\r
- find : function( arg0, arg1 /* [ listener || ( context + function ) || function ] */ ){\r
- var live = X.Callback._LIVE_LIST,\r
- i = live.length,\r
- listener, context, callback,\r
- f;\r
- if( typeof arg1 === 'function' ){\r
- context = arg0;\r
- callback = arg1;\r
- } else\r
- if( typeof arg0 === 'function' ){\r
- callback = arg0;\r
- } else\r
- if( arg0 && typeof arg0.handleEvent === 'function' ){\r
- listener = arg0;\r
- };\r
- \r
- for( ; i; ){\r
- f = live[ --i ];\r
- if( listener && f.listener === listener ){\r
- return f;\r
- } else\r
- if( context && f.context === context && f.callback === callback ){\r
- return f;\r
- } else \r
- if( f.callback === callback ){\r
- return f;\r
- };\r
- };\r
- return null;\r
- },\r
_contextCallback : function(){\r
var f = this,\r
a = f.a,\r
//s && s.push.apply( a, s );\r
if( s && s.length ){\r
ary = [];\r
- a.length && ary.push.apply( ary, a );\r
- ary.push.apply( ary, s );\r
+ a.length &&\r
+ (\r
+ a.length === 1 ?\r
+ ( ary[ 0 ] = a[ 0 ] ) :\r
+ ary.push.apply( ary, a )\r
+ );\r
+ s.length === 1 ?\r
+ ( ary[ ary.length ] = s[ 0 ] ) :\r
+ ary.push.apply( ary, s );\r
a = ary;\r
};\r
r = a.length === 0 ? c.call( x ) : c.apply( x, a );\r
//s && s.push.apply( a, s );\r
if( s && s.length ){\r
ary = [];\r
- a.length && ary.push.apply( ary, a );\r
- ary.push.apply( ary, s );\r
+ a.length &&\r
+ (\r
+ a.length === 1 ?\r
+ ( ary[ 0 ] = a[ 0 ] ) :\r
+ ary.push.apply( ary, a )\r
+ );\r
+ s.length === 1 ?\r
+ ( ary[ ary.length ] = s[ 0 ] ) :\r
+ ary.push.apply( ary, s );\r
a = ary;\r
};\r
- r = a.length === 0 ? c() : c.apply( null, a );\r
+ r = a.length === 0 ?\r
+ c() :\r
+ a.length === 1 ?\r
+ c( a[ 0 ] ) :\r
+ c.apply( null, a );\r
delete f.a;\r
//delete f.t;\r
return r;\r
ret = f();\r
if( ret & X.Callback.UN_LISTEN || c === 1 ){\r
list.splice( i, 1 );\r
- f.kill();\r
+ f.kill && f.kill();\r
queue.length = 0;\r
continue;\r
} else\r
for( ; i; ){\r
( f = list[ --i ] )( time );\r
delete f.uid;\r
- f.kill();\r
+ f.kill && f.kill();\r
};\r
list.length = 0;\r
};\r
var queue,\r
list = TICKET_LIST,\r
i = list.length,\r
- l = i;\r
+ l = i,\r
+ f;\r
for( ; i; ){\r
if( ( queue = list[ --i ] )[ INDEX_UID ] === uid ){\r
list.splice( i, 1 );\r
- X.Callback._correct( queue[ INDEX_CALLBACK ] );\r
+ f = queue[ INDEX_CALLBACK ];\r
+ f.kill && f.kill();\r
( /* queue[ INDEX_COUNT ] <= next || */ l === 1 ) && update();\r
queue.length = 0;\r
break;\r
if( f.uid === uid ){\r
list.splice( i, 1 );\r
delete f.uid;\r
- X.Callback._correct( f );\r
+ f.kill && f.kill();\r
l === 1 && cancelFrame ? cancelFrame( requestID ) : X.Timer.remove( requestID );\r
break; \r
};\r
_listeners : null,\r
_dispatching : 0, // dispatch 中の unlisten で使用\r
_unlistens : null, // dispatch 中の unlisten で使用\r
+ _needsIndex : false,\r
listen : function( type, arg1, arg2, arg3 ){\r
var list = this._listeners,\r
- i, f;\r
+ f;\r
+ if( this.listening( type, arg1, arg2, arg3 ) ) return this;\r
if( !list ) list = this._listeners = {};\r
if( !( list = list[ type ] ) ) list = this._listeners[ type ] = [];\r
- for( i = list.length; i; ){\r
- if( list[ --i ].same( arg1, arg2/* , arg3 */ ) ) return this;\r
- };\r
list[ list.length ] = f = X.Callback.create( arg1, arg2, arg3 );\r
f.once = X.EventDispatcher._once;\r
return this;\r
};\r
return this;\r
};\r
- if( arg1 === undefined && arg2 === undefined ){\r
+ if( arg1 === undefined ){\r
// 同一タイプを全て削除\r
if( !( list = list[ type ] ) ) return this;\r
for( i = list.length; i; ){\r
};\r
return this;\r
};\r
- if( !list || !( list = list[ type ] ) ) return this;\r
- for( i = list.length; i; ){\r
- f = list[ --i ];\r
- if( f.same( arg1, arg2, arg3 ) ){\r
- if( this._dispatching ){\r
- this._unlistens[ this._unlistens.length ] = f;\r
- } else {\r
- delete f.once;\r
- f.kill();\r
- list.splice( i, 1 );\r
- if( !list.length ){\r
- delete this._listeners[ type ];\r
- if( X.isEmptyObject( this._listeners ) ) delete this._listeners;\r
- };\r
- };\r
- return this;\r
+ \r
+ this._needsIndex = true;\r
+ i = this.listening( type, arg1, arg2, arg3 );\r
+ delete this._needsIndex;\r
+ if( i === false ) return this;\r
+\r
+ f = ( list = list[ type ] )[ i ];\r
+ if( this._dispatching ){\r
+ this._unlistens[ this._unlistens.length ] = f;\r
+ } else {\r
+ delete f.once;\r
+ f.kill && f.kill();\r
+ list.splice( i, 1 );\r
+ if( !list.length ){\r
+ delete this._listeners[ type ];\r
+ if( X.isEmptyObject( this._listeners ) ) delete this._listeners;\r
};\r
};\r
return this;\r
},\r
listening : function( type, arg1, arg2, arg3 ){\r
- var list = this._listeners, i;\r
+ var list = this._listeners, i, f;\r
+ if( type === undefined ) return !!list;\r
if( !list || !( list = list[ type ] ) ) return false;\r
+ if( arg1 === undefined ) return true;\r
for( i = list.length; i; ){\r
- if( list[ --i ].same( arg1, arg2 /* , arg3 */ ) ) return true;\r
+ f = list[ --i ];\r
+ if( f === arg1 || ( f.same && f.same( arg1, arg2, arg3 ) ) ) return this._needsIndex ? i : true;\r
};\r
return false;\r
},\r
for( i = this._unlistens.length ; i; ){\r
this.unlisten( e.type, this._unlistens[ --i ] );\r
};\r
- delete this._dispatching\r
+ delete this._dispatching;\r
delete this._unlistens; \r
};\r
\r
X.Dom.Node.prototype.listen = function( type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
var elm;
- if( this._xnodeType === 0 || this._xnodeType === 3 ) return this;
+ if( this._xnodeType === 0 || this._xnodeType === 3 || !arg2 ) return this;
( !this._listeners || !this._listeners[ type ] ) && this._addEvent( type );
- if( typeof arg2 === 'function' ){
- X.EventDispatcher.prototype.listen.call( this, type, this, arg2, arg3 );
- } else {
+ return typeof arg2 === 'function' ?
+ X.EventDispatcher.prototype.listen.call( this, type, this, arg2, arg3 ) :
X.EventDispatcher.prototype.listen.apply( this, arguments );
- };
- return this;
};
X.Dom.Node.prototype._addEvent =
});
-X.Dom.Node.prototype.unlisten = function( /* type, arg2, arg3, arg4 */ ){
- var list = this._listeners,
- type = arguments[ 0 ];
- l = list && type && list[ type ] && list[ type ].length;
+X.Dom.Node.prototype.unlisten = function( type /* , arg2, arg3, arg4 */ ){
+ var list = this._listeners,
+ l = list && type && list[ type ] && list[ type ].length;
X.EventDispatcher.prototype.unlisten.apply( this, arguments );
- if( 1 < arguments.length && !this._dispatching && l && !list[ type ] ){
+ if( type !== undefined && !this._dispatching && l && !list[ type ] ){
this._removeEvent( type );
};
};
}) :
(function(){
- var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( event, this.elm ) );
+ var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( event, this._rawNode ) );
if( ret & X.Callback.STOP_PROPAGATION ){
event.cancelBubble = true;
Node._systemNode = r.create( 'div' ).className( 'hidden-sysyem-node' );
r._xnodes.splice( r._xnodes.indexOf( Node._systemNode ), 1 ); // hide from api user
-} );
\ No newline at end of file
+} );
+
+