diff --git a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js index 3bb3dad96..cdd54d7fa 100644 --- a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js +++ b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js @@ -1,40 +1,1042 @@ +/** + * @Author: Bachir Soussi Chiadmi + * @Date: 18-12-2017 + * @Email: bachir@figureslibres.io + * @Filename: corpus.js + * @Last modified by: bach + * @Last modified time: 20-12-2017 + * @License: GPL-V3 + */ -(function($,Drupal,drupalSettings){EdlpCorpus=function(){var _activated=true;var _$body=$('body');var _$container=_$body;var _$canvas=$('').appendTo(_$container);var _canvas=_$canvas[0];var _ctx=_canvas.getContext('2d');var _canvas_props={'margin_top':100,'margin_right':0,'margin_bottom':100,'margin_left':0};var _physics=new Physics();var _nodes=[];var _articles_nodes=[];var _no_articles_nodes=[];var _nodes_by_entries={};var _nodes_by_nid={};var _nodes_Nid_Id={};var _nodes_centered=[];var _nodes_centered_attractions=[];var _playlist=[];var _p_velocity_factor=0.5;var _mouse_in=true;var _m_pos={x:0,y:0};var _node_hover_id=-1;var _node_opened_id=-1;var _$entrees_block=$('#block-edlpentreesblock');var _$entrees_block_termlinks=$('a.term-link',_$entrees_block);var _$articles_link;var _node_pop_up;var _settings=drupalSettings.edlp_corpus;var _ecolors=_settings.colors;var _attracter,_repulser_top,_repulser_center,_repulser_bottom,_scrambler_TL,_scrambler_TR,_scrambler_BR,_scrambler_BL,_scrambler_CL,_scrambler_CR;function init(){initCanvas();if(_activated){loadCorpus();}else{_$canvas.addClass('de-activated');}};function initCanvas(){window.addEventListener('resize',onResizeCanvas,false);onResizeCanvas();};function onResizeCanvas(){_canvas.width=window.innerWidth;_canvas.height=window.innerHeight;for(var i=0;i<_nodes.length;i++){_nodes[i].onResizeCanvas();resizePhysics();}};function loadCorpus(){var ajax_path=_settings.load_corpus_ajax_url;var path=window.location.origin+Drupal.url(ajax_path);$.getJSON(path,{}).done(function(data){onCorpusLoaded(data);}).fail(function(jqxhr,textStatus,error){onCorpusLoadError(jqxhr,textStatus,error);});};function onCorpusLoadError(jqxhr,textStatus,error){void 0;};function onCorpusLoaded(data){initPhysics();buildNodes(data.nodes);initArtilesLink();initNodePopup();initEvents();checkPreOpenedEntry();startAnime();};function initPhysics(){_attracter=_physics.makeParticle(1000);_attracter.fixed=true;_repulser_top=_physics.makeParticle(100);_repulser_top.fixed=true;_repulser_center=_physics.makeParticle(100);_repulser_center.fixed=true;_repulser_bottom=_physics.makeParticle(100);_repulser_bottom.fixed=true;_scrambler_TL=_physics.makeParticle(100);_scrambler_TL.fixed=true;_scrambler_TR=_physics.makeParticle(100);_scrambler_TR.fixed=true;_scrambler_BR=_physics.makeParticle(100);_scrambler_BR.fixed=true;_scrambler_BL=_physics.makeParticle(100);_scrambler_BL.fixed=true;_scrambler_CR=_physics.makeParticle(100);_scrambler_CR.fixed=true;_scrambler_CL=_physics.makeParticle(100);_scrambler_CL.fixed=true;resizePhysics();};function resizePhysics(){_attracter.position={x:_canvas.width/2,y:_canvas.height/2};_repulser_top.position={x:_canvas.width/2,y:0};_repulser_center.position={x:_canvas.width/2,y:_canvas.height/2};_repulser_bottom.position={x:_canvas.width/2,y:_canvas.height};_scrambler_TL.position={x:-200,y:_canvas.height/40};_scrambler_BL.position={x:-200,y:_canvas.height-_canvas.height/40};_scrambler_TR.position={x:_canvas.width+200,y:_canvas.height/40};_scrambler_BR.position={x:_canvas.width+200,y:_canvas.height-_canvas.height/40};};function buildNodes(nodes){var d;for(var i in nodes){d=i<1?true:false;new Node(i,nodes[i],d);_playlist.push({'id':i,'nid':nodes[i].nid,'audio_url':nodes[i].audio_url});}};function Node(i,node,d){this.id=i;for(key in node) -this[key]=node[key];_nodes.push(this);_nodes_by_nid[this.nid]=this;_nodes_Nid_Id[this.nid]=this.id;if(this.has_article==1){_articles_nodes.push(this);}else{_no_articles_nodes.push(this);} -for(var j=0;j3:this.r=10;break;case this.entrees.length>1&&this.entrees.length<=3:this.r=7;break;default:this.r=4;break;} -this.e_color='e_col_'+this.entrees[Math.floor(Math.random(this.entrees.length))];this.hover=false;this.opened=false;this.faded=false;this.center=false;this.aside=false;this.scrambling=false;this.n_repulses={};if(typeof Node.initialized=="undefined"){Node.prototype.init=function(){this.calcWallLimits();this.x=this.wall_limits.left+Math.random()*(this.wall_limits.right-this.wall_limits.left);this.y=this.wall_limits.top+Math.random()*(this.wall_limits.bottom-this.wall_limits.top);this.initPhysics();};Node.prototype.initPhysics=function(){this.p=_physics.makeParticle(this.mass,this.x,this.y);this.p.velocity=new Physics.Vector((Math.random()-0.5)*_p_velocity_factor,(Math.random()-0.5)*_p_velocity_factor);this.attract=_physics.makeAttraction(_attracter,this.p,1000,_canvas.width*2);this.attract.on=false;this.repulse_top=_physics.makeAttraction(_repulser_top,this.p,-60,_canvas.height/6);this.repulse_center=_physics.makeAttraction(_repulser_center,this.p,-50,_canvas.height/6);this.repulse_bottom=_physics.makeAttraction(_repulser_bottom,this.p,-60,_canvas.height/6);this.repulse_top.on=false;this.repulse_center.on=false;this.repulse_bottom.on=false;this.scramble_TL=_physics.makeAttraction(_scrambler_TL,this.p,-100,_canvas.height/2.5);this.scramble_TR=_physics.makeAttraction(_scrambler_TR,this.p,-100,_canvas.height/2.5);this.scramble_BR=_physics.makeAttraction(_scrambler_BR,this.p,-100,_canvas.height/2.5);this.scramble_BL=_physics.makeAttraction(_scrambler_BL,this.p,-100,_canvas.height/2.5);this.scramble_TL.on=false;this.scramble_TR.on=false;this.scramble_BR.on=false;this.scramble_BL.on=false;};Node.prototype.calcWallLimits=function(){this.wall_limits={top:_canvas_props.margin_top+this.r,right:_canvas.width-_canvas_props.margin_right-this.r,bottom:_canvas.height-_canvas_props.margin_bottom-this.r,left:_canvas_props.margin_left+this.r}};Node.prototype.onResizeCanvas=function(){this.calcWallLimits();};Node.prototype.onUpdate=function(){if(this.hover||this.opened){this.p.fixed=true;}else{this.p.fixed=false;} -if(this.center) -this.limitEvolutionZone();if(!this.p.resting()){this.checkWallBouncing();this.updatePos();} -if(_mouse_in&&!this.aside) -this.checkMouse();this.draw();};Node.prototype.checkVelocityThreshold=function(){if(!this.centered||!this.aside){if(Math.abs(this.p.velocity.x)this.wall_limits.right&&this.p.velocity.x>0:this.p.position.x=this.wall_limits.right;this.p.velocity.multiplyScalarXY(-1,1).multiplyScalar(0.75);break;case this.ythis.wall_limits.bottom&&this.p.velocity.y>0:this.p.position.y=this.wall_limits.bottom;this.p.velocity.multiplyScalarXY(1,-1).multiplyScalar(0.75);break;}};Node.prototype.updatePos=function(){this.x=this.p.position.x;this.y=this.p.position.y;};Node.prototype.checkMouse=function(){if(_m_pos.x>this.x-this.r&&_m_pos.xthis.y-this.r&&_m_pos.y0.4){this.p.velocity.multiplyScalar(0.995);}} -if(Math.abs(_attracter.position.x-this.x)>_canvas.width/3||Math.abs(_attracter.position.y-this.y)>_canvas.height/3){this.attract.on=true;}else{this.attract.on=false;}} -Node.prototype.setAside=function(){this.aside=true;this.stopScrambling();this.unsetCentered();this.repulse_top.on=true;this.repulse_center.on=true;this.repulse_bottom.on=true;} -Node.prototype.unsetAside=function(){this.aside=false;this.repulse_top.on=false;this.repulse_center.on=false;this.repulse_bottom.on=false;} -Node.prototype.scramble=function(){this.scrambling=true;this.unsetCentered();this.unsetAside();this.scramble_TL.on=true;this.scramble_TR.on=true;this.scramble_BR.on=true;this.scramble_BL.on=true;} -Node.prototype.stopScrambling=function(){this.scrambling=false;this.scramble_TL.on=false;this.scramble_TR.on=false;this.scramble_BR.on=false;this.scramble_BL.on=false;} -Node.prototype.draw=function(){_ctx.beginPath();_ctx.globalAlpha=this.faded?0.1:1;_ctx.fillStyle=_ecolors[this.e_color];_ctx.fillRect(this.x-this.r,this.y-this.r,this.r*2,this.r*2);if(this.opened){_ctx.lineWidth='1px';_ctx.strokeStyle='rgb(255,0,0)';_ctx.strokeRect(this.x-this.r-3,this.y-this.r-3,this.r*2+6,this.r*2+6);} -_ctx.globalAlpha=1;_ctx.closePath();};Node.initialized=true;} -this.init();};function checkParticulesCollisions(){var na,nb,ma,mb,w,h,dx,dy,makeup,newVelX1,newVelY1,newVelX2,newVelY2;for(var n=0,l=_nodes.length;n300){if(Math.random()>0.3)continue;}} -w=h=(na.r+nb.r);dx=na.p.position.x-nb.p.position.x;dy=na.p.position.y-nb.p.position.y;if(Math.abs(dx)>w||Math.abs(dy)>h)continue;if(Math.abs(dx)0){na.p.position.y+=makeup;nb.p.position.y-=makeup;}else{na.p.position.y-=makeup;nb.p.position.y+=makeup;} -newVelY1=(ma-mb)/(ma+mb)*na.p.velocity.y+2*mb/(ma+mb)*nb.p.velocity.y;newVelY2=(mb-ma)/(mb+ma)*nb.p.velocity.y+2*ma/(mb+ma)*na.p.velocity.y;na.p.velocity.y=newVelY1;nb.p.velocity.y=newVelY2;}else{makeup=(w-Math.abs(dx))/2;if(dx>0){na.p.position.x+=makeup;nb.p.position.x-=makeup;}else{na.p.position.x-=makeup;nb.p.position.x+=makeup;} -newVelX1=(ma-mb)/(ma+mb)*na.p.velocity.x+2*mb/(ma+mb)*nb.p.velocity.x;newVelX2=(mb-ma)/(mb+ma)*nb.p.velocity.x+2*ma/(mb+ma)*na.p.velocity.x;na.p.velocity.x=newVelX1;nb.p.velocity.x=newVelX2;} -na.p.velocity.multiplyScalar(0.90);nb.p.velocity.multiplyScalar(0.90);}}};function openNodeByNid(nid){closeNode();if(typeof _nodes_Nid_Id[nid]!='undefined'){_node_opened_id=_nodes_Nid_Id[nid];_nodes[_nodes_Nid_Id[nid]].open();}} -function closeNode(){if(_node_opened_id!=-1){_nodes[_node_opened_id].close();_node_opened_id=-1;}} -function createNodesRepulsions(){purgeNodesRepulsions();for(var n=0;n<_nodes_centered.length;n++){for(var q=n+1;q<_nodes_centered.length;q++){_physics.makeAttraction(_nodes_centered[n].p,_nodes_centered[q].p,-0.4,10);}}};function purgeNodesRepulsions(){for(var a=_physics.attractions.length-1;a>=0;a--){if(Math.abs(_physics.attractions[a].constant)<1){_physics.attractions.splice(a,1);}else{break;}}};function openEntree(tid,bubbling){var $link=_$entrees_block_termlinks.filter('[tid="'+tid+'"]');var $li=$link.parents('li');var sys_path=$link.attr('data-drupal-link-system-path');var url=$link.attr('href');if(!$li.is('.opened')){_$entrees_block_termlinks.parents('li').removeClass('opened');$li.addClass('opened');filterEntree(tid);if(bubbling){_$body.trigger({'type':'open_entree','tid':tid,'url':url,'sys_path':sys_path});}}else if(bubbling){$li.removeClass('opened');scrambleCollection();_$body.trigger({'type':'close_entree','tid':tid});}};function filterEntree(t){shutDownArticles();_nodes_centered=[];for(var n=0;n<_nodes.length;n++){if(_nodes[n].entrees.indexOf(t)==-1){_nodes[n].setAside();}else{_nodes[n].setCenteredOnEntree(t);_nodes_centered.push(_nodes[n]);}} -createNodesRepulsions();};function highlightEntries(){_$entrees_block_termlinks.removeClass('highlighted');var id=-1;if(_node_hover_id!=-1){id=_node_hover_id;}else if(_node_opened_id!=-1){id=_node_opened_id;} -var entree;if(id!=-1){for(var i=0;i<_nodes[id].entrees.length;i++){entree=_nodes[id].entrees[i];_$entrees_block_termlinks.filter(function(){return $(this).attr('tid')==entree;}).addClass('highlighted');}}};function filterSearchResults(nids){shutDownArticles();_nodes_centered=[];for(var n=0;n<_nodes.length;n++){if(nids.indexOf(_nodes[n].nid)==-1){_nodes[n].setAside();}else{_nodes[n].setCentered();_nodes_centered.push(_nodes[n]);}} -createNodesRepulsions();};function scrambleCollection(){for(var i=0;i<_nodes.length;i++){_nodes[i].scramble();} -stopScrambling();};function stopScrambling(){for(var i=0;i<_nodes.length;i++){setTimeout(function(n){n.stopScrambling();}.bind(this,_nodes[i]),1000+Math.random()*4000);}};function closeAllEntries(){_$entrees_block_termlinks.each(function(index,el){if($(this).parents('li').is('.opened')){$(this).trigger('click');return false;}});};function initArtilesLink(){_$articles_link=$('').html('Articles').attr("href","#articles").addClass('articles-link').on('click',onCLickedOnArticles);$('.item-list ul',_$entrees_block).append($('
  • ').append($('').append(_$articles_link)));};function onCLickedOnArticles(e){e.preventDefault();$(this).toggleClass('is-active');if($(this).is('.is-active')){filterArticles();closeAllEntries();}else{resetArticlesFilter();} -return false;};function filterArticles(){for(var i=0;i<_no_articles_nodes.length;i++){_no_articles_nodes[i].fade();}};function resetArticlesFilter(){for(var i=0;i<_no_articles_nodes.length;i++){_no_articles_nodes[i].unFade();}};function shutDownArticles(){if(_$articles_link.is('.is-active')) -_$articles_link.trigger('click');};function initEvents(){void 0;_$canvas.on('mousemove',function(event){event.preventDefault();_m_pos.x=event.originalEvent.clientX;_m_pos.y=event.originalEvent.clientY;}).on('mouseenter',function(event){_mouse_in=true;}).on('mouseout',function(event){_mouse_in=false;_node_pop_up.removeNode();}).on('click',function(event){if(event.target.tagName!="A"&&event.target.tagName!="INPUT"){event.preventDefault();if(_node_hover_id!=-1){var event={'type':'corpus-cliked-on-node','target_node':{'id':_node_hover_id,'nid':_nodes[_node_hover_id].nid,'audio_url':_nodes[_node_hover_id].audio_url},};_$canvas.trigger(event);}else{_$canvas.trigger('corpus-cliked-on-map');}}}).on('audio-node-opened',function(e){openNodeByNid(e.nid);}).on('audio-node-closed',function(e){closeNode();}).on('open-entree',function(e){openEntree(e.tid);}).on('close-all-entree',function(e){closeAllEntries();});_$entrees_block_termlinks.on('click',function(event){void 0;event.preventDefault();openEntree($(this).attr('tid'),true);return false;});_$body.on('chutier-action-done',function(e){_nodes_by_nid[e.target_id].chutier_action=e.new_action;}).on('search-results-loaded',function(e){filterSearchResults(e.results);}).on('search-closed',function(e){scrambleCollection();}).on('new-content-not-entree-ajax-loaded',function(e){if(_$entrees_block_termlinks.parents('li.opened').length){_$entrees_block_termlinks.parents('li').removeClass('opened');scrambleCollection();}});};function checkPreOpenedEntry(){_$entrees_block.find('li.entree').each(function(index,el){var $li=$(this);if($('a.is-active',$li).length){$li.addClass('opened');filterEntree($li.attr('tid'));return false;}});};function initNodePopup(){_node_pop_up=new NodePopUp();};function NodePopUp(){this.visible=false;this.node;this.$dom=$('
    ').addClass('node-popup').attr('pos','top-right').appendTo('body');this.$content=$('
    ').addClass('inner').appendTo(this.$dom);if(typeof NodePopUp.initialized=="undefined"){NodePopUp.prototype.setNode=function(n){this.node=n;this.setPositioning();this.setContent();};NodePopUp.prototype.setPositioning=function(){switch(true){case this.node.x>this.node.wall_limits.right-350&&this.node.ythis.node.wall_limits.right-350:this.$dom.attr('pos','top-left');break;case this.node.y').addClass('entrees');for(var i=0;i').addClass('entree').attr('tid',tid));} -var $chutier_action=$('').addClass('chutier-icon').attr('action',this.node.chutier_action);this.$content.append($entrees).append('

    '+this.node.title+'

    ').append('
    '+this.node.description+'
    ').append($chutier_action);};NodePopUp.prototype.removeNode=function(){this.node=false;};NodePopUp.prototype.draw=function(){if(this.node){this.$dom.css({'display':"block",'left':this.node.x+"px",'top':this.node.y+"px",});}else{this.$dom.css({'display':"none",});}};NodePopUp.initialized=true;}} -function render(){_ctx.clearRect(0,0,_canvas.width,_canvas.height);checkParticulesCollisions();for(var i=0;i<_nodes.length;i++){_nodes[i].onUpdate();} -_node_pop_up.draw();if(_node_hover_id!=-1){_canvas.style.cursor='pointer';}else{_canvas.style.cursor='auto';} -highlightEntries();};function startAnime(){_physics.onUpdate(render);_physics.play() -$('body').attr('corpus','map-ready').trigger({'type':'corpus-map-ready','playlist':_playlist});};init();} -$(document).ready(function($){var edlpcorpus=new EdlpCorpus();});})(jQuery,Drupal,drupalSettings); \ No newline at end of file +// JS performance improvement http://archive.oreilly.com/pub/a/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html + +/** + * depends on : + * physics.js : http://jonobr1.com/Physics/# + */ + +(function($, Drupal, drupalSettings) { + + EdlpCorpus = function(){ + var _activated = true; + var _$body = $('body'); + var _$container = _$body; + var _$canvas = $('').appendTo(_$container); + var _canvas = _$canvas[0]; + var _ctx = _canvas.getContext('2d'); + var _canvas_props = { + 'margin_top':100, + 'margin_right':0, + 'margin_bottom':100, + 'margin_left':0 + }; + var _physics = new Physics(); + var _nodes = []; + var _articles_nodes = []; + var _no_articles_nodes = []; + var _nodes_by_entries = {}; + var _nodes_by_nid = {}; + var _nodes_Nid_Id = {}; + var _nodes_centered = []; + var _nodes_centered_attractions = []; + + var _playlist = []; + + var _p_velocity_factor = 0.5; + var _mouse_in = true; + var _m_pos = {x:0, y:0}; + var _node_hover_id = -1; + var _node_opened_id = -1; + var _$entrees_block = $('#block-edlpentreesblock'); + var _$entrees_block_termlinks = $('a.term-link', _$entrees_block); + var _$articles_link; + var _node_pop_up; + // Colors depend on drupalSettings loaded by edlp_corpus.module + var _settings = drupalSettings.edlp_corpus; + var _ecolors = _settings.colors; + // Physics + var _attracter, + _repulser_top, + _repulser_center, + _repulser_bottom, + _scrambler_TL, + _scrambler_TR, + _scrambler_BR, + _scrambler_BL, + _scrambler_CL, + _scrambler_CR; + + // ____ _ __ + // / _/___ (_) /______ + // / // __ \/ / __/ ___/ + // _/ // / / / / /_(__ ) + // /___/_/ /_/_/\__/____/ + function init(){ + initCanvas(); + if(_activated){ + loadCorpus(); + }else{ + _$canvas.addClass('de-activated'); + } + }; + + // ___ + // / __|__ _ _ ___ ____ _ ___ + // | (__/ _` | ' \ V / _` (_-< + // \___\__,_|_||_\_/\__,_/__/ + function initCanvas(){ + // resize the canvas to fill browser window dynamically + window.addEventListener('resize', onResizeCanvas, false); + onResizeCanvas(); + }; + function onResizeCanvas() { + _canvas.width = window.innerWidth; + _canvas.height = window.innerHeight; + for (var i = 0; i < _nodes.length; i++) { + _nodes[i].onResizeCanvas(); + // move _attracter and _repulser to the center again + resizePhysics(); + } + }; + + // ___ + // / __|___ _ _ _ __ _ _ ___ + // | (__/ _ \ '_| '_ \ || (_-< + // \___\___/_| | .__/\_,_/__/ + // |_| + function loadCorpus(){ + // console.log('drupalSettings',drupalSettings); + // console.log('window.location', window.location); + // var path = window.location.origin + drupalSettings.basepath + "edlp/corpus"; + var ajax_path = _settings.load_corpus_ajax_url; + var path = window.location.origin + Drupal.url(ajax_path); + $.getJSON(path, {}) + .done(function(data){ + onCorpusLoaded(data); + }) + .fail(function(jqxhr, textStatus, error){ + onCorpusLoadError(jqxhr, textStatus, error); + }); + }; + function onCorpusLoadError(jqxhr, textStatus, error){ + console.warn('corpus load failed', jqxhr.responseText); + }; + function onCorpusLoaded(data){ + //console.log('corpus loaded : data', data); + // console.log('first node', data.nodes[0]); + // buildParticles(data.nodes); + initPhysics(); + buildNodes(data.nodes); + initArtilesLink(); + initNodePopup(); + initEvents(); + checkPreOpenedEntry(); + startAnime(); + }; + + // ___ _ _ + // | _ \ |_ _ _ __(_)__ ___ + // | _/ ' \ || (_-< / _(_-< + // |_| |_||_\_, /__/_\__/__/ + // |__/ + function initPhysics(){ + _attracter = _physics.makeParticle(1000); + _attracter.fixed = true; + _repulser_top = _physics.makeParticle(100); + _repulser_top.fixed = true; + _repulser_center = _physics.makeParticle(100); + _repulser_center.fixed = true; + _repulser_bottom = _physics.makeParticle(100); + _repulser_bottom.fixed = true; + _scrambler_TL = _physics.makeParticle(100); + _scrambler_TL.fixed = true; + _scrambler_TR = _physics.makeParticle(100); + _scrambler_TR.fixed = true; + _scrambler_BR = _physics.makeParticle(100); + _scrambler_BR.fixed = true; + _scrambler_BL = _physics.makeParticle(100); + _scrambler_BL.fixed = true; + _scrambler_CR = _physics.makeParticle(100); + _scrambler_CR.fixed = true; + _scrambler_CL = _physics.makeParticle(100); + _scrambler_CL.fixed = true; + // move _attracter and _repulser on window resize + resizePhysics(); + }; + function resizePhysics(){ + // attracters + _attracter.position = {x:_canvas.width/2, y:_canvas.height/2}; + // repulsers + _repulser_top.position = {x:_canvas.width/2, y:0}; + _repulser_center.position = {x:_canvas.width/2, y:_canvas.height/2}; + _repulser_bottom.position = {x:_canvas.width/2, y:_canvas.height}; + // scramblers + _scrambler_TL.position = {x:-200, y:_canvas.height/40}; + _scrambler_BL.position = {x:-200, y:_canvas.height-_canvas.height/40}; + // _scrambler_CL.position = {x:-200, y:_canvas.height/2}; + _scrambler_TR.position = {x:_canvas.width+200, y:_canvas.height/40}; + _scrambler_BR.position = {x:_canvas.width+200, y:_canvas.height-_canvas.height/40}; + // _scrambler_CR.position = {x:_canvas.width+200, y:_canvas.height/2}; + }; + + // _ _ _ + // | \| |___ __| |___ ___ + // | .` / _ \/ _` / -_|_-< + // |_|\_\___/\__,_\___/__/ + function buildNodes(nodes){ + //console.log("buildNodes", nodes); + var d; + for (var i in nodes) { + d = i < 1 ? true : false; + // _nodes.push(new Node(i,nodes[i],d)); + new Node(i,nodes[i],d); + + _playlist.push({ + 'id':i, + 'nid':nodes[i].nid, + 'audio_url':nodes[i].audio_url + }); + } + //console.log('_nodes',_nodes); + //console.log('_articles_nodes',_articles_nodes); + //console.log('_no_articles_nodes',_no_articles_nodes); + //console.log('_nodes_by_entries', _nodes_by_entries); + + //console.log('_physics.attractions.length', _physics.attractions.length); + }; + + function Node(i,node,d){ + this.id = i; + for(key in node) + this[key] = node[key]; + + // record the node in different lists + _nodes.push(this); + + _nodes_by_nid[this.nid] = this; + _nodes_Nid_Id[this.nid] = this.id; + + if(this.has_article == 1){ + _articles_nodes.push(this); + }else{ + _no_articles_nodes.push(this); + } + + for (var j = 0; j < this.entrees.length; j++) { + if(typeof _nodes_by_entries[this.entrees[j]] == 'undefined') + _nodes_by_entries[this.entrees[j]] = []; + + _nodes_by_entries[this.entrees[j]].push(this); + } + + this.debug = d; + this.mass = Math.max(1, this.entrees.length); //1; + this.velocity_threshold = 0.01; + // define radius regarding entries length + switch(true){ + case this.entrees.length > 3: + this.r = 10; + break; + case this.entrees.length > 1 && this.entrees.length <= 3: + this.r = 7; + break; + default: + this.r = 4; + break; + } + + this.e_color = 'e_col_'+this.entrees[Math.floor(Math.random(this.entrees.length))]; + + this.hover = false; + this.opened = false; + this.faded = false; + this.center = false; + this.aside = false; + this.scrambling = false; + + this.n_repulses = {}; + + // prototypes + if (typeof Node.initialized == "undefined") { + + Node.prototype.init = function(){ + this.calcWallLimits(); + + this.x = this.wall_limits.left + Math.random()*(this.wall_limits.right - this.wall_limits.left); + this.y = this.wall_limits.top + Math.random()*(this.wall_limits.bottom - this.wall_limits.top); + + this.initPhysics(); + + // if(this.id == '620'){ + // _node_pop_up.setNode(this); + // } + }; + + Node.prototype.initPhysics = function(){ + // particule + this.p = _physics.makeParticle(this.mass, this.x, this.y); + this.p.velocity = new Physics.Vector((Math.random()-0.5)*_p_velocity_factor, (Math.random()-0.5)*_p_velocity_factor); + // attracter + this.attract = _physics.makeAttraction(_attracter, this.p, 1000, _canvas.width*2); + this.attract.on = false; + // repulsers + this.repulse_top = _physics.makeAttraction(_repulser_top, this.p, -60, _canvas.height/6); + this.repulse_center = _physics.makeAttraction(_repulser_center, this.p, -50, _canvas.height/6); + this.repulse_bottom = _physics.makeAttraction(_repulser_bottom, this.p, -60, _canvas.height/6); + this.repulse_top.on = false; + this.repulse_center.on = false; + this.repulse_bottom.on = false; + // Scramblers + this.scramble_TL = _physics.makeAttraction(_scrambler_TL, this.p, -100, _canvas.height/2.5); + this.scramble_TR = _physics.makeAttraction(_scrambler_TR, this.p, -100, _canvas.height/2.5); + this.scramble_BR = _physics.makeAttraction(_scrambler_BR, this.p, -100, _canvas.height/2.5); + this.scramble_BL = _physics.makeAttraction(_scrambler_BL, this.p, -100, _canvas.height/2.5); + // this.scramble_CR = _physics.makeAttraction(_scrambler_CR, this.p, -50, _canvas.height/4); + // this.scramble_CL = _physics.makeAttraction(_scrambler_CL, this.p, -50, _canvas.height/4); + this.scramble_TL.on = false; + this.scramble_TR.on = false; + this.scramble_BR.on = false; + this.scramble_BL.on = false; + // this.scramble_CR.on = false; + // this.scramble_CL.on = false; + }; + + Node.prototype.calcWallLimits = function(){ + this.wall_limits = { + top: _canvas_props.margin_top +this.r, + right: _canvas.width -_canvas_props.margin_right -this.r, + bottom: _canvas.height -_canvas_props.margin_bottom -this.r, + left: _canvas_props.margin_left +this.r + } + }; + + Node.prototype.onResizeCanvas = function(){ + this.calcWallLimits(); + // TODO: when canvas is smaller what about nodes hors champs, they are coming back alone but it's too long + }; + + Node.prototype.onUpdate = function(){ + + // this.p.velocity.multiplyScalar(0.99); + if(this.hover || this.opened){ + this.p.fixed = true; + }else{ + this.p.fixed = false; + } + + if(this.center) + this.limitEvolutionZone(); + + if(!this.p.resting()){ + // this.checkVelocityThreshold(); + this.checkWallBouncing(); + this.updatePos(); + } + if(_mouse_in && !this.aside) + this.checkMouse(); + + // if(this.debug) + // console.log("Node pos: ", {x:this.x, y:this.y}); + this.draw(); + }; + + Node.prototype.checkVelocityThreshold = function(){ + if(!this.centered || !this.aside){ + if (Math.abs(this.p.velocity.x) < this.velocity_threshold + && Math.abs(this.p.velocity.y) < this.velocity_threshold){ + this.p.velocity.multiplyScalar(0); + // this.p.makeFixed(); + } + } + }; + + Node.prototype.checkWallBouncing = function(){ + switch(true){ + case this.x < this.wall_limits.left && this.p.velocity.x < 0: + this.p.position.x = this.wall_limits.left; + this.p.velocity.multiplyScalarXY(-1, 1).multiplyScalar(0.75); + break; + case this.x > this.wall_limits.right && this.p.velocity.x > 0: + this.p.position.x = this.wall_limits.right; + this.p.velocity.multiplyScalarXY(-1, 1).multiplyScalar(0.75); + break; + case this.y < this.wall_limits.top && this.p.velocity.y < 0 : + this.p.position.y = this.wall_limits.top; + this.p.velocity.multiplyScalarXY(1,-1).multiplyScalar(0.75); + break; + case this.y > this.wall_limits.bottom && this.p.velocity.y > 0 : + this.p.position.y = this.wall_limits.bottom; + this.p.velocity.multiplyScalarXY(1,-1).multiplyScalar(0.75); + break; + } + }; + + Node.prototype.updatePos = function(){ + this.x = this.p.position.x; + this.y = this.p.position.y; + }; + + Node.prototype.checkMouse = function(){ + + if( _m_pos.x > this.x - this.r + && _m_pos.x < this.x + this.r + && _m_pos.y > this.y - this.r + && _m_pos.y < this.y + this.r){ + if(_node_hover_id == -1 || _node_hover_id !== this.id){ + // console.log("Node hover", this.id); + this.hover = true; + _node_hover_id = this.id; + _node_pop_up.setNode(this); + } + }else{ + this.hover = false; + if (_node_hover_id == this.id) { + _node_hover_id = -1; + _node_pop_up.removeNode(); + } + } + }; + + Node.prototype.open = function(){ + this.opened = true; + _node_opened_id = this.id; + }; + Node.prototype.close = function(){ + this.opened = false; + }; + + Node.prototype.fade = function(){ + this.faded = true; + }; + Node.prototype.unFade = function(){ + this.faded = false; + }; + + Node.prototype.setCenteredOnEntree = function(tid){ + this.e_color = 'e_col_'+tid; + this.setCentered(); + }; + + Node.prototype.setCentered = function(){ + this.center = true; + this.stopScrambling(); + this.unsetAside(); + this.attract.on = true; + } + Node.prototype.unsetCentered = function(){ + this.center = false; + this.attract.on = false; + } + + Node.prototype.limitEvolutionZone = function(){ + // smouthly slow down node near center + // if(this.id == 1) + // console.log('this.p.velocity', this.p.velocity); + this.dist_to_attracter = this.p.distanceTo(_attracter); + if( this.dist_to_attracter < _canvas.width/4){ + if( this.p.velocity.length() > 0.4 ){ + this.p.velocity.multiplyScalar(0.995); + } + } + if( Math.abs(_attracter.position.x - this.x) > _canvas.width/3 + || Math.abs(_attracter.position.y - this.y) > _canvas.height/3){ + this.attract.on = true; + }else{ + this.attract.on = false; + } + } + + Node.prototype.setAside = function(){ + this.aside = true; + // this.fade(); + this.stopScrambling(); + this.unsetCentered(); + this.repulse_top.on = true; + this.repulse_center.on = true; + this.repulse_bottom.on = true; + } + Node.prototype.unsetAside = function(){ + this.aside = false; + // this.unFade(); + this.repulse_top.on = false; + this.repulse_center.on = false; + this.repulse_bottom.on = false; + } + + Node.prototype.scramble = function(){ + this.scrambling = true; + this.unsetCentered(); + this.unsetAside(); + this.scramble_TL.on = true; + this.scramble_TR.on = true; + this.scramble_BR.on = true; + this.scramble_BL.on = true; + // this.scramble_CR.on = true; + // this.scramble_CL.on = true; + } + Node.prototype.stopScrambling = function(){ + this.scrambling = false; + this.scramble_TL.on = false; + this.scramble_TR.on = false; + this.scramble_BR.on = false; + this.scramble_BL.on = false; + // this.scramble_CR.on = false; + // this.scramble_CL.on = false; + } + + Node.prototype.draw = function(){ + // carre plein + // clouleur aléatoire ds les entrees + // 3 tailles : + // - 1 entree : petit carre 5px + // - 2-3 entrees : moyen 7.5px + // - >3 entrees : grand 10px + // actif entouré de rouge + + _ctx.beginPath(); + _ctx.globalAlpha = this.faded ? 0.1 : 1; + // _ctx.fillStyle = !this.p.resting() ? _ecolors[this.e_color] : 'rgb(0, 0, 0)'; + _ctx.fillStyle = _ecolors[this.e_color]; + _ctx.fillRect(this.x - this.r,this.y - this.r,this.r*2,this.r*2); + + if(this.opened){ + _ctx.lineWidth = '1px'; + _ctx.strokeStyle = 'rgb(255,0,0)'; + _ctx.strokeRect(this.x - this.r-3,this.y - this.r-3,this.r*2+6,this.r*2+6); + } + _ctx.globalAlpha = 1; + _ctx.closePath(); + }; + + Node.initialized = true; + } + + this.init(); + }; + // TODO: we may convert a lot of computation into a web worker + // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers + function checkParticulesCollisions(){ + // pre create vars to save memory; + var na,nb, + ma,mb, + w,h,dx,dy, + makeup, + newVelX1, newVelY1, newVelX2, newVelY2; + // , angle; + // colisions between _particules + for (var n = 0, l = _nodes.length; n < l; n++) { + na = _nodes[n]; + ma = na.p.mass; + // avoid colliding for centered nodes + // if(_nodes[n].center) continue; + + // avoid colliding for scrambling nodes + if(na.scrambling) continue; + + for (var q = n+1; q < l; q++) { + nb = _nodes[q]; + mb = nb.p.mass; + // avoid impact between center and aside particules + if((na.center && nb.aside) || (na.aside && nb.center)) + continue; + + // avoid impact between two centered particulses that comes to the center + if(na.center && nb.center){ + if(Math.min(na.p.distanceTo(_attracter), nb.p.distanceTo(_attracter)) > 300){ + if( Math.random()>0.3 ) continue; + } + } + + w = h = (na.r+nb.r); + dx = na.p.position.x - nb.p.position.x; + dy = na.p.position.y - nb.p.position.y; + + // if both dx and dy are inferior to w & h so squares are colliding (overlapping) + // if( Math.abs(dx) <= w && Math.abs(dy) <= h){ console.log('colliding'); } + // else not so skip + if( Math.abs(dx) > w || Math.abs(dy) > h) continue; + + if(Math.abs(dx) < Math.abs(dy)){ // vertical collision + makeup = (h - Math.abs(dy))/2; + if(dy > 0){ // a is upper than b + na.p.position.y += makeup; + nb.p.position.y -= makeup; + }else{ // b is upper than a + na.p.position.y -= makeup; + nb.p.position.y += makeup; + } + // bounce + // https://en.wikipedia.org/wiki/Elastic_collision#One-dimensional_Newtonian + newVelY1 = (ma-mb)/(ma+mb)*na.p.velocity.y+2*mb/(ma+mb)*nb.p.velocity.y; + newVelY2 = (mb-ma)/(mb+ma)*nb.p.velocity.y+2*ma/(mb+ma)*na.p.velocity.y; + + na.p.velocity.y = newVelY1; + nb.p.velocity.y = newVelY2; + + }else{ // horizontal collision + makeup = (w - Math.abs(dx))/2; + if(dx > 0){ // a is at left of b + na.p.position.x += makeup; + nb.p.position.x -= makeup; + }else{ // b is at left of a + na.p.position.x -= makeup; + nb.p.position.x += makeup; + } + // bounce + // https://en.wikipedia.org/wiki/Elastic_collision#One-dimensional_Newtonian + newVelX1 = (ma-mb)/(ma+mb)*na.p.velocity.x+2*mb/(ma+mb)*nb.p.velocity.x; + newVelX2 = (mb-ma)/(mb+ma)*nb.p.velocity.x+2*ma/(mb+ma)*na.p.velocity.x; + + na.p.velocity.x = newVelX1; + nb.p.velocity.x = newVelX2; + } + + // slow down particule on impact + // na.p.velocity.multiplyScalar(na.center && na.p.velocity.length() < 1 ? 1.1 : 0.90); + // nb.p.velocity.multiplyScalar(nb.center && nb.p.velocity.length() < 1 ? 1.1 : 0.90); + na.p.velocity.multiplyScalar(0.90); + nb.p.velocity.multiplyScalar(0.90); + + } + } + }; + // show opened audio node + function openNodeByNid(nid){ + // console.log('Corpus openNode()', nid); + closeNode(); + if(typeof _nodes_Nid_Id[nid] != 'undefined'){ + // console.log('node exists'); + _node_opened_id = _nodes_Nid_Id[nid]; + _nodes[_nodes_Nid_Id[nid]].open(); + } + } + function closeNode(){ + if(_node_opened_id != -1){ + // if(typeof _nodes[_node_opened_id] !== 'undefined'){ + _nodes[_node_opened_id].close(); + // } + _node_opened_id = -1; + } + } + function createNodesRepulsions(){ + // how to delete all these attractions before creates new once + //console.log('_nodes_centered', _nodes_centered); + purgeNodesRepulsions(); + for (var n = 0; n < _nodes_centered.length; n++) { + for (var q = n+1; q < _nodes_centered.length; q++) { + _physics.makeAttraction(_nodes_centered[n].p, _nodes_centered[q].p, -0.4, 10); + } + } + }; + function purgeNodesRepulsions(){ + // console.log('_physics.attractions.length', _physics.attractions.length); + for (var a = _physics.attractions.length-1; a >= 0; a--) { + // assuming that only nodes repulsions have constant < 1 + // and are all at the end of array + if(Math.abs(_physics.attractions[a].constant) < 1){ + _physics.attractions.splice(a,1); + }else{ + break; + } + } + // console.log('_physics.attractions.length', _physics.attractions.length); + }; + + // ___ _ + // | __|_ _| |_ _ _ ___ ___ ___ + // | _|| ' \ _| '_/ -_) -_|_-< + // |___|_||_\__|_| \___\___/__/ + // TODO : this functionn is not clear as it should be called toggleEntry + function openEntree(tid, bubbling){ + //var $link = $('a.term-link[tid="'+tid+'"]'); + var $link = _$entrees_block_termlinks.filter('[tid="'+tid+'"]'); + var $li = $link.parents('li'); + var sys_path = $link.attr('data-drupal-link-system-path'); + var url = $link.attr('href'); + if(!$li.is('.opened')){ + _$entrees_block_termlinks.parents('li').removeClass('opened'); + $li.addClass('opened'); + filterEntree(tid); + if(bubbling){ + _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path}); + } + }else if(bubbling){ + $li.removeClass('opened'); + scrambleCollection(); + _$body.trigger({'type':'close_entree', 'tid':tid}); + } + }; + function filterEntree(t){ + shutDownArticles(); + + _nodes_centered = []; + for (var n = 0; n < _nodes.length; n++) { + if(_nodes[n].entrees.indexOf(t) == -1){ + _nodes[n].setAside(); + }else{ + _nodes[n].setCenteredOnEntree(t); + // record centered nodes for inter node repulsions + _nodes_centered.push(_nodes[n]); + } + } + createNodesRepulsions(); + }; + function highlightEntries(){ + _$entrees_block_termlinks.removeClass('highlighted'); + var id = -1; + if(_node_hover_id != -1){ + id = _node_hover_id; + }else if(_node_opened_id != -1){ + id = _node_opened_id; + } + var entree; + if(id != -1){ + for (var i = 0; i < _nodes[id].entrees.length; i++) { + entree = _nodes[id].entrees[i]; + _$entrees_block_termlinks.filter(function(){ + return $(this).attr('tid') == entree; + }).addClass('highlighted'); + } + } + }; + + // ___ _ + // / __| ___ __ _ _ _ __| |_ + // \__ \/ -_) _` | '_/ _| ' \ + // |___/\___\__,_|_| \__|_||_| + function filterSearchResults(nids){ + shutDownArticles(); + + _nodes_centered = []; + for (var n = 0; n < _nodes.length; n++) { + if(nids.indexOf(_nodes[n].nid) == -1){ + _nodes[n].setAside(); + }else{ + _nodes[n].setCentered(); + // record centered nodes for inter node repulsions + _nodes_centered.push(_nodes[n]); + } + } + createNodesRepulsions(); + }; + + // ___ _ _ _ + // / __| __ _ _ __ _ _ __ | |__| (_)_ _ __ _ + // \__ \/ _| '_/ _` | ' \| '_ \ | | ' \/ _` | + // |___/\__|_| \__,_|_|_|_|_.__/_|_|_||_\__, | + // |___/ + function scrambleCollection(){ + for (var i = 0; i < _nodes.length; i++) { + _nodes[i].scramble(); + } + // setTimeout(stopScrambling, 2000); + stopScrambling(); + }; + function stopScrambling(){ + for (var i = 0; i < _nodes.length; i++) { + setTimeout(function(n){ + n.stopScrambling(); + }.bind(this, _nodes[i]), 1000 + Math.random()*4000); + } + }; + function closeAllEntries(){ + _$entrees_block_termlinks.each(function(index, el) { + if($(this).parents('li').is('.opened')){ + $(this).trigger('click'); + return false; + } + }); + }; + + // _ _ _ _ + // /_\ _ _| |_(_)__| |___ ___ + // / _ \| '_| _| / _| / -_|_-< + // /_/ \_\_| \__|_\__|_\___/__/ + function initArtilesLink(){ + // add "articles link to blockentrees" + _$articles_link = $('
    ') + .html('Articles') + .attr("href", "#articles") + .addClass('articles-link') + .on('click', onCLickedOnArticles); + + $('.item-list ul',_$entrees_block).append( + $('
  • ').append( + $('').append(_$articles_link) + ) + ); + }; + function onCLickedOnArticles(e){ + e.preventDefault(); + $(this).toggleClass('is-active'); + if($(this).is('.is-active')){ + filterArticles(); + closeAllEntries(); + }else{ + resetArticlesFilter(); + } + // _$canvas.trigger({ + // 'type':'corpus-cliqued-on-articles' + // }); + return false; + }; + function filterArticles(){ + //console.log('filterArticles'); + for (var i = 0; i < _no_articles_nodes.length; i++) { + _no_articles_nodes[i].fade(); + } + }; + function resetArticlesFilter(){ + //console.log('resetArticlesFilter'); + for (var i = 0; i < _no_articles_nodes.length; i++) { + _no_articles_nodes[i].unFade(); + } + }; + function shutDownArticles(){ + // shutdown articles if active + if(_$articles_link.is('.is-active')) + _$articles_link.trigger('click'); + }; + + // ___ _ + // | __|_ _____ _ _| |_ ___ + // | _|\ V / -_) ' \ _(_-< + // |___|\_/\___|_||_\__/__/ + function initEvents(){ + console.log('Corpus, initEvents'); + _$canvas + .on('mousemove', function(event) { + event.preventDefault(); + _m_pos.x = event.originalEvent.clientX; + _m_pos.y = event.originalEvent.clientY; + }) + .on('mouseenter', function(event){ + // console.log('onMouseIN'); + _mouse_in = true; + }) + .on('mouseout', function(event){ + // console.log('onMouseOUT'); + _mouse_in = false; + _node_pop_up.removeNode(); + }) + .on('click', function(event) { + if(event.target.tagName != "A" && event.target.tagName != "INPUT"){ + // console.log("Corpus : click"); + event.preventDefault(); + if(_node_hover_id != -1){ + // console.log("corpus : click on node", _nodes[_node_hover_id]); + var event = { + 'type':'corpus-cliked-on-node', + 'target_node':{ + 'id':_node_hover_id, + 'nid':_nodes[_node_hover_id].nid, + 'audio_url':_nodes[_node_hover_id].audio_url + }, + }; + _$canvas.trigger(event); + // instead of directly opening the doc, create an event listener (e.g. : audio played from random) + // openNode(_node_hover_id); + }else{ + // console.log('corpus : click on map'); + _$canvas.trigger('corpus-cliked-on-map'); + } + } + }) + .on('audio-node-opened', function(e){ + // console.log('Corpus audio-node-opened', e); + openNodeByNid(e.nid); + }) + .on('audio-node-closed', function(e){ + closeNode(); + }) + .on('open-entree', function(e){ + openEntree(e.tid); + }) + .on('close-all-entree', function(e){ + closeAllEntries(); + }); + + _$entrees_block_termlinks.on('click', function(event) { + console.log('_$entrees_block_termlinks click', this); + event.preventDefault(); + openEntree($(this).attr('tid'), true); + // var $link = $(this); + // var tid = $link.attr('tid'); + // var $li = $link.parents('li'); + // var sys_path = $link.attr('data-drupal-link-system-path'); + // var url = $link.attr('href'); + // if(!$li.is('.opened')){ + // _$entrees_block_termlinks.parents('li').removeClass('opened'); + // $li.addClass('opened'); + // openEntree(tid); + // _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path}); + // }else{ + // $li.removeClass('opened'); + // scrambleCollection(); + // _$body.trigger({'type':'close_entree', 'tid':tid}); + // } + return false; + }); + + _$body + .on('chutier-action-done', function(e) { + _nodes_by_nid[e.target_id].chutier_action = e.new_action; + }) + .on('search-results-loaded', function(e){ + //console.log("Edlp Corpus, search-results-loaded",e.results); + // TODO: filter map's nodes + filterSearchResults(e.results); + }) + .on('search-closed', function(e){ + scrambleCollection(); + }) + .on('new-content-not-entree-ajax-loaded', function(e){ + // close all entries only if entry already opened + if(_$entrees_block_termlinks.parents('li.opened').length){ + _$entrees_block_termlinks.parents('li').removeClass('opened'); + scrambleCollection(); + } + }); + }; + + function checkPreOpenedEntry(){ + _$entrees_block.find('li.entree').each(function(index, el) { + var $li = $(this); + if($('a.is-active', $li).length){ + $li.addClass('opened'); + filterEntree($li.attr('tid')); + return false; + } + }); + }; + + // _ _ _ ___ _ _ + // | \| |___ __| |___| _ \___ _ __| | | |_ __ + // | .` / _ \/ _` / -_) _/ _ \ '_ \ |_| | '_ \ + // |_|\_\___/\__,_\___|_| \___/ .__/\___/| .__/ + // |_| |_| + function initNodePopup(){ + _node_pop_up = new NodePopUp(); + }; + function NodePopUp(){ + this.visible = false; + this.node; + this.$dom = $('
    ') + .addClass('node-popup') + .attr('pos', 'top-right') + .appendTo('body'); + this.$content = $('
    ').addClass('inner').appendTo(this.$dom); + + if (typeof NodePopUp.initialized == "undefined") { + + NodePopUp.prototype.setNode = function(n){ + // console.log('NodePopUp setNode()'); + this.node = n; + // positioning NodePopUp regarding node position + this.setPositioning(); + // update NodePopUp content + this.setContent(); + }; + + NodePopUp.prototype.setPositioning = function(){ + switch(true){ + case this.node.x > this.node.wall_limits.right-350 && this.node.y < this.node.wall_limits.top+200: + this.$dom.attr('pos', 'bottom-left'); + break; + case this.node.x > this.node.wall_limits.right-350: + this.$dom.attr('pos', 'top-left'); + break; + case this.node.y < this.node.wall_limits.top+200: + this.$dom.attr('pos', 'bottom-right'); + break; + default: + this.$dom.attr('pos', 'top-right'); + } + }; + + NodePopUp.prototype.setContent = function(){ + // console.log(this.node); + this.$content.html(''); + var $entrees = $('
    ').addClass('entrees'); + for (var i = 0; i < this.node.entrees.length; i++) { + var tid = this.node.entrees[i]; + $entrees.append($('').addClass('entree').attr('tid', tid)); + } + var $chutier_action = $('').addClass('chutier-icon').attr('action', this.node.chutier_action); + this.$content + .append($entrees) + .append('

    '+this.node.title+'

    ') + .append('
    '+this.node.description+'
    ') + .append($chutier_action); + }; + + NodePopUp.prototype.removeNode = function(){ + // console.log('NodePopUp removeNode()'); + this.node = false; + }; + + NodePopUp.prototype.draw = function(){ + if(this.node){ + this.$dom.css({ + 'display':"block", + 'left':this.node.x+"px", + 'top':this.node.y+"px", + }); + }else{ + this.$dom.css({ + 'display':"none", + }); + } + }; + + NodePopUp.initialized = true; + } + } + + // ___ _ + // | _ \___ _ _ __| |___ _ _ + // | / -_) ' \/ _` / -_) '_| + // |_|_\___|_||_\__,_\___|_| + function render(){ + _ctx.clearRect(0, 0, _canvas.width, _canvas.height); + + checkParticulesCollisions(); + + for (var i = 0; i < _nodes.length; i++) { + _nodes[i].onUpdate(); + } + + _node_pop_up.draw(); + + if(_node_hover_id != -1){ + _canvas.style.cursor = 'pointer'; + }else{ + _canvas.style.cursor = 'auto'; + } + // check for highlighted entries + highlightEntries(); + }; + + // ___ _ _ _ _ + // / __| |_ __ _ _ _| |_ /_\ _ _ (_)_ __ ___ + // \__ \ _/ _` | '_| _|/ _ \| ' \| | ' \/ -_) + // |___/\__\__,_|_| \__/_/ \_\_||_|_|_|_|_\___| + function startAnime(){ + _physics.onUpdate(render); + _physics.play() + $('body') + .attr('corpus', 'map-ready') + .trigger({ + 'type':'corpus-map-ready', + 'playlist':_playlist + }); + }; + + init(); + } + + $(document).ready(function($) { + var edlpcorpus = new EdlpCorpus(); + }); + +})(jQuery, Drupal, drupalSettings); diff --git a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/physics.min.js b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/physics.min.js index 8e7487968..c3ddff68c 100644 --- a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/physics.min.js +++ b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/physics.min.js @@ -1,38 +1,1153 @@ +/** + * Physics + * A requirified port of Traer Physics from Processing to JavaScript. + * Copyright (C) 2012 jonobr1 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;othis.originalPositions.length){this.originalPositions.push(new Vector());this.originalVelocities.push(new Vector());this.k1Forces.push(new Vector());this.k1Velocities.push(new Vector());this.k2Forces.push(new Vector());this.k2Velocities.push(new Vector());this.k3Forces.push(new Vector());this.k3Velocities.push(new Vector());this.k4Forces.push(new Vector());this.k4Velocities.push(new Vector());} -return this;},step:function(dt){var s=this.s;var p,x,y;this.allocateParticles();_.each(s.particles,function(p,i){if(!p.fixed){this.originalPositions[i].copy(p.position);this.originalVelocities[i].copy(p.velocity);} -p.force.clear();},this);s.applyForces();_.each(s.particles,function(p,i){if(!p.fixed){this.k1Forces[i].copy(p.force);this.k1Velocities[i].copy(p.velocity);} -p.force.clear();},this);_.each(s.particles,function(p,i){if(!p.fixed){var op=this.originalPositions[i];var k1v=this.k1Velocities[i];x=op.x+k1v.x*0.5*dt;y=op.y+k1v.y*0.5*dt;p.position.set(x,y);var ov=this.originalVelocities[i];var k1f=this.k1Forces[i];x=ov.x+k1f.x*0.5*dt/p.mass;y=ov.y+k1f.y*0.5*dt/p.mass;p.velocity.set(x,y);}},this);s.applyForces();_.each(s.particles,function(p,i){if(!p.fixed){this.k2Forces[i].copy(p.force);this.k2Velocities[i].copy(p.velocity);} -p.force.clear();},this);_.each(s.particles,function(p,i){if(!p.fixed){var op=this.originalPositions[i];var k2v=this.k2Velocities[i];p.position.set(op.x+k2v.x*0.5*dt,op.y+k2v.y*0.5*dt);var ov=this.originalVelocities[i];var k2f=this.k2Forces[i];p.velocity.set(ov.x+k2f.x*0.5*dt/p.mass,ov.y+k2f.y*0.5*dt/p.mass);}},this);s.applyForces();_.each(s.particles,function(p,i){if(!p.fixed){this.k3Forces[i].copy(p.force);this.k3Velocities[i].copy(p.velocity);} -p.force.clear();},this);_.each(s.particles,function(p,i){if(!p.fixed){var op=this.originalPositions[i];var k3v=this.k3Velocities[i];p.position.set(op.x+k3v.x*dt,op.y+k3v.y*dt) -var ov=this.originalVelocities[i];var k3f=this.k3Forces[i];p.velocity.set(ov.x+k3f.x*dt/p.mass,ov.y+k3f.y*dt/p.mass);}},this);s.applyForces();_.each(s.particles,function(p,i){if(!p.fixed){this.k4Forces[i].copy(p.force);this.k4Velocities[i].copy(p.velocity);}},this);_.each(s.particles,function(p,i){p.age+=dt;if(!p.fixed){var op=this.originalPositions[i];var k1v=this.k1Velocities[i];var k2v=this.k2Velocities[i];var k3v=this.k3Velocities[i];var k4v=this.k4Velocities[i];var x=op.x+dt/6.0*(k1v.x+2.0*k2v.x+2.0*k3v.x+k4v.x);var y=op.y+dt/6.0*(k1v.y+2.0*k2v.y+2.0*k3v.y+k4v.y);p.position.set(x,y);var ov=this.originalVelocities[i];var k1f=this.k1Forces[i];var k2f=this.k2Forces[i];var k3f=this.k3Forces[i];var k4f=this.k4Forces[i];x=ov.x+dt/(6.0*p.mass)*(k1f.x+2.0*k2f.x+2.0*k3f.x+k4f.x);y=ov.y+dt/(6.0*p.mass)*(k1f.y+2.0*k2f.y+2.0*k3f.y+k4f.y);p.velocity.set(x,y);}},this);return this;}});module.exports=Integrator;},{"./common":8,"./vector":12}],3:[function(require,module,exports){var _=require('./common'),Vector=require('./vector');function Particle(mass){this.position=new Vector();this.velocity=new Vector();this.force=new Vector();this.mass=mass;this.fixed=false;this.age=0;this.dead=false;} -_.extend(Particle.prototype,{distanceTo:function(p){return this.position.distanceTo(p.position);},makeFixed:function(){this.fixed=true;this.velocity.clear();return this;},reset:function(){this.age=0;this.dead=false;this.position.clear();this.velocity.clear();this.force.clear();this.mass=1.0;return this;},resting:function(){return this.fixed||this.velocity.isZero()&&this.force.isZero();}});module.exports=Particle;},{"./common":8,"./vector":12}],4:[function(require,module,exports){var _=require('./common'),Vector=require('./Vector'),Particle=require('./Particle'),Spring=require('./Spring'),Attraction=require('./Attraction'),Integrator=require('./Integrator');function ParticleSystem(){this.__equilibriumCriteria={particles:true,springs:true,attractions:true};this.__equilibrium=false;this.__optimized=false;this.particles=[];this.springs=[];this.attractions=[];this.forces=[];this.integrator=new Integrator(this);this.hasDeadParticles=false;var args=arguments.length;if(args===1){this.gravity=new Vector(0,arguments[0]);this.drag=ParticleSystem.DEFAULT_DRAG;}else if(args===2){this.gravity=new Vector(0,arguments[0]);this.drag=arguments[1];}else if(args===3){this.gravity=new Vector(arguments[0],arguments[1]);this.drag=arguments[3];}else{this.gravity=new Vector(0,ParticleSystem.DEFAULT_GRAVITY);this.drag=ParticleSystem.DEFAULT_DRAG;}} -_.extend(ParticleSystem,{DEFAULT_GRAVITY:0,DEFAULT_DRAG:0.001,Attraction:Attraction,Integrator:Integrator,Particle:Particle,Spring:Spring,Vector:Vector});_.extend(ParticleSystem.prototype,{optimize:function(b){this.__optimized=!!b;return this;},setGravity:function(x,y){this.gravity.set(x,y);return this;},setEquilibriumCriteria:function(particles,springs,attractions){this.__equilibriumCriteria.particles=!!particles;this.__equilibriumCriteria.springs=!!springs;this.__equilibriumCriteria.attractions=!!attractions;},tick:function(){this.integrator.step(arguments.length===0?1:arguments[0]);if(this.__optimized){this.__equilibrium=!this.needsUpdate();} -return this;},needsUpdate:function(){var i=0;if(this.__equilibriumCriteria.particles){for(i=0,l=this.particles.length;i=0||!_.isFunction(func)){return this;} -this.animations.push(func);return this;},onEquilibrium:function(func){if(_.indexOf(this.equilibriumCallbacks,func)>=0||!_.isFunction(func)){return this;} -this.equilibriumCallbacks.push(func);return this;},update:function(){if(!this.__equilibrium){return this;} -this.__equilibrium=false;if(this.playing){update.call(this);} -return this;}});function update(){var _this=this;this.tick();_.each(this.animations,function(a){a();});if((this.__optimized&&!this.__equilibrium||!this.__optimized)&&this.playing){raf(function(){update.call(_this);});} -if(this.__optimized&&this.__equilibrium){_.each(this.equilibriumCallbacks,function(a){a();});}} -module.exports=Physics;},{"./ParticleSystem":4,"./common":8,"./requestAnimationFrame":11}],6:[function(require,module,exports){var _=require('./common'),Vector=require('./vector');function Spring(a,b,k,d,l){this.constant=k;this.damping=d;this.length=l;this.a=a;this.b=b;this.on=true;} -_.extend(Spring.prototype,{currentLength:function(){return this.a.position.distanceTo(this.b.position);},update:function(){var a=this.a;var b=this.b;if(!(this.on&&(!a.fixed||!b.fixed)))return this;var a2b=new Vector().sub(a.position,b.position);var d=a2b.length();if(d===0){a2b.clear();}else{a2b.divideScalar(d);} -var fspring=-1*(d-this.length)*this.constant;var va2b=new Vector().sub(a.velocity,b.velocity);var fdamping=-1*this.damping*va2b.dot(a2b);var fr=fspring+fdamping;a2b.multiplyScalar(fr);if(!a.fixed){a.force.addSelf(a2b);} -if(!b.fixed){b.force.subSelf(a2b);} -return this;},resting:function(){var a=this.a;var b=this.b;var l=this.length;return!this.on||(a.fixed&&b.fixed)||(a.fixed&&(l===0?b.position.equals(a.position):b.position.distanceTo(a.position)<=l)&&b.resting())||(b.fixed&&(l===0?a.position.equals(b.position):a.position.distanceTo(b.position)<=l)&&a.resting());}});module.exports=Spring;},{"./common":8,"./vector":12}],7:[function(require,module,exports){var _=require('./common');function Vector(x,y){this.x=x||0;this.y=y||0;} -_.extend(Vector.prototype,{set:function(x,y){this.x=x;this.y=y;return this;},copy:function(v){this.x=v.x;this.y=v.y;return this;},clear:function(){this.x=0;this.y=0;return this;},clone:function(){return new Vector(this.x,this.y);},add:function(v1,v2){this.x=v1.x+v2.x;this.y=v1.y+v2.y;return this;},addSelf:function(v){this.x+=v.x;this.y+=v.y;return this;},sub:function(v1,v2){this.x=v1.x-v2.x;this.y=v1.y-v2.y;return this;},subSelf:function(v){this.x-=v.x;this.y-=v.y;return this;},multiplySelf:function(v){this.x*=v.x;this.y*=v.y;return this;},multiplyScalar:function(s){this.x*=s;this.y*=s;return this;},multiplyScalarXY:function(sx,sy){this.x*=sx;this.y*=sy;return this;},divideScalar:function(s){if(s){this.x/=s;this.y/=s;}else{this.set(0,0);} -return this;},negate:function(){return this.multiplyScalar(-1);},dot:function(v){return this.x*v.x+this.y*v.y;},lengthSquared:function(){return this.x*this.x+this.y*this.y;},length:function(){return Math.sqrt(this.lengthSquared());},normalize:function(){return this.divideScalar(this.length());},distanceTo:function(v){return Math.sqrt(this.distanceToSquared(v));},distanceToSquared:function(v){var dx=this.x-v.x,dy=this.y-v.y;return dx*dx+dy*dy;},setLength:function(l){return this.normalize().multiplyScalar(l);},equals:function(v){return(this.distanceTo(v)<0.0001);},lerp:function(v,t){var x=(v.x-this.x)*t+this.x;var y=(v.y-this.y)*t+this.y;return this.set(x,y);},isZero:function(){return(this.length()<0.0001);}});module.exports=Vector;},{"./common":8}],8:[function(require,module,exports){var breaker={};var ArrayProto=Array.prototype;var ObjProto=Object.prototype;var hasOwnProperty=ObjProto.hasOwnProperty;var slice=ArrayProto.slice;var nativeForEach=ArrayProto.forEach;var nativeIndexOf=ArrayProto.indexOf;var toString=ObjProto.toString;var has=function(obj,key){return hasOwnProperty.call(obj,key);};var each=function(obj,iterator,context){if(obj==null)return;if(nativeForEach&&obj.forEach===nativeForEach){obj.forEach(iterator,context);}else if(obj.length===+obj.length){for(var i=0,l=obj.length;i>1;iterator(array[mid]) this.originalPositions.length) { + this.originalPositions.push(new Vector()); + this.originalVelocities.push(new Vector()); + this.k1Forces.push(new Vector()); + this.k1Velocities.push(new Vector()); + this.k2Forces.push(new Vector()); + this.k2Velocities.push(new Vector()); + this.k3Forces.push(new Vector()); + this.k3Velocities.push(new Vector()); + this.k4Forces.push(new Vector()); + this.k4Velocities.push(new Vector()); + } + + return this; + + }, + + step: function(dt) { + + var s = this.s; + var p, x, y; + + this.allocateParticles(); + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + this.originalPositions[i].copy(p.position); + this.originalVelocities[i].copy(p.velocity); + } + p.force.clear(); + }, this); + + // K1 + + s.applyForces(); + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + this.k1Forces[i].copy(p.force); + this.k1Velocities[i].copy(p.velocity); + } + p.force.clear(); + }, this); + + // K2 + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + + var op = this.originalPositions[i]; + var k1v = this.k1Velocities[i]; + x = op.x + k1v.x * 0.5 * dt; + y = op.y + k1v.y * 0.5 * dt; + p.position.set(x, y); + + var ov = this.originalVelocities[i]; + var k1f = this.k1Forces[i]; + x = ov.x + k1f.x * 0.5 * dt / p.mass; + y = ov.y + k1f.y * 0.5 * dt / p.mass; + p.velocity.set(x, y); + + } + }, this); + + s.applyForces(); + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + this.k2Forces[i].copy(p.force); + this.k2Velocities[i].copy(p.velocity); + } + p.force.clear(); + }, this); + + // K3 + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + + var op = this.originalPositions[i]; + var k2v = this.k2Velocities[i]; + p.position.set(op.x + k2v.x * 0.5 * dt, op.y + k2v.y * 0.5 * dt); + + var ov = this.originalVelocities[i]; + var k2f = this.k2Forces[i]; + p.velocity.set(ov.x + k2f.x * 0.5 * dt / p.mass, ov.y + k2f.y * 0.5 * dt / p.mass); + } + }, this); + + s.applyForces(); + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + this.k3Forces[i].copy(p.force); + this.k3Velocities[i].copy(p.velocity); + } + p.force.clear(); + }, this); + + // K4 + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + + var op = this.originalPositions[i]; + var k3v = this.k3Velocities[i]; + p.position.set(op.x + k3v.x * dt, op.y + k3v.y * dt) + + var ov = this.originalVelocities[i]; + var k3f = this.k3Forces[i]; + p.velocity.set(ov.x + k3f.x * dt / p.mass, ov.y + k3f.y * dt / p.mass); + } + }, this); + + s.applyForces(); + + _.each(s.particles, function(p, i) { + if (!p.fixed) { + this.k4Forces[i].copy(p.force); + this.k4Velocities[i].copy(p.velocity); + } + }, this); + + // TOTAL + + _.each(s.particles, function(p, i) { + + p.age += dt; + + if (!p.fixed) { + + var op = this.originalPositions[i]; + var k1v = this.k1Velocities[i]; + var k2v = this.k2Velocities[i]; + var k3v = this.k3Velocities[i]; + var k4v = this.k4Velocities[i]; + + var x = op.x + dt / 6.0 * (k1v.x + 2.0 * k2v.x + 2.0 * k3v.x + k4v.x); + var y = op.y + dt / 6.0 * (k1v.y + 2.0 * k2v.y + 2.0 * k3v.y + k4v.y); + + p.position.set(x, y); + + var ov = this.originalVelocities[i]; + var k1f = this.k1Forces[i]; + var k2f = this.k2Forces[i]; + var k3f = this.k3Forces[i]; + var k4f = this.k4Forces[i]; + + x = ov.x + dt / (6.0 * p.mass) * (k1f.x + 2.0 * k2f.x + 2.0 * k3f.x + k4f.x); + y = ov.y + dt / (6.0 * p.mass) * (k1f.y + 2.0 * k2f.y + 2.0 * k3f.y + k4f.y); + + p.velocity.set(x, y); + + } + + }, this); + + return this; + + } + + }); + + module.exports = Integrator; + +},{"./common":8,"./vector":12}],3:[function(require,module,exports){ +var _ = require('./common') +, Vector = require('./vector') +; + + function Particle(mass) { + + this.position = new Vector(); + this.velocity = new Vector(); + this.force = new Vector(); + this.mass = mass; + this.fixed = false; + this.age = 0; + this.dead = false; + + } + + _.extend(Particle.prototype, { + + /** + * Get the distance between two particles. + */ + distanceTo: function(p) { + return this.position.distanceTo(p.position); + }, + + /** + * Make the particle fixed in 2D space. + */ + makeFixed: function() { + this.fixed = true; + this.velocity.clear(); + return this; + }, + + /** + * Reset a particle. + */ + reset: function() { + + this.age = 0; + this.dead = false; + this.position.clear(); + this.velocity.clear(); + this.force.clear(); + this.mass = 1.0; + + return this; + }, + + /** + * Returns a boolean describing whether the particle is in movement. + */ + resting: function() { + return this.fixed || this.velocity.isZero() && this.force.isZero(); + } + + }); + + module.exports = Particle; + +},{"./common":8,"./vector":12}],4:[function(require,module,exports){ +var _ = require('./common') +, Vector = require('./Vector') +, Particle = require('./Particle') +, Spring = require('./Spring') +, Attraction = require('./Attraction') +, Integrator = require('./Integrator') +; + + /** + * traer.js + * A particle-based physics engine ported from Jeff Traer's Processing + * library to JavaScript. This version is intended for use with the + * HTML5 canvas element. It is dependent on Three.js' Vector2 class, + * but can be overridden with any Vector2 class with the methods included. + * + * @author Jeffrey Traer Bernstein (original Java library) + * @author Adam Saponara (JavaScript port) + * @author Jono Brandel (requirified/optimization port) + * @author David Schoonover (Node/CommonJS/Browserify port) + * + * @version 0.3 + * @date March 25, 2012 + */ + + /** + * The whole kit and kaboodle. + * + * @class + */ + function ParticleSystem() { + + this.__equilibriumCriteria = { particles: true, springs: true, attractions: true }; + this.__equilibrium = false; // are we at equilibrium? + this.__optimized = false; + + this.particles = []; + this.springs = []; + this.attractions = []; + this.forces = []; + this.integrator = new Integrator(this); + this.hasDeadParticles = false; + + var args = arguments.length; + + if (args === 1) { + this.gravity = new Vector(0, arguments[0]); + this.drag = ParticleSystem.DEFAULT_DRAG; + } else if (args === 2) { + this.gravity = new Vector(0, arguments[0]); + this.drag = arguments[1]; + } else if (args === 3) { + this.gravity = new Vector(arguments[0], arguments[1]); + this.drag = arguments[3]; + } else { + this.gravity = new Vector(0, ParticleSystem.DEFAULT_GRAVITY); + this.drag = ParticleSystem.DEFAULT_DRAG; + } + + } + + _.extend(ParticleSystem, { + + DEFAULT_GRAVITY: 0, + + DEFAULT_DRAG: 0.001, + + Attraction: Attraction, + + Integrator: Integrator, + + Particle: Particle, + + Spring: Spring, + + Vector: Vector + + }); + + _.extend(ParticleSystem.prototype, { + + /** + * Set whether to optimize the simulation. This enables the check of whether + * particles are moving. + */ + optimize: function(b) { + this.__optimized = !!b; + return this; + }, + + /** + * Set the gravity of the ParticleSystem. + */ + setGravity: function(x, y) { + this.gravity.set(x, y); + return this; + }, + + /** + * Sets the criteria for equilibrium + */ + setEquilibriumCriteria: function(particles, springs, attractions) { + this.__equilibriumCriteria.particles = !!particles; + this.__equilibriumCriteria.springs = !!springs; + this.__equilibriumCriteria.attractions = !!attractions; + }, + + /** + * Update the integrator + */ + tick: function() { + this.integrator.step(arguments.length === 0 ? 1 : arguments[0]); + if (this.__optimized) { + this.__equilibrium = !this.needsUpdate(); + } + return this; + }, + + /** + * Checks all springs and attractions to see if the contained particles are + * inert / resting and returns a boolean. + */ + needsUpdate: function() { + var i = 0; + + if(this.__equilibriumCriteria.particles) { + for (i = 0, l = this.particles.length; i < l; i++) { + if (!this.particles[i].resting()) { + return true; + } + } + } + + if(this.__equilibriumCriteria.springs) { + for (i = 0, l = this.springs.length; i < l; i++) { + if (!this.springs[i].resting()) { + return true; + } + } + } + + if(this.__equilibriumCriteria.attractions) { + for (i = 0, l = this.attractions.length; i < l; i++) { + if (!this.attractions[i].resting()) { + return true; + } + } + } + + return false; + + }, + + /** + * Add a particle to the ParticleSystem. + */ + addParticle: function(p) { + + this.particles.push(p); + return this; + + }, + + /** + * Add a spring to the ParticleSystem. + */ + addSpring: function(s) { + + this.springs.push(s); + return this; + + }, + + /** + * Add an attraction to the ParticleSystem. + */ + addAttraction: function(a) { + + this.attractions.push(a); + return this; + + }, + + /** + * Makes and then adds Particle to ParticleSystem. + */ + makeParticle: function(m, x, y) { + + var mass = _.isNumber(m) ? m : 1.0; + var x = x || 0; + var y = y || 0; + + var p = new Particle(mass); + p.position.set(x, y); + this.addParticle(p); + return p; + + }, + + /** + * Makes and then adds Spring to ParticleSystem. + */ + makeSpring: function(a, b, k, d, l) { + + var s = new Spring(a, b, k, d, l); + this.addSpring(s); + return s; + + }, + + /** + * Makes and then adds Attraction to ParticleSystem. + */ + makeAttraction: function(a, b, k, d) { + + var a = new Attraction(a, b, k, d); + this.addAttraction(a); + return a; + + }, + + /** + * Wipe the ParticleSystem clean. + */ + clear: function() { + + this.particles.length = 0; + this.springs.length = 0; + this.attractions.length = 0; + + }, + + /** + * Calculate and apply forces. + */ + applyForces: function() { + + if (!this.gravity.isZero()) { + _.each(this.particles, function(p) { + p.force.addSelf(this.gravity); + }, this); + } + + var t = new Vector(); + + _.each(this.particles, function(p) { + t.set(p.velocity.x * -1 * this.drag, p.velocity.y * -1 * this.drag); + p.force.addSelf(t); + }, this); + + _.each(this.springs, function(s) { + s.update(); + }); + + _.each(this.attractions, function(a) { + a.update(); + }); + + _.each(this.forces, function(f) { + f.update(); + }); + + return this; + + }, + + /** + * Clear all particles in the system. + */ + clearForces: function() { + _.each(this.particles, function(p) { + p.clear(); + }); + return this; + } + + }); + + module.exports = ParticleSystem; + +},{"./Attraction":1,"./Integrator":2,"./Particle":3,"./Spring":6,"./Vector":7,"./common":8}],5:[function(require,module,exports){ +var _ = require('./common') +, raf = require('./requestAnimationFrame') +, ParticleSystem = require('./ParticleSystem') +; + + var updates = []; + + /** + * Extended singleton instance of ParticleSystem with convenience methods for + * Request Animation Frame. + * @class + */ + function Physics() { + + var _this = this; + + this.playing = false; + + ParticleSystem.apply(this, arguments); + + this.animations = []; + + this.equilibriumCallbacks = []; + + update.call(this); + + } + + _.extend(Physics, ParticleSystem, { + + superclass: ParticleSystem + + }); + + _.extend(Physics.prototype, ParticleSystem.prototype, { + + /** + * Play the animation loop. Doesn't affect whether in equilibrium or not. + */ + play: function() { + + if (this.playing) { + return this; + } + + this.playing = true; + this.__equilibrium = false; + update.call(this); + + return this; + + }, + + /** + * Pause the animation loop. Doesn't affect whether in equilibrium or not. + */ + pause: function() { + + this.playing = false; + return this; + + }, + + /** + * Toggle between playing and pausing the simulation. + */ + toggle: function() { + + if (this.playing) { + this.pause(); + } else { + this.play(); + } + + return this; + + }, + + onUpdate: function(func) { + + if (_.indexOf(this.animations, func) >= 0 || !_.isFunction(func)) { + return this; + } + + this.animations.push(func); + + return this; + + }, + + onEquilibrium: function(func) { + + if (_.indexOf(this.equilibriumCallbacks, func) >= 0 || !_.isFunction(func)) { + return this; + } + + this.equilibriumCallbacks.push(func); + + return this; + + }, + + /** + * Call update after values in the system have changed and this will fire + * it's own Request Animation Frame to update until things have settled + * to equilibrium — at which point the system will stop updating. + */ + update: function() { + + if (!this.__equilibrium) { + return this; + } + + this.__equilibrium = false; + if (this.playing) { + update.call(this); + } + + return this; + + } + + }); + + function update() { + + var _this = this; + + this.tick(); + + _.each(this.animations, function(a) { + a(); + }); + + if ((this.__optimized && !this.__equilibrium || !this.__optimized) && this.playing) { + + raf(function() { + update.call(_this); + }); + + } + + if (this.__optimized && this.__equilibrium){ + + _.each(this.equilibriumCallbacks, function(a) { + a(); + }); + + } + + } + + module.exports = Physics; + + +},{"./ParticleSystem":4,"./common":8,"./requestAnimationFrame":11}],6:[function(require,module,exports){ +var _ = require('./common') +, Vector = require('./vector') +; + + function Spring(a, b, k, d, l) { + + this.constant = k; + this.damping = d; + this.length = l; + this.a = a; + this.b = b; + this.on = true; + + } + + _.extend(Spring.prototype, { + + /** + * Returns the distance between particle a and particle b + * in 2D space. + */ + currentLength: function() { + return this.a.position.distanceTo(this.b.position); + }, + + /** + * Update spring logic. + */ + update: function() { + + var a = this.a; + var b = this.b; + if (!(this.on && (!a.fixed || !b.fixed))) return this; + + var a2b = new Vector().sub(a.position, b.position); + var d = a2b.length(); + + if (d === 0) { + a2b.clear(); + } else { + a2b.divideScalar(d); // Essentially normalize + } + + var fspring = -1 * (d - this.length) * this.constant; + + var va2b = new Vector().sub(a.velocity, b.velocity); + + var fdamping = -1 * this.damping * va2b.dot(a2b); + + var fr = fspring + fdamping; + + a2b.multiplyScalar(fr); + + if (!a.fixed) { + a.force.addSelf(a2b); + } + if (!b.fixed) { + b.force.subSelf(a2b); + } + + return this; + + }, + + /** + * Returns a boolean describing whether the spring is resting or not. + * Convenient for knowing whether or not the spring needs another update + * tick. + */ + resting: function() { + + var a = this.a; + var b = this.b; + var l = this.length; + + return !this.on || (a.fixed && b.fixed) + || (a.fixed && (l === 0 ? b.position.equals(a.position) : b.position.distanceTo(a.position) <= l) && b.resting()) + || (b.fixed && (l === 0 ? a.position.equals(b.position) : a.position.distanceTo(b.position) <= l) && a.resting()); + + } + + }); + + module.exports = Spring; + + +},{"./common":8,"./vector":12}],7:[function(require,module,exports){ +/** + * @author mr.doob / http://mrdoob.com/ + * @author philogb / http://blog.thejit.org/ + * @author egraether / http://egraether.com/ + * @author zz85 / http://www.lab4games.net/zz85/blog + * @author jonobr1 / http://jonobr1.com/ + */ + +var _ = require('./common'); + + /** + * A two dimensional vector. + */ + function Vector(x, y) { + + this.x = x || 0; + this.y = y || 0; + + } + + _.extend(Vector.prototype, { + + set: function(x, y) { + this.x = x; + this.y = y; + return this; + }, + + copy: function(v) { + this.x = v.x; + this.y = v.y; + return this; + }, + + clear: function() { + this.x = 0; + this.y = 0; + return this; + }, + + clone: function() { + return new Vector(this.x, this.y); + }, + + add: function(v1, v2) { + this.x = v1.x + v2.x; + this.y = v1.y + v2.y; + return this; + }, + + addSelf: function(v) { + this.x += v.x; + this.y += v.y; + return this; + }, + + sub: function(v1, v2) { + this.x = v1.x - v2.x; + this.y = v1.y - v2.y; + return this; + }, + + subSelf: function(v) { + this.x -= v.x; + this.y -= v.y; + return this; + }, + + multiplySelf: function(v) { + this.x *= v.x; + this.y *= v.y; + return this; + }, + + multiplyScalar: function(s) { + this.x *= s; + this.y *= s; + return this; + }, + + multiplyScalarXY: function(sx,sy) { + this.x *= sx; + this.y *= sy; + return this; + }, + + divideScalar: function(s) { + if (s) { + this.x /= s; + this.y /= s; + } else { + this.set(0, 0); + } + return this; + }, + + negate: function() { + return this.multiplyScalar(-1); + }, + + dot: function(v) { + return this.x * v.x + this.y * v.y; + }, + + lengthSquared: function() { + return this.x * this.x + this.y * this.y; + }, + + length: function() { + return Math.sqrt(this.lengthSquared()); + }, + + normalize: function() { + return this.divideScalar(this.length()); + }, + + distanceTo: function(v) { + return Math.sqrt(this.distanceToSquared(v)); + }, + + distanceToSquared: function(v) { + var dx = this.x - v.x, dy = this.y - v.y; + return dx * dx + dy * dy; + }, + + setLength: function(l) { + return this.normalize().multiplyScalar(l); + }, + + equals: function(v) { + return (this.distanceTo(v) < 0.0001 /* almost same position */); + }, + + lerp: function(v, t) { + var x = (v.x - this.x) * t + this.x; + var y = (v.y - this.y) * t + this.y; + return this.set(x, y); + }, + + isZero: function() { + return (this.length() < 0.0001 /* almost zero */ ); + } + + }); + + module.exports = Vector; + +},{"./common":8}],8:[function(require,module,exports){ + + /** + * Pulled only what's needed from: + * + * Underscore.js 1.3.3 + * (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. + * http://documentcloud.github.com/underscore + */ + + var breaker = {}; + var ArrayProto = Array.prototype; + var ObjProto = Object.prototype; + var hasOwnProperty = ObjProto.hasOwnProperty; + var slice = ArrayProto.slice; + var nativeForEach = ArrayProto.forEach; + var nativeIndexOf = ArrayProto.indexOf; + var toString = ObjProto.toString; + + var has = function(obj, key) { + return hasOwnProperty.call(obj, key); + }; + + var each = function(obj, iterator, context) { + + if (obj == null) return; + if (nativeForEach && obj.forEach === nativeForEach) { + obj.forEach(iterator, context); + } else if (obj.length === +obj.length) { + for (var i = 0, l = obj.length; i < l; i++) { + if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return; + } + } else { + for (var key in obj) { + if (_.has(obj, key)) { + if (iterator.call(context, obj[key], key, obj) === breaker) return; + } + } + } + + }; + + var identity = function(value) { + return value; + }; + + var sortedIndex = function(array, obj, iterator) { + iterator || (iterator = identity); + var low = 0, high = array.length; + while (low < high) { + var mid = (low + high) >> 1; + iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid; + } + return low; + }; + + module.exports = { + + has: has, + + each: each, + + extend: function(obj) { + each(slice.call(arguments, 1), function(source) { + for (var prop in source) { + obj[prop] = source[prop]; + } + }); + return obj; + }, + + indexOf: function(array, item, isSorted) { + if (array == null) return -1; + var i, l; + if (isSorted) { + i = sortedIndex(array, item); + return array[i] === item ? i : -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item); + for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i; + return -1; + }, + + sortedIndex: sortedIndex, + + identity: identity, + + isNumber: function(obj) { + return toString.call(obj) == '[object Number]'; + }, + + isFunction: function(obj) { + return toString.call(obj) == '[object Function]' || typeof obj == 'function'; + }, + + isUndefined: function(obj) { + return obj === void 0; + }, + + isNull: function(obj) { + return obj === null; + } + + }; + + +},{}],"H99CHA":[function(require,module,exports){ +var root = (function(){ return this; })() +, previousShortcut = root.Physics +; + +module.exports = root.Physics = require('./Physics'); + +},{"./Physics":5}],"physics":[function(require,module,exports){ +module.exports=require('H99CHA'); +},{}],11:[function(require,module,exports){ + /* + * Requirified version of Paul Irish's request animation frame. + * http://paulirish.com/2011/requestanimationframe-for-smart-animating/ + */ +module.exports = + window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function (callback) { + window.setTimeout(callback, 1000 / 60); + }; + +},{}],12:[function(require,module,exports){ +module.exports=require(7) +},{"./common":8}]},{},["H99CHA"]) diff --git a/sites/all/modules/figli/edlp_corpus/assets/dist/styles/corpus.min.css b/sites/all/modules/figli/edlp_corpus/assets/dist/styles/corpus.min.css index bc8b4c016..bf4479465 100644 --- a/sites/all/modules/figli/edlp_corpus/assets/dist/styles/corpus.min.css +++ b/sites/all/modules/figli/edlp_corpus/assets/dist/styles/corpus.min.css @@ -1 +1,71 @@ -canvas#corpus-map{position:absolute;-webkit-box-sizing:border-box;box-sizing:border-box;top:0;left:0;z-index:0}canvas#corpus-map.de-activated{background-color:#f4f4f4}div.node-popup{z-index:10;position:absolute;-webkit-box-sizing:content-box;box-sizing:content-box;width:300px;min-height:30px;top:60%;left:30%;pointer-events:none}div.node-popup .inner{padding:1em;outline:red solid 1px;background-color:#fff}div.node-popup:before{content:"";position:absolute;width:60px;height:0;border-top:1px solid red}div.node-popup[pos=bottom-right]{-webkit-transform:translateY(42px) translateX(42px);transform:translateY(42px) translateX(42px)}div.node-popup[pos=bottom-right]:before{top:-1px;left:-61px;-webkit-transform-origin:bottom right;transform-origin:bottom right;-webkit-transform:rotateZ(45deg);transform:rotateZ(45deg)}div.node-popup[pos=bottom-left]{-webkit-transform:translateX(-100%) translateY(42px) translateX(-42px);transform:translateX(-100%) translateY(42px) translateX(-42px)}div.node-popup[pos=bottom-left]:before{top:calc(100% +1px);left:100%;-webkit-transform-origin:top left;transform-origin:top left;-webkit-transform:rotateZ(-45deg);transform:rotateZ(-45deg)}div.node-popup[pos=top-left]{-webkit-transform:translateY(-100%) translateX(-100%) translateY(-42px) translateX(-42px);transform:translateY(-100%) translateX(-100%) translateY(-42px) translateX(-42px)}div.node-popup[pos=top-left]:before{bottom:0;left:100%;-webkit-transform-origin:top left;transform-origin:top left;-webkit-transform:rotateZ(45deg);transform:rotateZ(45deg)}div.node-popup[pos=top-right]{-webkit-transform:translateY(-100%) translateY(-42px) translateX(42px);transform:translateY(-100%) translateY(-42px) translateX(42px)}div.node-popup[pos=top-right]:before{top:calc(100% + 1px);left:-61px;-webkit-transform-origin:top right;transform-origin:top right;-webkit-transform:rotateZ(-45deg);transform:rotateZ(-45deg)} \ No newline at end of file +canvas#corpus-map { + position: absolute; + -webkit-box-sizing: border-box; + box-sizing: border-box; + top: 0; + left: 0; + z-index: 0; } + canvas#corpus-map.de-activated { + background-color: #f4f4f4; } + +div.node-popup { + z-index: 10; + position: absolute; + -webkit-box-sizing: content-box; + box-sizing: content-box; + width: 300px; + min-height: 30px; + pointer-events: none; + top: 60%; + left: 30%; + pointer-events: none; } + div.node-popup .inner { + padding: 1em; + outline: 1px solid red; + background-color: white; } + div.node-popup:before { + content: ""; + position: absolute; + width: 60px; + height: 0; + border-top: 1px solid red; } + div.node-popup[pos="bottom-right"] { + -webkit-transform: translateY(42px) translateX(42px); + transform: translateY(42px) translateX(42px); } + div.node-popup[pos="bottom-right"]:before { + top: -1px; + left: -61px; + -webkit-transform-origin: bottom right; + transform-origin: bottom right; + -webkit-transform: rotateZ(45deg); + transform: rotateZ(45deg); } + div.node-popup[pos="bottom-left"] { + -webkit-transform: translateX(-100%) translateY(42px) translateX(-42px); + transform: translateX(-100%) translateY(42px) translateX(-42px); } + div.node-popup[pos="bottom-left"]:before { + top: calc(100% +1px); + left: 100%; + -webkit-transform-origin: top left; + transform-origin: top left; + -webkit-transform: rotateZ(-45deg); + transform: rotateZ(-45deg); } + div.node-popup[pos="top-left"] { + -webkit-transform: translateY(-100%) translateX(-100%) translateY(-42px) translateX(-42px); + transform: translateY(-100%) translateX(-100%) translateY(-42px) translateX(-42px); } + div.node-popup[pos="top-left"]:before { + bottom: 0; + left: 100%; + -webkit-transform-origin: top left; + transform-origin: top left; + -webkit-transform: rotateZ(45deg); + transform: rotateZ(45deg); } + div.node-popup[pos="top-right"] { + -webkit-transform: translateY(-100%) translateY(-42px) translateX(42px); + transform: translateY(-100%) translateY(-42px) translateX(42px); } + div.node-popup[pos="top-right"]:before { + top: calc(100% + 1px); + left: -61px; + -webkit-transform-origin: top right; + transform-origin: top right; + -webkit-transform: rotateZ(-45deg); + transform: rotateZ(-45deg); } diff --git a/sites/all/modules/figli/edlp_search/assets/dist/scripts/edlp_search.min.js b/sites/all/modules/figli/edlp_search/assets/dist/scripts/edlp_search.min.js index d620521e8..d3b931337 100644 --- a/sites/all/modules/figli/edlp_search/assets/dist/scripts/edlp_search.min.js +++ b/sites/all/modules/figli/edlp_search/assets/dist/scripts/edlp_search.min.js @@ -1,4 +1,109 @@ +(function ($, Drupal, drupalSettings) { -(function($,Drupal,drupalSettings){var settings=drupalSettings.edlp_search;var _$body=$('body');var _$container;var _$form;function init(){initEvents();initAjax();};function initEvents(){$('body').on('new-content-ajax-loaded',initAjax).on('edlp_search_search_form-col-closed',onSearchClosed);};function initAjax(){_$form=$('#edlp-search-form:not(.ajax-enabled)');if(!_$form.length)return false;_$form=$('#edlp-search-form:not(.ajax-enabled)').on('submit',onSubmitForm).addClass('ajax-enabled');_$container=_$form.parents('.row');if(!_$container.length){_$container=_$form.parent();}};function onSubmitForm(e){e.preventDefault();var args={};args.keys=$('input[type="search"]',this).val();args.entries=[];$('input[type="checkbox"]:checked','#edit-entries').each(function(index,el){args.entries.push($(this).val());});args.langues=$('input[name="langues"]',this).val();args.genres=$('input[name="genres"]',this).val();loadResults(args);return false;};function loadResults(args){_$form.addClass('ajax-loading');_$body.addClass('ajax-loading');$('[theme="edlp_search_results"]',_$container).addClass('ajax-loading');var path=window.location.origin+drupalSettings.path.baseUrl+settings.results_ajax_url;$.getJSON(path,args).done(function(data){onResultsLoaded(data);}).fail(function(jqxhr,textStatus,error){onResultsLoadFail(jqxhr,textStatus,error);});};function onResultsLoaded(data){_$form.removeClass('ajax-loading');_$body.removeClass('ajax-loading');$prev_results=$('[theme="edlp_search_results"]',_$container);if($prev_results.length){$prev_results.replaceWith(data.rendered);}else{_$container.append(data.rendered);} -_$body.trigger({'type':'search-results-loaded','results':data.results_nids});};function onResultsLoadFail(jqxhr,textStatus,error){void 0;};function onSearchClosed(e){$('div[theme="edlp_search_results"]').remove();_$body.trigger({'type':'search-closed'});} -init();})(jQuery,Drupal,drupalSettings); \ No newline at end of file + var settings = drupalSettings.edlp_search; + var _$body = $('body'); + var _$container; + var _$form; + + function init(){ + // console.log('EdlpSearch Init', settings); + initEvents(); + initAjax(); + }; + + function initEvents(){ + $('body') + .on('new-content-ajax-loaded', initAjax) + .on('edlp_search_search_form-col-closed', onSearchClosed); + }; + + function initAjax(){ + _$form = $('#edlp-search-form:not(.ajax-enabled)'); + if(!_$form.length) return false; + + //console.log('EdlpSearch initAjaxForm()'); + _$form = $('#edlp-search-form:not(.ajax-enabled)') + .on('submit', onSubmitForm) + .addClass('ajax-enabled'); + _$container = _$form.parents('.row'); + if(!_$container.length){ + _$container = _$form.parent(); + } + }; + + function onSubmitForm(e){ + e.preventDefault(); + // console.log('onSubmitForm',e); + var args = {}; + + // search for key words + args.keys = $('input[type="search"]', this).val(); + + // entries filter + args.entries = []; + $('input[type="checkbox"]:checked', '#edit-entries').each(function(index, el) { + args.entries.push($(this).val()); + }); + + // langues + args.langues = $('input[name="langues"]', this).val(); + + // genres + args.genres = $('input[name="genres"]', this).val(); + + //console.log('EdlpSearch onSubmitForm() : args',args); + + loadResults(args); + + return false; + }; + + function loadResults(args){ + //console.log('EdlpSearch loadResults() : args', args); + _$form.addClass('ajax-loading'); + _$body.addClass('ajax-loading'); + $('[theme="edlp_search_results"]', _$container).addClass('ajax-loading'); + var path = window.location.origin + drupalSettings.path.baseUrl +settings.results_ajax_url; + $.getJSON(path, args) + .done(function(data){ + onResultsLoaded(data); + }) + .fail(function(jqxhr, textStatus, error){ + onResultsLoadFail(jqxhr, textStatus, error); + }); + }; + + function onResultsLoaded(data){ + // console.log('EdlpSearch onResultsLoaded()', data); + _$form.removeClass('ajax-loading'); + _$body.removeClass('ajax-loading'); + + // insert results col + $prev_results = $('[theme="edlp_search_results"]', _$container); + if($prev_results.length){ + $prev_results.replaceWith(data.rendered); + }else{ + _$container.append(data.rendered); + } + + // trigger event + _$body.trigger({ + 'type':'search-results-loaded', + 'results':data.results_nids + }); + + }; + + function onResultsLoadFail(jqxhr, textStatus, error){ + console.warn('EdlpSearch : search results ajax load failed : '+error, jqxhr.responseText); + }; + + function onSearchClosed(e){ + // console.log('Edlp Search onSearchClosed()'); + $('div[theme="edlp_search_results"]').remove(); + // trigger event + _$body.trigger({'type':'search-closed'}); + } + + init(); +})(jQuery, Drupal, drupalSettings); diff --git a/sites/all/modules/figli/edlp_studio/assets/dist/scripts/edlp_studio.min.js b/sites/all/modules/figli/edlp_studio/assets/dist/scripts/edlp_studio.min.js index 02a7660bb..a01cc879c 100644 --- a/sites/all/modules/figli/edlp_studio/assets/dist/scripts/edlp_studio.min.js +++ b/sites/all/modules/figli/edlp_studio/assets/dist/scripts/edlp_studio.min.js @@ -1,10 +1,408 @@ +(function ($, Drupal, drupalSettings) { -(function($,Drupal,drupalSettings){var _settings=drupalSettings.edlp_studio;var $composer;function init(){initEvents();initStudio();};function initEvents(){$('body').on('new-audio-cartel-loaded',initAjaxChutierLinks).on('new-content-ajax-loaded',initStudio).on('all-modal-closed',initStudio);};function initStudio(){if($('#studio-ui').length){$composer=$('.composition_ui .composer','#studio-ui');initAjaxChutierLinks();initAjaxCompoLinks();initDragAndDropUI();$('body').trigger({'type':'studio-initialized'});}else{$('body').trigger({'type':'studio-not-active'});}} -function initAjaxChutierLinks(){$('.chutier-ajax-link:not(.ajax-enabled)').addClass('ajax-enabled').on('click',onClickChutierAjaxLink);};function onClickChutierAjaxLink(e){e.preventDefault();addRemoveToChutier($(this));return false;};function addRemoveToChutier($link){var ajax_path=$link.attr('data-drupal-link-system-path');var path=window.location.origin+drupalSettings.path.baseUrl+ajax_path;$link.addClass('ajax-loading');$.getJSON(path,{}).done(function(data){onActionToChutierDone($link,data);}).fail(function(jqxhr,textStatus,error){onErrorActionToChutier(jqxhr,textStatus,error,$link);});};function onActionToChutierDone($link,data){$('body').trigger({'type':'chutier-action-done','action_done':data.action_done,'new_action':data.action_done=='add'?'remove':'add','target_id':$link.attr('target_id'),});$link.replaceWith(data.new_link);initAjaxChutierLinks();updateStudioChutier();};function onErrorActionToChutier(jqxhr,textStatus,error,$link){void 0;};function initAjaxCompoLinks(){$('.new-composition-link:not(.ajax-enabled)').on('click',onClickNewCompoLink).addClass('ajax-enabled');$('.composition-link:not(.ajax-enabled)').on('click',onClickCompoLink).addClass('ajax-enabled');$('.delete-composition-link:not(.ajax-enabled)').on('click',onClickDeleteCompoLink).addClass('ajax-enabled');};function onClickCompoLink(e){e.preventDefault();openCompo($(this));return false;};function openCompo($link){var cid=$link.attr('cid');var ajax_path=_settings.open_compo_ajax_url+'/'+cid;var path=window.location.origin+Drupal.url(ajax_path);$link.addClass('ajax-loading');$composer.addClass('ajax-loading');$.getJSON(path,{}).done(function(data){onOpenCompoDone(data,$link);}).fail(function(jqxhr,textStatus,error){onErrorOpenCompo(jqxhr,textStatus,error,$link);});};function onOpenCompoDone(data,$link){$('.composition-link').removeClass('is-active');$link.removeClass('ajax-loading').addClass('is-active');if($('.composition',$composer).length){$('.composition',$composer).replaceWith(data.compo);}else{$('header',$composer).after(data.compo);} -$composer.removeClass('ajax-loading');initDragAndDropUI();$('body').trigger({'type':'on-studio-compo-opened'});};function onErrorOpenCompo(jqxhr,textStatus,error,$link){$link.removeClass('ajax-loading');void 0;};function onClickNewCompoLink(e){e.preventDefault();setInputForNewCompoName($(this));return false;};function setInputForNewCompoName($link){var $form=$('
    ').addClass('new-compo-form').append($('').attr('type','text').attr('placeholder','new name')).append($('