Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding a feature that allows you to set options
So you can now add the attribute of "options" that will be parsed
as a JSON object and then passed to the handlebars compile
function with the source code.
  • Loading branch information
Kieron Gillespie committed Oct 10, 2018
1 parent deb5530 commit e8bc5b1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/jquery-autobars.js
Expand Up @@ -100,6 +100,16 @@
context.find('[type="text/x-handlebars-template"]')
.each(function (index, element) {
var loadUrl = $(element).attr('src');
var hbsOptions = {};

try {
hbsOptions = JSON.parse($(element).attr('options'));
}

catch(e) {
hbsOptions = {};
}

//var name = loadUrl.match(/([^\/]+)(?=\.\w+$)/)[0];
var name = methods.parseName(loadUrl);
//here we gather all our promises
Expand All @@ -108,7 +118,7 @@
url: loadUrl,
dataType: 'text'
}).done(function (data) {
$.handlebarTemplates[name] = Handlebars.compile(data);
$.handlebarTemplates[name] = Handlebars.compile(data, hbsOptions);
})
);
});
Expand Down Expand Up @@ -172,8 +182,8 @@
// we delay execution of the callback until all
// the promises are fulfilled!!
if (typeof(options.callback) === 'function') {
//Make the differed object accessible on page to chain multiple template-dependent methods
$.handlebarTemplates.deferred = $.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 e8bc5b1

Please sign in to comment.