Skip to content

Commit

Permalink
Make the differed object accessible on page to chain multiple
Browse files Browse the repository at this point in the history
template-dependent methods
  • Loading branch information
gopkumargopi committed Aug 18, 2015
1 parent 08ac1e4 commit 6d9e5e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion README.md
Expand Up @@ -85,7 +85,6 @@ $(fragment).autoBars({

Check the [example.html](example.html) for a complete running preview of what jQuery autobars can do


## Loading the handlebars templates from a list
If you don't like to set the script tags directly in your DOM you just have to specify a list of templates to be loaded for instance:

Expand Down Expand Up @@ -114,6 +113,24 @@ DOM will be ingnored and will be loaded using the template list instead
If you want to see an example check the [example2.html](example2.html) file


## Chaining methods to the jQuery autobars deferred object

When dealing with different JS modules you might want to chain your methods (that depend on the handlebars template) to the deferred object of jQuery autobars.
This way you don't have to wrap your methods in `$(document).autoBars()` to ensure loaded templates which causes multiple asynchronous call for the templates.
Instead chain your methods to the jQuery autobars deferred object `$.handlebarTemplates.deferred`

Example of chaining methods to the deferred object of jQuery autobars

```
var chain() {
// your method that depend on handlebars template loaded by autobars
}
//This way ensure your methods are called after jQuery autobars have loaded your templates.
$.handlebarTemplates.deferred = $.handlebarTemplates.deferred.then(chain, chain);
```

## Defaults plugin configuration
```
$.fn.autoBars.defaults = {
Expand Down
3 changes: 2 additions & 1 deletion src/jquery-autobars.js
Expand Up @@ -172,7 +172,8 @@
// we delay execution of the callback until all
// the promises are fulfilled!!
if (typeof(options.callback) === 'function') {
$.when.apply(this, promises).done(options.callback);
//Make the differed object accessible on page to chain multiple template-dependent methods
$.handlebarTemplates.deferred = $.when.apply(this, promises).done(options.callback);
}
// return the original jquery object
return this;
Expand Down

0 comments on commit 6d9e5e5

Please sign in to comment.