added productions menu block to ajax load

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-03 12:55:15 +01:00
parent 55f5d5b2f0
commit b1598ae231
5 changed files with 166 additions and 53 deletions
@@ -46,8 +46,7 @@
var $this = $(this);
// avoid already ajaxified links
if($this.is('.ajax-enable'))
return;
if($this.is('.ajax-enable')) return;
var sys_path = $this.attr('data-drupal-link-system-path');
if(sys_path){
@@ -70,36 +69,59 @@
var sys_path = $(this).attr('data-drupal-link-system-path');
if(sys_path == '<front>'){
closeAllModals();
backToFrontPage();
return false;
}
var path = window.location.origin + drupalSettings.path.baseUrl + sys_path +'/ajax';
closeAllModals();
var path = window.location.origin + drupalSettings.path.baseUrl + sys_path;
_$body.addClass('ajax-loading');
$link.addClass('ajax-loading');
$.getJSON(path, {}, function(data){
onAjaxLinkLoaded(data, $link, sys_path);
});
// $.getJSON(path, {}, function(data){
// onAjaxLinkLoaded(data, $link, sys_path);
// });
$.getJSON(path+'/ajax', {})
.done(function(data){
onAjaxLinkLoaded(data, $link, sys_path);
})
.fail(function(jqxhr, textStatus, error){
onAjaxLinkLoadError(jqxhr, textStatus, error, $link, sys_path);
});
return false;
};
function onAjaxLinkLoaded(data, $link, sys_path){
console.log('ajax link loaded');
_$content_container.html(data.rendered);
function onAjaxLinkLoadError(jqxhr, textStatus, error, $link, sys_path){
console.warn('fail : error', jqxhr.responseText);
$link.removeClass('ajax-loading');
_$body.removeClass('ajax-loading');
};
function onAjaxLinkLoaded(data, $link, sys_path){
console.log('ajax link loaded : data', data);
_$body.removeClass('ajax-loading');
// replace all content with newly loaded
_$content_container.html(data.rendered);
// add body class for currently loaded content
_$body.removeClass().addClass('path-'+sys_path.replace(/\//g, '-'));
// id node add a generic path-node class to body
m = sys_path.match(/^\/?(edlp\/node\/\d+)$/g);
if(m){
if(m)
_$body.addClass('path-edlp-node');
}
// handle clicked link classes
_$ajaxLinks.removeClass('is-active');
$link.removeClass('ajax-loading').addClass('is-active');
// if block attached (eg : from edlp_productions module)
if(typeof data.block != 'undefined'){
// if block not already added
if(!$('#'+data.block.id, '.region-'+data.block.region).length){
$('.region-'+data.block.region).append(data.block.rendered);
}
}
initScrollbars();
if(sys_path == "productions")
@@ -119,7 +141,7 @@
_$corpus_map = $('canvas#corpus-map');
_$corpus_map.on('corpus-cliked-on-map', function(e) {
console.log('theme : corpus-cliked-on-map');
closeAllModals();
backToFrontPage();
});
}
@@ -147,6 +169,20 @@
// });
};
// ___ _ ___
// | __| _ ___ _ _| |_| _ \__ _ __ _ ___
// | _| '_/ _ \ ' \ _| _/ _` / _` / -_)
// |_||_| \___/_||_\__|_| \__,_\__, \___|
// |___/
function backToFrontPage(){
closeAllModals();
// assume we are going back to front page
$('body').removeClass().addClass('path-frontpage');
$('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
}
// __ __ _ _
// | \/ |___ __| |__ _| |___
// | |\/| / _ \/ _` / _` | (_-<
@@ -156,8 +192,6 @@
// TODO: animate the remove
_$content_container.html('');
_$ajaxLinks.removeClass('is-active');
$('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
};
init();