Skip to content

Commit

Permalink
Combined domTargetResolver and targetSelector into target on the opti…
Browse files Browse the repository at this point in the history
…ons hash
  • Loading branch information
ifandelse committed Nov 30, 2011
1 parent 09b0e05 commit e3e19c8
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/loading/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $(function(){
return $.tmpl(template, model);
};
infuser.infuse("Example", {
targetSelector: "#target",
target: "#target",
render: function(target, template) {
// really ugly way to simulate long running template retrieval
setTimeout(function() { origRender(target, template); }, 4000);
Expand Down
4 changes: 2 additions & 2 deletions examples/shorthand/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $(function(){

$('#btnPlain').click(function(){
// Shorthand syntax allows you to retrieve the template, and attach to target DOM element all in one call
infuser.infuse("HelloWorld", { postRender: togglePlain, targetSelector: "#targetPlain" });
infuser.infuse("HelloWorld", { postRender: togglePlain, target: "#targetPlain" });
});

$('#btnFancy').click(function(){
Expand All @@ -35,7 +35,7 @@ $(function(){
.infuse(
"Example",
{
targetSelector: "#targetFancy",
target: "#targetFancy",
model: model,
preRender: function(target, template) { $(target).children().remove().end().fadeOut().hide(); },
render: function(target, template) { $(target).append(template).slideDown('slow'); },
Expand Down
2 changes: 1 addition & 1 deletion examples/trafficcop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var toggled = false,
infuser.infuse(
"Example",
{
targetSelector: "#target",
target: "#target",
model: menus[modelNum],
render: function(target, template) {
$(target).append(template).slideDown('slow');
Expand Down
2 changes: 1 addition & 1 deletion examples/underscore/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $(function(){
};
infuser.infuse("Example", {
model: model,
targetSelector: "#target",
target: "#target",
postRender: function(target) {
if(!toggled) {
$("#msg").text("The next click will use the locally cached template");
Expand Down
4 changes: 2 additions & 2 deletions lib/infuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var infuser = {
},

defaults: {
domTargetResolver: function(templateId) { return "#" + templateId }, // DEFAULT MAPPING
target: function(templateId) { return "#" + templateId }, // DEFAULT MAPPING
loadingTemplate: {
content: '<div class="infuser-loading">Loading...</div>',
transitionIn: function(target) {
Expand Down Expand Up @@ -174,7 +174,7 @@ var infuser = {
infuse: function(templateId, renderOptions) {
var self = this,
options = $.extend({}, self.defaults, renderOptions),
targetElement = options.targetSelector || options.domTargetResolver(templateId);
targetElement = typeof options.target === 'function' ? options.target(templateId) : options.target;
if(options.useLoadingTemplate) {
options.loadingTemplate.transitionIn(targetElement);
}
Expand Down
Binary file modified lib/infuser.min.gz.js
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/infuser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var infuser = {
},

defaults: {
domTargetResolver: function(templateId) { return "#" + templateId }, // DEFAULT MAPPING
target: function(templateId) { return "#" + templateId }, // DEFAULT MAPPING
loadingTemplate: {
content: '<div class="infuser-loading">Loading...</div>',
transitionIn: function(target) {
Expand Down Expand Up @@ -99,7 +99,7 @@ var infuser = {
infuse: function(templateId, renderOptions) {
var self = this,
options = $.extend({}, self.defaults, renderOptions),
targetElement = options.targetSelector || options.domTargetResolver(templateId);
targetElement = typeof options.target === 'function' ? options.target(templateId) : options.target;
if(options.useLoadingTemplate) {
options.loadingTemplate.transitionIn(targetElement);
}
Expand Down

0 comments on commit e3e19c8

Please sign in to comment.