123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- (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();
- if (_$body.is('.path-productions')) {
- initProductions();
- }
- };
- // ___ _ _ ___
- // / __| __ _ _ ___| | | _ ) __ _ _ _ ___
- // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-<
- // |___/\__|_| \___/_|_|___/\__,_|_| /__/
- 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, #block-productions').addClass('ajax-link');
- _$ajaxLinks = $('.ajax-link')
- .each(function(i,e){
- var $this = $(this);
- // avoid already ajaxified links
- if($this.is('.ajax-enable')) return;
- 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]);
- }
- $this.on('click', onClickAjaxLink).addClass('ajax-enable');
- })
- ;
- };
- 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>'){
- backToFrontPage();
- return false;
- }
- var path = window.location.origin + drupalSettings.path.baseUrl + sys_path;
- _$body.addClass('ajax-loading');
- $link.addClass('ajax-loading');
- // $.getJSON(path, {}, function(data){
- // onAjaxLinkLoaded(data, $link, sys_path);
- // });
- $.getJSON(path+'/ajax', {})
- .done(function(data){
- onAjaxLinkLoaded(data, $link, sys_path);
- })
- .fail(function(jqxhr, textStatus, error){
- onAjaxLinkLoadError(jqxhr, textStatus, error, $link, sys_path);
- });
- return false;
- };
- function onAjaxLinkLoadError(jqxhr, textStatus, error, $link, sys_path){
- console.warn('fail : error', jqxhr.responseText);
- $link.removeClass('ajax-loading');
- _$body.removeClass('ajax-loading');
- };
- function onAjaxLinkLoaded(data, $link, sys_path){
- console.log('ajax link loaded : data', data);
- _$body.removeClass('ajax-loading');
- // replace all content with newly loaded
- _$content_container.html(data.rendered);
- // add body class for currently loaded content
- _$body.removeClass().addClass('path-'+sys_path.replace(/\//g, '-'));
- // id node add a generic path-node class to body
- m = sys_path.match(/^\/?(edlp\/node\/\d+)$/g);
- if(m)
- _$body.addClass('path-edlp-node');
- // handle clicked link classes
- _$ajaxLinks.removeClass('is-active');
- $link.removeClass('ajax-loading').addClass('is-active');
- // if block attached (eg : from edlp_productions module)
- if(typeof data.block != 'undefined'){
- // if block not already added
- if(!$('#'+data.block.id, '.region-'+data.block.region).length){
- $('.region-'+data.block.region).append(data.block.rendered);
- }
- }
- initScrollbars();
- if(sys_path == "productions")
- initProductions();
- initAjaxLinks();
- };
- // ___
- // / __|___ _ _ _ __ _ _ ___
- // | (__/ _ \ '_| '_ \ || (_-<
- // \___\___/_| | .__/\_,_/__/
- // |_|
- 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');
- backToFrontPage();
- });
- }
- // ___ _ _ _
- // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___
- // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-<
- // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/
- function initProductions(){
- console.log('theme : initProductions');
- var $grid = $('.row', _$content_container).masonry({
- itemSelector:'.col',
- columnWidth:'.col-2'
- });
- // layout Masonry after each image loads
- $grid.imagesLoaded().progress( function() {
- $grid.masonry('layout');
- });
- // var $grid = $('.row', _$content_container).imagesLoaded( function() {
- // // init Masonry after all images have loaded
- // $grid.masonry({
- // itemSelector:'.col',
- // columnWidth:'.col-2'
- // });
- // });
- };
- // ___ _ ___
- // | __| _ ___ _ _| |_| _ \__ _ __ _ ___
- // | _| '_/ _ \ ' \ _| _/ _` / _` / -_)
- // |_||_| \___/_||_\__|_| \__,_\__, \___|
- // |___/
- function backToFrontPage(){
- closeAllModals();
- // assume we are going back to front page
- $('body').removeClass().addClass('path-frontpage');
- $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
- }
- // __ __ _ _
- // | \/ |___ __| |__ _| |___
- // | |\/| / _ \/ _` / _` | (_-<
- // |_| |_\___/\__,_\__,_|_/__/
- function closeAllModals(){
- console.log('theme : closeAllModals');
- // TODO: animate the remove
- _$content_container.html('');
- _$ajaxLinks.removeClass('is-active');
- };
- init();
- } // end EdlpTheme()
- $(document).ready(function($) {
- var edlptheme = new EdlpTheme();
- });
- })(jQuery);
|