Check out this link to view the demonstration - http://codepen.io/illpill/pen/VbeVEq
function sendTweet(message, author) {
window.open('https://twitter.com/intent/tweet?hashtags=thequotemachine&text=' + encodeURIComponent('"' + message + '" ' + author + " via"));
}
$('button.tweet').click(function() {
var currentQuote = $('#quote').text();
var currentAuthor = $('#author').text();
var truncatedString = truncateContent(currentQuote, currentAuthor)
sendTweet(truncatedString, currentAuthor);
});
It works like a charm on desktop. It extracts the quote and creates a tweet perfectly, but when I try it on my iPhone by tapping the button, nothing happens. Any thoughts on why this issue might occur?
This is the logic behind the truncateContent function:
function truncateContent(content, auth) {
var shorterContent = [];
var charCounter = 0;
contentSplit = content.split(" ");
if (content.length > (113 - auth.length)) {
for (var i = 0; i < contentSplit.length; i++) {
if (charCounter < (113 - auth.length)) {
charCounter += contentSplit[i].length + 1;
shorterContent.push(contentSplit[i]);
}
}
shorterContent.pop();
return (shorterContent.join(" ") + "...");
} else {
return content;
}
}