$("#create-widget").on("click", function (e) {
// prevent a second click while processing
// can be important when you are loading data from a server
// and when you are adding even more time for fadeOut/fadeIn
$(this).prop("disabled", true);
// show loading..., remove any prior widget
$("#widget").hide();
$("#loading").show();
$("#widget").empty();
// create a twitter timeline widget
// see https://dev.twitter.com/web/javascript/creating-widgets
twttr.widgets.createTimeline(
"317788461761429504", // Widget ID from Ed's twitter account
$("#widget").get(0), // use .get(0) to access HTML Element
{
height: 300,
screenName: $("#screen_name").val()
}).then(function (element) {
// called when timeline has been successfully created
console.log("timeline creation complete");
// adjust width since twitter uses 520px as maximum
// see https://dev.twitter.com/web/embedded-timelines#dimensions
$(element).css("width", "100%");
// stop saying "loading..." and show the widget
$("#loading").fadeOut("slow", function () {
// when fadeOut is complete...
$("#widget").fadeIn("slow", function () {
// when fadeIn is complete, finally re-enable the button
$("#create-widget").prop("disabled", false);
});
});
}, function (status) {
// called on failure, not sure what arguments twitter passes
// it appears to pass back the HTTP status from the API
// see https://dev.twitter.com/overview/api/response-codes
// so ((typeof status) === "number")
// I can also see that the JSON in the HTTP response header has
// an error message (string) which makes sense since this library call
// is presumably using the API (which includes an error message as well)
// but they don't seem to pass that to this callback
//...
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.
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!
Console
Debug your Fiddle with a minimal built-in JavaScript console.