corpus.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. /**
  2. * @Author: Bachir Soussi Chiadmi <bach>
  3. * @Date: 18-12-2017
  4. * @Email: bachir@figureslibres.io
  5. * @Filename: corpus.js
  6. * @Last modified by: bach
  7. * @Last modified time: 20-12-2017
  8. * @License: GPL-V3
  9. */
  10. // JS performance improvement http://archive.oreilly.com/pub/a/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html
  11. /**
  12. * depends on :
  13. * physics.js : http://jonobr1.com/Physics/#
  14. */
  15. (function($, Drupal, drupalSettings) {
  16. EdlpCorpus = function(){
  17. var _activated = true;
  18. var _$body = $('body');
  19. var _$container = _$body;
  20. var _$canvas = $('<canvas id="corpus-map">').appendTo(_$container);
  21. var _canvas = _$canvas[0];
  22. var _ctx = _canvas.getContext('2d');
  23. var _dpi = window.devicePixelRatio;
  24. var _scene_props = {
  25. width:window.innerWidth,
  26. height:window.innerHeight,
  27. // 'margin_top':90, // with red border on head
  28. 'margin_top':75, // without red border on head
  29. // 'margin_top':0,
  30. 'margin_right':0,
  31. 'margin_bottom':65,
  32. // 'margin_bottom':0,
  33. 'margin_left':0
  34. };
  35. var _evolution_zone = {
  36. left:_scene_props.width/4,
  37. right:_scene_props.width - _scene_props.width/4,
  38. center:_scene_props.width/2,
  39. };
  40. var _physics = new Physics();
  41. var _nodes = [];
  42. var _articles_nodes = [];
  43. var _no_articles_nodes = [];
  44. // var _articles_filter_on = false;
  45. var _nodes_by_entries = {};
  46. var _nodes_by_nid = {};
  47. var _nodes_Nid_Id = {};
  48. var _nodes_centered = [];
  49. var _nodes_centered_attractions = [];
  50. var _loaded = false;
  51. var _playlist = [];
  52. var _p_velocity_factor = 0.5;
  53. var _mouse_in = true;
  54. var _m_pos = {x:0, y:0};
  55. var _node_hover_id = -1;
  56. var _node_opened_id = -1;
  57. var _$entrees_block = $('#block-edlpentreesblock');
  58. var _$entrees_block_termlinks = $('a.term-link', _$entrees_block);
  59. var _$articles_link;
  60. var _node_pop_up;
  61. // Colors depend on drupalSettings loaded by edlp_corpus.module
  62. var _settings = drupalSettings.edlp_corpus;
  63. var _ecolors = _settings.colors;
  64. // Physics
  65. var _attracter;
  66. var check_parts_colid_frq = 2;
  67. var check_parts_colid_tick = 1;
  68. // ____ _ __
  69. // / _/___ (_) /______
  70. // / // __ \/ / __/ ___/
  71. // _/ // / / / / /_(__ )
  72. // /___/_/ /_/_/\__/____/
  73. function init(){
  74. initCanvas();
  75. if(_activated){
  76. loadCorpus();
  77. }else{
  78. _$canvas.addClass('de-activated');
  79. }
  80. };
  81. // ___
  82. // / __|__ _ _ ___ ____ _ ___
  83. // | (__/ _` | ' \ V / _` (_-<
  84. // \___\__,_|_||_\_/\__,_/__/
  85. function initCanvas(){
  86. // resize the canvas to fill browser window dynamically
  87. window.addEventListener('resize', onResizeCanvas, false);
  88. onResizeCanvas();
  89. };
  90. function onResizeCanvas() {
  91. // _dpi = 2;
  92. _scene_props.width = window.innerWidth;
  93. _scene_props.height = window.innerHeight;
  94. _canvas.style.width = _scene_props.width+'px';
  95. _canvas.style.height = _scene_props.height+'px';
  96. _canvas.width = _scene_props.width*_dpi;
  97. _canvas.height = _scene_props.height*_dpi;
  98. _ctx.scale(_dpi, _dpi);
  99. moveEvolutionZone();
  100. if(_loaded){
  101. for (var i = 0; i < _nodes.length; i++) {
  102. _nodes[i].onResizeCanvas();
  103. }
  104. // move _attracter and _repulser to their right places again
  105. // moveEvolutionZone() will trigger resizePhysics()
  106. // resizePhysics();
  107. }
  108. };
  109. // ___
  110. // / __|___ _ _ _ __ _ _ ___
  111. // | (__/ _ \ '_| '_ \ || (_-<
  112. // \___\___/_| | .__/\_,_/__/
  113. // |_|
  114. function loadCorpus(){
  115. // console.log('drupalSettings',drupalSettings);
  116. // console.log('window.location', window.location);
  117. // var path = window.location.origin + drupalSettings.basepath + "edlp/corpus";
  118. var ajax_path = _settings.load_corpus_ajax_url;
  119. var path = window.location.origin + Drupal.url(ajax_path);
  120. $.getJSON(path, {})
  121. .done(function(data){
  122. onCorpusLoaded(data);
  123. })
  124. .fail(function(jqxhr, textStatus, error){
  125. onCorpusLoadError(jqxhr, textStatus, error);
  126. });
  127. };
  128. function onCorpusLoadError(jqxhr, textStatus, error){
  129. console.warn('corpus load failed', jqxhr.responseText);
  130. };
  131. function onCorpusLoaded(data){
  132. console.log('corpus loaded : data', data);
  133. // console.log('first node', data.nodes[0]);
  134. // buildParticles(data.nodes);
  135. initPhysics();
  136. buildNodes(data.nodes);
  137. initArtilesLink();
  138. initNodePopup();
  139. initEvents();
  140. checkPreOpenedEntry();
  141. startAnime();
  142. _loaded = true;
  143. };
  144. // ___ _ _
  145. // | _ \ |_ _ _ __(_)__ ___
  146. // | _/ ' \ || (_-< / _(_-<
  147. // |_| |_||_\_, /__/_\__/__/
  148. // |__/
  149. function initPhysics(){
  150. _attracter = _physics.makeParticle(1000);
  151. _attracter.fixed = true;
  152. // move _attracter on window resize
  153. resizePhysics();
  154. };
  155. function resizePhysics(){
  156. // attracters
  157. if(typeof _attracter != 'undefined'){
  158. _attracter.position = {x:_evolution_zone.center, y:_scene_props.height/2};
  159. }
  160. };
  161. // _ _ _
  162. // | \| |___ __| |___ ___
  163. // | .` / _ \/ _` / -_|_-<
  164. // |_|\_\___/\__,_\___/__/
  165. function buildNodes(nodes){
  166. // console.log("buildNodes", nodes);
  167. var d;
  168. for (var i in nodes) {
  169. d = i < 1 ? true : false;
  170. // _nodes.push(new Node(i,nodes[i],d));
  171. new Node(i,nodes[i],d);
  172. _playlist.push({
  173. 'id':i,
  174. 'nid':nodes[i].nid,
  175. 'audio_url':nodes[i].audio_url,
  176. 'document_url':nodes[i].document_url,
  177. });
  178. }
  179. };
  180. function Node(i,node,d){
  181. this.id = i;
  182. for(key in node)
  183. this[key] = node[key];
  184. // record the node in different lists
  185. _nodes.push(this);
  186. _nodes_by_nid[this.nid] = this;
  187. _nodes_Nid_Id[this.nid] = this.id;
  188. if(this.has_article == 1){
  189. _articles_nodes.push(this);
  190. }else{
  191. _no_articles_nodes.push(this);
  192. }
  193. for (var j = 0; j < this.entrees.length; j++) {
  194. if(typeof _nodes_by_entries[this.entrees[j]] == 'undefined')
  195. _nodes_by_entries[this.entrees[j]] = [];
  196. _nodes_by_entries[this.entrees[j]].push(this);
  197. }
  198. this.debug = d;
  199. this.mass = Math.max(1, this.entrees.length); //1;
  200. this.velocity_threshold = 0.01;
  201. // define radius regarding entries length
  202. switch(true){
  203. case this.entrees.length > 3:
  204. this.r = 8;//10;
  205. break;
  206. case this.entrees.length > 1 && this.entrees.length <= 3:
  207. this.r = 5;//7;
  208. break;
  209. default:
  210. this.r = 3;//4;
  211. break;
  212. }
  213. this.d = this.r*2;
  214. this.e_color = 'e_col_'+this.entrees[Math.floor(Math.random(this.entrees.length))];
  215. // pre-rendering node virtual canvas
  216. this.canvas = document.createElement('canvas');
  217. this.canvas_ctx = this.canvas.getContext('2d');
  218. this.line_width = 1;
  219. this.w = this.r*2+this.line_width*2;
  220. this.w_2 = this.w/2;
  221. this.canvas.width = this.w;
  222. this.canvas.height = this.w;
  223. this.canvas_ctx.fillStyle = 'rgb(255,255,255)';
  224. this.canvas_ctx.lineWidth = this.line_width;
  225. this.wall_bouncing_elasticity = 0.75;
  226. // node states
  227. this.hover = false;
  228. this.opened = false;
  229. this.faded = false;
  230. this.center = false;
  231. this.aside = false;
  232. this.scrambling = false;
  233. // prototypes
  234. if (typeof Node.initialized == "undefined") {
  235. Node.prototype.init = function(){
  236. this.calcWallLimits();
  237. this.x = this.wall_limits.left + Math.random()*(this.wall_limits.right - this.wall_limits.left);
  238. this.y = this.wall_limits.top + Math.random()*(this.wall_limits.bottom - this.wall_limits.top);
  239. this.ori_pos = {x:this.x,y:this.y};
  240. // TODO: don't forget to move ori_pos on window resize
  241. //this.drawSprite();
  242. this.initPhysics();
  243. };
  244. // Node.prototype.drawSprite = function(){
  245. // _ctx.clearRect(0, 0, this.w, this.w);
  246. //
  247. // this.canvas_ctx.beginPath();
  248. // // white background
  249. // this.canvas_ctx.fillRect(0,0,this.w,this.w);
  250. //
  251. // this.canvas_ctx.globalAlpha = this.faded ? 0.15 : 1;
  252. //
  253. // if(this.opened){
  254. // // carre plein
  255. // // this.canvas_ctx.lineWidth = '1px';
  256. // // this.canvas_ctx.strokeStyle = 'rgb(255,0,0)';
  257. // // this.canvas_ctx.strokeRect(this.x - this.r-3,this.y - this.r-3,this.r*2+6,this.r*2+6);
  258. // // ou carre contour
  259. // this.canvas_ctx.save(); // save the normal context state (fill white)
  260. // this.canvas_ctx.fillStyle = _ecolors[this.e_color];
  261. // this.canvas_ctx.fillRect(this.line_width,this.line_width,this.d,this.d);
  262. // this.canvas_ctx.restore(); // restore the normal context state (fill white)
  263. // }
  264. // // else{
  265. // // // carre plein
  266. // // // this.canvas_ctx.fillStyle = _ecolors[this.e_color];
  267. // // // this.canvas_ctx.fillRect(this.x - this.r,this.y - this.r,this.d,this.d);
  268. // // // ou carre contour
  269. // // this.canvas_ctx.fillRect(this.line_width,this.line_width,this.d,this.d);
  270. // // }
  271. // this.canvas_ctx.strokeStyle = _ecolors[this.e_color];
  272. // this.canvas_ctx.strokeRect(this.line_width,this.line_width,this.d,this.d);
  273. // // this.canvas_ctx.globalAlpha = 1;
  274. // this.canvas_ctx.closePath();
  275. // };
  276. Node.prototype.initPhysics = function(){
  277. // particule
  278. this.p = _physics.makeParticle(this.mass, this.x, this.y);
  279. this.p.velocity = new Physics.Vector((Math.random()-0.5)*_p_velocity_factor, (Math.random()-0.5)*_p_velocity_factor);
  280. // origin position particule
  281. this.ori_p = _physics.makeParticle(1000, this.ori_pos.x, this.ori_pos.y);
  282. this.ori_p.fixed = true;
  283. // TODO: don't forget to move ori_p on window resize
  284. this.ori_p_attract = _physics.makeAttraction(this.ori_p, this.p, 1000, _scene_props.width*2);
  285. this.ori_p_attract.on = false;
  286. // attracter
  287. this.attract = _physics.makeAttraction(_attracter, this.p, 1000, _scene_props.width*2);
  288. this.attract.on = false;
  289. };
  290. Node.prototype.calcWallLimits = function(){
  291. this.wall_limits = {
  292. top: _scene_props.margin_top +this.r,
  293. right: _scene_props.width -_scene_props.margin_right -this.r,
  294. bottom: _scene_props.height -_scene_props.margin_bottom -this.r,
  295. left: _scene_props.margin_left +this.r
  296. }
  297. };
  298. Node.prototype.onResizeCanvas = function(){
  299. this.calcWallLimits();
  300. // TODO: scramble only if not aside or centered
  301. this.shuffleOriP();
  302. };
  303. Node.prototype.shuffleOriP = function(){
  304. this.ori_pos.x = this.wall_limits.left + Math.random()*(this.wall_limits.right - this.wall_limits.left);
  305. this.ori_pos.y = this.wall_limits.top + Math.random()*(this.wall_limits.bottom - this.wall_limits.top);
  306. this.scramble();
  307. };
  308. Node.prototype.onUpdate = function(){
  309. // this.p.velocity.multiplyScalar(0.99);
  310. if(this.hover || this.opened){
  311. this.p.fixed = true;
  312. }else{
  313. this.p.fixed = false;
  314. if(this.center)
  315. this.limitEvolutionZone();
  316. // if(!this.p.resting()){
  317. // this.checkVelocityThreshold();
  318. this.checkWallBouncing();
  319. this.updatePos();
  320. if(this.scrambling){
  321. this.checkOriPDist();
  322. }
  323. // }
  324. }
  325. if(_mouse_in && !this.aside && !this.faded)
  326. this.checkMouse();
  327. // this.move();
  328. this.redraw();
  329. };
  330. Node.prototype.checkVelocityThreshold = function(){
  331. if(!this.centered || !this.aside){
  332. if (Math.abs(this.p.velocity.x) < this.velocity_threshold
  333. && Math.abs(this.p.velocity.y) < this.velocity_threshold){
  334. this.p.velocity.multiplyScalar(0);
  335. // this.p.makeFixed();
  336. }
  337. }
  338. };
  339. Node.prototype.checkWallBouncing = function(){
  340. switch(true){
  341. case this.x < this.wall_limits.left && this.p.velocity.x < 0:
  342. this.p.position.x = this.wall_limits.left;
  343. this.p.velocity
  344. .multiplyScalarXY(-1, 1)
  345. .multiplyScalar(this.wall_bouncing_elasticity);
  346. break;
  347. case this.x > this.wall_limits.right && this.p.velocity.x > 0:
  348. this.p.position.x = this.wall_limits.right;
  349. this.p.velocity
  350. .multiplyScalarXY(-1, 1)
  351. .multiplyScalar(this.wall_bouncing_elasticity);
  352. break;
  353. case this.y < this.wall_limits.top && this.p.velocity.y < 0 :
  354. this.p.position.y = this.wall_limits.top;
  355. this.p.velocity
  356. .multiplyScalarXY(1,-1)
  357. .multiplyScalar(this.wall_bouncing_elasticity);
  358. break;
  359. case this.y > this.wall_limits.bottom && this.p.velocity.y > 0 :
  360. this.p.position.y = this.wall_limits.bottom;
  361. this.p.velocity
  362. .multiplyScalarXY(1,-1)
  363. .multiplyScalar(this.wall_bouncing_elasticity);
  364. break;
  365. }
  366. };
  367. Node.prototype.updatePos = function(){
  368. this.x = this.p.position.x;
  369. this.y = this.p.position.y;
  370. };
  371. Node.prototype.checkMouse = function(){
  372. if( _m_pos.x > this.x - this.r
  373. && _m_pos.x < this.x + this.r
  374. && _m_pos.y > this.y - this.r
  375. && _m_pos.y < this.y + this.r){
  376. if(_node_hover_id == -1 || _node_hover_id !== this.id){
  377. // console.log("Node hover", this.id);
  378. this.setHover();
  379. }
  380. }else{
  381. this.unsetHover();
  382. }
  383. };
  384. Node.prototype.setHover = function(){
  385. this.hover = true;
  386. _node_hover_id = this.id;
  387. _node_pop_up.setNode(this);
  388. };
  389. Node.prototype.unsetHover = function(){
  390. this.hover = false;
  391. if (_node_hover_id == this.id) {
  392. _node_hover_id = -1;
  393. _node_pop_up.removeNode();
  394. }
  395. };
  396. Node.prototype.open = function(){
  397. this.opened = true;
  398. _node_opened_id = this.id;
  399. //this.drawSprite();
  400. };
  401. Node.prototype.close = function(){
  402. this.opened = false;
  403. //this.drawSprite();
  404. };
  405. Node.prototype.fade = function(){
  406. this.faded = true;
  407. //this.drawSprite();
  408. };
  409. Node.prototype.unFade = function(){
  410. this.faded = false;
  411. //this.drawSprite();
  412. };
  413. Node.prototype.setCenteredOnEntree = function(tid){
  414. this.e_color = 'e_col_'+tid;
  415. this.setCentered();
  416. };
  417. Node.prototype.setCentered = function(){
  418. this.center = true;
  419. this.stopScrambling();
  420. this.unsetAside();
  421. this.attract.on = true;
  422. //this.drawSprite();
  423. }
  424. Node.prototype.unsetCentered = function(){
  425. this.center = false;
  426. this.attract.on = false;
  427. }
  428. Node.prototype.limitEvolutionZone = function(){
  429. // smouthly slow down node near center
  430. // if(this.id == 1)
  431. // console.log('this.p.velocity', this.p.velocity);
  432. this.dist_to_attracter = this.p.distanceTo(_attracter);
  433. if( this.dist_to_attracter < _scene_props.width/4){
  434. if( this.p.velocity.length() > 0.4 ){
  435. this.p.velocity.multiplyScalar(0.99); // 0.995
  436. }
  437. }
  438. // limit evolution zone
  439. // if( Math.abs(_attracter.position.x - this.x) > _scene_props.width/4
  440. // || Math.abs(_attracter.position.y - this.y) > _scene_props.height/4){
  441. if( this.x < _evolution_zone.left || this.x > _evolution_zone.right
  442. || Math.abs(_attracter.position.y - this.y) > _scene_props.height/4){
  443. this.attract.on = true;
  444. }else{
  445. this.attract.on = false;
  446. }
  447. }
  448. Node.prototype.setAside = function(){
  449. this.aside = true;
  450. // this.fade();
  451. this.stopScrambling();
  452. this.unsetCentered();
  453. this.ori_p.position.x = this.x < _scene_props.width /2 ? this.wall_limits.left : this.wall_limits.right;
  454. this.ori_p_attract.on = true;
  455. this.wall_bouncing_elasticity = 0.15;
  456. }
  457. Node.prototype.unsetAside = function(){
  458. // console.log('unsetAside');
  459. this.aside = false;
  460. this.ori_p_attract.on = false;
  461. this.ori_p.position.x = this.ori_pos.x;
  462. this.wall_bouncing_elasticity = 0.75;
  463. // this.unFade();
  464. }
  465. Node.prototype.resolveNormalPos = function(){
  466. // console.log("resolveNormalPos");
  467. switch(true){
  468. case this.center:
  469. this.unsetCentered();
  470. break;
  471. case this.aside:
  472. this.unsetAside();
  473. break;
  474. }
  475. };
  476. Node.prototype.scramble = function(){
  477. this.scrambling = true;
  478. this.unsetCentered();
  479. this.unsetAside();
  480. this.ori_p.position.x = this.ori_pos.x;
  481. this.ori_p.position.y = this.ori_pos.y;
  482. this.ori_p_attract.on = true;
  483. }
  484. Node.prototype.checkOriPDist = function(){
  485. if(this.p.distanceTo(this.ori_p) < 50){
  486. this.stopScrambling();
  487. }
  488. };
  489. Node.prototype.stopScrambling = function(){
  490. this.scrambling = false;
  491. this.ori_p_attract.on = false;
  492. // this.scramble_TL.on = false;
  493. // this.scramble_TR.on = false;
  494. // this.scramble_BR.on = false;
  495. // this.scramble_BL.on = false;
  496. // this.scramble_CR.on = false;
  497. // this.scramble_CL.on = false;
  498. }
  499. Node.prototype.move = function(){
  500. // just draw the virtual node canvas into the main scene canvas at the right position
  501. _ctx.drawImage(this.canvas, this.x-this.w_2, this.y-this.w_2);
  502. };
  503. Node.prototype.redraw = function(){
  504. _ctx.beginPath();
  505. // white background
  506. _ctx.fillStyle = 'rgb(255,255,255)';
  507. _ctx.fillRect(this.x-this.r,this.y-this.r,this.d,this.d);
  508. _ctx.globalAlpha = this.faded ? 0.15 : 1;
  509. if(this.opened){
  510. // carre plein
  511. // _ctx.lineWidth = '1px';
  512. // _ctx.strokeStyle = 'rgb(255,0,0)';
  513. // _ctx.strokeRect(this.x - this.r-3,this.y - this.r-3,this.r*2+6,this.r*2+6);
  514. // ou carre contour
  515. // _ctx.save(); // save the normal context state (fill white)
  516. _ctx.fillStyle = _ecolors[this.e_color];
  517. _ctx.fillRect(this.x-this.r,this.y-this.r,this.d,this.d);
  518. // _ctx.restore(); // restore the normal context state (fill white)
  519. }
  520. // else{
  521. // // carre plein
  522. // // _ctx.fillStyle = _ecolors[this.e_color];
  523. // // _ctx.fillRect(this.x - this.r,this.y - this.r,this.d,this.d);
  524. // // ou carre contour
  525. // _ctx.fillRect(this.line_width,this.line_width,this.d,this.d);
  526. // }
  527. _ctx.strokeStyle = _ecolors[this.e_color];
  528. _ctx.strokeRect(this.x-this.r,this.y-this.r,this.d,this.d);
  529. // _ctx.globalAlpha = 1;
  530. _ctx.closePath();
  531. };
  532. Node.initialized = true;
  533. }
  534. this.init();
  535. };
  536. // TODO: we may convert a lot of computation into a web worker
  537. // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
  538. function checkParticulesCollisions(){
  539. // do not run particule collision every frames
  540. if(check_parts_colid_tick < check_parts_colid_frq){
  541. check_parts_colid_tick++;
  542. return;
  543. }
  544. check_parts_colid_tick = 1;
  545. // pre create vars to save memory;
  546. var na,nb,
  547. ma,mb,
  548. w,h,dx,dy,
  549. makeup,
  550. newVelX1, newVelY1, newVelX2, newVelY2,
  551. Smamb;
  552. // , angle;
  553. // colisions between _particules
  554. for (var n = 0, l = _nodes.length; n < l; n++) {
  555. na = _nodes[n];
  556. // avoid colliding for scrambling nodes
  557. // avoid colliding for aside nodes
  558. // avoid colliding for centered nodes
  559. if(na.scrambling || na.aside ) continue; //|| na.center
  560. ma = na.p.mass;
  561. for (var q = n+1; q < l; q++) {
  562. nb = _nodes[q];
  563. // avoid impact between center and aside particules
  564. // if((na.center && nb.aside) || (na.aside && nb.center))
  565. // and between aside particules
  566. if(nb.aside)
  567. continue;
  568. // avoid impact between two centered particulses that comes to the center
  569. if(na.center && nb.center){
  570. if(Math.min(na.p.distanceTo(_attracter), nb.p.distanceTo(_attracter)) > 300){
  571. if( Math.random()>0.3 ) continue;
  572. }
  573. }
  574. w = h = (na.r+nb.r);
  575. // if(!na.aside && !nb.aside){
  576. w = h += 4; // add a saftey zone around squares eccept for aside squares
  577. // }
  578. // if both dx and dy are inferior to w & h so squares are colliding (overlapping)
  579. // if( Math.abs(dx) <= w && Math.abs(dy) <= h){ console.log('colliding'); }
  580. // else not so skip
  581. // if( Math.abs(dx) > w || Math.abs(dy) > h) continue;
  582. dx = na.p.position.x - nb.p.position.x;
  583. if( Math.abs(dx) > w ) continue;
  584. dy = na.p.position.y - nb.p.position.y;
  585. if(Math.abs(dy) > h) continue
  586. mb = nb.p.mass;
  587. Smamb = ma+mb;
  588. if(Math.abs(dx) < Math.abs(dy)){ // vertical collision
  589. makeup = (h - Math.abs(dy))/2;
  590. if(dy > 0){ // a is upper than b
  591. na.p.position.y += makeup;
  592. nb.p.position.y -= makeup;
  593. }else{ // b is upper than a
  594. na.p.position.y -= makeup;
  595. nb.p.position.y += makeup;
  596. }
  597. // bounce
  598. // https://en.wikipedia.org/wiki/Elastic_collision#One-dimensional_Newtonian
  599. newVelY1 = (ma-mb)/Smamb*na.p.velocity.y+2*mb/Smamb*nb.p.velocity.y;
  600. newVelY2 = (mb-ma)/Smamb*nb.p.velocity.y+2*ma/Smamb*na.p.velocity.y;
  601. na.p.velocity.y = newVelY1;
  602. nb.p.velocity.y = newVelY2;
  603. }else{ // horizontal collision
  604. makeup = (w - Math.abs(dx))/2;
  605. if(dx > 0){ // a is at left of b
  606. na.p.position.x += makeup;
  607. nb.p.position.x -= makeup;
  608. }else{ // b is at left of a
  609. na.p.position.x -= makeup;
  610. nb.p.position.x += makeup;
  611. }
  612. // bounce
  613. // https://en.wikipedia.org/wiki/Elastic_collision#One-dimensional_Newtonian
  614. newVelX1 = (ma-mb)/Smamb*na.p.velocity.x+2*mb/Smamb*nb.p.velocity.x;
  615. newVelX2 = (mb-ma)/Smamb*nb.p.velocity.x+2*ma/Smamb*na.p.velocity.x;
  616. na.p.velocity.x = newVelX1;
  617. nb.p.velocity.x = newVelX2;
  618. }
  619. // slow down particule on impact
  620. // na.p.velocity.multiplyScalar(na.center && na.p.velocity.length() < 1 ? 1.1 : 0.90);
  621. // nb.p.velocity.multiplyScalar(nb.center && nb.p.velocity.length() < 1 ? 1.1 : 0.90);
  622. na.p.velocity.multiplyScalar(0.90);
  623. nb.p.velocity.multiplyScalar(0.90);
  624. }
  625. }
  626. };
  627. // show opened audio node
  628. function openNodeByNid(nid){
  629. // console.log('Corpus openNode()', nid);
  630. closeNode();
  631. if(typeof _nodes_Nid_Id[nid] != 'undefined'){
  632. // console.log('node exists');
  633. _node_opened_id = _nodes_Nid_Id[nid];
  634. _nodes[_nodes_Nid_Id[nid]].open();
  635. }
  636. }
  637. function closeNode(){
  638. if(_node_opened_id != -1){
  639. // if(typeof _nodes[_node_opened_id] !== 'undefined'){
  640. _nodes[_node_opened_id].close();
  641. // }
  642. _node_opened_id = -1;
  643. }
  644. }
  645. function createNodesRepulsions(){
  646. // how to delete all these attractions before creates new once
  647. //console.log('_nodes_centered', _nodes_centered);
  648. purgeNodesRepulsions();
  649. for (var n = 0; n < _nodes_centered.length; n++) {
  650. for (var q = n+1; q < _nodes_centered.length; q++) {
  651. _physics.makeAttraction(_nodes_centered[n].p, _nodes_centered[q].p, -0.4, 10);
  652. }
  653. }
  654. };
  655. function purgeNodesRepulsions(){
  656. // console.log('_physics.attractions.length', _physics.attractions.length);
  657. for (var a = _physics.attractions.length-1; a >= 0; a--) {
  658. // assuming that only nodes repulsions have constant < 1
  659. // and are all at the end of array
  660. if(Math.abs(_physics.attractions[a].constant) < 1){
  661. _physics.attractions.splice(a,1);
  662. }else{
  663. break;
  664. }
  665. }
  666. // console.log('_physics.attractions.length', _physics.attractions.length);
  667. };
  668. // ___ _ _ _ ____
  669. // | __|_ _____| |_ _| |_(_)___ _ _ |_ /___ _ _ ___
  670. // | _|\ V / _ \ | || | _| / _ \ ' \ / // _ \ ' \/ -_)
  671. // |___|\_/\___/_|\_,_|\__|_\___/_||_| /___\___/_||_\___|
  672. function moveEvolutionZone(l, r){
  673. var left = l || 0;
  674. var right = r || 0;
  675. _evolution_zone.left = Math.max(_scene_props.width/5, left+20);
  676. _evolution_zone.right = Math.min(_scene_props.width - _scene_props.width/5, _scene_props.width-right+20);
  677. _evolution_zone.center = _evolution_zone.left + (_evolution_zone.right - _evolution_zone.left)/2;
  678. // move _attracter to the center of the zone
  679. resizePhysics();
  680. }
  681. // ___ _ ___ _ _ _ _
  682. // | _ \__ _ _ _ __| |___ _ __ | _ \ |__ _ _ _| (_)__| |_
  683. // | / _` | ' \/ _` / _ \ ' \ | _/ / _` | || | | (_-< _|
  684. // |_|_\__,_|_||_\__,_\___/_|_|_| |_| |_\__,_|\_, |_|_/__/\__|
  685. // |__/
  686. function updateRandomPlaylist(p){
  687. _$canvas.trigger({
  688. type:'update-random-playlist',
  689. playlist:p
  690. })
  691. };
  692. // ___ _
  693. // | __|_ _| |_ _ _ ___ ___ ___
  694. // | _|| ' \ _| '_/ -_) -_|_-<
  695. // |___|_||_\__|_| \___\___/__/
  696. function toggleEntree(tid, bubbling){
  697. var $link = _$entrees_block_termlinks.filter('[tid="'+tid+'"]');
  698. var $li = $link.parents('li');
  699. var sys_path = $link.attr('data-drupal-link-system-path');
  700. var url = $link.attr('href');
  701. var title = $link.text();
  702. if(!$li.is('.opened')){
  703. _$entrees_block_termlinks.parents('li').removeClass('opened');
  704. $li.addClass('opened');
  705. $li.parents('.item-list').addClass('opened')
  706. filterEntree(tid);
  707. if(bubbling){
  708. _$body.trigger({
  709. 'type':'open_entree',
  710. 'tid':tid,
  711. 'url':url,
  712. 'sys_path':sys_path,
  713. 'title':title
  714. });
  715. }
  716. // bubbling is true only when event is a real click on entree link
  717. }else if(bubbling){
  718. $li.removeClass('opened');
  719. $li.parents('.item-list').removeClass('opened')
  720. scrambleCollection();
  721. _$body.trigger({'type':'close_entree', 'tid':tid});
  722. }
  723. };
  724. function filterEntree(t){
  725. // shutDownArticles();
  726. _nodes_centered = [];
  727. for (var n = 0; n < _nodes.length; n++) {
  728. if(_nodes[n].entrees.indexOf(t) == -1){
  729. _nodes[n].setAside();
  730. }else{
  731. _nodes[n].setCenteredOnEntree(t);
  732. // record centered nodes for inter node repulsions
  733. _nodes_centered.push(_nodes[n]);
  734. }
  735. }
  736. updateRandomPlaylist(_nodes_centered);
  737. createNodesRepulsions();
  738. };
  739. function highlightEntries(){
  740. _$entrees_block_termlinks
  741. .parents('li').removeClass('highlighted')
  742. .parents('.item-list').removeClass('highlighted');
  743. var id = -1;
  744. if(_node_hover_id != -1){
  745. id = _node_hover_id;
  746. }else if(_node_opened_id != -1){
  747. id = _node_opened_id;
  748. }
  749. var entree;
  750. if(id != -1){
  751. for (var i = 0; i < _nodes[id].entrees.length; i++) {
  752. entree = _nodes[id].entrees[i];
  753. _$entrees_block_termlinks.filter(function(){
  754. return $(this).attr('tid') == entree;
  755. }).parents('li').addClass('highlighted')
  756. .parents('.item-list').addClass('highlighted');
  757. }
  758. }
  759. };
  760. // ___ _
  761. // / __| ___ __ _ _ _ __| |_
  762. // \__ \/ -_) _` | '_/ _| ' \
  763. // |___/\___\__,_|_| \__|_||_|
  764. // and ajax modal content filtering
  765. function filterByNids(nids){
  766. // shutDownArticles();
  767. _nodes_centered = [];
  768. for (var n = 0; n < _nodes.length; n++) {
  769. if(nids.indexOf(_nodes[n].nid) == -1){
  770. _nodes[n].setAside();
  771. }else{
  772. _nodes[n].setCentered();
  773. // record centered nodes for inter node repulsions
  774. _nodes_centered.push(_nodes[n]);
  775. }
  776. }
  777. updateRandomPlaylist(_nodes_centered);
  778. createNodesRepulsions();
  779. };
  780. // ___ _ _ _
  781. // / __| __ _ _ __ _ _ __ | |__| (_)_ _ __ _
  782. // \__ \/ _| '_/ _` | ' \| '_ \ | | ' \/ _` |
  783. // |___/\__|_| \__,_|_|_|_|_.__/_|_|_||_\__, |
  784. // |___/
  785. // function resolveNormalPosAllNodes(){
  786. // console.log('resolveNormalPosAllNodes');
  787. // for (var i = 0; i < _nodes.length; i++) {
  788. // _nodes[i].resolveNormalPos();
  789. // }
  790. // };
  791. function scrambleCollection(){
  792. // console.log('scrambleCollection');
  793. for (var i = 0; i < _nodes.length; i++) {
  794. _nodes[i].scramble();
  795. }
  796. updateRandomPlaylist(_playlist);
  797. // setTimeout(stopScrambling, 2000);
  798. // stopScrambling();
  799. };
  800. function closeAllEntries(){
  801. _$entrees_block_termlinks.each(function(index, el) {
  802. if($(this).parents('li').is('.opened')){
  803. $(this).trigger('click');
  804. return false;
  805. }
  806. });
  807. };
  808. // _ _ _ _
  809. // /_\ _ _| |_(_)__| |___ ___
  810. // / _ \| '_| _| / _| / -_|_-<
  811. // /_/ \_\_| \__|_\__|_\___/__/
  812. function initArtilesLink(){
  813. // add "articles link to blockentrees"
  814. var href = window.location.origin + drupalSettings.path.baseUrl +_settings.articlesindex_url;
  815. _$articles_link = $('<a>')
  816. .html('Articles')
  817. .attr("href", href)
  818. .attr("data-drupal-link-system-path", _settings.articlesindex_url)
  819. .addClass('articles-link ajax-link');
  820. // main.js from template will load the index then trigger the filter here
  821. // .on('click', onCLickedOnArticles);
  822. $('.item-list ul',_$entrees_block).append(
  823. $('<li>').append(
  824. $('<span class="oblique-wrapper">').append(_$articles_link)
  825. )
  826. );
  827. };
  828. // function onCLickedOnArticles(e){
  829. // e.preventDefault();
  830. // $(this).toggleClass('is-active');
  831. // if($(this).is('.is-active')){
  832. // activateArticlesFilter();
  833. // closeAllEntries();
  834. // }else{
  835. // deactivateArticlesFilter();
  836. // }
  837. // // _$canvas.trigger({
  838. // // 'type':'corpus-cliqued-on-articles'
  839. // // });
  840. // return false;
  841. // };
  842. // function activateArticlesFilter(){
  843. // //console.log('activateArticlesFilter');
  844. // _articles_filter_on = true;
  845. // // OPTION 1 : just fade no article nodes
  846. // // for (var i = 0; i < _no_articles_nodes.length; i++) {
  847. // // _no_articles_nodes[i].fade();
  848. // // }
  849. // // END OPTION 1
  850. //
  851. // // OPTION 2 : center the articles nodes and aside others
  852. // closeAllEntries();
  853. // _nodes_centered = [];
  854. // for (var i = 0; i < _articles_nodes.length; i++) {
  855. // _articles_nodes[i].setCentered();
  856. // // record centered nodes for inter node repulsions
  857. // _nodes_centered.push(_articles_nodes[i]);
  858. // }
  859. // for (var i = 0; i < _no_articles_nodes.length; i++) {
  860. // _no_articles_nodes[i].setAside();
  861. // }
  862. // // TODO: open an index of nodes with articles
  863. // // loadArticlesIndex();
  864. // // END OPTION 2
  865. //
  866. // updateRandomPlaylist(_articles_nodes);
  867. // if(typeof _paq !== 'undefined'){
  868. // // trackEvent(category, action, [name], [value])
  869. // _paq.push(['trackEvent', 'Corpus Articles', 'on']);
  870. // }
  871. // };
  872. // function loadArticlesIndex(){
  873. // var path = window.location.origin + drupalSettings.path.baseUrl +_settings.articlesindex_url+'/ajax';
  874. // $.getJSON(path)
  875. // .done(function(data){
  876. // onArticlesIndexLoaded(data);
  877. // })
  878. // .fail(function(jqxhr, textStatus, error){
  879. // onArticlesIndexLoadFail(jqxhr, textStatus, error);
  880. // });
  881. // };
  882. //
  883. // function onArticlesIndexLoaded(data){
  884. // // insert index col
  885. // _$container.find('main[role="main"] .row').append(data.rendered);
  886. //
  887. // // trigger event
  888. // _$body.trigger({
  889. // 'type':'articles-index-loaded',
  890. // 'results':data.results_nids
  891. // });
  892. // };
  893. //
  894. // function onArticlesIndexLoadFail(jqxhr, textStatus, error){
  895. // console.warn('EdlpCorpus : articles index ajax load failed : '+error, jqxhr.responseText);
  896. // };
  897. // function deactivateArticlesFilter(){
  898. // //console.log('deactivateArticlesFilter');
  899. // _articles_filter_on = false;
  900. //
  901. // // OPTION 1 : just fade no article nodes
  902. // // for (var i = 0; i < _no_articles_nodes.length; i++) {
  903. // // _no_articles_nodes[i].unFade();
  904. // // }
  905. //
  906. // // OPTION 2 : centered / aside
  907. // scrambleCollection();
  908. //
  909. // updateRandomPlaylist(_playlist);
  910. // if(typeof _paq !== 'undefined'){
  911. // // trackEvent(category, action, [name], [value])
  912. // _paq.push(['trackEvent', 'Corpus Articles', 'off']);
  913. // }
  914. // };
  915. // function shutDownArticles(){
  916. // shutdown articles if active
  917. // if(_$articles_link.is('.is-active'))
  918. // _$articles_link.trigger('click');
  919. // };
  920. // ___ _
  921. // | __|_ _____ _ _| |_ ___
  922. // | _|\ V / -_) ' \ _(_-<
  923. // |___|\_/\___|_||_\__/__/
  924. function initEvents(){
  925. console.log('Corpus, initEvents');
  926. _$canvas
  927. .on('mousemove', function(event) {
  928. event.preventDefault();
  929. _m_pos.x = event.originalEvent.clientX;
  930. _m_pos.y = event.originalEvent.clientY;
  931. })
  932. .on('mouseenter', function(event){
  933. // console.log('onMouseIN');
  934. _mouse_in = true;
  935. })
  936. .on('mouseout', function(event){
  937. // console.log('onMouseOUT');
  938. _mouse_in = false;
  939. _node_pop_up.removeNode();
  940. })
  941. .on('click', function(event) {
  942. if(event.target.tagName != "A" && event.target.tagName != "INPUT"){
  943. // console.log("Corpus : click");
  944. event.preventDefault();
  945. if(_node_hover_id != -1){
  946. // console.log("corpus : click on node", _nodes[_node_hover_id]);
  947. var event = {
  948. 'type':'corpus-cliked-on-node',
  949. 'target_node':_nodes[_node_hover_id],
  950. // 'article':_articles_filter_on
  951. };
  952. _$canvas.trigger(event);
  953. // instead of directly opening the doc, create an event listener (e.g. : audio played from random)
  954. // openNode(_node_hover_id);
  955. }else{
  956. // console.log('corpus : click on map');
  957. _$canvas.trigger('corpus-cliked-on-map');
  958. // shutDownArticles();
  959. }
  960. }
  961. })
  962. .on('mouseover-audio-link', function(e){
  963. console.log("Corpus on mouseover-audio-link", e);
  964. // _node_hover_id = _nodes_Nid_Id[e.nid];
  965. // _node_pop_up.setNode(_nodes_by_nid[e.nid]);
  966. _nodes_by_nid[e.nid].setHover();
  967. })
  968. .on('mouseout-audio-link', function(e){
  969. console.log("Corpus on mouseover-audio-link", e);
  970. // _node_hover_id = -1;
  971. // _node_pop_up.removeNode();
  972. _nodes_by_nid[e.nid].unsetHover();
  973. })
  974. .on('audio-node-opened', function(e){
  975. // console.log('Corpus audio-node-opened', e);
  976. openNodeByNid(e.nid);
  977. })
  978. .on('audio-node-closed', function(e){
  979. closeNode();
  980. })
  981. .on('open-entree', function(e){
  982. toggleEntree(e.tid);
  983. })
  984. .on('close-all-entree', function(e){
  985. closeAllEntries();
  986. })
  987. .on('scramble-collection', function(e){
  988. console.log('scramble-collection', e);
  989. // resolveNormalPosAllNodes();
  990. scrambleCollection();
  991. })
  992. .on('shuffle-collection', function(e){
  993. console.log('shuffle-collection', e);
  994. onResizeCanvas();
  995. });
  996. _$entrees_block_termlinks.on('click', function(event) {
  997. // console.log('_$entrees_block_termlinks click', this);
  998. event.preventDefault();
  999. toggleEntree($(this).attr('tid'), true);
  1000. // var $link = $(this);
  1001. // var tid = $link.attr('tid');
  1002. // var $li = $link.parents('li');
  1003. // var sys_path = $link.attr('data-drupal-link-system-path');
  1004. // var url = $link.attr('href');
  1005. // if(!$li.is('.opened')){
  1006. // _$entrees_block_termlinks.parents('li').removeClass('opened');
  1007. // $li.addClass('opened');
  1008. // toggleEntree(tid);
  1009. // _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path});
  1010. // }else{
  1011. // $li.removeClass('opened');
  1012. // scrambleCollection();
  1013. // _$body.trigger({'type':'close_entree', 'tid':tid});
  1014. // }
  1015. return false;
  1016. });
  1017. _$body
  1018. .on('chutier-action-done', function(e) {
  1019. _nodes_by_nid[e.target_id].chutier_action = e.new_action;
  1020. })
  1021. .on('ajax-node-loaded-linked-documents', function(e){
  1022. console.log("Edlp Corpus, ajax-node-loaded-linked-documents",e.nids);
  1023. // filter map's nodes
  1024. filterByNids(e.nids);
  1025. })
  1026. .on('search-results-loaded', function(e){
  1027. //console.log("Edlp Corpus, search-results-loaded",e.results);
  1028. // filter map's nodes
  1029. filterByNids(e.results);
  1030. })
  1031. .on('search-closed', function(e){
  1032. scrambleCollection();
  1033. })
  1034. .on('new-content-not-entree-ajax-loaded', function(e){
  1035. // close all entries only if entry already opened
  1036. // TODO: user the function close all entries ?
  1037. // closeAllEntries(); not working, is closing also the ajax loaded content
  1038. if(_$entrees_block_termlinks.parents('li.opened').length){
  1039. _$entrees_block_termlinks
  1040. .parents('li').removeClass('opened')
  1041. .parents('.item-list').removeClass('opened');
  1042. scrambleCollection();
  1043. }
  1044. })
  1045. .on('visible-space-changed', function(e){
  1046. // limits are absolute distance from each side (not positions from left)
  1047. moveEvolutionZone(e.left_limit, e.right_limit);
  1048. });
  1049. };
  1050. function checkPreOpenedEntry(){
  1051. _$entrees_block.find('li.entree').each(function(index, el) {
  1052. var $li = $(this);
  1053. if($('a.is-active', $li).length){
  1054. $li.addClass('opened')
  1055. .parents('.item-list').addClass('opened');
  1056. filterEntree($li.attr('tid'));
  1057. return false;
  1058. }
  1059. });
  1060. };
  1061. // _ _ _ ___ _ _
  1062. // | \| |___ __| |___| _ \___ _ __| | | |_ __
  1063. // | .` / _ \/ _` / -_) _/ _ \ '_ \ |_| | '_ \
  1064. // |_|\_\___/\__,_\___|_| \___/ .__/\___/| .__/
  1065. // |_| |_|
  1066. function initNodePopup(){
  1067. _node_pop_up = new NodePopUp();
  1068. };
  1069. function NodePopUp(){
  1070. this.visible = false;
  1071. this.node;
  1072. this.$dom = $('<div>')
  1073. .addClass('node-popup')
  1074. .attr('pos', 'top-right')
  1075. .appendTo('body');
  1076. this.$content = $('<div>').addClass('inner').appendTo(this.$dom);
  1077. if (typeof NodePopUp.initialized == "undefined") {
  1078. NodePopUp.prototype.setNode = function(n){
  1079. // console.log('NodePopUp setNode()');
  1080. this.node = n;
  1081. // positioning NodePopUp regarding node position
  1082. this.setPositioning();
  1083. // update NodePopUp content
  1084. this.setContent();
  1085. };
  1086. NodePopUp.prototype.setPositioning = function(){
  1087. switch(true){
  1088. case this.node.x > this.node.wall_limits.right-350 && this.node.y < this.node.wall_limits.top+200:
  1089. this.$dom.attr('pos', 'bottom-left');
  1090. break;
  1091. case this.node.x > this.node.wall_limits.right-350:
  1092. this.$dom.attr('pos', 'top-left');
  1093. break;
  1094. case this.node.y < this.node.wall_limits.top+200:
  1095. this.$dom.attr('pos', 'bottom-right');
  1096. break;
  1097. default:
  1098. this.$dom.attr('pos', 'top-right');
  1099. }
  1100. };
  1101. NodePopUp.prototype.setContent = function(){
  1102. // console.log(this.node);
  1103. this.$content.html('');
  1104. var $entrees = $('<div>').addClass('entrees');
  1105. for (var i = 0; i < this.node.entrees.length; i++) {
  1106. var tid = this.node.entrees[i];
  1107. $entrees.append($('<span>').addClass('entree').attr('tid', tid));
  1108. }
  1109. var $chutier_action = $('<span>').addClass('chutier-icon').attr('action', this.node.chutier_action);
  1110. this.$content
  1111. .append($entrees)
  1112. .append('<h2 class="title">'+this.node.title+'</h2>')
  1113. .append('<section class="description">'+this.node.description+'</section>')
  1114. .append($chutier_action);
  1115. };
  1116. NodePopUp.prototype.removeNode = function(){
  1117. // console.log('NodePopUp removeNode()');
  1118. this.node = false;
  1119. };
  1120. NodePopUp.prototype.draw = function(){
  1121. if(this.node){
  1122. this.$dom.css({
  1123. 'display':"block",
  1124. 'left':this.node.x+"px",
  1125. 'top':this.node.y+"px",
  1126. });
  1127. }else{
  1128. this.$dom.css({
  1129. 'display':"none",
  1130. });
  1131. }
  1132. };
  1133. NodePopUp.initialized = true;
  1134. }
  1135. }
  1136. // ___ _
  1137. // | _ \___ _ _ __| |___ _ _
  1138. // | / -_) ' \/ _` / -_) '_|
  1139. // |_|_\___|_||_\__,_\___|_|
  1140. function render(){
  1141. _ctx.clearRect(0, 0, _scene_props.width, _scene_props.height);
  1142. checkParticulesCollisions();
  1143. for (var i = 0; i < _nodes.length; i++) {
  1144. _nodes[i].onUpdate();
  1145. }
  1146. _node_pop_up.draw();
  1147. if(_node_hover_id != -1){
  1148. _canvas.style.cursor = 'pointer';
  1149. }else{
  1150. _canvas.style.cursor = 'auto';
  1151. }
  1152. // check for highlighted entries
  1153. highlightEntries();
  1154. };
  1155. // ___ _ _ _ _
  1156. // / __| |_ __ _ _ _| |_ /_\ _ _ (_)_ __ ___
  1157. // \__ \ _/ _` | '_| _|/ _ \| ' \| | ' \/ -_)
  1158. // |___/\__\__,_|_| \__/_/ \_\_||_|_|_|_|_\___|
  1159. function startAnime(){
  1160. _physics.onUpdate(render);
  1161. _physics.play()
  1162. $('body')
  1163. .attr('corpus', 'map-ready')
  1164. .trigger({
  1165. 'type':'corpus-map-ready',
  1166. 'playlist':_playlist
  1167. });
  1168. };
  1169. init();
  1170. }
  1171. $(document).ready(function($) {
  1172. if(drupalSettings.path.isFront && !edlp_mobile.device_is_mobile){
  1173. var edlpcorpus = new EdlpCorpus();
  1174. }
  1175. });
  1176. })(jQuery, Drupal, drupalSettings);