// simulate a long-running task
function getDataAsync() {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve($('#data').html());
}, 3000);
});
}
// register popover on button
$('#show-menu').popover({
container: 'body',
content: function () {
// credit: http://stackoverflow.com/a/14560039
// create a placeholder id
var tmpId = 'tmp-id-' + $.now();
// initiate data retrieval and attach a success handler
getDataAsync().then(function (data) {
$('#' + tmpId).removeClass('loading spinner').html(data);
});
// generate temporary content for the placeholder to show the user while we wait
return $('<div>').attr('id', tmpId).addClass('loading spinner');
},
html: true,
placement: 'bottom',
title: 'Create a thing',
trigger: 'hover'
});
// register click handler for dynamically-generated DOM elements
$(document).on('click', '.create', function (e) {
// manually hide the popover since we aren't interacting with it directly
$('#show-menu').popover('hide')
// do something creative with the data
$('#messages').append('Created a ' + $(e.target).attr('id') + ' and released it into the wild!<br/>');
});
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.