123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- (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 == '<front>'){
- 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="<front>"]').addClass('is-active');
- };
- init();
- }
- $(document).ready(function($) {
- var edlptheme = new EdlpTheme();
- });
- })(jQuery);
|