| author | cavaliet |
| Wed, 09 Nov 2011 17:33:26 +0100 | |
| changeset 31 | b910b4f7485f |
| parent 30 | d2fba1e3b94b |
| child 33 | 6c87166b819c |
| permissions | -rwxr-xr-x |
| 2 | 1 |
// -*- coding: utf-8 -*- |
2 |
function wikitag_init_tags_events() |
|
3 |
{ |
|
4 |
// Tag simple operations : activate/unactivate wp link, reset wp info, remove wp link, remove tag from list |
|
5 |
$(".wikitag_reset_wp_info").click(function(e){ |
|
6 |
if(confirm("Confirmez-vous le rétablissement du label original de ce tag ?")){ |
|
7 |
wikitag_update_tag(this); |
|
8 |
} |
|
9 |
}); |
|
10 |
$(".wikitag_remove_wp_link").click(function(e){ |
|
11 |
if(confirm("Confirmez-vous le suppression du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?")){ |
|
12 |
wikitag_update_tag(this); |
|
13 |
} |
|
14 |
}); |
|
15 |
$(".wikitag_remove_tag_from_list").click(function(){ |
|
16 |
if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){ |
|
17 |
wikitag_update_tag(this); |
|
18 |
} |
|
19 |
}); |
|
20 |
|
|
21 |
// Wikipedia search management (autocompletion and save changes) |
|
22 |
$.editable.addInputType('autocomplete', { |
|
23 |
element : $.editable.types.text.element, |
|
24 |
plugin : function(settings, original) { |
|
25 |
$('input', this).autocomplete(settings.autocomplete); |
|
26 |
} |
|
27 |
}); |
|
28 |
$(".wikipediatag").editable(modify_tag_url, { |
|
29 |
indicator : "<img src='"+static_url+"images/indicator.gif'>", |
|
30 |
type : "autocomplete", |
|
31 |
tooltip : "Cliquer pour éditer...", |
|
32 |
onblur : "submit", |
|
33 |
submitdata: { |
|
34 |
csrfmiddlewaretoken:global_csrf_token, |
|
35 |
wikitag_document_id:$('#wikitag_document_id').val(), |
|
| 12 | 36 |
num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined), |
37 |
nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined), |
|
38 |
sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined), |
|
39 |
searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined) |
|
| 2 | 40 |
}, |
41 |
callback : function(value, settings) { |
|
42 |
$('#wikitag_table_container').html(value); |
|
43 |
wikitag_init_tags_events(); |
|
44 |
}, |
|
45 |
onerror: function(settings, original, jqXHR) { |
|
46 |
resp = $.parseJSON(jqXHR.responseText); |
|
47 |
alert(resp.message); |
|
48 |
original.reset(); |
|
49 |
}, |
|
50 |
autocomplete : { |
|
51 |
source: function( request, response ) { |
|
52 |
$.ajax({ |
|
53 |
url: "http://fr.wikipedia.org/w/api.php", |
|
54 |
dataType: "jsonp", |
|
55 |
data: { |
|
56 |
action: "opensearch", |
|
57 |
limit: "20", |
|
58 |
namespace: "0", |
|
59 |
format: "json", |
|
60 |
search: request.term |
|
61 |
}, |
|
62 |
success: function( data ) { |
|
63 |
response( $.map( data[1], function( item ) { |
|
64 |
return { |
|
65 |
label: item, |
|
66 |
value: item |
|
67 |
} |
|
68 |
})); |
|
69 |
} |
|
70 |
}); |
|
71 |
}, |
|
72 |
minLength: 2, |
|
73 |
open: function() { |
|
74 |
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); |
|
75 |
}, |
|
76 |
close: function() { |
|
77 |
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); |
|
78 |
} |
|
79 |
} |
|
80 |
}); |
|
81 |
|
|
82 |
// Update alias management |
|
83 |
$(".wikitag_alias").editable(update_tag_alias_url, { |
|
84 |
indicator : "<img src='"+static_url+"images/indicator.gif'>", |
|
85 |
type : "text", |
|
86 |
placeholder:"", |
|
87 |
tooltip : "Cliquer pour éditer...", |
|
88 |
onblur : "submit", |
|
89 |
submitdata: { |
|
90 |
csrfmiddlewaretoken:global_csrf_token, |
|
91 |
wikitag_document_id:$('#wikitag_document_id').val(), |
|
| 12 | 92 |
num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined), |
93 |
nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined), |
|
94 |
sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined), |
|
95 |
searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined) |
|
| 2 | 96 |
}, |
97 |
callback : function(value, settings) { |
|
98 |
$('#wikitag_table_container').html(value); |
|
99 |
wikitag_init_tags_events(); |
|
100 |
} |
|
101 |
}); |
|
102 |
|
|
103 |
// Tag categories management |
|
104 |
$(".wikitag_category").editable(update_tag_category_url, { |
|
105 |
indicator : "<img src='"+static_url+"/images/indicator.gif'>", |
|
106 |
type : "select", |
|
107 |
data : categories_list, |
|
108 |
placeholder:"", |
|
109 |
tooltip : "Cliquer pour éditer...", |
|
110 |
onblur : "submit", |
|
111 |
submitdata: { |
|
112 |
csrfmiddlewaretoken:global_csrf_token, |
|
113 |
wikitag_document_id:$('#wikitag_document_id').val(), |
|
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
114 |
num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined), |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
115 |
nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined), |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
116 |
sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined), |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
117 |
searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined) |
| 2 | 118 |
}, |
119 |
callback : function(value, settings) { |
|
120 |
$('#wikitag_table_container').html(value); |
|
121 |
wikitag_init_tags_events(); |
|
122 |
} |
|
123 |
}); |
|
124 |
|
|
125 |
// Tag table drag and drop |
|
126 |
$("#wikitag_table").tableDnD({ |
|
127 |
onDragClass: "wikitag_dragged_row", |
|
128 |
onDrop: function(table, row){ |
|
129 |
old_order = row.id; |
|
130 |
$($(row).children()[1]).html("<img src='"+static_url+"/images/indicator.gif'/>"); |
|
131 |
rows = table.tBodies[0].rows; |
|
132 |
nb_rows = rows.length; |
|
133 |
for(var i=1; i<nb_rows; i++){ |
|
134 |
if(rows[i].id==old_order){ |
|
135 |
new_order = i; // No need to +1 because rows[0] are headers |
|
136 |
$.ajax({ |
|
137 |
url: tag_up_down_url, |
|
138 |
type: 'POST', |
|
139 |
data: {csrfmiddlewaretoken:global_csrf_token, |
|
140 |
wikitag_document_id:$('#wikitag_document_id').val(), |
|
141 |
new_order:new_order, |
|
142 |
old_order:old_order |
|
143 |
}, |
|
144 |
// bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType |
|
145 |
//dataType: 'json', |
|
146 |
success: function(msg, textStatus, XMLHttpRequest) { |
|
147 |
$('#wikitag_table_container').html(msg); |
|
148 |
wikitag_init_tags_events(); |
|
149 |
} |
|
150 |
}); |
|
151 |
} |
|
152 |
} |
|
153 |
}, |
|
154 |
dragHandle: "wikitag_updown_td" |
|
155 |
}); |
|
156 |
} |
|
157 |
||
158 |
function wikitag_init_datasheet_events() |
|
159 |
{ |
|
160 |
var select_done = false; |
|
161 |
// Wikipedia search management (new tag) |
|
162 |
$("#wikitag_wp_search").autocomplete({ |
|
163 |
source: function( request, response ) { |
|
164 |
$.ajax({ |
|
165 |
url: "http://fr.wikipedia.org/w/api.php", |
|
166 |
dataType: "jsonp", |
|
167 |
data: { |
|
168 |
action: "opensearch", |
|
169 |
limit: "20", |
|
170 |
namespace: "0", |
|
171 |
format: "json", |
|
172 |
search: request.term |
|
173 |
}, |
|
174 |
success: function( data ) { |
|
175 |
response( $.map( data[1], function( item ) { |
|
176 |
return { |
|
177 |
label: item, |
|
178 |
value: item |
|
179 |
} |
|
180 |
})); |
|
181 |
} |
|
182 |
}); |
|
183 |
}, |
|
184 |
select: function(event, ui) { |
|
185 |
// Since the event still did not update wp_search's val, we force it. |
|
186 |
$("#wikitag_wp_search").val(ui.item.label); |
|
187 |
select_done = true; |
|
188 |
$("#wikitag_ok_search").click(); |
|
189 |
}, |
|
190 |
minLength: 2, |
|
191 |
open: function() { |
|
192 |
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); |
|
193 |
}, |
|
194 |
close: function() { |
|
195 |
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); |
|
196 |
} |
|
197 |
}); |
|
198 |
$('#wikitag_wp_search').keyup(function(e){ |
|
199 |
if((e.keyCode==13) && ($("#wikitag_wp_search").val()!="") && (select_done==false)){ |
|
200 |
add_tag($("#wikitag_wp_search").val()); |
|
201 |
} |
|
202 |
select_done = false; |
|
203 |
}); |
|
204 |
$("#wikitag_ok_search").click(function(){ |
|
205 |
if($("#wikitag_wp_search").val()!=""){ |
|
206 |
add_tag($("#wikitag_wp_search").val()); |
|
207 |
} |
|
208 |
}); |
|
209 |
$("#wikitag_tags_sort").click(function(e){ |
|
210 |
e.preventDefault(); |
|
211 |
if(confirm("Confirmez-vous le tri des tags ?")) { |
|
212 |
reorder_tags(); |
|
213 |
} |
|
214 |
}); |
|
215 |
} |
|
216 |
||
|
31
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
217 |
function wikitag_init_search_context_events() |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
218 |
{ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
219 |
// We implement the behaviour on text select. Kolich is just an object name, it could be anything |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
220 |
if(!window.Kolich){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
221 |
Kolich = {}; |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
222 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
223 |
Kolich.Selector = {}; |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
224 |
Kolich.Selector.getSelected = function(){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
225 |
var t = ''; |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
226 |
if(window.getSelection){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
227 |
t = window.getSelection(); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
228 |
}else if(document.getSelection){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
229 |
t = document.getSelection(); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
230 |
}else if(document.selection){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
231 |
t = document.selection.createRange().text; |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
232 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
233 |
return t; |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
234 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
235 |
Kolich.Selector.mouseup = function(e){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
236 |
var st = Kolich.Selector.getSelected(); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
237 |
if(st!=''){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
238 |
// Behaviour after the text was selected |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
239 |
$("#wikitag_context_div").offset({left:e.pageX+10,top:e.pageY}); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
240 |
$("#wikitag_context_div").show(); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
241 |
$("#wikitag_context_div #wikitag_wp_search_context").val(st); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
242 |
$("#wikitag_context_div #wikitag_wp_search_context").autocomplete("search"); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
243 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
244 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
245 |
$(document).ready(function(){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
246 |
$(document).bind("mouseup", Kolich.Selector.mouseup); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
247 |
}); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
248 |
|
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
249 |
// Function to close the context window |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
250 |
$("#wikitag_context_close").click(function(e){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
251 |
$("#wikitag_context_div #wikitag_wp_search_context").autocomplete("close"); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
252 |
$("#wikitag_context_div").offset({left:0,top:0}); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
253 |
$("#wikitag_context_div").hide(); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
254 |
}); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
255 |
|
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
256 |
// Wikipedia search management (new tag) |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
257 |
$("#wikitag_wp_search_context").autocomplete({ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
258 |
source: function( request, response ) { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
259 |
$.ajax({ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
260 |
url: "http://fr.wikipedia.org/w/api.php", |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
261 |
dataType: "jsonp", |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
262 |
data: { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
263 |
action: "opensearch", |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
264 |
limit: "20", |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
265 |
namespace: "0", |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
266 |
format: "json", |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
267 |
search: request.term |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
268 |
}, |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
269 |
success: function( data ) { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
270 |
response( $.map( data[1], function( item ) { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
271 |
return { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
272 |
label: item, |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
273 |
value: item |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
274 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
275 |
})); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
276 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
277 |
}); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
278 |
}, |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
279 |
select: function(event, ui) { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
280 |
// Since the event still did not update wp_search's val, we force it. |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
281 |
$("#wikitag_wp_search_context").val(ui.item.label); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
282 |
add_tag($("#wikitag_wp_search_context").val()); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
283 |
$("#wikitag_context_close").click(); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
284 |
}, |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
285 |
minLength: 2, |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
286 |
open: function() { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
287 |
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
288 |
}, |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
289 |
close: function() { |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
290 |
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
291 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
292 |
}); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
293 |
$('#wikitag_wp_search_context').keyup(function(e){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
294 |
if((e.keyCode==13) && ($("#wikitag_wp_search_context").val()!="")){ |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
295 |
add_tag($("#wikitag_wp_search_context").val()); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
296 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
297 |
}); |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
298 |
} |
|
b910b4f7485f
First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents:
30
diff
changeset
|
299 |
|
| 2 | 300 |
function wikitag_update_tag(btn) |
301 |
{ |
|
302 |
new_checked = false; |
|
303 |
if ($(btn).is(".wikitag_remove_tag_from_list")) { |
|
304 |
var url = remove_tag_from_list_url; |
|
305 |
var id_tag = $(btn).attr('id'); |
|
306 |
} |
|
307 |
else if ($(btn).is(".wikitag_reset_wp_info")) { |
|
308 |
var url = reset_wp_info_url; |
|
309 |
var id_tag = $(btn).html(); |
|
310 |
$(btn).html("<img src='"+static_url+"/images/indicator.gif'>"); |
|
311 |
} |
|
312 |
else if ($(btn).is(".wikitag_remove_wp_link")) { |
|
313 |
var url = remove_wp_link_url; |
|
314 |
var id_tag = $(btn).attr('id'); |
|
315 |
} |
|
316 |
|
|
317 |
// 2 cases : |
|
318 |
// - ordered tag for one datasheet : $('#wikitag_document_id') is not null |
|
319 |
// - all tags list : $('#wikitag_document_id') is null and $('#num_page') and $('#nb_by_page') are not null |
|
320 |
$.ajax({ |
|
321 |
url: url, |
|
322 |
type: 'POST', |
|
323 |
data: {csrfmiddlewaretoken:global_csrf_token, |
|
324 |
wikitag_document_id:$('#wikitag_document_id').val(), |
|
| 12 | 325 |
num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined), |
326 |
nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined), |
|
327 |
sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined), |
|
328 |
searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined), |
|
| 2 | 329 |
tag_id:id_tag, |
330 |
activated:new_checked |
|
331 |
}, |
|
332 |
// bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType |
|
333 |
//dataType: 'json', |
|
334 |
success: function(msg, textStatus, XMLHttpRequest) { |
|
335 |
$('#wikitag_table_container').html(msg); |
|
336 |
wikitag_init_tags_events(); |
|
337 |
}, |
|
338 |
error: function(jqXHR, textStatus, errorThrown) { |
|
339 |
resp = $.parseJSON(jqXHR.responseText); |
|
340 |
alert(resp.message); |
|
341 |
$(btn).html(id_tag); |
|
342 |
} |
|
343 |
}); |
|
344 |
} |
|
345 |
||
346 |
function wikitag_up_down(arrow) |
|
347 |
{ |
|
348 |
if ($(arrow).is(".up")) { |
|
349 |
mv = "u"; |
|
350 |
} else { |
|
351 |
mv = "d"; |
|
352 |
} |
|
353 |
var url = tag_up_down_url; |
|
354 |
var id_tag = $(arrow).attr('id'); |
|
355 |
// This indicates the position (from 0) of the tag in the list. NB : it is different from the TagSheet.order in the database. |
|
356 |
var pos_tag = $(arrow).attr('pos'); |
|
357 |
$.ajax({ |
|
358 |
url: url, |
|
359 |
type: 'POST', |
|
360 |
data: {csrfmiddlewaretoken:global_csrf_token, |
|
361 |
wikitag_document_id:$('#wikitag_document_id').val(), |
|
362 |
tag_id:id_tag, |
|
363 |
move:mv, |
|
364 |
tag_pos:pos_tag |
|
365 |
}, |
|
366 |
// bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType |
|
367 |
//dataType: 'json', |
|
368 |
success: function(msg, textStatus, XMLHttpRequest) { |
|
369 |
$('#wikitag_table_container').html(msg); |
|
370 |
wikitag_init_tags_events(); |
|
371 |
} |
|
372 |
}); |
|
373 |
} |
|
374 |
||
375 |
function add_tag(tag_label) |
|
376 |
{ |
|
377 |
$("#wikitag_ok_search").html("<img src='"+static_url+"/images/indicator.gif'>"); |
|
378 |
var url = add_tag_url; |
|
379 |
$.ajax({ |
|
380 |
url: url, |
|
381 |
type: 'POST', |
|
382 |
data: {csrfmiddlewaretoken:global_csrf_token, |
|
383 |
wikitag_document_id:$('#wikitag_document_id').val(), |
|
384 |
value:tag_label |
|
385 |
}, |
|
386 |
// bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType |
|
387 |
//dataType: 'json', |
|
388 |
success: function(msg, textStatus, XMLHttpRequest) { |
|
389 |
$('#wikitag_table_container').html(msg); |
|
390 |
wikitag_init_tags_events(); |
|
391 |
// And scroll to the bottom |
|
392 |
$("html").animate({ scrollTop: $(document).height() }, 500); |
|
393 |
}, |
|
394 |
error: function(jqXHR, textStatus, errorThrown) { |
|
395 |
resp = $.parseJSON(jqXHR.responseText); |
|
396 |
alert(resp.message); |
|
397 |
}, |
|
398 |
complete: function(){ |
|
399 |
// We empty the input and hide the ok button |
|
400 |
$("#wikitag_wp_search").val(""); |
|
401 |
$("#wikitag_ok_search").html("<b>OK</b>"); |
|
402 |
} |
|
403 |
}); |
|
404 |
} |
|
405 |
||
406 |
function reorder_tags() { |
|
407 |
$('#wikitag_tags_sort').attr("disabled", "disabled"); |
|
408 |
var tag_sort_old_src = $("#wikitag_tags_sort").attr("src"); |
|
409 |
$("#wikitag_tags_sort").attr("src",static_url+"images/indicator.gif"); |
|
410 |
$.ajax({ |
|
411 |
url: reorder_tag_datasheet_url, |
|
412 |
type: 'POST', |
|
413 |
data: { |
|
414 |
csrfmiddlewaretoken:global_csrf_token, |
|
415 |
wikitag_document_id:$('#wikitag_document_id').val() |
|
416 |
}, |
|
417 |
success: function(msg, textStatus, XMLHttpRequest) { |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
418 |
$('#wikitag_table_container').html(msg); |
| 2 | 419 |
wikitag_init_tags_events(); |
420 |
// And scroll to the bottom |
|
421 |
$("html").animate({ scrollTop: $(document).height() }, 500); |
|
422 |
}, |
|
423 |
complete: function(){ |
|
424 |
$("#wikitag_tags_sort").attr("src",tag_sort_old_src); |
|
425 |
$('#wikitag_tags_sort').removeAttr("disabled"); |
|
426 |
} |
|
427 |
}); |
|
428 |
} |
|
429 |
||
|
11
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
430 |
function getUrlVars() |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
431 |
{ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
432 |
var vars = [], hash; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
433 |
if(window.location.href.indexOf('?')>=0){ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
434 |
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
435 |
for(var i = 0; i < hashes.length; i++) |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
436 |
{ |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
437 |
hash = hashes[i].split('='); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
438 |
vars.push(hash[0]); |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
439 |
vars[hash[0]] = hash[1]; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
440 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
441 |
} |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
442 |
return vars; |
|
5f038a505cd7
Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents:
2
diff
changeset
|
443 |
} |