site.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. function click_link() {
  2. $link = $('#text_figli p > a');
  3. $link.on('click',function(e) {
  4. e.preventDefault();
  5. var $loader = $(this).find('.loader');
  6. var $this = $(this);
  7. $href = $this.attr("href");
  8. url = $href.split("/");
  9. page = url[1];
  10. cat = url[2];
  11. project_name = url[3];
  12. if ($this.hasClass('open')) {
  13. $this.removeClass('open');
  14. $('#item_list.'+ cat).remove();
  15. } else {
  16. $('#item_list').remove();
  17. $('.open').removeClass('open');
  18. $loader.css('display','inline-block');
  19. $.ajax({
  20. url : '/' + page + '/' + cat, // La ressource ciblée
  21. type : 'GET', // Le type de la requête HTTP
  22. dataType:'html',
  23. async: false,
  24. success: function(data) {
  25. $(data).find('#item_list').addClass(cat).insertAfter($this);
  26. $this.addClass('open');
  27. lazy();
  28. },
  29. complete: function(data) {
  30. // console.log('cat', cat);
  31. $loader.hide();
  32. click_img(e, $this, $href, url, page, cat, project_name);
  33. closeAjax();
  34. },
  35. });
  36. }
  37. });
  38. };
  39. function click_list() {
  40. var $link = $('.list-projets li > a');
  41. $link.click(function(e) {
  42. $('.sidebar-right, .sidebar-right button.hamburger').removeClass('is-active');
  43. var idthis = $(this).attr("id");
  44. var $loader = $(this).parents('#start').find('#text_figli #'+idthis+' .loader');
  45. console.log('$loader',$loader);
  46. e.preventDefault();
  47. var $this = $(this);
  48. $href = $this.attr("href");
  49. url = $href.split("/");
  50. page = url[1];
  51. cat = url[2];
  52. project_name = url[3];
  53. var $link_txt = $('#text_figli a#'+cat);
  54. var $link_item = $('#item_list.'+cat);
  55. var $link_card = $('.card > #'+project_name + ' a');
  56. if ($link_txt.hasClass('open') && $link_card.parent().hasClass('open') ) {
  57. anchor($href);
  58. } else if ($link_txt.hasClass('open')) {
  59. anchor($href);
  60. $.ajax({
  61. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  62. type : 'GET', // Le type de la requête HTTP
  63. dataType:'html',
  64. // async: false,
  65. success: function(data) {
  66. $('#item_list.'+cat+' .card-image.open #item').remove();
  67. $('#item_list.'+cat+' .card-image').removeClass('open');
  68. $(data).find('#item').addClass(cat).insertAfter($link_card);
  69. $link_card.parent().addClass('open');
  70. lazy();
  71. },
  72. complete: function(data) {
  73. marg_item(project_name);
  74. closeAjax();
  75. anchor($href);
  76. },
  77. });
  78. } else {
  79. $('#item_list').remove();
  80. $('.open').removeClass('open');
  81. $loader.css('display','inline-block');
  82. $.ajax({
  83. url : '/' + page + '/' + cat, // La ressource ciblée
  84. type : 'GET', // Le type de la requête HTTP
  85. dataType:'html',
  86. // async: false,
  87. success: function(data) {
  88. $(data).find('#item_list').addClass(cat).insertAfter($link_txt);
  89. $link_txt.addClass('open');
  90. lazy();
  91. $('.card a').click(function (e) {
  92. e.preventDefault()
  93. })
  94. click_img(e, $this, $href, url, page, cat, project_name)
  95. },
  96. complete: function(data) {
  97. // console.log('cat', cat);
  98. $loader.hide();
  99. var $link_card = $('.card > #'+project_name + ' a');
  100. setTimeout( function(){
  101. // console.log('project_name', project_name);
  102. // console.log('$link_card', $link_card);
  103. if ($link_card.hasClass('open')) {
  104. } else {
  105. anchor($href);
  106. $.ajax({
  107. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  108. type : 'GET', // Le type de la requête HTTP
  109. dataType:'html',
  110. success: function(data) {
  111. $(data).find('#item').addClass(cat).insertAfter($link_card);
  112. $link_card.parent().addClass('open');
  113. lazy();
  114. },
  115. complete: function(data) {
  116. marg_item(project_name);
  117. closeAjax();
  118. anchor($href);
  119. scrollTop();
  120. },
  121. });
  122. }
  123. }, 500);
  124. }
  125. });
  126. }
  127. });
  128. }
  129. function click_img(e, $this, $href, url, page, cat, project_name) {
  130. $('section.' + cat +' .card-image > a').click(function(e) {
  131. var $this = $(this);
  132. $href = $this.attr("href");
  133. url = $href.split("/");
  134. page = url[1];
  135. cat = url[2];
  136. project_name = url[3];
  137. var $loader = $(this).parents('.card').find('.loader');
  138. e.preventDefault();
  139. if ($this.parent().hasClass('open')) {
  140. $this.parent().removeClass('open');
  141. $($this.parent().find('#item.'+ cat)).remove();
  142. } else {
  143. $loader.css('display','inline-block');
  144. $.ajax({
  145. url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
  146. type : 'GET', // Le type de la requête HTTP
  147. dataType:'html',
  148. success: function(data) {
  149. $('#item_list.'+cat+' .card-image.open #item').remove();
  150. $('#item_list.'+cat+' .card-image').removeClass('open');
  151. $(data).find('#item').addClass(cat).insertAfter($this);
  152. $this.parent().addClass('open');
  153. marg_item(project_name);
  154. anchor($href);
  155. lazy();
  156. scrollTop();
  157. // ScrollReveal().reveal($('#item_list > .card'), {
  158. // duration: 1000,
  159. // distance: '10px',
  160. // });
  161. },
  162. complete:function() {
  163. closeAjax();
  164. $('.loader').hide();
  165. }
  166. });
  167. }
  168. });
  169. }
  170. function anchor($href) {
  171. var aTag = $("#text_figli a[href='"+ $href +"']");
  172. console.log(aTag);
  173. // console.log('aTag.offset()', aTag.offset().top+10);
  174. $('html,body').animate({scrollTop: aTag.offset().top - 7},'slow');
  175. }
  176. function animate() {
  177. var $item_list = $('#item_list .card > .card-image');
  178. $item_list.fadeIn( "slow" );
  179. }
  180. function marg_item(project_name) {
  181. var $item = $('.card-image#'+project_name+' #item');
  182. var $card = $item.parents('.card');
  183. var pos_card = $card.offset().left-8;
  184. $item.css('margin-left', '-'+pos_card +'px');
  185. $(window).resize(function() {
  186. var pos_card = $card.offset().left-8;
  187. $item.css('margin-left', '-'+pos_card +'px');
  188. })
  189. }
  190. function mouseHover() {
  191. $link_cat = $('#text_figli p > a');
  192. $link_cat.mouseenter(function() {
  193. link_id = $(this).attr("id");
  194. $('html').append("<div class=circle_hover ></div>");
  195. // console.log('link_id',link_id);
  196. setTimeout(function () {
  197. $('.circle_hover').addClass('open '+ link_id);
  198. }, 10);
  199. mousePos();
  200. })
  201. .mouseleave(function() {
  202. $('html').find(".circle_hover").remove();
  203. });
  204. function mousePos() {
  205. var currentMousePos = { x: 0, y: 0 };
  206. var $circle = $('.circle_hover');
  207. $(document).mousemove(function(event) {
  208. currentMousePos.x = event.pageX;
  209. currentMousePos.y = event.pageY;
  210. $circle.css('left', currentMousePos.x );
  211. $circle.css('top', currentMousePos.y );
  212. });
  213. }
  214. };
  215. function lazy() {
  216. $('img.lazy').Lazy({
  217. effect: "fadeIn",
  218. effectTime: 500,
  219. threshold: 0
  220. });
  221. }
  222. function animate_burger() {
  223. var forEach=function(t,o,r){if("[object Object]"===Object.prototype.toString.call(t))for(var c in t)Object.prototype.hasOwnProperty.call(t,c)&&o.call(r,t[c],c,t);else for(var e=0,l=t.length;l>e;e++)o.call(r,t[e],e,t)};
  224. var hamburgers = document.querySelectorAll(".hamburger");
  225. var $hamburger = $('button.hamburger');
  226. if (hamburgers.length > 0) {
  227. forEach(hamburgers, function(hamburger) {
  228. hamburger.addEventListener("click", function() {
  229. this.classList.toggle("is-active");
  230. }, false);
  231. });
  232. }
  233. $hamburger.click(function() {
  234. $('.sidebar-right').toggleClass("is-active");
  235. })
  236. }
  237. function closeAjax() {
  238. var $button = $('#item #icone_list');
  239. $button.click(function() {
  240. $(this).parent().remove();
  241. $('.card-image').removeClass("open");
  242. });
  243. }
  244. function croix() {
  245. var $link = $("#text_figli p > a");
  246. var hamburger = "<div id='icone_list'><button class='hamburger hamburger--slider is-active' type='button'><span class='hamburger-box'><span class='hamburger-inner'></span></span></button></div>"
  247. var loader = "<div class='loader'></div>"
  248. $link.append(hamburger);
  249. $link.append(loader);
  250. }
  251. function scrollTop() {
  252. var $body = $("html, body");
  253. $('#item #top').click(function() {
  254. $body.stop().animate({scrollTop:0}, 500, 'swing', function() {
  255. });
  256. })
  257. }
  258. function imgmouse() {
  259. var currentMousePos = { x: 0, y: 0 };
  260. var $list_projets = $('.list-projets');
  261. var $img = $('.list-projets .img');
  262. $list_projets.mousemove(function(e) {
  263. var pos = $list_projets.offset();
  264. currentMousePos.x = e.pageX - pos.left ;
  265. currentMousePos.y = e.pageY - pos.top;
  266. $img.css('left', currentMousePos.x );
  267. $img.css('top', currentMousePos.y );
  268. });
  269. }
  270. function scrollreveal() {
  271. var $txt = $('#text_figli p');
  272. ScrollReveal().reveal($txt, {
  273. duration: 1000,
  274. distance: '10px',
  275. });
  276. }
  277. function clickmenu() {
  278. var $menu = $('.sidebar-right button');
  279. $menu.click(function() {
  280. $('#text_figli').toggleClass('hidden');
  281. $('html, body').toggleClass('hidden');
  282. });
  283. var $list_projetsA = $('.list-projets .container');
  284. $list_projetsA.click(function() {
  285. $('#text_figli').toggleClass('hidden');
  286. $('html, body').toggleClass('hidden');
  287. });
  288. }
  289. function scrollcustom() {
  290. $(window).on("load",function(){
  291. // $(".sidebar-right").mCustomScrollbar({
  292. // scrollbarPosition: "outside",
  293. // axis:"y",
  294. // });
  295. //
  296. // $("body").mCustomScrollbar({
  297. // scrollbarPosition: "outside",
  298. // axis:"y",
  299. // });
  300. });
  301. }
  302. $(document).ready(function($){
  303. scrollcustom();
  304. scrollreveal();
  305. click_link();
  306. click_list();
  307. mouseHover();
  308. animate_burger();
  309. croix();
  310. imgmouse();
  311. clickmenu();
  312. });