script_k.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var $link_txt = $('#text_figli p > a');
  2. var $link_list = $('.list-projets a');
  3. function ajax_txt($href,$this, this_id) {
  4. var $link_txt = $('#text_figli > p');
  5. var idlink_txt = $link_txt.attr("id");
  6. var search_id =$link_txt.find('#' + this_id);
  7. $.ajax({
  8. url : $href, // La ressource ciblée
  9. type : 'GET', // Le type de la requête HTTP
  10. dataType:'html',
  11. success: function(data) {
  12. $(data).find('.card').addClass(this_id).insertAfter(search_id);
  13. var $card = $('#text_figli .card .card-image > a');
  14. $card.click(function(e) {
  15. e.preventDefault();
  16. var $this = $(this);
  17. var $href = $this.attr("href");
  18. var this_id = $this.parent('.card-image').attr("id");
  19. if ($this.parent('.card-image').hasClass('views')) {
  20. $('#'+this_id+' #item').remove();
  21. $this.parent('.card-image').removeClass("views");
  22. }else{
  23. $.ajax({
  24. url : $href, // La ressource ciblée
  25. type : 'GET', // Le type de la requête HTTP
  26. dataType:'html',
  27. success: function(data) {
  28. $(data).find('#item').insertAfter($this);
  29. $(window).on('resize', function(x){
  30. var x = $this.offset();
  31. var x = $this.offset();
  32. var Wwindow = $('#text_figli').width();
  33. var Wcard = $this.parents('.card').width();
  34. var xcard = $this.offset().left;
  35. var marginR = Wwindow - (Wcard + xcard);
  36. console.log('x.left resize =',x.left);
  37. $this.parent('.card-image').find('#item').css('margin-left', -x.left+8);
  38. $this.parents('.card').css('margin-right', marginR);
  39. });
  40. var x = $this.offset();
  41. var Wwindow = $('#text_figli').width();
  42. var Wcard = $this.parents('.card').width();
  43. var xcard = $this.offset().left;
  44. var marginR = Wwindow - (Wcard + xcard);
  45. // si la distance entre l'image précédente et la bord droit du text est supérieur ou égale
  46. // a un card
  47. // alors soustrai xcard a la marg calculer de this.
  48. // sinon tu ne change rien
  49. console.log('marginR', marginR);
  50. // console.log('x.left',x.left);
  51. // console.log('marginR',marginR.right);
  52. $this.parent('.card-image').find('#item').css('margin-left', -x.left+8);
  53. $this.parents('.card').css('margin-right', marginR);
  54. }
  55. });
  56. $this.parent('.card-image').addClass('views');
  57. }
  58. });
  59. }
  60. });
  61. }
  62. function ajax_liste($href,$this, this_id) {
  63. var $link_txt = $('#text_figli > p');
  64. var idlink_txt = $link_txt.attr("id");
  65. var search_id =$link_txt.find('#' + this_id);
  66. console.log('$href',$href);
  67. var url = $href.split("/");
  68. var id = url[url.length - 2];
  69. var projetc_name = url[url.length - 1];
  70. console.log('projetc_name',projetc_name);
  71. $.ajax({
  72. url : '/projets/' + id, // La ressource ciblée
  73. type : 'GET', // Le type de la requête HTTP
  74. dataType:'html',
  75. success: function(data) {
  76. $(data).find('.card').addClass(this_id).insertAfter(search_id);
  77. },
  78. complete: function(){
  79. // Handle the complete event
  80. setTimeout( function(){
  81. $.ajax({
  82. url : '/projets/' + id + '/' + projetc_name, // La ressource ciblée
  83. type : 'GET', // Le type de la requête HTTP
  84. dataType:'html',
  85. success: function(data) {
  86. var $link_item = $('#text_figli > p > .card');
  87. var idlink_txt = $link_txt.attr("id");
  88. var search_id =$link_item.find('#' + projetc_name);
  89. console.log('search_id',id);
  90. $(data).find('#item').insertAfter(search_id);
  91. console.log('complete2');
  92. },
  93. })
  94. }, 2000);
  95. }
  96. });
  97. }
  98. function deploy() {
  99. $link_txt.click(function(e){
  100. e.preventDefault();
  101. var $this = $(this);
  102. var $href = $this.attr("href");
  103. var this_id = $this.attr("id");
  104. if ($this.hasClass('open')) {
  105. $('.card.'+this_id).remove();
  106. $this.removeClass("open");
  107. }else{
  108. ajax_txt($href, $this, this_id);
  109. $this.addClass('open');
  110. }
  111. });
  112. $link_list.click(function(e){
  113. e.preventDefault();
  114. var $this = $(this);
  115. var $href = $this.attr("href");
  116. var this_id = $this.attr("id");
  117. if ($this.hasClass('open')) {
  118. $('.card.'+this_id).remove();
  119. $this.removeClass("open");
  120. }else{
  121. ajax_liste($href, $this, this_id);
  122. $this.addClass('open');
  123. }
  124. });
  125. }
  126. jQuery(document).ready(function($){
  127. deploy();
  128. });