script.js 9.8 KB

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