script.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. console.log('dateValue',dateValue);
  126. $("<span>"+dateValue+"</span>").prependTo($(this));
  127. }
  128. });
  129. },
  130. }
  131. })
  132. });
  133. var $footer_slide = $('footer .__slide');
  134. $footer_slide.each(function() {
  135. $(this).flickity({
  136. cellAlign: 'left',
  137. pageDots: false,
  138. autoPlay: true,
  139. pauseAutoPlayOnHover: false,
  140. contain: true,
  141. prevNextButtons: false,
  142. })
  143. });
  144. var $slide_paragrpahe = $('main .paragraph .__slide');
  145. $slide_paragrpahe.each(function() {
  146. $(this).flickity({
  147. cellAlign: 'left',
  148. pageDots: false,
  149. prevNextButtons: false,
  150. contain: true,
  151. watchCSS: true,
  152. })
  153. });
  154. }
  155. function burger() {
  156. var hamburgers = document.querySelector(".hamburger");
  157. var nav = document.querySelector(".nav-main");
  158. hamburgers.addEventListener("click", function() {
  159. this.classList.toggle("is-active");
  160. nav.classList.toggle("is-active");
  161. $('html, body').toggleClass("is-active");
  162. $('#block-popsu-colloque-branding').toggleClass("is-active");
  163. });
  164. }
  165. function replaceAny(){
  166. var $selects = $(".js-form-type-select .form-select");
  167. $.each( $selects , function(i) {
  168. var selectOptionAll = $(this).find("option[value='All']");
  169. var optionContent = selectOptionAll.html();
  170. if ($(this).attr('id') == 'edit-field-theme-target-id') {
  171. var newhtml = optionContent.replace("- Any -", "Thèmes");
  172. } else if ($(this).attr('id') == 'edit-field-type-de-publication-target-id' ) {
  173. var newhtml = optionContent.replace("- Any -", "Publications");
  174. } else {
  175. // nothing
  176. }
  177. selectOptionAll.html(newhtml);
  178. });
  179. }
  180. function select_custom() {
  181. var x, i, j, l, ll, selElmnt, a, b, c;
  182. /* Look for any elements with the class "form-select": */
  183. x = document.querySelectorAll(".js-form-item-field-theme-target-id, .js-form-item-field-type-de-publication-target-id ");
  184. l = x.length;
  185. for (i = 0; i < l; i++) {
  186. selElmnt = x[i].getElementsByTagName("select")[0];
  187. ll = selElmnt.length;
  188. /* For each element, create a new DIV that will act as the selected item: */
  189. a = document.createElement("DIV");
  190. a.setAttribute("class", "select-selected");
  191. a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
  192. x[i].appendChild(a);
  193. /* For each element, create a new DIV that will contain the option list: */
  194. b = document.createElement("DIV");
  195. b.setAttribute("class", "select-items select-hide");
  196. for (j = 1; j < ll; j++) {
  197. /* For each option in the original select element,
  198. create a new DIV that will act as an option item: */
  199. c = document.createElement("DIV");
  200. c.innerHTML = selElmnt.options[j].innerHTML;
  201. c.addEventListener("click", function(e) {
  202. /* When an item is clicked, update the original select box,
  203. and the selected item: */
  204. var y, i, k, s, h, sl, yl;
  205. s = this.parentNode.parentNode.getElementsByTagName("select")[0];
  206. sl = s.length;
  207. h = this.parentNode.previousSibling;
  208. for (i = 0; i < sl; i++) {
  209. if (s.options[i].innerHTML == this.innerHTML) {
  210. s.selectedIndex = i;
  211. h.innerHTML = this.innerHTML;
  212. y = this.parentNode.getElementsByClassName("same-as-selected");
  213. yl = y.length;
  214. for (k = 0; k < yl; k++) {
  215. y[k].removeAttribute("class");
  216. }
  217. this.setAttribute("class", "same-as-selected");
  218. break;
  219. }
  220. }
  221. h.click();
  222. });
  223. b.appendChild(c);
  224. }
  225. x[i].appendChild(b);
  226. a.addEventListener("click", function(e) {
  227. /* When the select box is clicked, close any other select boxes,
  228. and open/close the current select box: */
  229. e.stopPropagation();
  230. closeAllSelect(this);
  231. this.nextSibling.classList.toggle("select-hide");
  232. this.classList.toggle("select-arrow-active");
  233. });
  234. }
  235. function closeAllSelect(elmnt) {
  236. /* A function that will close all select boxes in the document,
  237. except the current select box: */
  238. var x, y, i, xl, yl, arrNo = [];
  239. x = document.getElementsByClassName("select-items");
  240. y = document.getElementsByClassName("select-selected");
  241. xl = x.length;
  242. yl = y.length;
  243. for (i = 0; i < yl; i++) {
  244. if (elmnt == y[i]) {
  245. arrNo.push(i)
  246. } else {
  247. y[i].classList.remove("select-arrow-active");
  248. }
  249. }
  250. for (i = 0; i < xl; i++) {
  251. if (arrNo.indexOf(i)) {
  252. x[i].classList.add("select-hide");
  253. }
  254. }
  255. }
  256. /* If the user clicks anywhere outside the select box,
  257. then close all select boxes: */
  258. document.addEventListener("click", closeAllSelect);
  259. }
  260. function remove_isactive() {
  261. $( window ).resize(function() {
  262. var width = $(window).width();
  263. if (width <= '1185') {
  264. $('header .is-active').removeClass("is-active");
  265. $('body.is-active').removeClass("is-active");
  266. }
  267. });
  268. }
  269. $( document ).ready(function() {
  270. // currenturl();
  271. notes();
  272. slide();
  273. burger();
  274. replaceAny();
  275. select_custom();
  276. remove_isactive();
  277. });
  278. })(jQuery);