script.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 = "<div class='main_logo'></div>";
  185. $(".about .views-row").prepend(elem);
  186. var header_container = "<div class='header_container'></div>";
  187. $('#home_blocks-block_2').after(header_container);
  188. //reconstruction header
  189. var header = $('.views-element-container').find("header");
  190. $(header).each((index , element) => {
  191. let parent_id = $(header[index]).parents().eq(2).attr("id");
  192. let words = $(header[index]).text().trim().split(" ");
  193. let newcontent = words.join('<br>');
  194. $(header[index]).empty();
  195. $(header[index]).append(newcontent);
  196. $(header[index]).attr('data-dom', parent_id);
  197. let h = $(header[index]).clone();
  198. if(index == 0){
  199. $(h).append('<span class="arrow"><br>▼</span>');
  200. $(h).addClass("active");
  201. }
  202. $('.header_container').append(h);
  203. });
  204. $("#home_themes-block_1 header").remove();
  205. $("#home_themes-block_1>div>div").slick({
  206. slidesToShow: 5,
  207. slidesToScroll: 4,
  208. centerMode: false,
  209. // centerPadding: '10%',
  210. infinite: false,
  211. responsive: [
  212. {
  213. breakpoint: 800,
  214. settings: {
  215. slidesToShow: 2,
  216. slidesToScroll: 1,
  217. centerPadding: '10px',
  218. }
  219. }]
  220. });
  221. containers_id.forEach((element) => {
  222. $("#"+element).fadeOut();
  223. });
  224. $("#"+$('.header_container').find(".active").data("dom")).fadeIn();
  225. }
  226. //ajout header motif in page static
  227. if($(".page-node-type-static").length > 0){
  228. let elem = "<div class='layout__region layout__region--top'></div>"
  229. $(".layout--threecol-25-50-25").prepend(elem);
  230. }
  231. //last-ressources empty item
  232. $(".last-ressources .views-field-field-programme .field-content").each(function(){
  233. if ($(this).children().length == 0) {
  234. $(this).append("POPSU")
  235. $(this).addClass("empty");
  236. }
  237. });
  238. //menu ouvertur sur page event et actu
  239. if($(".page-node-type-evenement").length > 0 || $(".page-node-type-actualite").length > 0){
  240. $('.views-element-container header').click(function(){
  241. $(this).parent().find(".view-grouping").fadeToggle();
  242. $(this).parent().find(".views-row").fadeToggle();
  243. });
  244. $('.view-grouping-header').click(function(){
  245. $(this).parent().find(".view-grouping-content").slideToggle();
  246. });
  247. }
  248. if($(".page-node-type-programme").length > 0 || $(".page-node-type-projet").length > 0 || $(".page-node-type-theme").length > 0 ){
  249. $(".field_ressources_liees article").each(function(){
  250. let title = $(this).find("h2").clone();
  251. $(this).find("h2").remove();
  252. $(this).find("div").first().append(title);
  253. })
  254. $('.views-element-container header').click(function(){
  255. $(this).parent().find(".view-grouping").fadeToggle();
  256. $(this).parent().find(".views-row").fadeToggle();
  257. });
  258. $('.view-grouping-header').click(function(){
  259. $(this).parent().find(".view-grouping-content").slideToggle();
  260. });
  261. //test hauteur
  262. let hb = $(".block-region-second .body").height();
  263. let ttp = 0;
  264. $(".block-region-second .body p").each(function(){
  265. ttp = ttp + $(this).height() ;
  266. });
  267. if(hb < ttp + 30){
  268. $(".block-region-second .body").append('<footer><a class="more">Lire la suite</a></footer>');
  269. }else{
  270. $(".block-region-second .body").addClass("body_open");
  271. }
  272. //reteste on windows resize
  273. window.addEventListener('resize', function(){
  274. $(".block-region-second .body").removeClass("body_open");
  275. let hb = $(".block-region-second .body").height();
  276. let ttp = 0;
  277. $(".block-region-second .body p").each(function(){
  278. ttp = ttp + $(this).height() ;
  279. });
  280. if(hb < ttp+30){
  281. if($(".block-region-second .body footer").length == 0){
  282. $(".block-region-second .body").append('<footer><a class="more">Lire la suite</a></footer>');
  283. }
  284. }else{
  285. if($(".block-region-second .body footer").length > 0){
  286. $(".block-region-second .body footer").remove();
  287. }
  288. $(".block-region-second .body").addClass("body_open");
  289. }
  290. });
  291. let elem = "<div class='main_logo'></div>"
  292. if( $("body").hasClass("programme-7") || $("body").hasClass("programme-6") || $("body").hasClass("programme-27") ){
  293. if(mobile != true){
  294. $('#projets-block_2').prepend(elem);
  295. }else{
  296. $('#projets-block_2').append(elem);
  297. $(".main_logo").css("position","relative");
  298. }
  299. }else{
  300. $('#projets-block_2').append(elem);
  301. $(".main_logo").css("position","relative")
  302. }
  303. // ouverture et fermeture des paragraphes
  304. $(".field_titre").on("click", function(){
  305. let e = $(this).parent().find(".field_texte");
  306. $(e).toggleClass("crop");
  307. $(this).toggleClass("rotate");
  308. });
  309. $(".field_partenaires").parent().find("h2").on("click", function(){
  310. $(this).toggleClass("rotate");
  311. if($(".field_partenaires").is(":visible")){
  312. $(".field_partenaires").fadeOut("slow");
  313. }else{
  314. $(".field_partenaires").fadeIn("slow", function(){
  315. $(this).css("display","grid")
  316. });
  317. }
  318. });
  319. $(".field_equipes").parent().find("h2").on("click", function(){
  320. $(this).toggleClass("rotate");
  321. if($(".field_equipes").is(":visible")){
  322. $(".field_equipes").fadeOut("slow");
  323. }else{
  324. $(".field_equipes").fadeIn("slow", function(){
  325. $(this).css("display","grid")
  326. });
  327. }
  328. });
  329. $(".block-region-second .body").on("click", ".more", function(){
  330. $(".body").toggleClass("body_open");
  331. if($('.body_open').length > 0){
  332. $(this).empty().html("Fermer")
  333. }else{
  334. $(this).empty().html("Lire la suite")
  335. }
  336. });
  337. $(".layout__region--bottom .field_ressources_liees>div:nth-of-type(2)").slick({
  338. slidesToShow: 3,
  339. slidesToScroll: 1,
  340. centerMode: true,
  341. centerPadding: '60px',
  342. infinite: true,
  343. responsive: [
  344. {
  345. breakpoint: 800,
  346. settings: {
  347. slidesToShow: 2,
  348. centerPadding: '0',
  349. }
  350. },
  351. {
  352. breakpoint: 400,
  353. settings: {
  354. slidesToShow: 1,
  355. centerPadding: '0',
  356. }
  357. }]
  358. });
  359. };
  360. //page about navigation :
  361. if($(".page-node-type-static").length > 0){
  362. $(".field_titre").on("click", function(){
  363. let elem = $(this).find('div:not([class])').html();
  364. $(".block-region-second").find(".field_titre").each(function(){
  365. let title = $(this).html();
  366. if($(".field_groupe_documents").length > 0){
  367. title = $($(title)[2]).html();
  368. }
  369. if(title == elem){
  370. $('html,body').animate({
  371. scrollTop: $(this).offset().top
  372. }, 'slow');
  373. return false;
  374. }
  375. });
  376. });
  377. }
  378. //hide empty or unclickable sidebar
  379. if($(".block-region-first").find("a").length == 0 ){
  380. if($(".page-node-type-static").length == 0 ){
  381. $(".block-region-first").hide();
  382. }
  383. };
  384. //crop text for collection
  385. // $(".block-region-third .views-field-description__value").addClass("hidden_text");
  386. // $(".block-region-third .views-field-description__value").on("click", function(){
  387. // $(this).removeClass('hidden_text');
  388. // })
  389. });