Onlinetest
10-16-2008, 06:36 PM
I'm working javascript for todo gadget and i get some bugs. This is my code todo.xml of gadget todo :
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs author="eXoPlatform"
title="Todo"
directory_title="Todo"
title_url="http://www.n2lose.org"
height="235">
<Require feature="setprefs" />
</ModulePrefs>
<UserPref name="todoList"
datatype="list"/>
<Content type="html">
<![CDATA[
<style type="text/css">
body {
margin: 0;
outline: none;
font: normal 100%/1.25 Verdana, Tahoma, Arial, Helvetica, sans-serif;
text-decoration: none;
text-align: center;
}
img {
border:none;
}
li {
list-style-type:none;
}
.clear {
clear:both;
width:0;
height:0;
line-height:0;
font-size:0;
}
.Note {
background: url(/n2lose/skin/image/Note.jpg) top left no-repeat;
width: 160px;
height: 235px;
margin: 0 auto;
padding: 42px 18px 0 18px;
}
.write {
width: 155px;
height: 165px;
overflow: auto;
}
.write input {
background: url(/n2lose/skin/image/line.gif) bottom left repeat-x;
font-size: 11px;
color: #be0d08;
border: none;
width: 100%;
line-height: auto;
font-style: italic;
margin-bottom: 2px;
height: 18px;
}
</style>
<script type="text/javascript">
var prefs = new gadgets.Prefs();
var keynum;
var parentGadgets = window.top.gadgets;
var gadget = parentGadgets.container.getGadget(prefs.getModuleId());
function onLoad() {
var appendParrent = document.getElementById("write");
var inputlist = top.eXo.core.DOMUtil.findDescendantsByTagName(appendParrent,"input");
var j = inputlist.length ;
while(j--) {
inputlist[j].onkeyup = finish(this,event) ;
inputlist[j].onfocus = checkIndex(this,event) ;
}
var lists = window.top.JSON.stringify(gadget.getUserPrefs());
if(lists == "{}") return;
lists = lists.substring(1,lists.length-1);
var listsTodo = lists.split("|");
for(var i=0; i<listsTodo.length; i++) {
if(i>6) {
var input = document.createElement("input");
input.setAttribute("type","text");
input.setAttribute("name",i+1);
input.onkeyup = finish(this,event);
input.setAttribute("id",i+1);
appendParrent.insertBefore(input,null);
}
var tmp = document.getElementById(parseInt(i)+1);
tmp.value = listsTodo[i];
}
}
function finish(element,e) {
var lists = window.top.JSON.stringify(gadget.getUserPrefs());
if(lists.length == 0 || lists == "{}") lists = null;
else {
lists = lists.substring(1,lists.length-1);
var listTodo = lists.split("|");
}
var appendParrent = document.getElementById("write");
var nameElement = parseInt(element.name) + 1;
if(window.event) {
keynum = e.keyCode;
}else if(e.which) {
keynum = e.which;
}
if(keynum == 13) {
if(nameElement == 8 && element.nextSibling.nextSibling!=null) {
element.nextSibling.nextSibling.focus();
return;
}
if(nameElement > 8 && element.nextSibling!=null) {
element.nextSibling.focus();
return;
}
if(nameElement > 7) {
var input = document.createElement("input");
input.setAttribute("type","text");
input.setAttribute("name",nameElement);
input.setAttribute("onkeydown","finish(this,event);");
input.setAttribute("id",nameElement);
appendParrent.insertBefore(input,null);
}
var nextInput = element.nextSibling.nextSibling;
if(nameElement > 8) nextInput = element.nextSibling;
if(nextInput.value == null || nextInput.value==""){
nextInput.value = nameElement + ".";
if(lists == null) lists = element.value;
else {
lists = lists + "|" + element.value;
}
} else
{
var oldStr = listTodo[parseInt(nameElement-2)];
var lists = lists.replace(oldStr,element.value);
}
prefs.setArray("todoList",[lists]);
gadget.setUserPrefs(lists);
nextInput.focus();
}
}
</script>
<body onload="onLoad()">
<div class="Note">
<div class="write" id="write">
<input type="text" id="1" onfocus="javascript: if(this.value == '1. Type new task here') this.value='1.'" value="1. Type new task here" name="1" onkeyup="finish(this,event);"/>
<input type="text" id="2" name="2" onkeyup="finish(this,event);"/>
<input type="text" id="3" name="3" onkeyup="finish(this,event);"/>
<input type="text" id="4" name="4" onkeyup="finish(this,event);"/>
<input type="text" id="5" name="5" onkeyup="finish(this,event);"/>
<input type="text" id="6" name="6" onkeyup="finish(this,event);"/>
<input type="text" id="7" name="7" onkeyup="finish(this,event);"/>
</div>
</div>
</body>
]]>
</Content>
</Module>
above is code todo.xml of todo gadget. anybody help javascript :
1. When anybody add new task, he typing follow i can save to there. 'Cause when you typing a task you must be press Enter key to save task.
2. Check index of Task when he press enter key or Tab por mouse new Tabs.
Anybody help me please?
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs author="eXoPlatform"
title="Todo"
directory_title="Todo"
title_url="http://www.n2lose.org"
height="235">
<Require feature="setprefs" />
</ModulePrefs>
<UserPref name="todoList"
datatype="list"/>
<Content type="html">
<![CDATA[
<style type="text/css">
body {
margin: 0;
outline: none;
font: normal 100%/1.25 Verdana, Tahoma, Arial, Helvetica, sans-serif;
text-decoration: none;
text-align: center;
}
img {
border:none;
}
li {
list-style-type:none;
}
.clear {
clear:both;
width:0;
height:0;
line-height:0;
font-size:0;
}
.Note {
background: url(/n2lose/skin/image/Note.jpg) top left no-repeat;
width: 160px;
height: 235px;
margin: 0 auto;
padding: 42px 18px 0 18px;
}
.write {
width: 155px;
height: 165px;
overflow: auto;
}
.write input {
background: url(/n2lose/skin/image/line.gif) bottom left repeat-x;
font-size: 11px;
color: #be0d08;
border: none;
width: 100%;
line-height: auto;
font-style: italic;
margin-bottom: 2px;
height: 18px;
}
</style>
<script type="text/javascript">
var prefs = new gadgets.Prefs();
var keynum;
var parentGadgets = window.top.gadgets;
var gadget = parentGadgets.container.getGadget(prefs.getModuleId());
function onLoad() {
var appendParrent = document.getElementById("write");
var inputlist = top.eXo.core.DOMUtil.findDescendantsByTagName(appendParrent,"input");
var j = inputlist.length ;
while(j--) {
inputlist[j].onkeyup = finish(this,event) ;
inputlist[j].onfocus = checkIndex(this,event) ;
}
var lists = window.top.JSON.stringify(gadget.getUserPrefs());
if(lists == "{}") return;
lists = lists.substring(1,lists.length-1);
var listsTodo = lists.split("|");
for(var i=0; i<listsTodo.length; i++) {
if(i>6) {
var input = document.createElement("input");
input.setAttribute("type","text");
input.setAttribute("name",i+1);
input.onkeyup = finish(this,event);
input.setAttribute("id",i+1);
appendParrent.insertBefore(input,null);
}
var tmp = document.getElementById(parseInt(i)+1);
tmp.value = listsTodo[i];
}
}
function finish(element,e) {
var lists = window.top.JSON.stringify(gadget.getUserPrefs());
if(lists.length == 0 || lists == "{}") lists = null;
else {
lists = lists.substring(1,lists.length-1);
var listTodo = lists.split("|");
}
var appendParrent = document.getElementById("write");
var nameElement = parseInt(element.name) + 1;
if(window.event) {
keynum = e.keyCode;
}else if(e.which) {
keynum = e.which;
}
if(keynum == 13) {
if(nameElement == 8 && element.nextSibling.nextSibling!=null) {
element.nextSibling.nextSibling.focus();
return;
}
if(nameElement > 8 && element.nextSibling!=null) {
element.nextSibling.focus();
return;
}
if(nameElement > 7) {
var input = document.createElement("input");
input.setAttribute("type","text");
input.setAttribute("name",nameElement);
input.setAttribute("onkeydown","finish(this,event);");
input.setAttribute("id",nameElement);
appendParrent.insertBefore(input,null);
}
var nextInput = element.nextSibling.nextSibling;
if(nameElement > 8) nextInput = element.nextSibling;
if(nextInput.value == null || nextInput.value==""){
nextInput.value = nameElement + ".";
if(lists == null) lists = element.value;
else {
lists = lists + "|" + element.value;
}
} else
{
var oldStr = listTodo[parseInt(nameElement-2)];
var lists = lists.replace(oldStr,element.value);
}
prefs.setArray("todoList",[lists]);
gadget.setUserPrefs(lists);
nextInput.focus();
}
}
</script>
<body onload="onLoad()">
<div class="Note">
<div class="write" id="write">
<input type="text" id="1" onfocus="javascript: if(this.value == '1. Type new task here') this.value='1.'" value="1. Type new task here" name="1" onkeyup="finish(this,event);"/>
<input type="text" id="2" name="2" onkeyup="finish(this,event);"/>
<input type="text" id="3" name="3" onkeyup="finish(this,event);"/>
<input type="text" id="4" name="4" onkeyup="finish(this,event);"/>
<input type="text" id="5" name="5" onkeyup="finish(this,event);"/>
<input type="text" id="6" name="6" onkeyup="finish(this,event);"/>
<input type="text" id="7" name="7" onkeyup="finish(this,event);"/>
</div>
</div>
</body>
]]>
</Content>
</Module>
above is code todo.xml of todo gadget. anybody help javascript :
1. When anybody add new task, he typing follow i can save to there. 'Cause when you typing a task you must be press Enter key to save task.
2. Check index of Task when he press enter key or Tab por mouse new Tabs.
Anybody help me please?