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