Skip to content

A tiny addition to jQuery. A few simple methods for creating Deferreds that resolve on certain DOM changes.

License

Notifications You must be signed in to change notification settings

Avaq/jQuery-DOMTimers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jQuery DOMTimers (version 1.0.1)

Introduction

Adds two functions to the jQuery library: $.DOMReady() - Returns a Deferred that resolves when the DOM is ready. $.DOMRendered() - Returns a Deferred that resolves when the DOM has finished rendering the HTML.

Why?!

This is part of my personal project to turn every asynchronous task in JavaScript into a jQuery.Deferred. It would make my, and your life as a JavaScript programmer that much easier.

This plug-in allows for code like this:

//The function that uses data returned from the ajax request to the server to render a page.
function renderPage(data){
  
  //Do some rendering. This is done asynchronously by the browser.
  $('body').html('<p>' + data.message + '</p>');

  //Return a deferred that resolves when the rendering is done.
  return $.DOMRendered();

}

//Load the page after both the AJAX request has completed, and the DOM is ready.
$.when($.ajax('my/url.json'), $.DOMReady()).done(function(ajax, domready){
  
  //Render the page using the first result from the ajax Deferred and alert the user when we're all done.
  renderPage(ajax[0]).done(function(){
    alert('Page has loaded and rendered!');
  });

});

Download

See all available downloads.

jQuery methods

jQuery.DOMReady()

Returns a Deferred.promise() that resolves as soon as the DOM has loaded. After the DOM has loaded, additional calls to this method return the same Deferred.promise() object.

jQuery.DOMRendered()

Each call to this method creates new promise objects that each resolve as soon as the DOM has finished rendering.

License

Copyright (c) 2012-2013 Avaq, https://github.com/Avaq

jQuery DOMTimers is licensed under the MIT license. The license is included as LICENSE in this directory.

About

A tiny addition to jQuery. A few simple methods for creating Deferreds that resolve on certain DOM changes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published