webfaction and repo.or.cz deployment done
[worddb.git] / static / js / jquery.translations.js
blob28a474ba1ec6ef26a42acda6d929641f577b1b3d
1 $.fn.translatize = function (options) {
2 return this.each(function(i, o){
3 $(o).hoverIntent({
4 sensitivity: 1, interval: 200, timeout: 500,
5 over: function(){
6 $(".translations", o).slideDown("slow");
7 },
8 out: function() {
9 $(".translations", o).slideUp("slow");
11 });
12 jQuery(".add_translation", o).after(
13 '<div class="add_translation_box">\
14 <div class="header">Add word</div>\
15 <form method="post" action="/w/ajax/word/add-translation/">\
16 <input type="text" class="word_ac">\
17 <input type="hidden" name="other_word">\
18 <input type="hidden" name="word"><br>\
19 <input type="submit" class="add_it" value="Add it">\
20 </form>\
21 <a href="#f" class="not_really">Not really</a>\
22 </div>'
24 jQuery("input[@name=word]").val(get_word_id(o));
25 jQuery(".add_translation", o).unbind().click(function(){
26 $(this).blur();
27 jQuery(".add_translation_box", o).toggle("slow");
28 $("input.word_ac", o).val("").get(0).focus();
29 return false;
30 });
31 jQuery(".not_really", o).unbind().click(function(){
32 jQuery(".add_translation_box", o).toggle("hide");
33 return false;
34 });
35 var search_url = "/w/ajax/search/?exclude_word=" + get_word_id(o);
36 search_url += "&exclude_language=" + get_class_data(o, "lang_");
37 jQuery("input.word_ac", o).autocomplete(
38 search_url, {
39 mustMatch: true,
40 onItemSelect: function(li){
41 $("input[@name=other_word]", o).val(li.extra);
45 jQuery("li", o).each(function(i2, o2){
46 $(o2).append(
47 '<img class="dnone remover" \
48 src="/media/img/admin/icon_deletelink.gif">\
49 <div>\
50 Are you sure to remove this?\
51 <form method="post" action="/w/ajax/word/remove-translation/">\
52 <input type="hidden" name="other_word">\
53 <input type="hidden" name="word"><br>\
54 <input type="submit" value="Remove it">\
55 </form>\
56 <a href="#f" class="not_really">Not really</a>\
57 </div>\
58 ');
59 $("input[@name=word]", o2).val(get_word_id(o));
60 $("input[@name=other_word]", o2).val(get_word_id(o2));
61 $("img.remover, a.not_really", o2).click(function(){
62 $("div", o2).toggle();
63 return false;
64 });
65 jQuery(o2).hover(function(){
66 jQuery("img", o2).show();
67 }, function() {
68 jQuery("img", o2).hide();
69 });
70 });
71 });
74 function get_word_id(o){
75 var classes = jQuery(o).attr("class").split(" ");
76 var word_id = "";
77 $.each(classes, function(i, cls){
78 if(cls.indexOf("w_") == 0){
79 word_id = cls.substring(2);
81 });
82 return word_id;