script.js 8.6 KB

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