script.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. function gestionarray() {
  2. // dyn_data.split();
  3. console.log(dyn_data.mappoints[1].id);
  4. $("#page").addClass(dyn_data.mappoints[1].id);
  5. }
  6. function map() {
  7. var mymap = L.map('mapid').setView([48.9267935,2.3569287], 16);
  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: [50, 50],
  15. iconAnchor: [25, 25],
  16. }
  17. });
  18. var markers = {};
  19. var greenIcon = new LeafIcon({iconUrl: 'user/themes/r2c/images/handler.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. };
  27. function scrollbar(){
  28. $(window).on("load",function(){
  29. $("#start > div > div").mCustomScrollbar({
  30. axis:"y",
  31. setTop: 0,
  32. });
  33. });
  34. }
  35. function clickhand(){
  36. $(".handler").on("mousedown", function (e) {
  37. e.preventDefault();
  38. $(this).addClass("mouseDown");
  39. }).on("mouseup", function () {
  40. $(this).removeClass("mouseDown");
  41. });
  42. };
  43. function drag() {
  44. var $hand = $( ".handler" );
  45. var $hand1 = $( ".hand1" );
  46. var $hand2 = $( ".hand2" );
  47. var p = 100;
  48. //marge
  49. var mrg = 1;
  50. // Blocs
  51. // find
  52. var $recits = $hand.parents('#page').find('#recits');
  53. var $itw = $hand.parents('#page').find("#interviews");
  54. var $img = $hand.parents('#page').find("#images");
  55. var $stmp = $hand.parents('#page').find("#streetmap");
  56. var $rs = $hand.parents('#page').find("#reseaux-sociaux");
  57. var $links = $hand.parents('#page').find("#links");
  58. // handler
  59. // dimension
  60. var $Whand = parseFloat($hand.outerWidth(true));
  61. var $Hhand = parseFloat($hand.outerHeight(true));
  62. $hand1.draggable({
  63. containment: "#start",
  64. scroll: false,
  65. drag: function(event, ui){
  66. var oW = parseFloat($("#start").outerWidth(true));
  67. var oH = parseFloat($("#start").outerHeight(true));
  68. var ajustH = (100 * ( 25/ oH )) + "%";
  69. var stophand = (0.8 * oW) - 130;
  70. ui.position.left = Math.max( 200, ui.position.left );
  71. ui.position.left = Math.min( stophand, ui.position.left );
  72. // handler
  73. // position
  74. var pos = $hand1.position();
  75. var pos1 = $hand2.position();
  76. var pos11 = parseFloat(pos1.left) + 25;
  77. // center handler
  78. var ajustW = $Whand / 2;
  79. var ajustH = $Hhand / 2;
  80. // position XY
  81. var xPos = ( p * parseFloat( ((ui.position.left)) / oW) ) + "%" ;
  82. var yPos = ( p * parseFloat( ((ui.position.top)) / oH ) ) + "%" ;
  83. var xPos2 = ( p * parseFloat( ((ui.position.left ) ) / oW) ) + "%";
  84. var yPos2 = ( p * parseFloat( ((ui.position.top ) ) / oH) ) + "%" ;
  85. var xPos3 = ( p * parseFloat( (pos1.left + ajustW) / oW) ) + "%";
  86. var yPos3 = ( p * parseFloat( (ui.position.top ) / oH) ) + "%" ;
  87. //handler2
  88. var $handler2 = $(this).parent().find('.hand2');
  89. var PosHand = ( parseFloat(p * parseFloat((pos11 - 25) / oW)) - parseFloat(p * parseFloat( (ui.position.left) / oW)) ) + "%";
  90. // application dimension
  91. $hand2.css({
  92. 'top': yPos3,
  93. })
  94. $recits.css({
  95. "width": xPos,
  96. "height": yPos,
  97. "left": "-2px",
  98. })
  99. $itw.css({
  100. "left":xPos2,
  101. "width": PosHand,
  102. "height": yPos,
  103. "min-width": "200px"
  104. })
  105. $img.css({
  106. "height": yPos,
  107. "min-width": "200px",
  108. })
  109. $stmp.css({
  110. "width":xPos,
  111. "top": yPos2,
  112. "bottom":"1px",
  113. "height": 'auto',
  114. })
  115. $links.css({
  116. "top": yPos2,
  117. "left":xPos2,
  118. "width":PosHand,
  119. "bottom":"1px",
  120. "height": 'auto',
  121. })
  122. $rs.css({
  123. "top": yPos2,
  124. "bottom":0,
  125. "height": 'auto',
  126. })
  127. // if itw < 200
  128. var testPourcent = parseFloat( p * parseFloat(ui.position.left + 238) / oW ) + "%";
  129. var img200 = parseFloat( p * parseFloat( (oW - (pos11 - 25 )) / oW) ) + "%" ;
  130. if ( $itw.width() < 200) {
  131. $img.css({
  132. "width": img200,
  133. })
  134. $rs.css({
  135. "width": img200,
  136. })
  137. $hand2.css({
  138. 'left':testPourcent,
  139. })
  140. } else {}
  141. },
  142. stop: function( event, ui ) {
  143. var parent = $(this).parents('#start');
  144. $(this).css({
  145. left:parseInt($(this).css('left'))/parent.width()*100+"%",
  146. top: parseInt($(this).css('top'))/parent.height()*100+"%",
  147. });
  148. },
  149. });
  150. $hand2.draggable({
  151. containment: "#start",
  152. scroll: false,
  153. drag: function(event, ui){
  154. var oW = parseFloat($("#start").outerWidth(true));
  155. var oH = parseFloat($("#start").outerHeight(true));
  156. var stophand = (oW - 200) - 50;
  157. console.log(stophand)
  158. ui.position.left = Math.max( 400, ui.position.left );
  159. ui.position.left = Math.min( stophand, ui.position.left );
  160. // handler
  161. // position
  162. var pos = $hand1.position();
  163. var pos1 = $hand2.position();
  164. var pos11 = parseFloat(pos.left) + 25;
  165. // center
  166. var ajustW = $Whand / 2 - 1;
  167. var ajustH = $Hhand / 2 + 1;
  168. var ajustW200 = $Whand / 2 + 6;
  169. var ajustW2 = $Whand / 2 + 1;
  170. var ajustH2 = $Hhand / 2 + 1;
  171. var ajustW3 = $Whand / 2 + 3;
  172. var ajustH3 = $Hhand / 2 + 1;
  173. // position XY
  174. var xPos = ( p * parseFloat( ( oW - (ui.position.left) ) / oW) + "%" );
  175. var yPos = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  176. var xPos2 = ( p * parseFloat( ( oW - (ui.position.left) ) / oW ) ) + "%";
  177. var yPos2 = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  178. // var xPos3 = ( p * parseFloat( (oW - (pos.left)) / oW ) ) + "%";
  179. var xPos3 = ( p * parseFloat( (pos1.left + ajustW) / oW) ) + "%";
  180. var yPos3 = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  181. //handler2
  182. var $handler2 = $(this).parent().find('.hand2');
  183. var PosHand = (parseFloat(xPos3) - parseFloat(xPos)) + "%";
  184. var PosHand1 = ( parseFloat(p * parseFloat( (ui.position.left) / oW)) - parseFloat(p * parseFloat((pos11 - 25) / oW))) + "%";
  185. // application dimension
  186. $hand1.css({
  187. 'top': yPos3,
  188. })
  189. $recits.css({
  190. "height": yPos,
  191. })
  192. $itw.css({
  193. "width": PosHand1,
  194. "height": yPos,
  195. })
  196. $img.css({
  197. "width": xPos,
  198. "height": yPos,
  199. })
  200. $stmp.css({
  201. "top": yPos2,
  202. "bottom":"1px",
  203. "height": 'auto',
  204. })
  205. $rs.css({
  206. "width":xPos,
  207. "top": yPos2,
  208. "bottom":0,
  209. "height": 'auto',
  210. })
  211. $links.css({
  212. "top": yPos2,
  213. "width":PosHand1,
  214. "bottom":"1px",
  215. "height": 'auto',
  216. })
  217. // if itw < 200
  218. var test = ui.position.left - 225;
  219. var testPourcent = ( p * parseFloat(test) / oW ) + "%";
  220. var img200 = ( p * parseFloat( ((pos.left) ) / oW) + "%" );
  221. if ( $itw.width() < 200) {
  222. $recits.css({
  223. "width": img200,
  224. })
  225. $stmp.css({
  226. "width": img200,
  227. })
  228. $itw.css({
  229. "left": img200,
  230. })
  231. $links.css({
  232. "left": img200,
  233. })
  234. $hand1.css({
  235. 'left':test,
  236. })
  237. }else {
  238. }
  239. },
  240. stop: function( event, ui ) {
  241. var parent = $(this).parents("#start");
  242. $(this).css({
  243. left:parseInt($(this).css('left'))/parent.width()*100+"%",
  244. top: parseInt($(this).css('top'))/parent.height()*100+"%",
  245. });
  246. },
  247. });
  248. };
  249. function dragcanvas() {
  250. var $reseau = $('#reseaux-sociaux canvas');
  251. var $links = $('#links svg')
  252. $links.draggable({
  253. scroll: false
  254. });
  255. $reseau.draggable({
  256. scroll: false
  257. });
  258. }
  259. function mCustomScrollbar() {
  260. $('.blocs').mCustomScrollbar({
  261. scrollInertia: 100,
  262. });
  263. $('.blocs').mCustomScrollbar("update");
  264. $(document).on("click","a[href^='#']",function(e){
  265. e.preventDefault();
  266. // var id = [];
  267. // var href = $(this).attr("href");
  268. // var letter = $.inArray('#', href);
  269. // console.log('L',letter);
  270. // var target = $(href).parents(".mCustomScrollbar");
  271. //
  272. // if(target.length){
  273. // e.preventDefault();
  274. // target.mCustomScrollbar("scrollTo",href,{
  275. // scrollInertia:1000,
  276. // // offset: 0
  277. // });
  278. // }
  279. // console.log('target', target);
  280. // console.log('href', href);
  281. var hrefs = $(this).attr("href").split(',');
  282. console.log('hrefs', hrefs);
  283. var h, h_parts;
  284. var regex = /^#(([^_]+)_(.+))/g;
  285. for (var i = 0; i < hrefs.length; i++) {
  286. h = hrefs[i];
  287. // h = h.replace(/^#/, '');
  288. // console.log('h', h);
  289. var h_parts = regex.exec(h);
  290. // h_parts = h.match();
  291. console.log('h_parts', h_parts);
  292. // a partir de là tu peux synchro chacun des blocks en focntion de
  293. // h_parts[2] est la première partie qui te dit de quel block il s'agit
  294. // h_parts[3] est l'ancre
  295. // etc
  296. switch (h_parts[2]) {
  297. case case 'mp':
  298. // tu synchro interview
  299. break;
  300. case case 'rct':
  301. // tu synchro récit
  302. break;
  303. case case 'img':
  304. // tu synchro image
  305. break;
  306. // case '':
  307. // etc
  308. // break;
  309. default:
  310. }
  311. }
  312. });
  313. }
  314. $(document).ready(function() {
  315. // gestionarray();
  316. mCustomScrollbar();
  317. clickhand();
  318. drag();
  319. dragcanvas();
  320. map();
  321. // D3js();
  322. // scrollbar();
  323. });