site.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. lazyload();
  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. lazyload();
  61. // animate();
  62. marg_item(project_name);
  63. },
  64. });
  65. } else {
  66. $.ajax({
  67. url : '/' + page + '/' + cat, // La ressource ciblée
  68. type : 'GET', // Le type de la requête HTTP
  69. dataType:'html',
  70. success: function(data) {
  71. $(data).find('#item_list').addClass(cat).insertAfter($link_txt);
  72. $link_txt.addClass('open');
  73. anchor($href);
  74. $('.card a').click(function (e) {
  75. e.preventDefault()
  76. })
  77. click_img(e, $this, $href, url, page, cat, project_name)
  78. },
  79. complete: function(data) {
  80. console.log('cat', cat);
  81. lazyload();
  82. var $link_card = $('.card > #'+project_name + ' a');
  83. setTimeout( function(){
  84. console.log('project_name', project_name);
  85. console.log('$link_card', $link_card);
  86. if ($link_card.hasClass('open')) {
  87. }else {
  88. anchor($href);
  89. $.ajax({
  90. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  91. type : 'GET', // Le type de la requête HTTP
  92. dataType:'html',
  93. success: function(data) {
  94. $(data).find('#item').addClass(cat).insertAfter($link_card);
  95. $link_card.parent().addClass('open');
  96. },
  97. complete: function(data) {
  98. // animate();
  99. lazyload();
  100. marg_item(project_name);
  101. },
  102. });
  103. }
  104. }, 900);
  105. }
  106. });
  107. }
  108. });
  109. }
  110. function click_img(e, $this, $href, url, page, cat, project_name) {
  111. $('section.' + cat +' .card-image > a').click(function(e) {
  112. var $this = $(this);
  113. $href = $this.attr("href");
  114. url = $href.split("/");
  115. page = url[1];
  116. cat = url[2];
  117. project_name = url[3];
  118. e.preventDefault();
  119. if ($this.parent().hasClass('open')) {
  120. $this.parent().removeClass('open');
  121. $($this.parent().find('#item.'+ cat)).remove();
  122. } else {
  123. $.ajax({
  124. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  125. type : 'GET', // Le type de la requête HTTP
  126. dataType:'html',
  127. success: function(data) {
  128. $('#item_list.'+cat+' .card-image.open #item').remove();
  129. $('#item_list.'+cat+' .card-image').removeClass('open');
  130. $(data).find('#item').addClass(cat).insertAfter($this);
  131. $this.parent().addClass('open');
  132. marg_item(project_name);
  133. anchor($href);
  134. },
  135. complete:function() {
  136. lazyload();
  137. }
  138. });
  139. }
  140. });
  141. }
  142. function anchor($href) {
  143. var aTag = $("a[href='"+ $href +"']");
  144. // console.log('aTag.offset()', aTag.offset().top+10);
  145. $('html,body').animate({scrollTop: aTag.offset().top-7},'slow');
  146. }
  147. function animate() {
  148. var $item_list = $('#item_list .card > .card-image');
  149. $item_list.fadeIn( "slow" );
  150. }
  151. function marg_item(project_name) {
  152. var $item = $('.card-image#'+project_name+' #item');
  153. var $item_offset = $item.offset().left-8;
  154. var $card = $item.parents('.card');
  155. var $item_list = $item.parents('#item_list');
  156. var pos_card = $card.offset().left;
  157. var margin_right = $item_list.width() - (pos_card + $card.width());
  158. console.log('$card.width()',$card.width());
  159. console.log('pos_card',pos_card);
  160. console.log('$item_list',$item_list.width());
  161. $item.css('margin-left', '-'+$item_offset +'px');
  162. // $item.parents('.card').css('margin-right', margin_right);
  163. }
  164. function mouseHover() {
  165. $link_cat = $('#text_figli p > a');
  166. $link_cat.mouseenter(function() {
  167. link_id = $(this).attr("id");
  168. $('html').append("<div class=circle_hover ></div>");
  169. console.log('link_id',link_id);
  170. setTimeout(function () {
  171. $('.circle_hover').addClass('open '+ link_id);
  172. }, 10);
  173. mousePos();
  174. })
  175. .mouseleave(function() {
  176. $('html').find(".circle_hover").remove();
  177. });
  178. function mousePos() {
  179. var currentMousePos = { x: 0, y: 0 };
  180. var $circle = $('.circle_hover');
  181. $(document).mousemove(function(event) {
  182. currentMousePos.x = event.pageX;
  183. currentMousePos.y = event.pageY;
  184. $circle.css('left', currentMousePos.x );
  185. $circle.css('top', currentMousePos.y );
  186. });
  187. }
  188. };
  189. function lazyload() {
  190. $('.lazy').Lazy({
  191. // your configuration goes here
  192. // scrollDirection: 'vertical',
  193. effect: "fadeIn",
  194. effectTime: 900,
  195. threshold: 0
  196. // visibleOnly: true,
  197. // onError: function(element) {
  198. // console.log('error loading ' + element.data('src'));
  199. // }
  200. });
  201. }
  202. $(document).ready(function($){
  203. click_link();
  204. click_list();
  205. mouseHover();
  206. });