(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()"); // TODO: redirect all no-front pages to front with write hash _$body.on('corpus-map-ready', onCorpusMapReady); initScrollbars(); initAjaxLinks(); if (_$body.is('.path-productions')) { initProductions(); } initAudioPlayer(); }; // _ _ _ // /_\ _ _ __| (_)___ // / _ \ || / _` | / _ \ // /_/ \_\_,_\__,_|_\___/ // // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/samples/gg589528%28v%3dvs.85%29 // https://www.binarytides.com/using-html5-audio-element-javascript/ // function initAudioPlayer(){ _audio_player = new AudioPlayer(); }; function AudioPlayer(){ var that = this; this.fid; this.audio = new Audio(); // audio events this.audio_events = ["loadedmetadata","progress","canplay","timeupdate","ended"]; // UI dom objects this.$container = $('
') .appendTo('header[role="banner"] .region-header'); this.$timeline = $('
').addClass('time-line').appendTo(this.$container); this.$loader = $('
').addClass('loader').appendTo(this.$timeline); this.$cursor = $('
').addClass('cursor').appendTo(this.$timeline); this.$duration = $('
').addClass('duration').appendTo(this.$container); this.$currentTime = $('
').addClass('current-time').appendTo(this.$container); if (typeof AudioPlayer.initialized == "undefined") { AudioPlayer.prototype.init = function(){ // init audio events var fn = ''; for (var i = 0; i < this.audio_events.length; i++) { fn = this.audio_events[i]; // capitalize first letter of event (only cosmetic :p ) fn = 'on'+fn.charAt(0).toUpperCase()+fn.slice(1); this.audio.addEventListener( this.audio_events[i], this[fn].bind(this), true); } }; AudioPlayer.prototype.loadSound = function(url){ console.log('AudioPlayer loadSound : url', url); this.audio.src = url; // this.play(); }; AudioPlayer.prototype.play = function(){ console.log('AudioPlayer play()'); this.audio.play(); }; AudioPlayer.prototype.onLoadedmetadata = function(){ var rem = parseInt(this.audio.duration, 10), mins = Math.floor(rem/60,10), secs = rem - mins*60; this.$duration.html(''+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+''); }; AudioPlayer.prototype.onProgress = function(){ // var myBuffered = this.audio.buffered; // var mySeekable = this.audio.seekable; if( this.audio.buffered.length ){ // var fromPercent = this.fromPercent; // var value = percentLoad - fromPercent; // if( value<0 ) value = 0; // this.$loadingBar.css({width: value + '%',marginLeft:fromPercent + '%'}); this.$loader.css({ 'width':parseInt(((this.audio.buffered.end(0) / this.audio.duration) * 100), 10)+'%' }); } }; AudioPlayer.prototype.onCanplay = function(){ this.play(); }; AudioPlayer.prototype.onTimeupdate = function(){ // console.log('Audio update()', this.audio.currentTime); this.$cursor.css({ 'left':(this.audio.currentTime/this.audio.duration * 50)+"px" }); var rem = parseInt(this.audio.currentTime, 10), mins = Math.floor(rem/60,10), secs = rem - mins*60; this.$currentTime.html(''+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+''); }; AudioPlayer.prototype.onEnded = function(){ console.log('AudioPlayer onEnded'); }; AudioPlayer.initialized = true; this.init(); } }; // ___ _ _ ___ // / __| __ _ _ ___| | | _ ) __ _ _ _ ___ // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-< // |___/\__|_| \___/_|_|___/\__,_|_| /__/ 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, article.node h2.node-title, .productions-subtree, .productions-parent').addClass('ajax-link'); _$ajaxLinks = $('.ajax-link:not(.ajax-enabled)') .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 == ''){ 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('ajaxlink load failed', 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(); }) .on('corpus-cliked-on-node', function(e) { console.log('theme : corpus-cliked-on-node', e); _audio_player.loadSound(e.target_node.audio_url); }); } // ___ _ _ _ // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___ // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-< // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/ 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=""]').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);