]> git.0d.be Git - panikweb-studioneau.git/blob - panikweb_studioneau/templates/includes/footer.html
don't break on carrousel with a single item
[panikweb-studioneau.git] / panikweb_studioneau / templates / includes / footer.html
1 <nav class="footer">
2   {% for cell in cells %}
3   <ul class="footer-list-{{forloop.counter0}} {{ cell.css_class_names }}">
4     {% for link in cell.get_items %}
5     <li class="{{ link.link_page.slug }}"><a href="{{ link.get_url }}"><span>{{ link.get_additional_label }}</span></a></li>
6     {% endfor %}
7   </ul>
8   {% endfor %}
9 </nav>
10 <script>
11 $(function() {
12  function init_page() {
13    // burger
14    if ($('#extra-menu.with-links').length == 0) {
15      $('.footer-list-1').clone().appendTo($('#extra-menu'));
16      $('.footer-list-0').clone().appendTo($('#extra-menu'));
17      $('#extra-menu').addClass('with-links').find('a').ajaxifyClick();
18    }
19    init_roll_buttons();
20    init_newsletter_form();
21  }
22
23  var roll_timeout = null;
24  function init_roll_buttons() {
25    if ($('#focus').length == 0) return;
26    if ($('#focus').hasClass('initialized')) return;
27    if (roll_timeout) {
28      clearTimeout(roll_timeout);
29      roll_timeout = null;
30    }
31    $('#next').on('click', function(ev, autoroll) {
32      if (roll_timeout && !autoroll) { clearTimeout(roll_timeout); roll_timeout = null; }
33      var current_position = $(window).scrollTop();
34      var $first = $('#focus .item:not(.transition)').first();
35      var $last = $('#focus .item:not(.transition)').last();
36      if ($first.length == 0) return;
37      var $cloned = $first.clone();
38      $cloned.addClass('transition').insertBefore($('#focus .item').first());
39      $cloned.on('transitionend', function() { $cloned.remove(); });
40      $first.detach().insertAfter($last);
41      $cloned[0].offsetHeight; // redraw
42      $cloned.addClass('faded');
43      if (autoroll) {
44        /* this is required to avoid some strange autoscrolling when the next
45           button is not in the viewport */
46        $(window).scrollTop(current_position);
47      }
48      if (autoroll) { roll_timeout = setTimeout(function() {$('#next').trigger('click', ['autoroll']); }, 10000); }
49    });
50    $('#prev').on('click', function(ev, autoroll) {
51      if (roll_timeout && !autoroll) { clearTimeout(roll_timeout); roll_timeout = null; }
52      var $first = $('#focus .item:not(.transition)').first();
53      var $last = $('#focus .item:not(.transition)').last();
54      if ($first.length == 0) return;
55      var $cloned = $first.clone();
56      $cloned.addClass('transition').insertBefore($('#focus .item').first());
57      $cloned.on('transitionend', function() { $cloned.remove(); });
58      $last.detach().insertBefore($first);
59      $cloned[0].offsetHeight; // redraw
60      $cloned.addClass('faded');
61      if (autoroll) { roll_timeout = setTimeout(function() {$('#next').trigger('click', ['autoroll']); }, 10000); }
62    });
63    $('#focus').addClass('initialized');
64    roll_timeout = setTimeout(function() {$('#next').trigger('click', ['autoroll']); }, 10000);
65  }
66  function init_newsletter_form() {
67    $('#subscribe-form').off('submit').on('submit', function() {
68      var $form = $(this);
69      var url = $form.attr('action');
70      var data = $form.serialize();
71      $.post(url, data).done(function() {
72        $form.removeClass('error');
73        $form.find('input').attr('disabled', 'disabled');
74        $form.find('button').text('OK').attr('disabled', 'disabled');
75      }).fail(function() {
76        $form.addClass('error');
77      });;
78      return false;
79    });
80  }
81  $(document).on('panikweb:load-page', init_page);
82  init_page();
83
84  $(function() {
85    $(document).on('panikweb:week-change', function() {
86      var $week_title = $('#week > h2');
87      if ($('#week .current-week').length) {
88        $week_title.text($week_title.data('this-week-label'));
89      } else {
90        $week_title.text($week_title.data('other-week-label') +
91          ' (' + $('.program.tabs button').first().data('neau-text') +
92          ' - ' + $('.program.tabs button').last().data('neau-text') + ')');
93      }
94    });
95  });
96
97 });
98 </script>