script.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. import 'slick-carousel';
  2. var mobile = false;
  3. var containers_id = ["projets-block_1","programmes-block_4","home_themes-block_1"];
  4. $(function(){
  5. console.log("$ ready !!");
  6. if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i)){
  7. mobile = true;
  8. }
  9. if($(".path-frontpage").length > 0){
  10. // $("#"+).fadeIn();
  11. $('.last-news').slick({
  12. slidesToShow: 1,
  13. slidesToScroll: 1,
  14. centerMode: true,
  15. centerPadding: '300px',
  16. responsive: [
  17. {
  18. breakpoint: 800,
  19. settings: {
  20. centerPadding: '0',
  21. }
  22. }]
  23. });
  24. $('.last-ressources').slick({
  25. slidesToShow: 3,
  26. slidesToScroll: 1,
  27. centerMode: true,
  28. centerPadding: '60px',
  29. infinite: true,
  30. responsive: [
  31. {
  32. breakpoint: 800,
  33. settings: {
  34. slidesToShow: 2,
  35. centerPadding: '0',
  36. }
  37. },
  38. {
  39. breakpoint: 400,
  40. settings: {
  41. slidesToShow: 1,
  42. centerPadding: '0',
  43. }
  44. }]
  45. });
  46. }
  47. if($("#programme_toc-block_5").length > 0){
  48. $('#programme_toc-block_5>div>div').slick({
  49. slidesToShow: 1,
  50. slidesToScroll: 1,
  51. centerMode: true,
  52. centerPadding: '200px',
  53. responsive: [
  54. {
  55. breakpoint: 800,
  56. settings: {
  57. centerPadding: '0',
  58. adaptiveHeight: true
  59. }
  60. }]
  61. });
  62. }
  63. $('#centre_de_ressources-block_2>div>div').slick({
  64. slidesToShow: 3,
  65. slidesToScroll: 1,
  66. centerMode: false,
  67. centerPadding: '60px',
  68. infinite: true,
  69. responsive: [
  70. {
  71. breakpoint: 800,
  72. settings: {
  73. slidesToShow: 1,
  74. slidesToScroll: 1,
  75. centerPadding: '40px',
  76. centerMode: true,
  77. }
  78. }]
  79. });
  80. if($(".path-actus").length > 0){
  81. let elem = $("#actus_blocks-block_2").find("footer").detach();
  82. $("#actus_blocks-block_2").append(elem);
  83. $('#actus_blocks-block_2>div>div').slick({
  84. slidesToShow: 3,
  85. slidesToScroll: 1,
  86. centerMode: false,
  87. centerPadding: '60px',
  88. infinite: false,
  89. responsive: [
  90. {
  91. breakpoint: 800,
  92. settings: {
  93. slidesToShow: 1,
  94. slidesToScroll: 1,
  95. centerMode: true,
  96. centerPadding: '30px',
  97. }
  98. }]
  99. });
  100. elem = $("#actus_blocks-block_1").find("footer").detach();
  101. $("#actus_blocks-block_1").append(elem);
  102. $('#actus_blocks-block_1>div>div').slick({
  103. slidesToShow: 3,
  104. slidesToScroll: 1,
  105. centerMode: false,
  106. centerPadding: '60px',
  107. infinite: false,
  108. responsive: [
  109. {
  110. breakpoint: 800,
  111. settings: {
  112. slidesToShow: 1,
  113. slidesToScroll: 1,
  114. centerMode: true,
  115. centerPadding: '30px',
  116. }
  117. }]
  118. });
  119. $('#home_blocks-block_3>div>div').slick({
  120. slidesToShow: 3,
  121. slidesToScroll: 1,
  122. centerMode: false,
  123. centerPadding: '60px',
  124. infinite: false,
  125. responsive: [
  126. {
  127. breakpoint: 800,
  128. settings: {
  129. slidesToShow: 1,
  130. slidesToScroll: 1,
  131. centerPadding: '0',
  132. }
  133. }]
  134. });
  135. }
  136. if($('.path-centre-de-ressources').length > 0){
  137. let elem = $(".content_container").find(".views-element-container header>div");
  138. $(elem[0]).slick({
  139. slidesToShow: 3,
  140. slidesToScroll: 1,
  141. centerMode: false,
  142. centerPadding: '60px',
  143. responsive: [
  144. {
  145. breakpoint: 800,
  146. settings: {
  147. slidesToShow: 1,
  148. slidesToScroll: 1,
  149. centerMode: true,
  150. centerPadding: '30px',
  151. }
  152. }]
  153. });
  154. }
  155. $('.close-block').click(function(){
  156. $(this).parent().fadeOut();
  157. if(mobile == true){
  158. $("body").css("overflow","auto");
  159. }
  160. });
  161. $('.open-block').click(function(){
  162. $(this).prev().css("display","grid");
  163. if(mobile == true){
  164. $("body").css("overflow","hidden");
  165. }
  166. });
  167. $("body").on("click", ".header_container header", function(){
  168. $('.header_container').find("header").removeClass('active');
  169. $('.header_container').find("header .arrow").remove();
  170. $(this).append('<span class="arrow"><br>▼</span>');
  171. $(this).toggleClass('active');
  172. containers_id.forEach((element) => {
  173. $("#"+element).fadeOut();
  174. });
  175. var d = $(this).data("dom");
  176. $("#"+d).fadeIn(function(){
  177. if(d == "home_themes-block_1"){
  178. $("#home_themes-block_1>div>div").slick('refresh');
  179. }
  180. });
  181. });
  182. // HOME PAGE
  183. if($(".path-frontpage").length > 0){
  184. //let elem = $(".field_logo").clone();
  185. let elem = "<div class='main_logo'></div>";
  186. $(".about .views-row").prepend(elem);
  187. var header_container = "<div class='header_container'></div>";
  188. $('#home_blocks-block_2').after(header_container);
  189. //reconstruction header
  190. var header = $('.views-element-container').find("header");
  191. $(header).each((index , element) => {
  192. let parent_id = $(header[index]).parents().eq(2).attr("id");
  193. let words = $(header[index]).text().trim().split(" ");
  194. let newcontent = words.join('<br>');
  195. $(header[index]).empty();
  196. $(header[index]).append(newcontent);
  197. $(header[index]).attr('data-dom', parent_id);
  198. let h = $(header[index]).clone();
  199. if(index == 0){
  200. $(h).append('<span class="arrow"><br>▼</span>');
  201. $(h).addClass("active");
  202. }
  203. $('.header_container').append(h);
  204. });
  205. $("#home_themes-block_1 header").remove();
  206. $("#home_themes-block_1>div>div").slick({
  207. slidesToShow: 5,
  208. slidesToScroll: 4,
  209. centerMode: false,
  210. // centerPadding: '10%',
  211. infinite: false,
  212. responsive: [
  213. {
  214. breakpoint: 800,
  215. settings: {
  216. slidesToShow: 2,
  217. slidesToScroll: 1,
  218. centerPadding: '10px',
  219. }
  220. }]
  221. });
  222. containers_id.forEach((element) => {
  223. $("#"+element).fadeOut();
  224. });
  225. $("#"+$('.header_container').find(".active").data("dom")).fadeIn();
  226. }
  227. //ajout header motif in page static
  228. if($(".page-node-type-static").length > 0){
  229. let elem = "<div class='layout__region layout__region--top'></div>"
  230. $(".layout--threecol-25-50-25").prepend(elem);
  231. }
  232. //last-ressources empty item
  233. $(".last-ressources .views-field-field-programme .field-content").each(function(){
  234. if ($(this).children().length == 0) {
  235. $(this).append("POPSU")
  236. $(this).addClass("empty");
  237. }
  238. });
  239. //menu ouvertur sur page event et actu
  240. if($(".page-node-type-evenement").length > 0 || $(".page-node-type-actualite").length > 0){
  241. $('.views-element-container header').on('click', function(){
  242. $(this).parent().find(".view-grouping").fadeToggle();
  243. $(this).parent().find(".views-row").fadeToggle();
  244. });
  245. $('.view-grouping-header').on('click', function(){
  246. $(this).parent().find(".view-grouping-content").slideToggle();
  247. });
  248. }
  249. if($(".page-node-type-programme").length > 0 || $(".page-node-type-projet").length > 0 || $(".page-node-type-theme").length > 0 ){
  250. $(".field_ressources_liees article").each(function(){
  251. let title = $(this).find("h2").clone();
  252. $(this).find("h2").remove();
  253. $(this).find("div").first().append(title);
  254. })
  255. $('.views-element-container header').on("click", function(){
  256. //$(this).parent().find(".view-grouping").fadeToggle();
  257. console.log($(this).parent().find("h3"));
  258. if($(this).parent().children("h3").length > 0){
  259. // for territoires which are grouped by regions
  260. $(this).parent().find("h3").fadeToggle();
  261. }else{
  262. $(this).parent().find(".views-row").fadeToggle();
  263. }
  264. });
  265. // popsu 1
  266. // $('')
  267. $('#programme_toc-block_9 header').on('click', function(){
  268. $(this).parent().find(".view-grouping").fadeToggle();
  269. $(this).parent().find(".views-row").fadeToggle();
  270. });
  271. //page projet
  272. $("#programme_toc-block_10 h3").on('click', function(){
  273. // pour territoire
  274. $(this).nextUntil("h3").fadeToggle();
  275. });
  276. //page programme
  277. // pour territoire (h3 are regions)
  278. $("#programme_toc-block_4 h3").on('click', function(){
  279. console.log(this);
  280. $(this).nextUntil("h3").fadeToggle();
  281. });
  282. $('.view-grouping-header').on('click', function(){
  283. $(this).parent().find(".view-grouping-content").slideToggle();
  284. });
  285. //test hauteur
  286. let hb = $(".block-region-second .body").height();
  287. let ttp = 0;
  288. $(".block-region-second .body p").each(function(){
  289. ttp = ttp + $(this).height() ;
  290. });
  291. if(hb < ttp + 30){
  292. $(".block-region-second .body").append('<footer><a class="more">Lire la suite</a></footer>');
  293. }else{
  294. $(".block-region-second .body").addClass("body_open");
  295. }
  296. //reteste on windows resize
  297. window.addEventListener('resize', function(){
  298. $(".block-region-second .body").removeClass("body_open");
  299. let hb = $(".block-region-second .body").height();
  300. let ttp = 0;
  301. $(".block-region-second .body p").each(function(){
  302. ttp = ttp + $(this).height() ;
  303. });
  304. if(hb < ttp+30){
  305. if($(".block-region-second .body footer").length == 0){
  306. $(".block-region-second .body").append('<footer><a class="more">Lire la suite</a></footer>');
  307. }
  308. }else{
  309. if($(".block-region-second .body footer").length > 0){
  310. $(".block-region-second .body footer").remove();
  311. }
  312. $(".block-region-second .body").addClass("body_open");
  313. }
  314. });
  315. let url = $(".block-region-second .field_logo img").attr("src");
  316. console.log(url)
  317. let elem = "<div class='main_logo'></div>";
  318. elem = $(elem).css("background","50%/contain no-repeat url("+url+")");
  319. ///let elem = "<div class='main_logo'></div>"
  320. if( $("body").hasClass("programme-7") || $("body").hasClass("programme-6") || $("body").hasClass("programme-27") ){
  321. if(mobile != true){
  322. $('#projets-block_2').prepend(elem);
  323. }else{
  324. $('#projets-block_2').append(elem);
  325. $(".main_logo").css("position","relative");
  326. }
  327. }else{
  328. //block-region-second
  329. if($('#projets-block_2').length > 0){
  330. $('#projets-block_2').append(elem);
  331. }else{
  332. //ici retiré $( ".path-node.programme-878").length > 0 || $( ".path-node.programme-883").length > 0
  333. //remplacé par page nodetype programme -> à tester
  334. if( $(".page-node-type-projet").length == undefined || $(".page-node-type-theme").length == undefined || $( ".page-node-type-programme").length > 0){
  335. $('.block-region-second').prepend(elem);
  336. }
  337. }
  338. $(".main_logo").css("position","relative");
  339. }
  340. // ouverture et fermeture des paragraphes
  341. $(".field_titre").on("click", function(){
  342. let e = $(this).parent().find(".field_texte");
  343. $(e).toggleClass("crop");
  344. $(this).toggleClass("rotate");
  345. });
  346. $(".field_partenaires").parent().find("h2").on("click", function(){
  347. $(this).toggleClass("rotate");
  348. if($(".field_partenaires").is(":visible")){
  349. $(".field_partenaires").fadeOut("slow");
  350. }else{
  351. $(".field_partenaires").fadeIn("slow", function(){
  352. $(this).css("display","grid")
  353. });
  354. }
  355. });
  356. $(".field_equipes").parent().find("h2").on("click", function(){
  357. $(this).toggleClass("rotate");
  358. if($(".field_equipes").is(":visible")){
  359. $(".field_equipes").fadeOut("slow");
  360. }else{
  361. $(".field_equipes").fadeIn("slow", function(){
  362. $(this).css("display","grid")
  363. });
  364. }
  365. });
  366. $(".block-region-second .body").on("click", ".more", function(){
  367. $(".body").toggleClass("body_open");
  368. if($('.body_open').length > 0){
  369. $(this).empty().html("Fermer")
  370. }else{
  371. $(this).empty().html("Lire la suite")
  372. }
  373. });
  374. $(".layout__region--bottom .field_ressources_liees>div:nth-of-type(2)").slick({
  375. slidesToShow: 3,
  376. slidesToScroll: 1,
  377. centerMode: true,
  378. centerPadding: '60px',
  379. infinite: true,
  380. responsive: [
  381. {
  382. breakpoint: 800,
  383. settings: {
  384. slidesToShow: 2,
  385. centerPadding: '0',
  386. }
  387. },
  388. {
  389. breakpoint: 400,
  390. settings: {
  391. slidesToShow: 1,
  392. centerPadding: '0',
  393. }
  394. }]
  395. });
  396. };
  397. //page about navigation :
  398. if($(".page-node-type-static").length > 0){
  399. $(".field_titre").on("click", function(){
  400. let elem = $(this).find('div:not([class])').html();
  401. $(".block-region-second").find(".field_titre").each(function(){
  402. let title = $(this).html();
  403. if($(".field_groupe_documents").length > 0){
  404. title = $($(title)[2]).html();
  405. }
  406. if(title == elem){
  407. $('html,body').animate({
  408. scrollTop: $(this).offset().top
  409. }, 'slow');
  410. return false;
  411. }
  412. });
  413. });
  414. }
  415. //hide empty or unclickable sidebar
  416. if($(".block-region-first").find("a").length == 0 ){
  417. if($(".page-node-type-static").length == 0 ){
  418. $(".block-region-first").hide();
  419. }
  420. };
  421. //spec ressources video
  422. if($(".page-node-type-ressource").find(".ressources-video").length > 0){
  423. let vid = $(".field_videos").parents().eq(0);
  424. let prog = $(".field_programme").parents().eq(0);
  425. $(vid).clone().insertAfter(prog);
  426. $(vid).remove();
  427. }
  428. //spec ressources diaporama
  429. if($(".page-node-type-ressource").find(".ressources-reportage-photographique").length > 0){
  430. let diapo = $("#node\\:field_diaporama");
  431. let prog = $("#node\\:field_programme");
  432. $(diapo).clone().insertAfter(prog);
  433. $(diapo).remove();
  434. let elem = $(".content_container").find("#node\\:field_diaporama>div.field_diaporama");
  435. console.log('elem', elem);
  436. $(elem[0]).slick({
  437. slidesToShow: 1,
  438. slidesToScroll: 1,
  439. centerMode: false,
  440. centerPadding: '60px',
  441. responsive: [
  442. {
  443. breakpoint: 800,
  444. settings: {
  445. slidesToShow: 1,
  446. slidesToScroll: 1,
  447. centerMode: true,
  448. centerPadding: '30px',
  449. }
  450. }]
  451. });
  452. }
  453. //ressources page projet
  454. if($(".page-node-type-projet").length > 0){
  455. let art = $(".views-field-field-ressources-liees article");
  456. art.each(function(){
  457. let t = $(this).find("h2");
  458. $(t).clone().insertAfter($(this).find(".field_image"));
  459. $(t).remove();
  460. });
  461. }
  462. //crop text for collection
  463. // $(".block-region-third .views-field-description__value").addClass("hidden_text");
  464. // $(".block-region-third .views-field-description__value").on("click", function(){
  465. // $(this).removeClass('hidden_text');
  466. // })
  467. // patch exode urbain partenaire //
  468. if($(".programme-878").length > 0){
  469. let title = $(".programme-878 .field_partenaires div").first()[0];
  470. $(title).addClass("field_titre");
  471. let paragraphe = $(".programme-878 .field_partenaires div")[1];
  472. $(paragraphe).addClass("field_texte crop");
  473. $(".field_partenaires").on("click",".field_titre", function(){
  474. let e = $(this).parent().find(".field_texte");
  475. $(e).toggleClass("crop");
  476. $(this).toggleClass("rotate");
  477. });
  478. }
  479. });
  480. ////////// disable click droit souris
  481. jQuery(document).ready(function () {
  482. //Disable cut copy paste
  483. jQuery('body').bind('cut copy paste', function (e) {
  484. e.preventDefault();
  485. });
  486. //Disable mouse right click
  487. jQuery("img").on("contextmenu",function(e){
  488. return false;
  489. });
  490. });