script.js 9.7 KB

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