script.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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').click(function(){
  242. $(this).parent().find(".view-grouping").fadeToggle();
  243. $(this).parent().find(".views-row").fadeToggle();
  244. });
  245. $('.view-grouping-header').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').click(function(){
  256. //$(this).parent().find(".view-grouping").fadeToggle();
  257. console.log($(this).parent().find("h3"));
  258. if($(this).parent().find("h3").length > 0){
  259. $(this).parent().find("h3").fadeToggle();
  260. }else{
  261. $(this).parent().find(".views-row").fadeToggle();
  262. }
  263. });
  264. //page projet
  265. $("#programme_toc-block_10 h3").click(function(){
  266. $(this).nextUntil("h3").fadeToggle();
  267. });
  268. //page programme
  269. $("#programme_toc-block_4 h3").click(function(){
  270. console.log(this);
  271. $(this).nextUntil("h3").fadeToggle();
  272. });
  273. $('.view-grouping-header').click(function(){
  274. $(this).parent().find(".view-grouping-content").slideToggle();
  275. });
  276. //test hauteur
  277. let hb = $(".block-region-second .body").height();
  278. let ttp = 0;
  279. $(".block-region-second .body p").each(function(){
  280. ttp = ttp + $(this).height() ;
  281. });
  282. if(hb < ttp + 30){
  283. $(".block-region-second .body").append('<footer><a class="more">Lire la suite</a></footer>');
  284. }else{
  285. $(".block-region-second .body").addClass("body_open");
  286. }
  287. //reteste on windows resize
  288. window.addEventListener('resize', function(){
  289. $(".block-region-second .body").removeClass("body_open");
  290. let hb = $(".block-region-second .body").height();
  291. let ttp = 0;
  292. $(".block-region-second .body p").each(function(){
  293. ttp = ttp + $(this).height() ;
  294. });
  295. if(hb < ttp+30){
  296. if($(".block-region-second .body footer").length == 0){
  297. $(".block-region-second .body").append('<footer><a class="more">Lire la suite</a></footer>');
  298. }
  299. }else{
  300. if($(".block-region-second .body footer").length > 0){
  301. $(".block-region-second .body footer").remove();
  302. }
  303. $(".block-region-second .body").addClass("body_open");
  304. }
  305. });
  306. let url = $(".block-region-second .field_logo img").attr("src");
  307. console.log(url)
  308. let elem = "<div class='main_logo'></div>";
  309. elem = $(elem).css("background","50%/contain no-repeat url("+url+")");
  310. ///let elem = "<div class='main_logo'></div>"
  311. if( $("body").hasClass("programme-7") || $("body").hasClass("programme-6") || $("body").hasClass("programme-27") ){
  312. if(mobile != true){
  313. $('#projets-block_2').prepend(elem);
  314. }else{
  315. $('#projets-block_2').append(elem);
  316. $(".main_logo").css("position","relative");
  317. }
  318. }else{
  319. //block-region-second
  320. if($('#projets-block_2').length > 0){
  321. $('#projets-block_2').append(elem);
  322. }else{
  323. //ici retiré $( ".path-node.programme-878").length > 0 || $( ".path-node.programme-883").length > 0
  324. //remplacé par page nodetype programme -> à tester
  325. if( $(".page-node-type-projet").length == undefined || $(".page-node-type-theme").length == undefined || $( ".page-node-type-programme").length > 0){
  326. $('.block-region-second').prepend(elem);
  327. }
  328. }
  329. $(".main_logo").css("position","relative");
  330. }
  331. // ouverture et fermeture des paragraphes
  332. $(".field_titre").on("click", function(){
  333. let e = $(this).parent().find(".field_texte");
  334. $(e).toggleClass("crop");
  335. $(this).toggleClass("rotate");
  336. });
  337. $(".field_partenaires").parent().find("h2").on("click", function(){
  338. $(this).toggleClass("rotate");
  339. if($(".field_partenaires").is(":visible")){
  340. $(".field_partenaires").fadeOut("slow");
  341. }else{
  342. $(".field_partenaires").fadeIn("slow", function(){
  343. $(this).css("display","grid")
  344. });
  345. }
  346. });
  347. $(".field_equipes").parent().find("h2").on("click", function(){
  348. $(this).toggleClass("rotate");
  349. if($(".field_equipes").is(":visible")){
  350. $(".field_equipes").fadeOut("slow");
  351. }else{
  352. $(".field_equipes").fadeIn("slow", function(){
  353. $(this).css("display","grid")
  354. });
  355. }
  356. });
  357. $(".block-region-second .body").on("click", ".more", function(){
  358. $(".body").toggleClass("body_open");
  359. if($('.body_open').length > 0){
  360. $(this).empty().html("Fermer")
  361. }else{
  362. $(this).empty().html("Lire la suite")
  363. }
  364. });
  365. $(".layout__region--bottom .field_ressources_liees>div:nth-of-type(2)").slick({
  366. slidesToShow: 3,
  367. slidesToScroll: 1,
  368. centerMode: true,
  369. centerPadding: '60px',
  370. infinite: true,
  371. responsive: [
  372. {
  373. breakpoint: 800,
  374. settings: {
  375. slidesToShow: 2,
  376. centerPadding: '0',
  377. }
  378. },
  379. {
  380. breakpoint: 400,
  381. settings: {
  382. slidesToShow: 1,
  383. centerPadding: '0',
  384. }
  385. }]
  386. });
  387. };
  388. //page about navigation :
  389. if($(".page-node-type-static").length > 0){
  390. $(".field_titre").on("click", function(){
  391. let elem = $(this).find('div:not([class])').html();
  392. $(".block-region-second").find(".field_titre").each(function(){
  393. let title = $(this).html();
  394. if($(".field_groupe_documents").length > 0){
  395. title = $($(title)[2]).html();
  396. }
  397. if(title == elem){
  398. $('html,body').animate({
  399. scrollTop: $(this).offset().top
  400. }, 'slow');
  401. return false;
  402. }
  403. });
  404. });
  405. }
  406. //hide empty or unclickable sidebar
  407. if($(".block-region-first").find("a").length == 0 ){
  408. if($(".page-node-type-static").length == 0 ){
  409. $(".block-region-first").hide();
  410. }
  411. };
  412. //spec ressources video
  413. if($(".page-node-type-ressource").find(".ressources-video").length > 0){
  414. let vid = $(".field_videos").parents().eq(0);
  415. let prog = $(".field_programme").parents().eq(0);
  416. $(vid).clone().insertAfter(prog);
  417. $(vid).remove();
  418. }
  419. //ressources page projet
  420. if($(".page-node-type-projet").length > 0){
  421. let art = $(".views-field-field-ressources-liees article");
  422. art.each(function(){
  423. let t = $(this).find("h2");
  424. $(t).clone().insertAfter($(this).find(".field_image"));
  425. $(t).remove();
  426. });
  427. }
  428. //crop text for collection
  429. // $(".block-region-third .views-field-description__value").addClass("hidden_text");
  430. // $(".block-region-third .views-field-description__value").on("click", function(){
  431. // $(this).removeClass('hidden_text');
  432. // })
  433. // patch exode urbain partenaire //
  434. if($(".programme-878").length > 0){
  435. let title = $(".programme-878 .field_partenaires div").first()[0];
  436. $(title).addClass("field_titre");
  437. let paragraphe = $(".programme-878 .field_partenaires div")[1];
  438. $(paragraphe).addClass("field_texte crop");
  439. $(".field_partenaires").on("click",".field_titre", function(){
  440. let e = $(this).parent().find(".field_texte");
  441. $(e).toggleClass("crop");
  442. $(this).toggleClass("rotate");
  443. });
  444. }
  445. });