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