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