// Sandbox variables
var totalLoadingTime = 10000; //Change this to simulate different loading times
// ____________ //
var loadingOverlayDelay = 1000; // Time it takes to display the loading overlay after a click
var width;
var messageTimeout;
var messageDelay = 5000 // "Loading..." text delay to display
$('.data-linked').on('click', function() {
// No need to worry about this - It's already in the system
$('.data-linked').removeClass('active');
$(this).addClass('active');
disableClicks(); // Disables clicks
startLoading(); // Simulates the loading of content
});
// Function to simulate the loading of the content
function startLoading() {
var start = new Date;
(function update() {
if ((new Date - start) >= totalLoadingTime) {
removeLoading();
} else if ((new Date - start) >= loadingOverlayDelay && (new Date - start) < (loadingOverlayDelay + 10)) {
addLoading();
setTimeout(update, 0);
} else {
setTimeout(update, 0);
}
})();
};
// Function that will disable clicks on both side of the UI
function disableClicks() {
$('#directory-list, #directory-details').addClass('disabled'); // Disables List
}
// Function that will fade in the loading overlay
function addLoading() {
calculateWidth();
// The following adds Loading Overlay to a specific area depending on the device width
if (width >= 640) {
$('#directory-details').find('.directory-loading').fadeIn(400);
} else {
$('#directory-list').find('.directory-loading').fadeIn(400);
}
// Delay to display the "Loading..." text
messageTimeout = setTimeout(function() {
$('.directory-loading .loading-text').hide().text("Loading...").fadeIn(250);
}, messageDelay);
}
// Function that will remove the loading overlay and enable clicks
function removeLoading() {
clearTimeout(messageTimeout); // Clears delay for text to appear
calculateWidth();
// The following removes Loading Overlay from a specific area depending on the device width
...
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.