Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (111 loc) · 4.44 KB
/
Copy pathscript.js
File metadata and controls
132 lines (111 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* @date 20130405 Leo Eibler <dokuwiki@sprossenwanne.at> \n
* replace old sack() method with new jQuery method and use post instead of get - see https://www.dokuwiki.org/devel:jqueryfaq \n
* @date 20130407 Leo Eibler <dokuwiki@sprossenwanne.at> \n
* use jQuery for finding the elements \n
* @date 20130408 Christian Marg <marg@rz.tu-clausthal.de> \n
* change only the clicked todoitem instead of all items with the same text \n
* @date 20130408 Leo Eibler <dokuwiki@sprossenwanne.at> \n
* migrate changes made by Christian Marg to current version of plugin (use jQuery) \n
* @date 20130410 by Leo Eibler <dokuwiki@sprossenwanne.at> / http://www.eibler.at \n
* bugfix: encoding html code (security risk <todo><script>alert('hi')</script></todo>) - bug reported by Andreas \n
* @date 20130413 Christian Marg <marg@rz.tu-clausthal.de> \n
* bugfix: chk.attr('checked') returns checkbox state from html - use chk.is(':checked') - see http://www.unforastero.de/jquery/checkbox-angehakt.php \n
* @date 20130413 by Leo Eibler <dokuwiki@sprossenwanne.at> / http://www.eibler.at \n
* bugfix: config option Strikethrough \n
*/
/**
* html-layout:
*
* +input[checkbox].todocheckbox
* +span.todotext
* -del
* --span.todoinnertext
* ---anchor with text or text only
*/
var ToDoPlugin = {
/**
* lock to prevent simultanous requests
*/
locked: false,
/**
* @brief onclick method for input element
*
* @param {jQuery} $chk the jQuery input element
*/
todo: function ($chk) {
//skip when locked
if (ToDoPlugin.locked) {
return;
}
//set lock
ToDoPlugin.locked = true;
var $spanTodoinnertext = $chk.nextAll("span.todotext:first").find("span.todoinnertext"),
param = $chk.data(), // contains: index, pageid, date, strikethrough
checked = !$chk.is(':checked');
// if the data-index attribute is set, this is a call from the page where the todos are defined
if (param.index === undefined) param.index = -1;
if ($spanTodoinnertext.length) {
/**
* Callback function update the todoitem when save request succeed
*
* @param {Array} data returned by ajax request
*/
var whenCompleted = function (data) {
//update date after edit and show alert when needed
if (data.date) {
jQuery('input.todocheckbox').data('date', data.date);
}
if (data.message) {
alert(data.message);
}
//apply styling, or undo checking checkbox
if (data.succeed) {
$chk.prop('checked', checked);
if (checked) {
if (param.strikethrough && !$spanTodoinnertext.parent().is("del")) {
$spanTodoinnertext.wrap("<del></del>");
}
} else {
if ($spanTodoinnertext.parent().is("del")) {
$spanTodoinnertext.unwrap();
}
}
}
//release lock
ToDoPlugin.locked = false;
};
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_todo',
index: param.index,
pageid: param.pageid,
checked: checked ? "1" : "0",
date: param.date
},
whenCompleted,
'json'
);
} else {
alert("Appropriate javascript element not found.\nReverting checkmark.");
}
}
};
jQuery(function(){
// add handler to checkbox
jQuery('input.todocheckbox').click(function(e){
e.preventDefault();
e.stopPropagation();
var $this = jQuery(this);
// undo checking the checkbox
$this.prop('checked', !$this.is(':checked'));
ToDoPlugin.todo($this);
});
// add click handler to todotext spans when marked with 'clickabletodo'
jQuery('span.todotext.clickabletodo').click(function(){
//Find the checkbox node we need
var $chk = jQuery(this).prevAll('input.todocheckbox:first');
ToDoPlugin.todo($chk);
});
});