(function($) { EdlpTheme = function(){ var _$body = $('body'); var _is_front = _$body.is('.path-frontpage'); var _$corpus_map; var _$content_container = $('.layout-container>main>.layout-content'); var _$ajaxLinks; function init(){ console.log("EdlpTheme init()"); _$body.on('corpus-map-ready', onCorpusMapReady); initScrollbars(); initAjaxLinks(); }; // ___ _ _ ___ // / __| __ _ _ ___| | | _ ) __ _ _ _ ___ // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-< // |___/\__|_| \___/_|_|___/\__,_|_| /__/ function initScrollbars(){ console.log("initScrollbars"); $('.os-scroll').overlayScrollbars({ overflowBehavior:{x:'h',y:'scroll'} }); }; // _ _ // /_\ (_)__ ___ __ // / _ \ | / _` \ \ / // /_/ \_\/ \__,_/_\_\ // |__/ // TODO: add url hash nav // TODO: implement history.js function initAjaxLinks(){ console.log('initAjaxLinks'); $('a', '#block-mainnavigation, #block-footer.menu--footer').addClass('ajax-link'); _$ajaxLinks = $('.ajax-link') .each(function(i,e){ var $this = $(this); var sys_path = $this.attr('data-drupal-link-system-path'); if(sys_path){ // convert node link to edlp_ajax_node module links m = sys_path.match(/^\/?(node\/\d+)$/g); if(m) $this.attr('data-drupal-link-system-path', 'edlp/'+m[0]); } }) .on('click', onClickAjaxLink); ; }; function onClickAjaxLink(e){ e.preventDefault(); var $link = $(this); if($link.is('.is-active')) return false; var sys_path = $(this).attr('data-drupal-link-system-path'); if(sys_path == ''){ closeAllModals(); return false; } // TODO: drupal settings not defined on NOT front page var path = window.location.origin + drupalSettings.basepath + sys_path +'/ajax'; closeAllModals(); _$body.addClass('ajax-loading'); $link.addClass('ajax-loading'); $.getJSON(path, {}, function(data){ onAjaxLinkLoaded(data, $link, sys_path); }); return false; }; function onAjaxLinkLoaded(data, $link, sys_path){ console.log('ajax link loaded : data', data); _$content_container.html(data.rendered); _$body.removeClass('ajax-loading'); _$body.removeClass().addClass('path-'+sys_path); _$ajaxLinks.removeClass('is-active'); $link.removeClass('ajax-loading').addClass('is-active'); initScrollbars(); }; // corpus function onCorpusMapReady(e){ console.log('theme : onCorpusReady'); _$corpus_map = $('canvas#corpus-map'); _$corpus_map.on('corpus-cliked-on-map', function(e) { console.log('theme : corpus-cliked-on-map'); closeAllModals(); }); } //modals function closeAllModals(){ console.log('theme : closeAllModals'); // TODO: animate the remove _$content_container.html(''); _$ajaxLinks.removeClass('is-active'); $('a[data-drupal-link-system-path=""]').addClass('is-active'); }; init(); } $(document).ready(function($) { var edlptheme = new EdlpTheme(); }); })(jQuery);