penguin/AstroJS

Javascript framework for my blog

commit cde4dd8c601226a5fe77c197342a7aa9652a0d81

author斟酌 鵬兄 <tgckpg@gmail.com>
date2016-04-03T16:35:59Z
subjectPrevent instance init collision
commit cde4dd8c601226a5fe77c197342a7aa9652a0d81
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2016-04-03T16:35:59Z

    Prevent instance init collision
---
 botanjs/src/Components/Vim/VimArea.js | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

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