script.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. // addClass
  2. function Cmaplink() {
  3. }
  4. // Streetmap
  5. function map() {
  6. var mymap = L.map('mapid').setView([48.9367935,2.3569287], 17);
  7. setTimeout(mymap.invalidateSize.bind(map));
  8. L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
  9. maxZoom: 18,
  10. id: 'mapbox.streets'
  11. }).addTo(mymap);
  12. var LeafIcon = L.Icon.extend({
  13. options: {
  14. iconSize: [15, 49],
  15. iconAnchor: [7.5, 5],
  16. }
  17. });
  18. var markers = {};
  19. var greenIcon = new LeafIcon({iconUrl: 'user/themes/r2c/images/pointeur2.svg'})
  20. for (var i = 0; i < dyn_data.mappoints.length; i++) {
  21. var id = dyn_data.mappoints[i].id;
  22. markers[id] = L.marker([dyn_data.mappoints[i].lat, dyn_data.mappoints[i].long], {icon: greenIcon}).bindPopup(dyn_data.mappoints[i].title).addTo(mymap);
  23. // console.log("dyn_datad2", dyn_data.mappoints[i].title);
  24. markers[id]._icon.id = id;
  25. }
  26. var mappoints = $('#streetmap img');
  27. for (var i = 0; i < dyn_data.mappoints.length; i++) {
  28. var target = dyn_data.mappoints[i].target;
  29. console.log('target',target);
  30. mappoints.attr('href', target );
  31. }
  32. };
  33. // change mouse_event
  34. function clickhand(){
  35. $(".handler").on("mousedown", function (e) {
  36. e.preventDefault();
  37. $(this).addClass("mouseDown");
  38. }).on("mouseup", function () {
  39. $(this).removeClass("mouseDown");
  40. });
  41. };
  42. function drag() {
  43. var $hand = $( ".handler" );
  44. var $hand1 = $( ".hand1" );
  45. var $hand2 = $( ".hand2" );
  46. var p = 100;
  47. //marge
  48. var mrg = 1;
  49. // Blocs
  50. // find
  51. var $recits = $hand.parents('#page').find('#recits');
  52. var $itw = $hand.parents('#page').find("#interviews");
  53. var $img = $hand.parents('#page').find("#images");
  54. var $stmp = $hand.parents('#page').find("#streetmap");
  55. var $rs = $hand.parents('#page').find("#reseaux-sociaux");
  56. var $links = $hand.parents('#page').find("#links");
  57. // handler
  58. // dimension
  59. var $Whand = parseFloat($hand.outerWidth(true));
  60. var $Hhand = parseFloat($hand.outerHeight(true));
  61. $hand1.draggable({
  62. containment: "#start",
  63. scroll: false,
  64. drag: function(event, ui){
  65. var oW = parseFloat($("#start").outerWidth(true));
  66. var oH = parseFloat($("#start").outerHeight(true));
  67. var ajustH = (100 * ( 25/ oH )) + "%";
  68. var stophand = (0.8 * oW) - 130;
  69. ui.position.left = Math.max( 200, ui.position.left );
  70. ui.position.left = Math.min( stophand, ui.position.left );
  71. // handler
  72. // position
  73. var pos = $hand1.position();
  74. var pos1 = $hand2.position();
  75. var pos11 = parseFloat(pos1.left) + 25;
  76. // center handler
  77. var ajustW = $Whand / 2;
  78. var ajustH = $Hhand / 2;
  79. // position XY
  80. var xPos = ( p * parseFloat( ((ui.position.left)) / oW) ) + "%" ;
  81. var yPos = ( p * parseFloat( ((ui.position.top)) / oH ) ) + "%" ;
  82. var xPos2 = ( p * parseFloat( ((ui.position.left ) ) / oW) ) + "%";
  83. var yPos2 = ( p * parseFloat( ((ui.position.top ) ) / oH) ) + "%" ;
  84. var xPos3 = ( p * parseFloat( (pos1.left + ajustW) / oW) ) + "%";
  85. var yPos3 = ( p * parseFloat( (ui.position.top ) / oH) ) + "%" ;
  86. //handler2
  87. var $handler2 = $(this).parent().find('.hand2');
  88. var PosHand = ( parseFloat(p * parseFloat((pos11 - 25) / oW)) - parseFloat(p * parseFloat( (ui.position.left) / oW)) ) + "%";
  89. // application dimension
  90. $hand2.css({
  91. 'top': yPos3,
  92. })
  93. $recits.css({
  94. "width": xPos,
  95. "height": yPos,
  96. "left": "-2px",
  97. })
  98. $itw.css({
  99. "left":xPos2,
  100. "width": PosHand,
  101. "height": yPos,
  102. "min-width": "200px"
  103. })
  104. $img.css({
  105. "height": yPos,
  106. "min-width": "200px",
  107. })
  108. $stmp.css({
  109. "width":xPos,
  110. "top": yPos2,
  111. "bottom":"1px",
  112. "height": 'auto',
  113. })
  114. $links.css({
  115. "top": yPos2,
  116. "left":xPos2,
  117. "width":PosHand,
  118. "bottom":"1px",
  119. "height": 'auto',
  120. })
  121. $rs.css({
  122. "top": yPos2,
  123. "bottom":0,
  124. "height": 'auto',
  125. })
  126. // if itw < 200
  127. var testPourcent = parseFloat( p * parseFloat(ui.position.left + 238) / oW ) + "%";
  128. var img200 = parseFloat( p * parseFloat( (oW - (pos11 - 25 )) / oW) ) + "%" ;
  129. if ( $itw.width() < 200) {
  130. $img.css({
  131. "width": img200,
  132. })
  133. $rs.css({
  134. "width": img200,
  135. })
  136. $hand2.css({
  137. 'left':testPourcent,
  138. })
  139. } else {}
  140. },
  141. stop: function( event, ui ) {
  142. var parent = $(this).parents('#start');
  143. $(this).css({
  144. left:parseInt($(this).css('left'))/parent.width()*100+"%",
  145. top: parseInt($(this).css('top'))/parent.height()*100+"%",
  146. });
  147. },
  148. });
  149. $hand2.draggable({
  150. containment: "#start",
  151. scroll: false,
  152. drag: function(event, ui){
  153. var oW = parseFloat($("#start").outerWidth(true));
  154. var oH = parseFloat($("#start").outerHeight(true));
  155. var stophand = (oW - 200) - 50;
  156. console.log(stophand)
  157. ui.position.left = Math.max( 400, ui.position.left );
  158. ui.position.left = Math.min( stophand, ui.position.left );
  159. // handler
  160. // position
  161. var pos = $hand1.position();
  162. var pos1 = $hand2.position();
  163. var pos11 = parseFloat(pos.left) + 25;
  164. // center
  165. var ajustW = $Whand / 2 - 1;
  166. var ajustH = $Hhand / 2 + 1;
  167. var ajustW200 = $Whand / 2 + 6;
  168. var ajustW2 = $Whand / 2 + 1;
  169. var ajustH2 = $Hhand / 2 + 1;
  170. var ajustW3 = $Whand / 2 + 3;
  171. var ajustH3 = $Hhand / 2 + 1;
  172. // position XY
  173. var xPos = ( p * parseFloat( ( oW - (ui.position.left) ) / oW) + "%" );
  174. var yPos = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  175. var xPos2 = ( p * parseFloat( ( oW - (ui.position.left) ) / oW ) ) + "%";
  176. var yPos2 = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  177. // var xPos3 = ( p * parseFloat( (oW - (pos.left)) / oW ) ) + "%";
  178. var xPos3 = ( p * parseFloat( (pos1.left + ajustW) / oW) ) + "%";
  179. var yPos3 = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  180. //handler2
  181. var $handler2 = $(this).parent().find('.hand2');
  182. var PosHand = (parseFloat(xPos3) - parseFloat(xPos)) + "%";
  183. var PosHand1 = ( parseFloat(p * parseFloat( (ui.position.left) / oW)) - parseFloat(p * parseFloat((pos11 - 25) / oW))) + "%";
  184. // application dimension
  185. $hand1.css({
  186. 'top': yPos3,
  187. })
  188. $recits.css({
  189. "height": yPos,
  190. })
  191. $itw.css({
  192. "width": PosHand1,
  193. "height": yPos,
  194. })
  195. $img.css({
  196. "width": xPos,
  197. "height": yPos,
  198. })
  199. $stmp.css({
  200. "top": yPos2,
  201. "bottom":"1px",
  202. "height": 'auto',
  203. })
  204. $rs.css({
  205. "width":xPos,
  206. "top": yPos2,
  207. "bottom":0,
  208. "height": 'auto',
  209. })
  210. $links.css({
  211. "top": yPos2,
  212. "width":PosHand1,
  213. "bottom":"1px",
  214. "height": 'auto',
  215. })
  216. // if itw < 200
  217. var test = ui.position.left - 225;
  218. var testPourcent = ( p * parseFloat(test) / oW ) + "%";
  219. var img200 = ( p * parseFloat( ((pos.left) ) / oW) + "%" );
  220. if ( $itw.width() < 200) {
  221. $recits.css({
  222. "width": img200,
  223. })
  224. $stmp.css({
  225. "width": img200,
  226. })
  227. $itw.css({
  228. "left": img200,
  229. })
  230. $links.css({
  231. "left": img200,
  232. })
  233. $hand1.css({
  234. 'left':test,
  235. })
  236. }else {}
  237. },
  238. stop: function( event, ui ) {
  239. var parent = $(this).parents("#start");
  240. $(this).css({
  241. left:parseInt($(this).css('left'))/parent.width()*100+"%",
  242. top: parseInt($(this).css('top'))/parent.height()*100+"%",
  243. });
  244. },
  245. });
  246. };
  247. // draggable
  248. function dragcanvas() {
  249. var $reseau = $('#reseaux-sociaux canvas');
  250. var $links = $('#links svg')
  251. $links.draggable({
  252. scroll: false
  253. });
  254. $reseau.draggable({
  255. scroll: false
  256. });
  257. }
  258. // hidden scroll + synchro
  259. function mCustomScrollbar() {
  260. $('.blocs').mCustomScrollbar({
  261. mouseWheel:{
  262. deltaFactor: 5
  263. },
  264. scrollInertia: 1000,
  265. });
  266. $(document).on("click","a[href^='#'],#links .nodes text[href^='#'],#streetmap img[href^='#']",function(e){
  267. e.preventDefault();
  268. var hrefs = $(this).attr("href").split(',');
  269. console.log('hrefs', hrefs);
  270. var h, h_parts;
  271. for (var i = 0; i < hrefs.length; i++) {
  272. h = hrefs[i];
  273. h_parts = h.match(/^#(([^_]+)_(.+)$)/);
  274. console.log('h_parts', h_parts);
  275. function scrollTo() {
  276. var href = target.find(h_parts[0]);
  277. e.preventDefault();
  278. target.mCustomScrollbar("scrollTo",href,{
  279. scrollInertia:1000,
  280. });
  281. }
  282. switch (h_parts[2]) {
  283. case 'rct':
  284. var target = $('#recits.mCustomScrollbar');
  285. scrollTo();
  286. break;
  287. case 'int':
  288. var target = $('#interviews.mCustomScrollbar');
  289. scrollTo();
  290. break;
  291. case 'img':
  292. var target = $('#images.mCustomScrollbar');
  293. scrollTo();
  294. break;
  295. case 'mp':
  296. var target = $('#streetmap.mCustomScrollbar');
  297. scrollTo();
  298. break;
  299. case 'lk':
  300. var target = $('#links.mCustomScrollbar');
  301. scrollTo();
  302. var href = target.find(h_parts[0]);
  303. var text = $('.nodes text.group1');
  304. var text2 = $('.nodes text.group2');
  305. var text3 = $('.nodes text.group3');
  306. console.log('cc');
  307. text.css({
  308. 'font-size':'inherit',
  309. 'fill':'black',
  310. });
  311. text2.css({
  312. 'font-size':'inherit',
  313. 'fill':'grey',
  314. });
  315. text3.css({
  316. 'font-size':'inherit',
  317. 'fill':'lightgrey',
  318. });
  319. if (href) {
  320. href.css({
  321. 'font-size':'1.2rem',
  322. 'fill':'blue',
  323. });
  324. }
  325. break;
  326. // case 'rs':
  327. // var target = $('#reseaux-sociaux.mCustomScrollbar');
  328. // scrollTo();
  329. // break;
  330. // case '':
  331. // etc
  332. // break;
  333. default:
  334. }
  335. }
  336. });
  337. }
  338. function clicklinkmap() {
  339. $("text#lk_martine").on("click", function(){
  340. // var href = target.find(h_parts[0]);
  341. // var text = $('.nodes text.group1');
  342. // var text2 = $('.nodes text.group2');
  343. // var text3 = $('.nodes text.group3');
  344. // text.css({
  345. // 'font-size':'inherit',
  346. // 'fill':'black',
  347. // });
  348. // text2.css({
  349. // 'font-size':'inherit',
  350. // 'fill':'grey',
  351. // });
  352. // text3.css({
  353. // 'font-size':'inherit',
  354. // 'fill':'lightgrey',
  355. // });
  356. //
  357. // if (href) {
  358. // href.css({
  359. // 'font-size':'1.2rem',
  360. // 'fill':'blue',
  361. // });
  362. // }
  363. // $("svg .nodes text").css({
  364. // 'font-size':'1.2rem',
  365. // 'z-index': '999',
  366. // 'fill':'blue',
  367. // })
  368. });
  369. }
  370. function paperjs() {
  371. paper.install(window);
  372. window.onload = function() {
  373. // Get a reference to the canvas object
  374. var canvas = document.getElementById('canvas');
  375. // Create an empty project and a view for the canvas:
  376. paper.setup(canvas);
  377. // Create a Paper.js Path to draw a line into it:
  378. // The amount of segment points we want to create:
  379. var amount = [1, 2, 3, 4, 5];
  380. var height = 200;
  381. var width = 500;
  382. // Create a new path and style it:
  383. var path = new paper.Path({
  384. fillColor: 'grey',
  385. });
  386. path.blendMode = 'multiply';
  387. path.closed = true;
  388. path.fullySelected = false;
  389. path._reseaux = "facebook";
  390. console.log('path',path);
  391. var path2 = new paper.Path({
  392. fillColor: 'grey',
  393. });
  394. path2.blendMode = 'multiply';
  395. path2.closed = true;
  396. path2.fullySelected = false;
  397. path._reseaux = "twitter";
  398. var path3 = new paper.Path({
  399. fillColor: 'grey',
  400. });
  401. path3.blendMode = 'multiply';
  402. path3.closed = true;
  403. path3.fullySelected = false;
  404. path._reseaux = "email";
  405. for (var i = 0; i <= amount.length; i++) {
  406. var maxPoint = new paper.Point(100, 100);
  407. var point = maxPoint;
  408. path.add(point);
  409. }
  410. for (var i = 0; i <= amount.length; i++) {
  411. var maxPoint = new paper.Point(100, 100);
  412. var point = maxPoint;
  413. path2.add(point);
  414. }
  415. for (var i = 0; i <= amount.length; i++) {
  416. var maxPoint = new paper.Point(100, 100);
  417. var point = maxPoint;
  418. path3.add(point);
  419. }
  420. // dimension blob
  421. // position blog
  422. view.onFrame = function(event) {
  423. for (var i = 0; i <= amount.length; i++) {
  424. var width = 350;
  425. var height = 200;
  426. movx = Math.cos(event.time * (0.02)) * 400;
  427. movy = Math.sin(event.time * (0.05)) * 200;
  428. var left = width + movx + 200;
  429. var top = height + movy;
  430. var segment = path.segments[i];
  431. var sinus = Math.sin(event.time * ( - 0.05) + i);
  432. var cos = Math.cos(event.time * ( - 0.05) + i);
  433. var rotatex = Math.sin(event.time * Math.PI/180) + i;
  434. segment.point.x = cos * width + left + 100;
  435. segment.point.y = sinus * height + top + 100;
  436. path.rotate(rotatex);
  437. path.smooth();
  438. }
  439. for (var i = 0; i <= amount.length; i++) {
  440. var width2 = 50;
  441. var height2 = 60;
  442. movx = Math.sin(event.time * (-0.025)) * 400;
  443. movy = Math.sin(event.time * (0.06)) * 300;
  444. var left = width2 - movx + 200;
  445. var top = height2 - movy;
  446. var segment2 = path2.segments[i];
  447. var sinus = Math.sin(event.time * (0.5) + i);
  448. var cos = Math.cos(event.time * (0.5) + i);
  449. var rotatex2 = Math.sin(event.time * Math.PI/270) + i;
  450. segment2.point.x = cos * width2 + left + 400;
  451. segment2.point.y = sinus * height2 + top + 300;
  452. path2.rotate(rotatex2);
  453. path2.smooth();
  454. }
  455. for (var i = 0; i <= amount.length; i++) {
  456. var width3 = 150;
  457. var height3 = 60;
  458. movx = Math.sin(event.time * (0.025)) * 400;
  459. movy = Math.sin(event.time * (-0.1)) * 300;
  460. var left = width3 - movx + 100;
  461. var top = height3 - movy;
  462. var segment = path3.segments[i];
  463. var sinus = Math.sin(event.time * (0.3) + i);
  464. var cos = Math.cos(event.time * (0.3) + i);
  465. var rotatex3 = Math.sin(event.time * Math.PI/360) + i;
  466. segment.point.x = cos * width3 + left + 400;
  467. segment.point.y = sinus * height3 + top + 300;
  468. path3.rotate(rotatex3);
  469. path3.smooth();
  470. }
  471. }
  472. $("a[href^='#facebook']").click(function(){
  473. path.fillColor = 'blue';
  474. console.log('true');
  475. });
  476. $("a[href^='#twitter']").click(function(){
  477. path2.fillColor = 'red';
  478. console.log('true');
  479. });
  480. $("a[href^='#instagram']").click(function(){
  481. path.fillColor = 'pink';
  482. console.log('true');
  483. });
  484. }
  485. }
  486. //
  487. // function clickcanvena() {
  488. // console.log('path_reseaux',path._reseaux);
  489. // }
  490. $(document).ready(function() {
  491. paperjs();
  492. // clickcanvena();
  493. clicklinkmap();
  494. mCustomScrollbar();
  495. clickhand();
  496. drag();
  497. dragcanvas();
  498. map();
  499. clicklinkmap();
  500. // paperjs();
  501. // D3js();
  502. });