From b2a95b4f99debc4d165bb0122b03b8e67f26b669 Mon Sep 17 00:00:00 2001
From: prathamesh
Date: Wed, 12 Feb 2014 13:01:30 +0530
Subject: Modified snippet
Snippet textarea extends according to the length of the snippet
with numbering.
The textarea to write code is dynamic with numbering. The
textarea extends as per the length of the code.
---
testapp/static/exam/js/question.js | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
(limited to 'testapp/static/exam/js/question.js')
diff --git a/testapp/static/exam/js/question.js b/testapp/static/exam/js/question.js
index cb6807e..2bf6f60 100644
--- a/testapp/static/exam/js/question.js
+++ b/testapp/static/exam/js/question.js
@@ -58,6 +58,17 @@ function replaceSelection (input, replaceString)
}
}
+function autoresize()
+{
+ var ta = document.getElementById('answer');
+ var divta = document.getElementById('AnswerWithLines');
+ ta.style.height="";
+ var height = ta.scrollHeight;
+ ta.style.height = 'auto';
+ ta.style.height = height+'px';
+ divta.style.height = height+'px';
+}
+
function catchTab(item,e)
{
if(navigator.userAgent.match("Gecko"))
@@ -76,7 +87,7 @@ function catchTab(item,e)
}
}
-var lineObjOffsetTop = 2;
+var lineObjOffsetTop = 0;
function addLineNumbers(id)
{
@@ -85,19 +96,20 @@ function addLineNumbers(id)
var content = document.getElementById('snippet').value;
ta.parentNode.insertBefore(el,ta);
el.appendChild(ta);
- el.className='textAreaWithLines';
el.style.width = (ta.offsetWidth + 30) + 'px';
ta.style.position = 'absolute';
ta.style.left = '30px';
- el.style.height = (ta.offsetHeight + 2) + 'px';
+ ta.scrollHeight=""
+ el.style.border = 'none';
el.style.overflow='hidden';
el.style.position = 'relative';
el.style.width = (ta.offsetWidth + 30) + 'px';
var lineObj = document.createElement('DIV');
lineObj.style.position = 'absolute';
lineObj.style.top = lineObjOffsetTop + 'px';
- lineObj.style.left = '0px';
lineObj.style.width = '27px';
+ lineObj.style.fontSize= '18px';
+ lineObj.style.foregroundColor='black';
el.insertBefore(lineObj,ta);
lineObj.style.textAlign = 'right';
lineObj.className='lineObj';
@@ -105,6 +117,10 @@ function addLineNumbers(id)
split_content = content.split('\n');
if(id == "answer")
{
+ el.className='AnswerWithLines';
+ el.id='AnswerWithLines';
+ el.style.height = (ta.scrollHeight) + 'px';
+
for(var no=split_content.length+1;no<1000;no++)
{
if(string.length>0)string = string + '
';
@@ -113,6 +129,10 @@ function addLineNumbers(id)
}
else
{
+ el.className='SnippetWithLines';
+ el.id='SnippetWithLines';
+ el.style.height = (ta.scrollHeight) + 'px';
+
for(var no=1;no<=split_content.length;no++)
{
if(string.length>0)string = string + '
';
@@ -124,6 +144,7 @@ function addLineNumbers(id)
ta.onblur = function() { positionLineObj(lineObj,ta); };
ta.onfocus = function() { positionLineObj(lineObj,ta); };
ta.onmouseover = function() { positionLineObj(lineObj,ta); };
+ ta.onkeyup = function(){autoresize();};
lineObj.innerHTML = string;
}
--
cgit
From 1fbe87bde5e27afb77728f6b195e6c1d57204fa3 Mon Sep 17 00:00:00 2001
From: prathamesh
Date: Thu, 5 Jun 2014 18:11:27 +0530
Subject: Blank lines removed.
---
testapp/static/exam/js/question.js | 2 --
1 file changed, 2 deletions(-)
(limited to 'testapp/static/exam/js/question.js')
diff --git a/testapp/static/exam/js/question.js b/testapp/static/exam/js/question.js
index 2bf6f60..75baf76 100644
--- a/testapp/static/exam/js/question.js
+++ b/testapp/static/exam/js/question.js
@@ -120,7 +120,6 @@ function addLineNumbers(id)
el.className='AnswerWithLines';
el.id='AnswerWithLines';
el.style.height = (ta.scrollHeight) + 'px';
-
for(var no=split_content.length+1;no<1000;no++)
{
if(string.length>0)string = string + '
';
@@ -132,7 +131,6 @@ function addLineNumbers(id)
el.className='SnippetWithLines';
el.id='SnippetWithLines';
el.style.height = (ta.scrollHeight) + 'px';
-
for(var no=1;no<=split_content.length;no++)
{
if(string.length>0)string = string + '
';
--
cgit