glossary_auto.js.html.twig 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {% if add_ready %}
  2. $(function() {
  3. $(window).on("load", function (e) {
  4. {% endif %}
  5. var my_text = $(".glossary-content").html();
  6. var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php?{{ _p.web_cid_query }}";
  7. var imageSource = "{{ _p.web }}main/inc/lib/javascript/indicator.gif";
  8. var indicatorImage ='<img src="' + imageSource + '" />';
  9. $.ajax({
  10. contentType: "application/x-www-form-urlencoded",
  11. beforeSend: function(content_object) {},
  12. type: "POST",
  13. url: ajaxRequestUrl,
  14. data: "glossary_data=true",
  15. success: function(datas) {
  16. if (datas.length==0) {
  17. return false;
  18. }
  19. // glossary terms
  20. data_terms=datas.split("[|.|_|.|-|.|]");
  21. var complex_array = new Array();
  22. var cp_complex_array = new Array();
  23. for(i=0;i<data_terms.length;i++) {
  24. specific_terms=data_terms[i].split("__|__|");
  25. var real_term = specific_terms[1]; // glossary term
  26. var real_code = specific_terms[0]; // glossary id
  27. complex_array[real_code] = real_term;
  28. cp_complex_array[real_code] = real_term;
  29. }
  30. complex_array.reverse();
  31. for (var my_index in complex_array) {
  32. n = complex_array[my_index];
  33. if (n == null) {
  34. n = '';
  35. } else {
  36. for (var cp_my_index in cp_complex_array) {
  37. cp_data = cp_complex_array[cp_my_index];
  38. if (cp_data == null) {
  39. cp_data = '';
  40. } else {
  41. if (cp_data == n) {
  42. my_index = cp_my_index;
  43. }
  44. }
  45. }
  46. $('body').removeHighlight().highlight(n, my_index);
  47. }
  48. }
  49. var complex_array = new Array();
  50. //mouse on click
  51. $("body").on("click", ".glossary-ajax", function(e) {
  52. random_id = Math.round(Math.random()*100);
  53. div_show_id = "div_show_id";
  54. div_content_id = "div_content_id";
  55. $(this).append("<div id="+div_show_id+"><div id="+div_content_id+">&nbsp;</div></div>");
  56. var $target = $(this);
  57. //$("#"+div_show_id).dialog("destroy");
  58. $("#"+div_show_id).dialog({
  59. autoOpen: false,
  60. width: 600,
  61. height: 200,
  62. position: { my: 'left top', at: 'right top', of: $target },
  63. close: function(){
  64. $("div#"+div_show_id).remove();
  65. $("div#"+div_content_id).remove();
  66. }
  67. });
  68. notebook_id = $(this).attr("name");
  69. data_notebook = notebook_id.split("link");
  70. my_glossary_id = data_notebook[1];
  71. $.ajax({
  72. contentType: "application/x-www-form-urlencoded",
  73. beforeSend: function(content_object) {
  74. $("div#"+div_content_id).html(indicatorImage);
  75. },
  76. type: "POST",
  77. url: ajaxRequestUrl,
  78. data: "glossary_id="+my_glossary_id,
  79. success: function(datas) {
  80. $("div#"+div_content_id).html(datas);
  81. $("#"+div_show_id).dialog("open");
  82. }
  83. });
  84. });
  85. }
  86. });
  87. {% if add_ready %}
  88. });
  89. });
  90. {% endif %}