123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- function click_link() {
- $link = $('#text_figli p > a');
- $link.click(function(e) {
- e.preventDefault();
- var $this = $(this);
- $href = $this.attr("href");
- url = $href.split("/");
- page = url[1];
- cat = url[2];
- project_name = url[3];
- if ($this.hasClass('open')) {
- $this.removeClass('open');
- $('#item_list.'+ cat).remove();
- } else {
- $.ajax({
- url : '/' + page + '/' + cat, // La ressource ciblée
- type : 'GET', // Le type de la requête HTTP
- dataType:'html',
- success: function(data) {
- $(data).find('#item_list').addClass(cat).insertAfter($this);
- $this.addClass('open');
- },
- complete: function(data) {
- console.log('cat', cat);
- click_img(e, $this, $href, url, page, cat, project_name);
- }
- });
- }
- });
- };
- function click_list() {
- var $link = $('.list-projets li > a');
- $link.click(function(e) {
- e.preventDefault();
- var $this = $(this);
- $href = $this.attr("href");
- url = $href.split("/");
- page = url[1];
- cat = url[2];
- project_name = url[3];
- var $link_txt = $('#text_figli a#'+cat);
- var $link_item = $('#item_list.'+cat);
- var $link_card = $('.card > #'+project_name + ' a');
- if ($link_txt.hasClass('open') && $link_card.parent().hasClass('open') ) {
- console.log('anchor');
- anchor($href);
- }else if ($link_txt.hasClass('open')) {
- $.ajax({
- url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
- type : 'GET', // Le type de la requête HTTP
- dataType:'html',
- success: function(data) {
- $(data).find('#item').addClass(cat).insertAfter($link_card);
- $link_card.parent().addClass('open');
- },
- });
- } else {
- $.ajax({
- url : '/' + page + '/' + cat, // La ressource ciblée
- type : 'GET', // Le type de la requête HTTP
- dataType:'html',
- success: function(data) {
- $(data).find('#item_list').addClass(cat).insertAfter($link_txt);
- $link_txt.addClass('open');
- anchor($href);
- $('.card a').click(function (e) {
- e.preventDefault()
- })
- click_img(e, $this, $href, url, page, cat, project_name)
- },
- complete: function(data) {
- console.log('cat', cat);
- var $link_card = $('.card > #'+project_name + ' a');
- setTimeout( function(){
- console.log('project_name', project_name);
- console.log('$link_card', $link_card);
- if ($link_card.hasClass('open')) {
- }else {
- anchor($href);
- $.ajax({
- url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
- type : 'GET', // Le type de la requête HTTP
- dataType:'html',
- success: function(data) {
- $(data).find('#item').addClass(cat).insertAfter($link_card);
- $link_card.parent().addClass('open');
- },
- });
- }
- }, 1500);
- }
- });
- }
- });
- }
- function click_img(e, $this, $href, url, page, cat, project_name) {
- // $link_img = $('.card .card-image > a');
- $('section.' + cat +' .card-image > a').click(function(e) {
- var $this = $(this);
- $href = $this.attr("href");
- url = $href.split("/");
- page = url[1];
- cat = url[2];
- project_name = url[3];
- e.preventDefault();
- if ($this.parent().hasClass('open')) {
- $this.parent().removeClass('open');
- $($this.parent().find('#item.'+ cat)).remove();
- } else {
- $.ajax({
- url : '/' + page + '/' + cat + '/' + project_name, // La ressource ciblée
- type : 'GET', // Le type de la requête HTTP
- dataType:'html',
- success: function(data) {
- $(data).find('#item').addClass(cat).insertAfter($this);
- $this.parent().addClass('open');
- },
- });
- }
- });
- }
- function anchor($href) {
- var aTag = $("a[href='"+ $href +"']");
- $('html,body').animate({scrollTop: aTag.offset().top},'slow');
- }
- $(document).ready(function($){
- click_link();
- click_list();
- });
|