main.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. (function($) {
  2. EdlpTheme = function(){
  3. var _$body = $('body');
  4. var _is_front = _$body.is('.path-frontpage');
  5. var _$corpus_map;
  6. var _$content_container = $('.layout-container>main>.layout-content');
  7. function init(){
  8. console.log("EdlpTheme init()");
  9. _$body.on('corpus-map-ready', onCorpusMapReady);
  10. initScrollbars();
  11. initAjaxLinks();
  12. };
  13. // ___ _ _ ___
  14. // / __| __ _ _ ___| | | _ ) __ _ _ _ ___
  15. // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-<
  16. // |___/\__|_| \___/_|_|___/\__,_|_| /__/
  17. function initScrollbars(){
  18. console.log("initScrollbars");
  19. $('.os-scroll').overlayScrollbars({
  20. overflowBehavior:{x:'h',y:'scroll'}
  21. });
  22. };
  23. // _ _
  24. // /_\ (_)__ ___ __
  25. // / _ \ | / _` \ \ /
  26. // /_/ \_\/ \__,_/_\_\
  27. // |__/
  28. function initAjaxLinks(){
  29. console.log('initAjaxLinks');
  30. $('a', '#block-mainnavigation').on('click', onClickAjaxLink);
  31. };
  32. function onClickAjaxLink(e){
  33. e.preventDefault();
  34. // TODO: drupal settings not defined on NOT front page
  35. var sys_path = $(this).attr('data-drupal-link-system-path');
  36. var path = window.location.origin + drupalSettings.basepath + sys_path +'/ajax';
  37. closeAllModals();
  38. _$body.addClass('ajax-loading');
  39. $.getJSON(path, {}, function(data){
  40. onAjaxLinkLoaded(data, sys_path);
  41. });
  42. return false;
  43. };
  44. function onAjaxLinkLoaded(data, sys_path){
  45. console.log('ajax link loaded : data', data);
  46. _$content_container.html(data.rendered);
  47. _$body.removeClass().addClass('path-'+sys_path);
  48. _$body.removeClass('ajax-loading');
  49. initScrollbars();
  50. };
  51. // corpus
  52. function onCorpusMapReady(e){
  53. console.log('theme : onCorpusReady');
  54. _$corpus_map = $('canvas#corpus-map');
  55. _$corpus_map.on('corpus-cliked-on-map', function(e) {
  56. console.log('theme : corpus-cliked-on-map');
  57. closeAllModals();
  58. });
  59. }
  60. //modals
  61. function closeAllModals(){
  62. console.log('theme : closeAllModals');
  63. // TODO: animate the remove
  64. _$content_container.html('');
  65. };
  66. init();
  67. }
  68. $(document).ready(function($) {
  69. var edlptheme = new EdlpTheme();
  70. });
  71. })(jQuery);