View Single Post
Old 03-11-2012, 12:19 PM   PM User | #1
helloJS
New to the CF scene

 
Join Date: Mar 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
helloJS is an unknown quantity at this point
Smile How to transform 2 similar functions in only one ?

Hello, I have the code in the annexe wich is working but grossly redondant, clearly, I would like to have only one function toggleEditor(), that would manage the global variables editInstance with a parameter or something equivalent to avoid having 2 twin like functions. Thanks for your suggestions.

HJS


Annexe :
Code:
 
<html>
<body>

<script src="../flovinax.js" type="text/javascript"></script>
<script>
var editInstance= null;
function toggleEditor1(edtN) {
	if(editInstance===null) {
		editInstance = new flovinaxa({fullPanel : true}).panelInstance(edtN);
	} else {
		editInstance.removeInstance(edtN);
		editInstance= null;
	}
}

var editInstance2= null;
function toggleEditor2(edtN) {
	if(editInstance2===null) {
		editInstance2 = new flovinaxa({fullPanel : true}).panelInstance(edtN);
	} else {
		editInstance2.removeInstance(edtN);
		editInstance2= null;
	}
}
</script>	


<div>
	<textarea style="width: 800px; height: 200px;" id="myArea"></textarea>
	<br />
	<button onClick="toggleEditor1('myArea');">+</button>
</div>
<div style="clear: both;"></div>


<div>
	<textarea style="width: 800px; height: 200px;" id="myArea2"></textarea>
	<br />
	<button onClick="toggleEditor2('myArea2');">+</button>
</div>
<div style="clear: both;"></div>

</body>
</html>
helloJS is offline   Reply With Quote