Skip to content

Commit

Permalink
fixing bug for doing cb() for multiple loads
Browse files Browse the repository at this point in the history
  • Loading branch information
badunk committed Mar 23, 2014
1 parent 14b6b3b commit bb5df53
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
var content = self.window().document.body.innerHTML;
return content;
};
self.load = function(html, cb){
self.load = function(html){
var cb = typeof arguments[arguments.length - 1] === 'function' ? arguments[arguments.length -1] : null;
addToContainer(self.read.apply(self, arguments), cb);
};
self.set = function(html){
Expand All @@ -43,12 +44,12 @@
addToContainer(objToHTML(obj));
};
self.read = function(){
var htmlChunks = [];
var htmlChunks = '';

Array.prototype.slice.call(arguments, 0).forEach(function(argument){
if (typeof argument === 'string') htmlChunks.push(getFixtureHtml(argument));
if (typeof argument === 'string') htmlChunks += getFixtureHtml(argument);
});
return htmlChunks.join('');
return htmlChunks;
};
self.clearCache = function(){
fixturesCache = {};
Expand Down Expand Up @@ -84,7 +85,7 @@
doc.write(html);
doc.close();
};
var addToContainer = function(html){
var addToContainer = function(html, cb){
var container = document.getElementById(self.containerId);
if (!container) createContainer.apply(self, arguments);
else self.window().document.body.innerHTML += html;
Expand Down

0 comments on commit bb5df53

Please sign in to comment.