Giter VIP home page Giter VIP logo

jquery-whenslow's Introduction

jQuery.whenSlow

There has been lots of research into response times and progress indicators.

When you display a status indicator and your operation is pretty quick (<= 1 second), some sort of flickering occurs by showing/hiding the status indicator. This can feel like the application is glitchy. To prevent this, the status indicator should only be shown once the operation is taking long enough for the user to notice. This jQuery plugin helps with this problem.

Download

Grab the script, download the full repository or fork it on GitHub.

Use

var view = {
  showLoadingIndicator: function() {
    $(document.body).append('<span>Loading...</span>');
  }
};

// The first parameter to $.whenSlow is always a jQuery Promise.
var promise = $.ajax({ url: '/foo/bars' });

$.whenSlow(promise, function() {
  view.showLoadingIndicator();
});

// or

$.whenSlow(promise, 'showLoadingIndicator', view);

Configuration

You can change $.whenSlow.defaults.slow if you want to redefine the minimum duration of a slow operation.

jquery-whenslow's People

Contributors

thecloudlesssky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jquery-whenslow's Issues

When execution finishes...

I just saw this plugin and it seems interesting but I have one question, suppose I pass an ajax request to the plugin and a function that shows an element with a spinner on screen. From what I understand if the request takes more than 500 ms it will execute the function and the spinner element will be shown. Although the plugin doesn't offer any way to pass a function to hide the "loading" element once the ajax request completes.
I believe there should be a way to pass the ajax request (promise), and two functions, one that will be executed in the execution time is reached and one that will be executed once the promise "finishes" and only in the case the first function was executed (if the first function was never executed there's no need to execute the second one to perform a clean up).

Does it make sense?

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.