more cleanup

v1.18.x
barisusakli 11 years ago
parent 9b63facf6f
commit cabc3e5e3d

@ -4,12 +4,18 @@
define(['composer'], function(composer) { define(['composer'], function(composer) {
var PostTools = {}; var PostTools = {},
topicName;
PostTools.init = function(tid, threadState) { PostTools.init = function(tid, threadState) {
topicName = templates.get('topic_name');
var topicName = templates.get('topic_name'); addPostHandlers(tid, threadState);
addShareHandlers();
};
function addPostHandlers(tid, threadState) {
$('.topic').on('click', '.post_reply', function() { $('.topic').on('click', '.post_reply', function() {
if (threadState.locked !== '1') { if (threadState.locked !== '1') {
onReplyClicked($(this), tid, topicName); onReplyClicked($(this), tid, topicName);
@ -27,11 +33,11 @@ define(['composer'], function(composer) {
}); });
$('#post-container').on('click', '.upvote', function() { $('#post-container').on('click', '.upvote', function() {
onUpvoteClicked($(this)); toggleVote($(this), '.upvoted', 'posts.upvote');
}); });
$('#post-container').on('click', '.downvote', function() { $('#post-container').on('click', '.downvote', function() {
onDownvoteClicked($(this)); toggleVote($(this), '.downvoted', 'posts.downvote');
}); });
$('#post-container').on('click', '.flag', function() { $('#post-container').on('click', '.flag', function() {
@ -58,9 +64,7 @@ define(['composer'], function(composer) {
$(this).parents('.btn-group').find('.dropdown-toggle').click(); $(this).parents('.btn-group').find('.dropdown-toggle').click();
return false; return false;
}); });
}
addShareHandlers(topicName);
};
function onReplyClicked(button, tid, topicName) { function onReplyClicked(button, tid, topicName) {
var selectionText = '', var selectionText = '',
@ -110,14 +114,6 @@ define(['composer'], function(composer) {
return false; return false;
} }
function onUpvoteClicked(button) {
toggleVote(button, '.upvoted', 'posts.upvote');
}
function onDownvoteClicked(button) {
toggleVote(button, '.downvoted', 'posts.downvote');
}
function toggleVote(button, className, method) { function toggleVote(button, className, method) {
var post = button.parents('.post-row'), var post = button.parents('.post-row'),
currentState = post.find(className).length; currentState = post.find(className).length;
@ -227,7 +223,13 @@ define(['composer'], function(composer) {
}); });
} }
function addShareHandlers(topicName) { function addShareHandlers() {
function openShare(url, pid, width, height) {
window.open(url + encodeURIComponent(window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + pid), '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no');
return false;
}
$('#post-container').on('shown.bs.dropdown', '.share-dropdown', function() { $('#post-container').on('shown.bs.dropdown', '.share-dropdown', function() {
var pid = getPid($(this)); var pid = getPid($(this));
$('#post_' + pid + '_link').val(window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + pid); $('#post_' + pid + '_link').val(window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + pid);
@ -243,18 +245,15 @@ define(['composer'], function(composer) {
}); });
$('#post-container').on('click', '.twitter-share', function () { $('#post-container').on('click', '.twitter-share', function () {
window.open('https://twitter.com/intent/tweet?url=' + encodeURIComponent(window.location.href + '#' + getPid($(this))) + '&text=' + topicName, '_blank', 'width=550,height=420,scrollbars=no,status=no'); return openShare('https://twitter.com/intent/tweet?text=' + topicName + '&url=', getPid($(this)), 550, 420);
return false;
}); });
$('#post-container').on('click', '.facebook-share', function () { $('#post-container').on('click', '.facebook-share', function () {
window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.location.href + '#' + getPid($(this))), '_blank', 'width=626,height=436,scrollbars=no,status=no'); return openShare('https://www.facebook.com/sharer/sharer.php?u=', getPid($(this)), 626, 436);
return false;
}); });
$('#post-container').on('click', '.google-share', function () { $('#post-container').on('click', '.google-share', function () {
window.open('https://plus.google.com/share?url=' + encodeURIComponent(window.location.href + '#' + getPid($(this))), '_blank', 'width=500,height=570,scrollbars=no,status=no'); return openShare('https://plus.google.com/share?url=', getPid($(this)), 500, 570);
return false;
}); });
} }

Loading…
Cancel
Save