corpus.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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. console.log("moveEvolutionZone",left,right);
  676. console.log("_scene_props", _scene_props);
  677. _evolution_zone.left =
  678. left == 0
  679. ? left+20
  680. : Math.max(_scene_props.width/5, left+20);
  681. _evolution_zone.right =
  682. right == 0
  683. ? _scene_props.width-right+20
  684. : Math.min(_scene_props.width - _scene_props.width/5, _scene_props.width-right+20);
  685. _evolution_zone.center = _evolution_zone.left + (_evolution_zone.right - _evolution_zone.left)/2;
  686. console.log("moveEvolutionZone",_evolution_zone);
  687. // move _attracter to the center of the zone
  688. resizePhysics();
  689. }
  690. // ___ _ ___ _ _ _ _
  691. // | _ \__ _ _ _ __| |___ _ __ | _ \ |__ _ _ _| (_)__| |_
  692. // | / _` | ' \/ _` / _ \ ' \ | _/ / _` | || | | (_-< _|
  693. // |_|_\__,_|_||_\__,_\___/_|_|_| |_| |_\__,_|\_, |_|_/__/\__|
  694. // |__/
  695. function updateRandomPlaylist(p){
  696. _$canvas.trigger({
  697. type:'update-random-playlist',
  698. playlist:p
  699. })
  700. };
  701. // ___ _
  702. // | __|_ _| |_ _ _ ___ ___ ___
  703. // | _|| ' \ _| '_/ -_) -_|_-<
  704. // |___|_||_\__|_| \___\___/__/
  705. function toggleEntree(tid, bubbling){
  706. var $link = _$entrees_block_termlinks.filter('[tid="'+tid+'"]');
  707. var $li = $link.parents('li');
  708. var sys_path = $link.attr('data-drupal-link-system-path');
  709. var url = $link.attr('href');
  710. var title = $link.text();
  711. if(!$li.is('.opened')){
  712. _$entrees_block_termlinks.parents('li').removeClass('opened');
  713. $li.addClass('opened');
  714. $li.parents('.item-list').addClass('opened')
  715. filterEntree(tid);
  716. if(bubbling){
  717. _$body.trigger({
  718. 'type':'open_entree',
  719. 'tid':tid,
  720. 'url':url,
  721. 'sys_path':sys_path,
  722. 'title':title
  723. });
  724. }
  725. // bubbling is true only when event is a real click on entree link
  726. }else if(bubbling){
  727. $li.removeClass('opened');
  728. $li.parents('.item-list').removeClass('opened')
  729. scrambleCollection();
  730. _$body.trigger({'type':'close_entree', 'tid':tid});
  731. }
  732. };
  733. function filterEntree(t){
  734. // shutDownArticles();
  735. _nodes_centered = [];
  736. for (var n = 0; n < _nodes.length; n++) {
  737. if(_nodes[n].entrees.indexOf(t) == -1){
  738. _nodes[n].setAside();
  739. }else{
  740. _nodes[n].setCenteredOnEntree(t);
  741. // record centered nodes for inter node repulsions
  742. _nodes_centered.push(_nodes[n]);
  743. }
  744. }
  745. updateRandomPlaylist(_nodes_centered);
  746. createNodesRepulsions();
  747. };
  748. function highlightEntries(){
  749. _$entrees_block_termlinks
  750. .parents('li').removeClass('highlighted')
  751. .parents('.item-list').removeClass('highlighted');
  752. var id = -1;
  753. if(_node_hover_id != -1){
  754. id = _node_hover_id;
  755. }else if(_node_opened_id != -1){
  756. id = _node_opened_id;
  757. }
  758. var entree;
  759. if(id != -1){
  760. for (var i = 0; i < _nodes[id].entrees.length; i++) {
  761. entree = _nodes[id].entrees[i];
  762. _$entrees_block_termlinks.filter(function(){
  763. return $(this).attr('tid') == entree;
  764. }).parents('li').addClass('highlighted')
  765. .parents('.item-list').addClass('highlighted');
  766. }
  767. }
  768. };
  769. // ___ _
  770. // / __| ___ __ _ _ _ __| |_
  771. // \__ \/ -_) _` | '_/ _| ' \
  772. // |___/\___\__,_|_| \__|_||_|
  773. // and ajax modal content filtering
  774. function filterByNids(nids){
  775. // shutDownArticles();
  776. _nodes_centered = [];
  777. for (var n = 0; n < _nodes.length; n++) {
  778. if(nids.indexOf(_nodes[n].nid) == -1){
  779. _nodes[n].setAside();
  780. }else{
  781. _nodes[n].setCentered();
  782. // record centered nodes for inter node repulsions
  783. _nodes_centered.push(_nodes[n]);
  784. }
  785. }
  786. updateRandomPlaylist(_nodes_centered);
  787. createNodesRepulsions();
  788. };
  789. // ___ _ _ _
  790. // / __| __ _ _ __ _ _ __ | |__| (_)_ _ __ _
  791. // \__ \/ _| '_/ _` | ' \| '_ \ | | ' \/ _` |
  792. // |___/\__|_| \__,_|_|_|_|_.__/_|_|_||_\__, |
  793. // |___/
  794. // function resolveNormalPosAllNodes(){
  795. // console.log('resolveNormalPosAllNodes');
  796. // for (var i = 0; i < _nodes.length; i++) {
  797. // _nodes[i].resolveNormalPos();
  798. // }
  799. // };
  800. function scrambleCollection(){
  801. // console.log('scrambleCollection');
  802. for (var i = 0; i < _nodes.length; i++) {
  803. _nodes[i].scramble();
  804. }
  805. updateRandomPlaylist(_playlist);
  806. // setTimeout(stopScrambling, 2000);
  807. // stopScrambling();
  808. };
  809. function closeAllEntries(){
  810. _$entrees_block_termlinks.each(function(index, el) {
  811. if($(this).parents('li').is('.opened')){
  812. $(this).trigger('click');
  813. return false;
  814. }
  815. });
  816. };
  817. // _ _ _ _
  818. // /_\ _ _| |_(_)__| |___ ___
  819. // / _ \| '_| _| / _| / -_|_-<
  820. // /_/ \_\_| \__|_\__|_\___/__/
  821. function initArtilesLink(){
  822. // add "articles link to blockentrees"
  823. var href = window.location.origin + drupalSettings.path.baseUrl +_settings.articlesindex_url;
  824. _$articles_link = $('<a>')
  825. .html('Articles')
  826. .attr("href", href)
  827. .attr("data-drupal-link-system-path", _settings.articlesindex_url)
  828. .addClass('articles-link ajax-link');
  829. // main.js from template will load the index then trigger the filter here
  830. // .on('click', onCLickedOnArticles);
  831. $('.item-list ul',_$entrees_block).append(
  832. $('<li>').append(
  833. $('<span class="oblique-wrapper">').append(_$articles_link)
  834. )
  835. );
  836. };
  837. // function onCLickedOnArticles(e){
  838. // e.preventDefault();
  839. // $(this).toggleClass('is-active');
  840. // if($(this).is('.is-active')){
  841. // activateArticlesFilter();
  842. // closeAllEntries();
  843. // }else{
  844. // deactivateArticlesFilter();
  845. // }
  846. // // _$canvas.trigger({
  847. // // 'type':'corpus-cliqued-on-articles'
  848. // // });
  849. // return false;
  850. // };
  851. // function activateArticlesFilter(){
  852. // //console.log('activateArticlesFilter');
  853. // _articles_filter_on = true;
  854. // // OPTION 1 : just fade no article nodes
  855. // // for (var i = 0; i < _no_articles_nodes.length; i++) {
  856. // // _no_articles_nodes[i].fade();
  857. // // }
  858. // // END OPTION 1
  859. //
  860. // // OPTION 2 : center the articles nodes and aside others
  861. // closeAllEntries();
  862. // _nodes_centered = [];
  863. // for (var i = 0; i < _articles_nodes.length; i++) {
  864. // _articles_nodes[i].setCentered();
  865. // // record centered nodes for inter node repulsions
  866. // _nodes_centered.push(_articles_nodes[i]);
  867. // }
  868. // for (var i = 0; i < _no_articles_nodes.length; i++) {
  869. // _no_articles_nodes[i].setAside();
  870. // }
  871. // // TODO: open an index of nodes with articles
  872. // // loadArticlesIndex();
  873. // // END OPTION 2
  874. //
  875. // updateRandomPlaylist(_articles_nodes);
  876. // if(typeof _paq !== 'undefined'){
  877. // // trackEvent(category, action, [name], [value])
  878. // _paq.push(['trackEvent', 'Corpus Articles', 'on']);
  879. // }
  880. // };
  881. // function loadArticlesIndex(){
  882. // var path = window.location.origin + drupalSettings.path.baseUrl +_settings.articlesindex_url+'/ajax';
  883. // $.getJSON(path)
  884. // .done(function(data){
  885. // onArticlesIndexLoaded(data);
  886. // })
  887. // .fail(function(jqxhr, textStatus, error){
  888. // onArticlesIndexLoadFail(jqxhr, textStatus, error);
  889. // });
  890. // };
  891. //
  892. // function onArticlesIndexLoaded(data){
  893. // // insert index col
  894. // _$container.find('main[role="main"] .row').append(data.rendered);
  895. //
  896. // // trigger event
  897. // _$body.trigger({
  898. // 'type':'articles-index-loaded',
  899. // 'results':data.results_nids
  900. // });
  901. // };
  902. //
  903. // function onArticlesIndexLoadFail(jqxhr, textStatus, error){
  904. // console.warn('EdlpCorpus : articles index ajax load failed : '+error, jqxhr.responseText);
  905. // };
  906. // function deactivateArticlesFilter(){
  907. // //console.log('deactivateArticlesFilter');
  908. // _articles_filter_on = false;
  909. //
  910. // // OPTION 1 : just fade no article nodes
  911. // // for (var i = 0; i < _no_articles_nodes.length; i++) {
  912. // // _no_articles_nodes[i].unFade();
  913. // // }
  914. //
  915. // // OPTION 2 : centered / aside
  916. // scrambleCollection();
  917. //
  918. // updateRandomPlaylist(_playlist);
  919. // if(typeof _paq !== 'undefined'){
  920. // // trackEvent(category, action, [name], [value])
  921. // _paq.push(['trackEvent', 'Corpus Articles', 'off']);
  922. // }
  923. // };
  924. // function shutDownArticles(){
  925. // shutdown articles if active
  926. // if(_$articles_link.is('.is-active'))
  927. // _$articles_link.trigger('click');
  928. // };
  929. // ___ _
  930. // | __|_ _____ _ _| |_ ___
  931. // | _|\ V / -_) ' \ _(_-<
  932. // |___|\_/\___|_||_\__/__/
  933. function initEvents(){
  934. console.log('Corpus, initEvents');
  935. _$canvas
  936. .on('mousemove', function(event) {
  937. event.preventDefault();
  938. _m_pos.x = event.originalEvent.clientX;
  939. _m_pos.y = event.originalEvent.clientY;
  940. })
  941. .on('mouseenter', function(event){
  942. // console.log('onMouseIN');
  943. _mouse_in = true;
  944. })
  945. .on('mouseout', function(event){
  946. // console.log('onMouseOUT');
  947. _mouse_in = false;
  948. _node_pop_up.removeNode();
  949. })
  950. .on('click', function(event) {
  951. if(event.target.tagName != "A" && event.target.tagName != "INPUT"){
  952. // console.log("Corpus : click");
  953. event.preventDefault();
  954. if(_node_hover_id != -1){
  955. // console.log("corpus : click on node", _nodes[_node_hover_id]);
  956. var event = {
  957. 'type':'corpus-cliked-on-node',
  958. 'target_node':_nodes[_node_hover_id],
  959. // 'article':_articles_filter_on
  960. };
  961. _$canvas.trigger(event);
  962. // instead of directly opening the doc, create an event listener (e.g. : audio played from random)
  963. // openNode(_node_hover_id);
  964. }else{
  965. // console.log('corpus : click on map');
  966. _$canvas.trigger('corpus-cliked-on-map');
  967. // shutDownArticles();
  968. }
  969. }
  970. })
  971. .on('mouseover-audio-link', function(e){
  972. console.log("Corpus on mouseover-audio-link", e);
  973. // _node_hover_id = _nodes_Nid_Id[e.nid];
  974. // _node_pop_up.setNode(_nodes_by_nid[e.nid]);
  975. _nodes_by_nid[e.nid].setHover();
  976. })
  977. .on('mouseout-audio-link', function(e){
  978. console.log("Corpus on mouseover-audio-link", e);
  979. // _node_hover_id = -1;
  980. // _node_pop_up.removeNode();
  981. _nodes_by_nid[e.nid].unsetHover();
  982. })
  983. .on('audio-node-opened', function(e){
  984. // console.log('Corpus audio-node-opened', e);
  985. openNodeByNid(e.nid);
  986. })
  987. .on('audio-node-closed', function(e){
  988. closeNode();
  989. })
  990. .on('open-entree', function(e){
  991. toggleEntree(e.tid);
  992. })
  993. .on('close-all-entree', function(e){
  994. closeAllEntries();
  995. })
  996. .on('scramble-collection', function(e){
  997. console.log('scramble-collection', e);
  998. // resolveNormalPosAllNodes();
  999. scrambleCollection();
  1000. })
  1001. .on('shuffle-collection', function(e){
  1002. console.log('shuffle-collection', e);
  1003. onResizeCanvas();
  1004. });
  1005. _$entrees_block_termlinks.on('click', function(event) {
  1006. // console.log('_$entrees_block_termlinks click', this);
  1007. event.preventDefault();
  1008. toggleEntree($(this).attr('tid'), true);
  1009. // var $link = $(this);
  1010. // var tid = $link.attr('tid');
  1011. // var $li = $link.parents('li');
  1012. // var sys_path = $link.attr('data-drupal-link-system-path');
  1013. // var url = $link.attr('href');
  1014. // if(!$li.is('.opened')){
  1015. // _$entrees_block_termlinks.parents('li').removeClass('opened');
  1016. // $li.addClass('opened');
  1017. // toggleEntree(tid);
  1018. // _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path});
  1019. // }else{
  1020. // $li.removeClass('opened');
  1021. // scrambleCollection();
  1022. // _$body.trigger({'type':'close_entree', 'tid':tid});
  1023. // }
  1024. return false;
  1025. });
  1026. _$body
  1027. .on('chutier-action-done', function(e) {
  1028. _nodes_by_nid[e.target_id].chutier_action = e.new_action;
  1029. })
  1030. .on('ajax-node-loaded-linked-documents', function(e){
  1031. console.log("Edlp Corpus, ajax-node-loaded-linked-documents",e.nids);
  1032. // filter map's nodes
  1033. filterByNids(e.nids);
  1034. })
  1035. .on('search-results-loaded', function(e){
  1036. //console.log("Edlp Corpus, search-results-loaded",e.results);
  1037. // filter map's nodes
  1038. filterByNids(e.results);
  1039. })
  1040. .on('search-closed', function(e){
  1041. scrambleCollection();
  1042. })
  1043. .on('new-content-not-entree-ajax-loaded', function(e){
  1044. // close all entries only if entry already opened
  1045. // TODO: user the function close all entries ?
  1046. // closeAllEntries(); not working, is closing also the ajax loaded content
  1047. if(_$entrees_block_termlinks.parents('li.opened').length){
  1048. _$entrees_block_termlinks
  1049. .parents('li').removeClass('opened')
  1050. .parents('.item-list').removeClass('opened');
  1051. scrambleCollection();
  1052. }
  1053. })
  1054. .on('visible-space-changed', function(e){
  1055. // limits are absolute distance from each side (not positions from left)
  1056. moveEvolutionZone(e.left_limit, e.right_limit);
  1057. });
  1058. };
  1059. function checkPreOpenedEntry(){
  1060. _$entrees_block.find('li.entree').each(function(index, el) {
  1061. var $li = $(this);
  1062. if($('a.is-active', $li).length){
  1063. $li.addClass('opened')
  1064. .parents('.item-list').addClass('opened');
  1065. filterEntree($li.attr('tid'));
  1066. return false;
  1067. }
  1068. });
  1069. };
  1070. // _ _ _ ___ _ _
  1071. // | \| |___ __| |___| _ \___ _ __| | | |_ __
  1072. // | .` / _ \/ _` / -_) _/ _ \ '_ \ |_| | '_ \
  1073. // |_|\_\___/\__,_\___|_| \___/ .__/\___/| .__/
  1074. // |_| |_|
  1075. function initNodePopup(){
  1076. _node_pop_up = new NodePopUp();
  1077. };
  1078. function NodePopUp(){
  1079. this.visible = false;
  1080. this.node;
  1081. this.$dom = $('<div>')
  1082. .addClass('node-popup')
  1083. .attr('pos', 'top-right')
  1084. .appendTo('body');
  1085. this.$content = $('<div>').addClass('inner').appendTo(this.$dom);
  1086. if (typeof NodePopUp.initialized == "undefined") {
  1087. NodePopUp.prototype.setNode = function(n){
  1088. // console.log('NodePopUp setNode()');
  1089. this.node = n;
  1090. // positioning NodePopUp regarding node position
  1091. this.setPositioning();
  1092. // update NodePopUp content
  1093. this.setContent();
  1094. };
  1095. NodePopUp.prototype.setPositioning = function(){
  1096. // switch(true){
  1097. // case this.node.x > this.node.wall_limits.right-350-_evolution_zone.right && this.node.y < this.node.wall_limits.top+200:
  1098. // this.$dom.attr('pos', 'bottom-left');
  1099. // break;
  1100. // case this.node.x > this.node.wall_limits.right-350-_evolution_zone.right:
  1101. // this.$dom.attr('pos', 'top-left');
  1102. // break;
  1103. // case this.node.y < this.node.wall_limits.top+200:
  1104. // this.$dom.attr('pos', 'bottom-right');
  1105. // break;
  1106. // default:
  1107. // this.$dom.attr('pos', 'top-right');
  1108. // }
  1109. switch(true){
  1110. case this.node.x > _evolution_zone.right-350 && this.node.y < this.node.wall_limits.top+200:
  1111. this.$dom.attr('pos', 'bottom-left');
  1112. break;
  1113. case this.node.x > _evolution_zone.right-350:
  1114. this.$dom.attr('pos', 'top-left');
  1115. break;
  1116. case this.node.y < this.node.wall_limits.top+200:
  1117. this.$dom.attr('pos', 'bottom-right');
  1118. break;
  1119. default:
  1120. this.$dom.attr('pos', 'top-right');
  1121. }
  1122. };
  1123. NodePopUp.prototype.setContent = function(){
  1124. // console.log(this.node);
  1125. this.$content.html('');
  1126. var $entrees = $('<div>').addClass('entrees');
  1127. for (var i = 0; i < this.node.entrees.length; i++) {
  1128. var tid = this.node.entrees[i];
  1129. $entrees.append($('<span>').addClass('entree').attr('tid', tid));
  1130. }
  1131. var $chutier_action = $('<span>').addClass('chutier-icon').attr('action', this.node.chutier_action);
  1132. this.$content
  1133. .append($entrees)
  1134. .append('<h2 class="title">'+this.node.title+'</h2>')
  1135. .append('<section class="description">'+this.node.description+'</section>')
  1136. .append($chutier_action);
  1137. };
  1138. NodePopUp.prototype.removeNode = function(){
  1139. // console.log('NodePopUp removeNode()');
  1140. this.node = false;
  1141. };
  1142. NodePopUp.prototype.draw = function(){
  1143. if(this.node){
  1144. this.$dom.css({
  1145. 'display':"block",
  1146. 'left':this.node.x+"px",
  1147. 'top':this.node.y+"px",
  1148. });
  1149. }else{
  1150. this.$dom.css({
  1151. 'display':"none",
  1152. });
  1153. }
  1154. };
  1155. NodePopUp.initialized = true;
  1156. }
  1157. }
  1158. // ___ _
  1159. // | _ \___ _ _ __| |___ _ _
  1160. // | / -_) ' \/ _` / -_) '_|
  1161. // |_|_\___|_||_\__,_\___|_|
  1162. function render(){
  1163. _ctx.clearRect(0, 0, _scene_props.width, _scene_props.height);
  1164. checkParticulesCollisions();
  1165. for (var i = 0; i < _nodes.length; i++) {
  1166. _nodes[i].onUpdate();
  1167. }
  1168. _node_pop_up.draw();
  1169. if(_node_hover_id != -1){
  1170. _canvas.style.cursor = 'pointer';
  1171. }else{
  1172. _canvas.style.cursor = 'auto';
  1173. }
  1174. // check for highlighted entries
  1175. highlightEntries();
  1176. };
  1177. // ___ _ _ _ _
  1178. // / __| |_ __ _ _ _| |_ /_\ _ _ (_)_ __ ___
  1179. // \__ \ _/ _` | '_| _|/ _ \| ' \| | ' \/ -_)
  1180. // |___/\__\__,_|_| \__/_/ \_\_||_|_|_|_|_\___|
  1181. function startAnime(){
  1182. _physics.onUpdate(render);
  1183. _physics.play()
  1184. $('body')
  1185. .attr('corpus', 'map-ready')
  1186. .trigger({
  1187. 'type':'corpus-map-ready',
  1188. 'playlist':_playlist
  1189. });
  1190. };
  1191. init();
  1192. }
  1193. $(document).ready(function($) {
  1194. if(drupalSettings.path.isFront && !edlp_mobile.device_is_mobile){
  1195. var edlpcorpus = new EdlpCorpus();
  1196. }
  1197. });
  1198. })(jQuery, Drupal, drupalSettings);