Prevent instance init collision

This commit is contained in:
斟酌 鵬兄 2016-04-04 00:35:59 +08:00
parent a72dcd8ca9
commit cde4dd8c60
1 changed files with 15 additions and 4 deletions

View File

@ -44,14 +44,25 @@
/* stage @param {Dandelion.IDOMElement} */ /* stage @param {Dandelion.IDOMElement} */
var VimArea = function( stage ) var VimArea = function( stage )
{ {
if( !stage ) return; if( !stage ) throw new Error( "Invalid argument" );
stage = IDOMElement( stage );
var element = stage.element; var element = stage.element;
if( element.nodeName != "TEXTAREA" ) if(!( element && element.nodeName == "TEXTAREA" ))
{ {
debug.Error( "Element is not compatible for VimArea" ); throw new Error( "This element is not compatible for VimArea" );
return; }
for( var i in Insts )
{
var inst = Insts[ i ];
if( inst.stage.element == element )
{
debug.Info( "Instance exists" );
return inst;
}
} }
stage.setAttribute( new DataKey( "vimarea", 1 ) ); stage.setAttribute( new DataKey( "vimarea", 1 ) );