main.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. var _$ajaxLinks;
  8. function init(){
  9. console.log("EdlpTheme init()");
  10. _$body.on('corpus-map-ready', onCorpusMapReady);
  11. initScrollbars();
  12. initAjaxLinks();
  13. };
  14. // ___ _ _ ___
  15. // / __| __ _ _ ___| | | _ ) __ _ _ _ ___
  16. // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-<
  17. // |___/\__|_| \___/_|_|___/\__,_|_| /__/
  18. function initScrollbars(){
  19. console.log("initScrollbars");
  20. $('.os-scroll').overlayScrollbars({
  21. overflowBehavior:{x:'h',y:'scroll'}
  22. });
  23. };
  24. // _ _
  25. // /_\ (_)__ ___ __
  26. // / _ \ | / _` \ \ /
  27. // /_/ \_\/ \__,_/_\_\
  28. // |__/
  29. // TODO: add url hash nav
  30. // TODO: implement history.js
  31. function initAjaxLinks(){
  32. console.log('initAjaxLinks');
  33. $('a', '#block-mainnavigation, #block-footer.menu--footer').addClass('ajax-link');
  34. _$ajaxLinks = $('.ajax-link')
  35. .each(function(i,e){
  36. var $this = $(this);
  37. var sys_path = $this.attr('data-drupal-link-system-path');
  38. if(sys_path){
  39. // convert node link to edlp_ajax_node module links
  40. m = sys_path.match(/^\/?(node\/\d+)$/g);
  41. if(m) $this.attr('data-drupal-link-system-path', 'edlp/'+m[0]);
  42. }
  43. })
  44. .on('click', onClickAjaxLink);
  45. ;
  46. };
  47. function onClickAjaxLink(e){
  48. e.preventDefault();
  49. var $link = $(this);
  50. if($link.is('.is-active'))
  51. return false;
  52. var sys_path = $(this).attr('data-drupal-link-system-path');
  53. if(sys_path == '<front>'){
  54. closeAllModals();
  55. return false;
  56. }
  57. // TODO: drupal settings not defined on NOT front page
  58. var path = window.location.origin + drupalSettings.basepath + sys_path +'/ajax';
  59. closeAllModals();
  60. _$body.addClass('ajax-loading');
  61. $link.addClass('ajax-loading');
  62. $.getJSON(path, {}, function(data){
  63. onAjaxLinkLoaded(data, $link, sys_path);
  64. });
  65. return false;
  66. };
  67. function onAjaxLinkLoaded(data, $link, sys_path){
  68. console.log('ajax link loaded : data', data);
  69. _$content_container.html(data.rendered);
  70. _$body.removeClass('ajax-loading');
  71. _$body.removeClass().addClass('path-'+sys_path);
  72. _$ajaxLinks.removeClass('is-active');
  73. $link.removeClass('ajax-loading').addClass('is-active');
  74. initScrollbars();
  75. };
  76. // corpus
  77. function onCorpusMapReady(e){
  78. console.log('theme : onCorpusReady');
  79. _$corpus_map = $('canvas#corpus-map');
  80. _$corpus_map.on('corpus-cliked-on-map', function(e) {
  81. console.log('theme : corpus-cliked-on-map');
  82. closeAllModals();
  83. });
  84. }
  85. //modals
  86. function closeAllModals(){
  87. console.log('theme : closeAllModals');
  88. // TODO: animate the remove
  89. _$content_container.html('');
  90. _$ajaxLinks.removeClass('is-active');
  91. $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
  92. };
  93. init();
  94. }
  95. $(document).ready(function($) {
  96. var edlptheme = new EdlpTheme();
  97. });
  98. })(jQuery);