script.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. function map() {
  2. var mymap = L.map('mapid').setView([48.866667, 2.333333], 14);
  3. L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
  4. maxZoom: 18,
  5. attribution: '<a href="https://www.openstreetmap.org/"></a>'
  6. + '<a href="https://creativecommons.org/licenses/by-sa/2.0/"></a>'
  7. + '<a href="https://www.mapbox.com/"></a>',
  8. id: 'mapbox.streets'
  9. }).addTo(mymap);
  10. var LeafIcon = L.Icon.extend({
  11. options: {
  12. iconSize: [50, 50],
  13. iconAnchor: [25, 25],
  14. }
  15. });
  16. var greenIcon = new LeafIcon({iconUrl: 'user/themes/r2c/images/handler.svg'})
  17. L.marker([48.866667, 2.333333], {icon: greenIcon}).bindPopup("Coucou").addTo(mymap);
  18. // $(document).ready(function() {
  19. //
  20. // var array = []
  21. // console.log(array);
  22. //
  23. // var $mappoint = $('#streetmap > div:nth-child(n+2)');
  24. // array.push('{{module.header.id}}');
  25. // console.log(array);
  26. //
  27. // });
  28. };
  29. function scrollbar(){
  30. $(window).on("load",function(){
  31. $("#start > div > div").mCustomScrollbar({
  32. axis:"y",
  33. setTop: 0,
  34. });
  35. });
  36. }
  37. function clickhand(){
  38. $(".handler").on("mousedown", function (e) {
  39. e.preventDefault();
  40. $(this).addClass("mouseDown");
  41. }).on("mouseup", function () {
  42. $(this).removeClass("mouseDown");
  43. });
  44. };
  45. function drag() {
  46. var $hand = $( ".handler" );
  47. var $hand1 = $( ".hand1" );
  48. var $hand2 = $( ".hand2" );
  49. var p = 100;
  50. //marge
  51. var mrg = 1;
  52. // Blocs
  53. // find
  54. var $recits = $hand.parents('#page').find('#recits');
  55. var $itw = $hand.parents('#page').find("#interviews");
  56. var $img = $hand.parents('#page').find("#images");
  57. var $stmp = $hand.parents('#page').find("#streetmap");
  58. var $rs = $hand.parents('#page').find("#reseaux-sociaux");
  59. var $links = $hand.parents('#page').find("#links");
  60. // handler
  61. // dimension
  62. var $Whand = parseFloat($hand.outerWidth(true));
  63. var $Hhand = parseFloat($hand.outerHeight(true));
  64. $hand1.draggable({
  65. containment: "#start",
  66. scroll: false,
  67. drag: function(event, ui){
  68. var oW = parseFloat($("#start").outerWidth(true));
  69. var oH = parseFloat($("#start").outerHeight(true));
  70. var ajustH = (100 * ( 25/ oH )) + "%";
  71. var stophand = (0.8 * oW) - 130;
  72. ui.position.left = Math.max( 200, ui.position.left );
  73. ui.position.left = Math.min( stophand, ui.position.left );
  74. // handler
  75. // position
  76. var pos = $hand1.position();
  77. var pos1 = $hand2.position();
  78. var pos11 = parseFloat(pos1.left) + 25;
  79. // center handler
  80. var ajustW = $Whand / 2;
  81. var ajustH = $Hhand / 2;
  82. // position XY
  83. var xPos = ( p * parseFloat( ((ui.position.left)) / oW) ) + "%" ;
  84. var yPos = ( p * parseFloat( ((ui.position.top)) / oH ) ) + "%" ;
  85. var xPos2 = ( p * parseFloat( ((ui.position.left ) ) / oW) ) + "%";
  86. var yPos2 = ( p * parseFloat( ((ui.position.top ) ) / oH) ) + "%" ;
  87. var xPos3 = ( p * parseFloat( (pos1.left + ajustW) / oW) ) + "%";
  88. var yPos3 = ( p * parseFloat( (ui.position.top ) / oH) ) + "%" ;
  89. //handler2
  90. var $handler2 = $(this).parent().find('.hand2');
  91. var PosHand = ( parseFloat(p * parseFloat((pos11 - 25) / oW)) - parseFloat(p * parseFloat( (ui.position.left) / oW)) ) + "%";
  92. // application dimension
  93. $hand2.css({
  94. 'top': yPos3,
  95. })
  96. $recits.css({
  97. "width": xPos,
  98. "height": yPos,
  99. "left": "-2px",
  100. })
  101. $itw.css({
  102. "left":xPos2,
  103. "width": PosHand,
  104. "height": yPos,
  105. "min-width": "200px"
  106. })
  107. $img.css({
  108. "height": yPos,
  109. "min-width": "200px",
  110. })
  111. $stmp.css({
  112. "width":xPos,
  113. "top": yPos2,
  114. "bottom":"1px",
  115. "height": 'auto',
  116. })
  117. $rs.css({
  118. "top": yPos2,
  119. "left":xPos2,
  120. "width":PosHand,
  121. "bottom":"1px",
  122. "height": 'auto',
  123. })
  124. $links.css({
  125. "top": yPos2,
  126. "bottom":0,
  127. "height": 'auto',
  128. })
  129. // if itw < 200
  130. var testPourcent = parseFloat( p * parseFloat(ui.position.left + 238) / oW ) + "%";
  131. var img200 = parseFloat( p * parseFloat( (oW - (pos11 - 25 )) / oW) ) + "%" ;
  132. if ( $itw.width() < 200) {
  133. $img.css({
  134. "width": img200,
  135. })
  136. $links.css({
  137. "width": img200,
  138. })
  139. $hand2.css({
  140. 'left':testPourcent,
  141. })
  142. } else {}
  143. },
  144. stop: function( event, ui ) {
  145. var parent = $(this).parents('#start');
  146. $(this).css({
  147. left:parseInt($(this).css('left'))/parent.width()*100+"%",
  148. top: parseInt($(this).css('top'))/parent.height()*100+"%",
  149. });
  150. },
  151. });
  152. $hand2.draggable({
  153. containment: "#start",
  154. scroll: false,
  155. drag: function(event, ui){
  156. var oW = parseFloat($("#start").outerWidth(true));
  157. var oH = parseFloat($("#start").outerHeight(true));
  158. var stophand = (oW - 200) - 50;
  159. console.log(stophand)
  160. ui.position.left = Math.max( 400, ui.position.left );
  161. ui.position.left = Math.min( stophand, ui.position.left );
  162. // handler
  163. // position
  164. var pos = $hand1.position();
  165. var pos1 = $hand2.position();
  166. var pos11 = parseFloat(pos.left) + 25;
  167. // center
  168. var ajustW = $Whand / 2 - 1;
  169. var ajustH = $Hhand / 2 + 1;
  170. var ajustW200 = $Whand / 2 + 6;
  171. var ajustW2 = $Whand / 2 + 1;
  172. var ajustH2 = $Hhand / 2 + 1;
  173. var ajustW3 = $Whand / 2 + 3;
  174. var ajustH3 = $Hhand / 2 + 1;
  175. // position XY
  176. var xPos = ( p * parseFloat( ( oW - (ui.position.left) ) / oW) + "%" );
  177. var yPos = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  178. var xPos2 = ( p * parseFloat( ( oW - (ui.position.left) ) / oW ) ) + "%";
  179. var yPos2 = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  180. // var xPos3 = ( p * parseFloat( (oW - (pos.left)) / oW ) ) + "%";
  181. var xPos3 = ( p * parseFloat( (pos1.left + ajustW) / oW) ) + "%";
  182. var yPos3 = ( p * parseFloat( (ui.position.top ) / oH ) ) + "%" ;
  183. //handler2
  184. var $handler2 = $(this).parent().find('.hand2');
  185. var PosHand = (parseFloat(xPos3) - parseFloat(xPos)) + "%";
  186. var PosHand1 = ( parseFloat(p * parseFloat( (ui.position.left) / oW)) - parseFloat(p * parseFloat((pos11 - 25) / oW))) + "%";
  187. // application dimension
  188. $hand1.css({
  189. 'top': yPos3,
  190. })
  191. $recits.css({
  192. "height": yPos,
  193. })
  194. $itw.css({
  195. "width": PosHand1,
  196. "height": yPos,
  197. })
  198. $img.css({
  199. "width": xPos,
  200. "height": yPos,
  201. })
  202. $stmp.css({
  203. "top": yPos2,
  204. "bottom":"1px",
  205. "height": 'auto',
  206. })
  207. $rs.css({
  208. "top": yPos2,
  209. "width":PosHand1,
  210. "bottom":"1px",
  211. "height": 'auto',
  212. })
  213. $links.css({
  214. "width":xPos,
  215. "top": yPos2,
  216. "bottom":0,
  217. "height": 'auto',
  218. })
  219. // if itw < 200
  220. var test = ui.position.left - 200;
  221. var testPourcent = ( p * parseFloat(test) / oW ) + "%";
  222. var img200 = ( p * parseFloat( ((pos.left) ) / oW) + "%" );
  223. if ( $itw.width() < 200) {
  224. $recits.css({
  225. "width": img200,
  226. })
  227. $stmp.css({
  228. "width": img200,
  229. })
  230. $itw.css({
  231. "left": img200,
  232. })
  233. $rs.css({
  234. "left": img200,
  235. })
  236. $hand1.css({
  237. 'left':test,
  238. })
  239. }else {
  240. }
  241. },
  242. stop: function( event, ui ) {
  243. var parent = $(this).parents("#start");
  244. $(this).css({
  245. left:parseInt($(this).css('left'))/parent.width()*100+"%",
  246. top: parseInt($(this).css('top'))/parent.height()*100+"%",
  247. });
  248. },
  249. });
  250. };
  251. function dragcanvas() {
  252. var $links = $('#links canvas');
  253. var $reseau = $('#reseaux-sociaux svg')
  254. $links.draggable({
  255. // containment:"#start",
  256. scroll: false
  257. });
  258. $reseau.draggable({
  259. scroll: false
  260. });
  261. }
  262. $(document).ready(function() {
  263. clickhand();
  264. drag();
  265. dragcanvas();
  266. map();
  267. // scrollbar();
  268. });