var consoleLine = "<p class=\"console-line\"></p>";
//console log emulation
console = {
log: function(text) {
$("#console-log").append($(consoleLine).html(text));
}
}
var testyTest = "My line goes here!";
console.log(testyTest);
var quoteStr = '\"A ship in port is safe, but that is not what ships are for. Sail out to sea and do new things. Extra, blah, blah, blah, blah.\"';
var nameStr = '<a href=\"http://www.biography.com/people/grace-hopper-21406809#early-life\">Rear Admiral Grace Hopper</a>';
console.log(quoteStr);
console.log(nameStr);
//strips HTML markup out of the string
var cleanedNameStr = nameStr.replace(/<[^>]*>?/gi, '');
console.log(cleanedNameStr);
//max tweet == 140 char. " - " and stripped nameStr needs
//to be allowed for in length of tweet. So....
var maxLength = 140 - (3 + cleanedNameStr.length);
console.log("tweet room = " + maxLength);
var isLess140 = true;
//check quoteStr against maxLength. If longer, split into
//pieces at periods
if (quoteStr.length > maxLength) {
console.log("this string is too long.");
//split quote strigs up at periods before checking length
var strArray = quoteStr.split(".");
var tweetStr = " ";
var ct = 0;
console.log(tweetStr);
}
do{
tweetStr += strArray[ct] + ". ";
console.log(tweetStr);
ct++;
console.log(ct);
var strALen = tweetStr.length;
console.log(strALen);
var strB = strArray[ct];
console.log(strB);
var strBLen = strB.length;
console.log(strBLen);
if ((strALen + strBLen) >= maxLength){
isLess140 = false;
}
} while( isLess140 === true);
//push the quote to the twitter button
function dynamicURL(combinedStr) {
//also assign the values to a string for twitter
var twitterURL = "https://twitter.com/intent/tweet?text=" + combinedStr;
document.getElementById("tweettext") = twitterURL;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.