site.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. function click_link() {
  2. $link = $('#text_figli p > a');
  3. $link.click(function(e) {
  4. e.preventDefault();
  5. var $this = $(this);
  6. $href = $this.attr("href");
  7. url = $href.split("/");
  8. page = url[1];
  9. cat = url[2];
  10. project_name = url[3];
  11. if ($this.hasClass('open')) {
  12. $this.removeClass('open');
  13. $('#item_list.'+ cat).remove();
  14. } else {
  15. $.ajax({
  16. url : '/' + page + '/' + cat, // La ressource ciblée
  17. type : 'GET', // Le type de la requête HTTP
  18. dataType:'html',
  19. success: function(data) {
  20. $(data).find('#item_list').addClass(cat).insertAfter($this);
  21. $this.addClass('open');
  22. },
  23. complete: function(data) {
  24. console.log('cat', cat);
  25. // animate();
  26. click_img(e, $this, $href, url, page, cat, project_name);
  27. }
  28. });
  29. }
  30. });
  31. };
  32. function click_list() {
  33. var $link = $('.list-projets li > a');
  34. $link.click(function(e) {
  35. e.preventDefault();
  36. var $this = $(this);
  37. $href = $this.attr("href");
  38. url = $href.split("/");
  39. page = url[1];
  40. cat = url[2];
  41. project_name = url[3];
  42. var $link_txt = $('#text_figli a#'+cat);
  43. var $link_item = $('#item_list.'+cat);
  44. var $link_card = $('.card > #'+project_name + ' a');
  45. if ($link_txt.hasClass('open') && $link_card.parent().hasClass('open') ) {
  46. anchor($href);
  47. }else if ($link_txt.hasClass('open')) {
  48. anchor($href);
  49. $.ajax({
  50. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  51. type : 'GET', // Le type de la requête HTTP
  52. dataType:'html',
  53. success: function(data) {
  54. $('#item_list.'+cat+' .card-image.open #item').remove();
  55. $('#item_list.'+cat+' .card-image').removeClass('open');
  56. $(data).find('#item').addClass(cat).insertAfter($link_card);
  57. $link_card.parent().addClass('open');
  58. },
  59. complete: function(data) {
  60. // animate();
  61. marg_item(project_name);
  62. },
  63. });
  64. } else {
  65. $.ajax({
  66. url : '/' + page + '/' + cat, // La ressource ciblée
  67. type : 'GET', // Le type de la requête HTTP
  68. dataType:'html',
  69. success: function(data) {
  70. $(data).find('#item_list').addClass(cat).insertAfter($link_txt);
  71. $link_txt.addClass('open');
  72. anchor($href);
  73. $('.card a').click(function (e) {
  74. e.preventDefault()
  75. })
  76. click_img(e, $this, $href, url, page, cat, project_name)
  77. },
  78. complete: function(data) {
  79. console.log('cat', cat);
  80. var $link_card = $('.card > #'+project_name + ' a');
  81. setTimeout( function(){
  82. console.log('project_name', project_name);
  83. console.log('$link_card', $link_card);
  84. if ($link_card.hasClass('open')) {
  85. }else {
  86. anchor($href);
  87. $.ajax({
  88. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  89. type : 'GET', // Le type de la requête HTTP
  90. dataType:'html',
  91. success: function(data) {
  92. $(data).find('#item').addClass(cat).insertAfter($link_card);
  93. $link_card.parent().addClass('open');
  94. },
  95. complete: function(data) {
  96. // animate();
  97. marg_item(project_name);
  98. },
  99. });
  100. }
  101. }, 900);
  102. }
  103. });
  104. }
  105. });
  106. }
  107. function click_img(e, $this, $href, url, page, cat, project_name) {
  108. $('section.' + cat +' .card-image > a').click(function(e) {
  109. var $this = $(this);
  110. $href = $this.attr("href");
  111. url = $href.split("/");
  112. page = url[1];
  113. cat = url[2];
  114. project_name = url[3];
  115. e.preventDefault();
  116. if ($this.parent().hasClass('open')) {
  117. $this.parent().removeClass('open');
  118. $($this.parent().find('#item.'+ cat)).remove();
  119. } else {
  120. $.ajax({
  121. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  122. type : 'GET', // Le type de la requête HTTP
  123. dataType:'html',
  124. success: function(data) {
  125. $('#item_list.'+cat+' .card-image.open #item').remove();
  126. $('#item_list.'+cat+' .card-image').removeClass('open');
  127. $(data).find('#item').addClass(cat).insertAfter($this);
  128. $this.parent().addClass('open');
  129. marg_item(project_name);
  130. anchor($href);
  131. },
  132. });
  133. }
  134. });
  135. }
  136. function anchor($href) {
  137. var aTag = $("a[href='"+ $href +"']");
  138. // console.log('aTag.offset()', aTag.offset().top+10);
  139. $('html,body').animate({scrollTop: aTag.offset().top-7},'slow');
  140. }
  141. function animate() {
  142. var $item_list = $('#item_list .card > .card-image');
  143. $item_list.fadeIn( "slow" );
  144. }
  145. function marg_item(project_name) {
  146. var $item = $('.card-image#'+project_name+' #item');
  147. var $item_offset = $item.offset().left-8;
  148. var $card = $item.parents('.card');
  149. var $item_list = $item.parents('#item_list');
  150. var pos_card = $card.offset().left;
  151. var margin_right = $item_list.width() - (pos_card + $card.width());
  152. console.log('$card.width()',$card.width());
  153. console.log('pos_card',pos_card);
  154. console.log('$item_list',$item_list.width());
  155. $item.css('margin-left', '-'+$item_offset +'px');
  156. // $item.parents('.card').css('margin-right', margin_right);
  157. }
  158. function mouseHover() {
  159. $link_cat = $('#text_figli p > a');
  160. $link_cat.mouseenter(function() {
  161. link_id = $(this).attr("id");
  162. $('html').append("<div class=circle_hover ></div>");
  163. console.log('link_id',link_id);
  164. setTimeout(function () {
  165. $('.circle_hover').addClass('open '+ link_id);
  166. }, 10);
  167. mousePos();
  168. })
  169. .mouseleave(function() {
  170. $('html').find(".circle_hover").remove();
  171. });
  172. function mousePos() {
  173. var currentMousePos = { x: 0, y: 0 };
  174. var $circle = $('.circle_hover');
  175. $(document).mousemove(function(event) {
  176. currentMousePos.x = event.pageX;
  177. currentMousePos.y = event.pageY;
  178. $circle.css('left', currentMousePos.x );
  179. $circle.css('top', currentMousePos.y );
  180. });
  181. }
  182. };
  183. $(document).ready(function($){
  184. click_link();
  185. click_list();
  186. mouseHover();
  187. });