script.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. (function ($) {
  2. function currenturl() {
  3. $link.each(function(i){
  4. var url = $(this).attr('href');
  5. var current = window.location.pathname;
  6. if (url == current) {
  7. $(this).addClass('current');
  8. $(this).parents('.navigation__item').addClass('current');
  9. }
  10. });
  11. }
  12. function notes() {
  13. var $link = $('#presentation a');
  14. var allNotes = $ ('.notes > div');
  15. allNotes.hide();
  16. $link.each(function(){
  17. $(this).click(function(e) {
  18. $this = $(this);
  19. if ( $this.is('#ressource') || $this.is('#bibliographie') ) {
  20. e.preventDefault();
  21. var $url = $this.attr("href");
  22. if ($( ".side_notes" )[0]) {
  23. $( ".side_notes" ).fadeOut(200, function() {
  24. $(this).remove();
  25. });
  26. } else if ($('.notes > div')[0]) {
  27. $( ".notes > div" ).fadeOut(200);
  28. }
  29. content_type($url, $this);
  30. ajax($url, $this);
  31. } else if ($this.is('#note')) {
  32. e.preventDefault();
  33. var id_notes = $this.attr('href');
  34. var notes = $(".notes "+id_notes);
  35. if ($( ".side_notes" )[0]) {
  36. $( ".side_notes" ).fadeOut(200, function() {
  37. $(this).remove();
  38. });
  39. } else if ($('.notes > div')[0]) {
  40. $( ".notes > div" ).fadeOut(200);
  41. }
  42. notes.fadeIn(200);
  43. position_link($this, notes);
  44. $(window).resize(function() {
  45. position_link($this, notes);
  46. });
  47. close();
  48. }
  49. });
  50. })
  51. function content_type($url, $this) {
  52. if ($this.is('#ressource')) {
  53. $("<div class='side_notes'><div class='wrap'><a href="+$url+"></a></div> </div>").insertAfter(".__wrap_side article");
  54. } else if ( $this.is('#bibliographie') ) {
  55. $("<div class='side_notes'><div class='wrap'></div></>").insertAfter(".__wrap_side article");
  56. }
  57. }
  58. function ajax($url , $this) {
  59. $.ajax({
  60. url: $url + '#publicationAjax',
  61. method: "GET",
  62. dataType:'text',
  63. async: true,
  64. success: function(data) {
  65. if ($this.is('#ressource')) {
  66. var hero = 'article .__wrapper .__hero';
  67. var head = 'article .__wrapper .__head';
  68. $(data).find(hero +','+ head).appendTo('.side_notes > div a').hide().fadeIn(200);
  69. $("<div class='close'></div>").appendTo(".side_notes > div");
  70. }else if ($this.is('#bibliographie')) {
  71. $(data).find('article.bibliographie').appendTo('.side_notes > div');
  72. $("<div class='close'></div>").appendTo(".side_notes > div");
  73. }
  74. position_link($this);
  75. $(window).resize(function() {
  76. position_link($this);
  77. });
  78. close();
  79. },
  80. })
  81. }
  82. function position_link($this, id_notes) {
  83. var $top_link = $this.position().top;
  84. var width = $(window).width();
  85. if ( $this.is('#ressource') || $this.is('#bibliographie') ) {
  86. $('.side_notes').css("top", $top_link);
  87. }
  88. if ( $this.is('#note') ) {
  89. id_notes.css("top", $top_link);
  90. }
  91. if (width <= '754') {
  92. var $top_link = $this.offset().top;
  93. if ( $this.is('#ressource') || $this.is('#bibliographie') ) {
  94. $('.side_notes').css("top", $top_link);
  95. }
  96. if ( $this.is('#note') ) {
  97. id_notes.css("top", $top_link);
  98. }
  99. }
  100. }
  101. function close() {
  102. var $croix = $('.close');
  103. $croix.click(function(e) {
  104. $(this).parents('.side_notes').fadeOut(200, function() {
  105. $(this).remove();
  106. });
  107. $(this).parents('.notes > div').fadeOut(200);
  108. });
  109. }
  110. }
  111. function slide() {
  112. var $slide = $('main section .__slide');
  113. var thumbnails = $('.__slide article.programme.is-selected');
  114. var $head_date = $('#block-views-block-slide-programme-block-1 section.first:before');
  115. $slide.each(function() {
  116. $(this).flickity({
  117. cellAlign: 'left',
  118. pageDots: false,
  119. contain: true,
  120. on: {
  121. ready: function() {
  122. var dates = {},
  123. date;
  124. var $cells = this.cells;
  125. $('.__slide article.programme[data-date]').each(function(i, el){
  126. date = $(el).data('date');
  127. if (dates.hasOwnProperty(date)) {
  128. dates[date] += 1;
  129. $(this).addClass('last');
  130. }
  131. else {
  132. dates[date] = 1;
  133. $(this).addClass('first');
  134. var dateValue = $(this).data('date');
  135. console.log('dateValue',dateValue);
  136. $("<span>"+dateValue+"</span>").prependTo($(this));
  137. }
  138. });
  139. },
  140. }
  141. })
  142. });
  143. var $footer_slide = $('footer .__slide');
  144. $footer_slide.each(function() {
  145. $(this).flickity({
  146. cellAlign: 'left',
  147. pageDots: false,
  148. autoPlay: true,
  149. pauseAutoPlayOnHover: false,
  150. contain: true,
  151. prevNextButtons: false,
  152. })
  153. });
  154. var $slide_paragrpahe = $('main .paragraph .__slide');
  155. $slide_paragrpahe.each(function() {
  156. $(this).flickity({
  157. cellAlign: 'left',
  158. pageDots: false,
  159. prevNextButtons: false,
  160. contain: true,
  161. watchCSS: true,
  162. })
  163. });
  164. }
  165. function burger() {
  166. var hamburgers = document.querySelector(".hamburger");
  167. var nav = document.querySelector(".nav-main");
  168. hamburgers.addEventListener("click", function() {
  169. this.classList.toggle("is-active");
  170. nav.classList.toggle("is-active");
  171. $('html, body').toggleClass("is-active");
  172. $('#block-popsu-colloque-branding').toggleClass("is-active");
  173. });
  174. }
  175. function replaceAny(){
  176. var $selects = $(".js-form-type-select .form-select");
  177. $.each( $selects , function(i) {
  178. var selectOptionAll = $(this).find("option[value='All']");
  179. var optionContent = selectOptionAll.html();
  180. if ($(this).attr('id') == 'edit-field-theme-target-id') {
  181. var newhtml = optionContent.replace("- Any -", "Thèmes");
  182. } else if ($(this).attr('id') == 'edit-field-type-de-publication-target-id' ) {
  183. var newhtml = optionContent.replace("- Any -", "Publications");
  184. } else {
  185. // nothing
  186. }
  187. selectOptionAll.html(newhtml);
  188. });
  189. }
  190. function select_custom() {
  191. var x, i, j, l, ll, selElmnt, a, b, c;
  192. /* Look for any elements with the class "form-select": */
  193. x = document.querySelectorAll(".js-form-item-field-theme-target-id, .js-form-item-field-type-de-publication-target-id ");
  194. l = x.length;
  195. for (i = 0; i < l; i++) {
  196. selElmnt = x[i].getElementsByTagName("select")[0];
  197. ll = selElmnt.length;
  198. /* For each element, create a new DIV that will act as the selected item: */
  199. a = document.createElement("DIV");
  200. a.setAttribute("class", "select-selected");
  201. a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
  202. x[i].appendChild(a);
  203. /* For each element, create a new DIV that will contain the option list: */
  204. b = document.createElement("DIV");
  205. b.setAttribute("class", "select-items select-hide");
  206. for (j = 1; j < ll; j++) {
  207. /* For each option in the original select element,
  208. create a new DIV that will act as an option item: */
  209. c = document.createElement("DIV");
  210. c.innerHTML = selElmnt.options[j].innerHTML;
  211. c.addEventListener("click", function(e) {
  212. /* When an item is clicked, update the original select box,
  213. and the selected item: */
  214. var y, i, k, s, h, sl, yl;
  215. s = this.parentNode.parentNode.getElementsByTagName("select")[0];
  216. sl = s.length;
  217. h = this.parentNode.previousSibling;
  218. for (i = 0; i < sl; i++) {
  219. if (s.options[i].innerHTML == this.innerHTML) {
  220. s.selectedIndex = i;
  221. h.innerHTML = this.innerHTML;
  222. y = this.parentNode.getElementsByClassName("same-as-selected");
  223. yl = y.length;
  224. for (k = 0; k < yl; k++) {
  225. y[k].removeAttribute("class");
  226. }
  227. this.setAttribute("class", "same-as-selected");
  228. break;
  229. }
  230. }
  231. h.click();
  232. });
  233. b.appendChild(c);
  234. }
  235. x[i].appendChild(b);
  236. a.addEventListener("click", function(e) {
  237. /* When the select box is clicked, close any other select boxes,
  238. and open/close the current select box: */
  239. e.stopPropagation();
  240. closeAllSelect(this);
  241. this.nextSibling.classList.toggle("select-hide");
  242. this.classList.toggle("select-arrow-active");
  243. });
  244. }
  245. function closeAllSelect(elmnt) {
  246. /* A function that will close all select boxes in the document,
  247. except the current select box: */
  248. var x, y, i, xl, yl, arrNo = [];
  249. x = document.getElementsByClassName("select-items");
  250. y = document.getElementsByClassName("select-selected");
  251. xl = x.length;
  252. yl = y.length;
  253. for (i = 0; i < yl; i++) {
  254. if (elmnt == y[i]) {
  255. arrNo.push(i)
  256. } else {
  257. y[i].classList.remove("select-arrow-active");
  258. }
  259. }
  260. for (i = 0; i < xl; i++) {
  261. if (arrNo.indexOf(i)) {
  262. x[i].classList.add("select-hide");
  263. }
  264. }
  265. }
  266. /* If the user clicks anywhere outside the select box,
  267. then close all select boxes: */
  268. document.addEventListener("click", closeAllSelect);
  269. }
  270. function remove_isactive() {
  271. $( window ).resize(function() {
  272. var width = $(window).width();
  273. if (width <= '1185') {
  274. $('header .is-active').removeClass("is-active");
  275. $('body.is-active').removeClass("is-active");
  276. }
  277. });
  278. }
  279. $( document ).ready(function() {
  280. notes();
  281. slide();
  282. burger();
  283. replaceAny();
  284. select_custom();
  285. remove_isactive();
  286. });
  287. })(jQuery);