main.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. window._coliberatorURL = 'http://localhost/coliberator/';
  2. window.Coliberator = {
  3. data: {},
  4. templates: {
  5. speaker: function (data){
  6. return '<li data-id="'+data.id+'" class="participant-item"><a href="#" class="participant" title="Click for more details"><img src="'+data.imageURL+'" alt="'+data.name+'"/><span class="participant-details">'+data.name+'</span></a></li>';
  7. },
  8. speakerDescription: function (data){
  9. var presentations = '<div class="presentations"><span class="category">Speaks about:</span><ul>',
  10. i, l, v;
  11. for (i = 0, l = data.presentations.length; i < l; i ++) {
  12. v = data.presentations[i];
  13. presentations += '<li>' + v.title + '</li>';
  14. }
  15. presentations += '</ul></div>';
  16. return '<div class="pop-up"><div class="details"><img src="'+data.imageURL+'" alt="'+data.name+'"/><h2>'+data.name+'</h2><span class="description">'+data.description+'</span>'+presentations+'<button class="close-btn" title="Close the description panel"></button></div></div>';
  17. },
  18. presentation: function (data){
  19. return '<li><span class="when">'+data.when+'</span><span class="title">'+data.title+'</span><span class="details"> de '+data.name+'</span><p>'+data.description+'</p></li>';
  20. }
  21. },
  22. build: {
  23. presentations: function (data) {
  24. var el = $('#presentations'),
  25. i, l, v = '';
  26. for (i = 0, l = data.length; i < l; i ++) {
  27. v += Coliberator.templates.presentation(data[i]);
  28. }
  29. el.append(v);
  30. el.on('click','li', Coliberator.build.showPresentationDescription);
  31. },
  32. speakers: function (data) {
  33. var el = $('#speakers'),
  34. i, l, v = '';
  35. for (i = 0, l = data.length; i < l; i ++) {
  36. v += Coliberator.templates.speaker(data[i]);
  37. }
  38. el.append(v);
  39. el.on('click','li', Coliberator.build.speakerDescription);
  40. },
  41. speakerDescription: function (ev) {
  42. var $this = $(this),
  43. data,
  44. $descrEl,
  45. closeFunction = function () {
  46. var $el = $(this);
  47. $el.animate({
  48. top: '100%'
  49. },'fast', function() {
  50. $el.parent().remove();
  51. $el.remove();
  52. $el.blur();
  53. $this.focus();
  54. $('body').off();
  55. });
  56. };
  57. $this.blur();
  58. ev.preventDefault();
  59. data = Coliberator.data.speakers[$this.data('id')];
  60. $descrEl = $(Coliberator.templates.speakerDescription(data));
  61. // ... event participants .append
  62. $('body').prepend($descrEl);
  63. var $details = $descrEl.find('.details').animate({
  64. top: '25%'
  65. },'fast').on('click','.close-btn', function(){
  66. $el = $(this.parentElement);
  67. closeFunction.call($details);
  68. });
  69. $('body').keypress(function(e){
  70. // bind escape to the close modal functionality
  71. if (e.keyCode == 27) {
  72. closeFunction.call($details);
  73. }
  74. });
  75. // set focus on the close button: fixes a bug where you could press
  76. // enter multiple times on participant and helps ux
  77. $details.find('.close-btn').focus();
  78. },
  79. showPresentationDescription: function (ev) {
  80. var $this = $(this),
  81. data,
  82. $descrEl;
  83. ev.preventDefault();
  84. $this.find('p').stop().slideToggle();
  85. }
  86. }
  87. }
  88. $(document).ready(function() {
  89. Coliberator.build.speakers(Coliberator.data.speakers);
  90. Coliberator.build.presentations(Coliberator.data.presentations);
  91. $('.header-container').on('click','a',function (){
  92. //scrollTop: $(this).offset().top + 'px'
  93. var el = $($(this).attr('href')), top;
  94. if (el.length) {
  95. top = el.offset().top - $('.header-container').outerHeight();
  96. } else {
  97. top = 0;
  98. }
  99. $('body').animate({
  100. scrollTop: top + 'px'
  101. }, 'fast');
  102. });
  103. });