xref: /plugin/todo/script.js (revision 63314d65712f1adc68da8cdacf392664edfd7023)
1var myAjax = new sack();
2
3function whenCompleted(){
4  if(myAjax.response){
5    alert(myAjax.response);
6  }
7
8	/*if (myAjax.responseStatus){
9		var string = "<p>Status Code: " + myAjax.responseStatus[0] + "</p><p>Status Message: " + myAjax.responseStatus[1] + "</p><p>URLString Sent: " + myAjax.URLString + "</p><p>Response: " + myAjax.response + "</p>";
10	} else {
11		var string = "<p>URLString Sent: " + myAjax.URLString + "</p>";
12	}
13	alert(string);*/
14}
15
16function clickSpan(span, id){
17  //Find the checkbox node we need
18  var chk;
19  var preve = span.previousSibling;
20  while(preve){
21    if(preve.nodeType == 1){
22      chk = preve;
23      break;
24    }
25    preve = preve.previousSibling;
26  }
27
28  if(chk && chk.nodeName == "INPUT"){
29    //Change the checkbox
30    chk.checked = !chk.checked;
31
32    //Do we require strikethrough
33    var strike;
34    if(chk.checked == true){
35      strike = true;
36    }else{
37      strike = false;
38    }
39
40    //Call the todo function
41    todo(chk, id, strike);
42  }else{
43	  alert("Appropriate javascript element not found.");
44  }
45}
46
47function todo(chk, path, strike){
48
49  /*
50  ** +Checkbox
51  ** +Span
52  ** -Hidden
53  ** -Span
54  ** --Anchor
55  ** ---Del
56  */
57
58  var span;
59  var nexte = chk.nextSibling;
60
61  //Find the SPAN node we need...
62  while(nexte){
63    if(nexte.nodeType == 1){
64      span = nexte;
65      break;
66    }
67    nexte = nexte.nextSibling;
68  }
69
70  //Verify we found the correct node
71  if(span && span.nodeName == "SPAN"){
72    if(chk.checked == true){
73      //alert("true");
74      if(strike == 1){
75        span.lastChild.innerHTML = "<del>" + decodeURIComponent(span.firstChild.value.replace(/\+/g, " ")) + "</del>";
76      }
77      myAjax.setVar("checked", "1");
78    }else{
79      //alert("false");
80      span.lastChild.innerHTML = decodeURIComponent(span.firstChild.value.replace(/\+/g, " "));
81      myAjax.setVar("checked", "0");
82    }
83
84    //alert(path);
85    myAjax.setVar("origVal", span.firstChild.value);
86  	myAjax.setVar("path", path);
87  	myAjax.requestFile = DOKU_BASE+'lib/plugins/todo/ajax.php';
88  	myAjax.method = "GET";
89  	myAjax.onCompletion = whenCompleted;
90  	myAjax.runAJAX();
91	}else{
92	  alert("Appropriate javascript element not found.\nReverting checkmark.");
93	  chk.checked = !chk.checked;
94  }
95}