← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1962: Fix javascript bug in IE. Centralize the duplicated script.

 

------------------------------------------------------------
revno: 1962
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Fri 2010-06-04 00:23:13 +0700
message:
  Fix javascript bug in IE. Centralize the duplicated script.
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/denum.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/expression.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js	2010-06-02 17:00:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js	2010-06-03 17:23:13 +0000
@@ -788,3 +788,38 @@
 		operandList.add( option, null );	
 	}
 }
+
+function insertTextCommon( inputAreaName, inputText )
+{
+	var inputArea = document.getElementById( inputAreaName );
+	
+	// IE support
+	if ( document.selection ) 
+	{
+		inputArea.focus();
+        sel = document.selection.createRange();
+        sel.text = inputText;
+        inputArea.focus();
+	}
+	// MOZILLA/NETSCAPE support
+	else if ( inputArea.selectionStart || inputArea.selectionStart == '0' ) 
+	{
+	
+		var startPos = inputArea.selectionStart;
+		var endPos = inputArea.selectionEnd;
+		
+		var existingText = inputArea.value;
+		var textBefore = existingText.substring( 0, startPos );
+		var textAfter = existingText.substring( endPos, existingText.length );
+
+		inputArea.value = textBefore + inputText + textAfter;
+	}
+	else 
+	{
+		inputArea.value += inputText;
+		inputArea.focus();
+	}
+
+	setCaretToPos( inputArea, inputArea.value.length );
+}
+

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/denum.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/denum.js	2010-06-02 17:00:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/denum.js	2010-06-03 17:23:13 +0000
@@ -161,22 +161,11 @@
 
 function insertText( inputAreaName, inputText, radioGroupName )
 {
-	var inputArea = document.getElementById( inputAreaName );
-	
-	var startPos = inputArea.selectionStart;
-	var endPos = inputArea.selectionEnd;
-	
-	var existingText = inputArea.value;
-	var textBefore = existingText.substring( 0, startPos );
-	var textAfter = existingText.substring( endPos, existingText.length );
-	
-	inputArea.value = textBefore + inputText + textAfter;
-	
+	insertTextCommon( inputAreaName, inputText );	
+
 	disableRadioGroup( radioGroupName );
 	
 	updateFormulaText( inputAreaName );
-	
-	setCaretToPos( inputArea, inputArea.value.length);
 }
 
 function updateFormulaText( formulaFieldName )

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/expression.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/expression.js	2010-06-02 17:00:23 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/expression.js	2010-06-03 17:23:13 +0000
@@ -34,20 +34,9 @@
 
 function insertText( inputAreaName, inputText )
 {
-	var inputArea = document.getElementById( inputAreaName );
-	
-	var startPos = inputArea.selectionStart;
-	var endPos = inputArea.selectionEnd;
-	
-	var existingText = inputArea.value;
-	var textBefore = existingText.substring( 0, startPos );
-	var textAfter = existingText.substring( endPos, existingText.length );
-	
-	inputArea.value = textBefore + inputText + textAfter;
+	insertTextCommon( inputAreaName, inputText );	
 	
 	updateTextualExpression( inputAreaName );
-	
-	setCaretToPos( inputArea, inputArea.value.length);
 }
 
 function filterDataElements( dataSetName, filterName )