Created
February 24, 2016 04:02
-
-
Save NaokiStark/8f71575f6312b4a34cd8 to your computer and use it in GitHub Desktop.
fixed repeated buttons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const serverURL = 'http://glacial-cove-76906.herokuapp.com'; | |
getVotes= function(shoutId,cb){ | |
$.get(serverURL+'/get-votes?shout_id='+shoutId,function(res,status){ | |
return cb(res,status); | |
}); | |
} | |
renderButtons = function(){ | |
if(window.location.pathname ==='/mi'){ | |
$('.shout-footer > .s-action-list').each(function(){ | |
var shoutId = $(this).attr('data-id').trim(); | |
var self = this; | |
var $container = $($(self).closest('.activity-element')); | |
//Fabi | |
if($container.hasClass('negative-added')) | |
return true; //continue | |
//Mark as added - Fabi | |
$container.addClass('negative-added'); | |
getVotes(shoutId,function(res,status){ | |
var button = $( | |
`<div class="button-action-s pointer no-me-gusta" title="No me gusta"> | |
<div class="action-number" style="float:right;"> | |
${res?'<span class="like_count">'+res.count+'</span>': '<span class="like_count"> 0 </span>' } | |
</div> | |
<i class="icon-pulgarabajo" style="opacity:.6!important;"></i> | |
</div>`) | |
var test = $(self).children('.action-vote').before(button); | |
button.on('click', function(){ | |
var likes = parseInt(button.find('span.like_count').text()); | |
button.find('span.like_count').text(likes+1); | |
vote(shoutId); | |
}); | |
}); | |
}) | |
}else{ | |
$('.list-main-actions').each(function(){ | |
var self = this; | |
var shoutId = $('.shout-action-like').attr('data-id').trim(); | |
var $container = $($(self).closest('.shout-item')); | |
//Fabi | |
if($container.hasClass('negative-added')) | |
return true; //continue | |
//Mark as added - Fabi | |
$container.addClass('negative-added'); | |
getVotes(shoutId,function(res,status){ | |
var button = $( | |
`<li> | |
<a href="#" class="icon-pulgarabajo no-me-gusta" title="Votá negativo a este shout"> | |
<span class="like_count"> | |
${res?res.count:'0'} | |
</span> | |
</a> | |
</li>`); | |
$(self).append(button); | |
button.on('click', function(event,asd){ | |
var likes = parseInt(button.find('span.like_count').text()); | |
button.find('span.like_count').text(likes+1); | |
vote(shoutId); | |
}); | |
}); | |
}) | |
} | |
} | |
vote= function(shoutId){ | |
var avatarUrl = ''; | |
var user_id = ''; | |
var nick = $('.user-name').text().trim(); | |
$.get('http://api.taringa.net/user/nick/view/'+nick,function(res,status){ | |
user_id = res.id; | |
avatarUrl=res.avatar? res.avatar.medium:''; | |
$.post(serverURL+'/vote',{ | |
shout_id:shoutId, | |
avatarUrl:avatarUrl, | |
nick:nick, | |
user_id:user_id | |
},function(res,status){ | |
console.log(res,status); | |
}); | |
}) | |
} | |
$(document).ready(function(){ | |
//Stylesheet | |
var Stylesheet =".button-action-s.no-me-gusta .action-number{float:right;} .button-action-s.no-me-gusta .icon-pulgarabajo{float:left;margin:2px 11px;margin-right:2px;} "; | |
$('head').append('<style>'+Stylesheet+'</style>'); | |
renderButtons(); | |
}); | |
//Fabi | |
if(window.location.pathname ==='/mi'){ | |
// /mi | |
$('#Feed-list').onResize().on('resize',function(event){ | |
renderButtons(); | |
}); | |
} | |
else{ | |
// /shouts | |
$('.shouts-list').onResize().on('resize',function(event){ | |
renderButtons(); | |
}); | |
} | |
//Doesn't work | |
/* | |
$(document).ajaxSuccess(function(ev, jqXHR, settg) { | |
if (settg.url.indexOf('ajax/feed/fetch') > -1 || settg.url.indexOf('serv/more/trend') > -1) { | |
renderButtons(); | |
} | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment