160 lines
4.3 KiB
JavaScript
160 lines
4.3 KiB
JavaScript
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();
|
|
});
|