Commit fbccb76bb7cb89f8afb50ea8c1b3337e2c9f92f9

Authored by Victor Costa
1 parent a69f25d3

Change participate button event

Showing 1 changed file with 28 additions and 27 deletions   Show diff stats
js/main.js
... ... @@ -695,6 +695,34 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun
695 695 $('.calendar-container').html(calendarTemplate(params));
696 696 $('.calendar-container .calendar.' + active_category).show();
697 697 // $('.calendar-container .calendar').slick();
  698 +
  699 + $(document).off('click', '#talk__button-participate');
  700 + $(document).on('click', '#talk__button-participate', function(e) {
  701 + e.preventDefault();
  702 + var $bt = $(this);
  703 + if(!logged_in) {
  704 + $('#login-button').click();
  705 + $('html, body').animate({scrollTop: 0}, 'fast');
  706 + } else {
  707 + $.ajax({
  708 + type: 'post',
  709 + url: host + '/api/v1/articles/' + $(this).data('event-id') + '/follow',
  710 + data: {
  711 + private_token: Main.private_token
  712 + }
  713 + }).done(function(data) {
  714 + var message = 'Sua participação foi registrada com sucesso';
  715 + if(!data.success) {
  716 + message = 'Sua participação já foi registrada';
  717 + } else {
  718 + var value= $bt.closest('.talk__participate').find('.talk__value');
  719 + value.text(parseInt(value.text()) + 1);
  720 + }
  721 + Main.displaySuccess($bt.closest('.talk__participate'), message, 2000, 'icon-proposal-sent');
  722 + });
  723 + }
  724 + });
  725 +
698 726 });
699 727 });
700 728 },
... ... @@ -1147,33 +1175,6 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun
1147 1175 e.preventDefault();
1148 1176 });
1149 1177  
1150   - $(document).on('click', '#talk__button-participate', function(e) {
1151   - e.preventDefault();
1152   - var $bt = $(this);
1153   - if(!logged_in) {
1154   - $('#login-button').click();
1155   - $('html, body').animate({scrollTop: 0}, 'fast');
1156   - } else {
1157   - $.ajax({
1158   - type: 'post',
1159   - url: host + '/api/v1/articles/' + $(this).data('event-id') + '/follow',
1160   - data: {
1161   - private_token: Main.private_token
1162   - }
1163   - }).done(function(data) {
1164   - var message = 'Sua participação foi registrada com sucesso';
1165   - if(!data.success) {
1166   - message = 'Sua participação já foi registrada';
1167   - } else {
1168   - var value= $bt.closest('.talk__participate').find('.talk__value');
1169   - value.text(parseInt(value.text()) + 1);
1170   - }
1171   - Main.displaySuccess($bt.closest('.talk__participate'), message, 2000, 'icon-proposal-sent');
1172   - });
1173   - }
1174   - });
1175   -
1176   -
1177 1178 });
1178 1179  
1179 1180 window.addEventListener("message", function(ev) {
... ...