| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 | (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","canplay","playing","pause","timeupdate","ended"];      // UI dom objects      this.$container   = $('<div id="audio-player">');      // btns      this.$btns        = $('<div>').addClass('btns').appendTo(this.$container);      this.$previous    = $('<div>').addClass('previous').appendTo(this.$btns);      this.$playpause   = $('<div>').addClass('play-pause').appendTo(this.$btns);      this.$next        = $('<div>').addClass('next').appendTo(this.$btns);      // timeline      this.$timelinecont= $('<div>').addClass('time-line-container').appendTo(this.$container);      this.$timeline    = $('<div>').addClass('time-line').appendTo(this.$timelinecont);      this.$loader      = $('<div>').addClass('loader').appendTo(this.$timeline);      this.$cursor      = $('<div>').addClass('cursor').appendTo(this.$timeline);      // time      this.$time        = $('<div>').addClass('time').appendTo(this.$container);      this.$currentTime = $('<div>').addClass('current-time').html('00:00').appendTo(this.$time);      this.$duration    = $('<div>').addClass('duration').html('00:00').appendTo(this.$time);      // hiding      this.hideTimer = false;      this.hideTimeMS = 10000;      this.init();    };    AudioPlayer.prototype = {      init(){        // append ui to document        this.$container.appendTo('header[role="banner"] .region-header');        // record timeline width        this.timeline_w = parseInt(this.$timeline.width());        // 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);        }        // init btns events        this.$playpause.on('click', this.togglePlayPause.bind(this));        // TODO: previous and next btns      },      setSRC(url){        console.log('AudioPlayer setSRC : url', url);        this.clearTimeOutToHide();        this.audio.src = url;        this.show();      },      onLoadedmetadata(){        var rem = parseInt(this.audio.duration, 10),            mins = Math.floor(rem/60,10),            secs = rem - mins*60;        this.$duration.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');        this.updateLoadingBar();      },      updateLoadingBar(){        this.$loader.css({          'width':parseInt((100 * this.audio.buffered.end(0) / this.audio.duration), 10)+'%'        });        if( this.audio.buffered.end(0) < this.audio.duration ){          // loop through this function until file is fully loaded          var that = this;          window.requestAnimationFrame(that.updateLoadingBar.bind(that));        }else{          console.log('Audio fully loaded');        }      },      onCanplay(){        this.play();      },      play(){        this.audio.play();      },      togglePlayPause(){        if(this.audio.paused){          this.audio.play();        }else{          this.audio.pause();        }      },      onPlaying(){        this.$container.addClass('is-playing');      },      onPause(){        this.$container.removeClass('is-playing');      },      onTimeupdate(){        // move cursor        this.$cursor.css({          'left':(this.audio.currentTime/this.audio.duration * this.timeline_w)+"px"        });        // update time text display        var rem = parseInt(this.audio.currentTime, 10),            mins = Math.floor(rem/60,10),            secs = rem - mins*60;        this.$currentTime.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');      },      onEnded(){        this.$container.removeClass('is-playing');        this.timeOutToHide();      },      show(){        this.$container.addClass('visible');      },      timeOutToHide(){        this.clearTimeOutToHide();        this.hideTimer = setTimeout(this.hide.bind(this), this.hideTimeMS);      },      clearTimeOutToHide(){        if(this.hideTimer){          clearTimeout(this.hideTimer);        }      },      hide(){        this.$container.removeClass('visible');      }    }    //  ___             _ _ ___    // / __| __ _ _ ___| | | _ ) __ _ _ _ ___    // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-<    // |___/\__|_| \___/_|_|___/\__,_|_| /__/    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 == '<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('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.setSRC(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="<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);
 |