main.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. if (_$body.is('.path-productions')) {
  14. initProductions();
  15. }
  16. };
  17. // ___ _ _ ___
  18. // / __| __ _ _ ___| | | _ ) __ _ _ _ ___
  19. // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-<
  20. // |___/\__|_| \___/_|_|___/\__,_|_| /__/
  21. function initScrollbars(){
  22. console.log("initScrollbars");
  23. $('.os-scroll').overlayScrollbars({
  24. overflowBehavior:{x:'h',y:'scroll'}
  25. });
  26. };
  27. // _ _
  28. // /_\ (_)__ ___ __
  29. // / _ \ | / _` \ \ /
  30. // /_/ \_\/ \__,_/_\_\
  31. // |__/
  32. // TODO: add url hash nav
  33. // TODO: implement history.js
  34. function initAjaxLinks(){
  35. console.log('initAjaxLinks');
  36. $('a', '#block-mainnavigation, #block-footer.menu--footer, #block-productions').addClass('ajax-link');
  37. _$ajaxLinks = $('.ajax-link')
  38. .each(function(i,e){
  39. var $this = $(this);
  40. // avoid already ajaxified links
  41. if($this.is('.ajax-enable'))
  42. return;
  43. var sys_path = $this.attr('data-drupal-link-system-path');
  44. if(sys_path){
  45. // convert node link to edlp_ajax_node module links
  46. m = sys_path.match(/^\/?(node\/\d+)$/g);
  47. if(m) $this.attr('data-drupal-link-system-path', 'edlp/'+m[0]);
  48. }
  49. $this.on('click', onClickAjaxLink).addClass('ajax-enable');
  50. })
  51. ;
  52. };
  53. function onClickAjaxLink(e){
  54. e.preventDefault();
  55. var $link = $(this);
  56. if($link.is('.is-active'))
  57. return false;
  58. var sys_path = $(this).attr('data-drupal-link-system-path');
  59. if(sys_path == '<front>'){
  60. closeAllModals();
  61. return false;
  62. }
  63. var path = window.location.origin + drupalSettings.path.baseUrl + sys_path +'/ajax';
  64. closeAllModals();
  65. _$body.addClass('ajax-loading');
  66. $link.addClass('ajax-loading');
  67. $.getJSON(path, {}, function(data){
  68. onAjaxLinkLoaded(data, $link, sys_path);
  69. });
  70. return false;
  71. };
  72. function onAjaxLinkLoaded(data, $link, sys_path){
  73. console.log('ajax link loaded');
  74. _$content_container.html(data.rendered);
  75. _$body.removeClass('ajax-loading');
  76. // add body class for currently loaded content
  77. _$body.removeClass().addClass('path-'+sys_path.replace(/\//g, '-'));
  78. // id node add a generic path-node class to body
  79. m = sys_path.match(/^\/?(edlp\/node\/\d+)$/g);
  80. if(m){
  81. _$body.addClass('path-edlp-node');
  82. }
  83. _$ajaxLinks.removeClass('is-active');
  84. $link.removeClass('ajax-loading').addClass('is-active');
  85. initScrollbars();
  86. if(sys_path == "productions")
  87. initProductions();
  88. initAjaxLinks();
  89. };
  90. // ___
  91. // / __|___ _ _ _ __ _ _ ___
  92. // | (__/ _ \ '_| '_ \ || (_-<
  93. // \___\___/_| | .__/\_,_/__/
  94. // |_|
  95. function onCorpusMapReady(e){
  96. console.log('theme : onCorpusReady');
  97. _$corpus_map = $('canvas#corpus-map');
  98. _$corpus_map.on('corpus-cliked-on-map', function(e) {
  99. console.log('theme : corpus-cliked-on-map');
  100. closeAllModals();
  101. });
  102. }
  103. // ___ _ _ _
  104. // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___
  105. // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-<
  106. // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/
  107. function initProductions(){
  108. console.log('theme : initProductions');
  109. var $grid = $('.row', _$content_container).masonry({
  110. itemSelector:'.col',
  111. columnWidth:'.col-2'
  112. });
  113. // layout Masonry after each image loads
  114. $grid.imagesLoaded().progress( function() {
  115. $grid.masonry('layout');
  116. });
  117. // var $grid = $('.row', _$content_container).imagesLoaded( function() {
  118. // // init Masonry after all images have loaded
  119. // $grid.masonry({
  120. // itemSelector:'.col',
  121. // columnWidth:'.col-2'
  122. // });
  123. // });
  124. };
  125. // __ __ _ _
  126. // | \/ |___ __| |__ _| |___
  127. // | |\/| / _ \/ _` / _` | (_-<
  128. // |_| |_\___/\__,_\__,_|_/__/
  129. function closeAllModals(){
  130. console.log('theme : closeAllModals');
  131. // TODO: animate the remove
  132. _$content_container.html('');
  133. _$ajaxLinks.removeClass('is-active');
  134. $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
  135. };
  136. init();
  137. } // end EdlpTheme()
  138. $(document).ready(function($) {
  139. var edlptheme = new EdlpTheme();
  140. });
  141. })(jQuery);