[FIX] website_blog: fix "select to tweet" feature
There was two main problems with the feature - The author name was not properly fetched so the feature which was supposed to add the author of the blog post in the tweet never worked -> this commit simply deletes it - The code was considering the url length in the size of the tweet, so if the url was 135 characters long, it considered that only 5 characters have to be taken in the selected text... which is wrong as twitter URL are all shortened to 23 characters by twitter opw-741530
This commit is contained in:
@@ -22,9 +22,12 @@
|
||||
popover_content += '<a class="o_share_comment mr12"><i class="fa fa-comment fa-lg mr4 ml4"/></a>';
|
||||
}
|
||||
if($('.blog_title, .blog_content').hasClass('js_tweet')){
|
||||
var current_url = window.location.href;
|
||||
var tweet_selected_text = this.getSelection('string').substring(0,option.maxLength-(current_url.length+option.author_name.length+7));
|
||||
var text = encodeURIComponent(_.str.sprintf('\"%s\" --@%s %s', tweet_selected_text, option.author_name, current_url));
|
||||
var tweet = '"%s" - %s';
|
||||
var baseLength = tweet.replace(/%s/g, '').length;
|
||||
// Shorten the selected text to match the tweet max length
|
||||
// Note: all (non-localhost) urls in a tweet have 23 characters https://support.twitter.com/articles/78124
|
||||
var selectedText = this.getSelection('string').substring(0, option.maxLength - baseLength - 23);
|
||||
var text = encodeURIComponent(_.str.sprintf(tweet, selectedText, window.location.href));
|
||||
popover_content += '<a onclick="window.open(\''+option.shareLink+text+'\',\'_'+option.target+'\',\'location=yes,height=570,width=520,scrollbars=yes,status=yes\')"><i class="ml4 mr4 fa fa-twitter fa-lg"/></a>';
|
||||
}
|
||||
return popover_content;
|
||||
|
||||
@@ -58,7 +58,7 @@ function shareArticle(event){
|
||||
|
||||
$(document).ready(function() {
|
||||
if ($('.website_blog').length) {
|
||||
$(".js_tweet, .js_comment").share({'author_name': $('#blog_author').text()});
|
||||
$(".js_tweet, .js_comment").share({});
|
||||
$('.cover_footer').on('click', page_transist);
|
||||
$('a[href^="#blog_content"]').on('click', animate);
|
||||
$('.o_twitter, .o_facebook, .o_linkedin, .o_google, .o_twitter_complete, .o_facebook_complete, .o_linkedin_complete, .o_google_complete').on('click', shareArticle);
|
||||
|
||||
Reference in New Issue
Block a user