Skip to content

Commit 5dbc86b

Browse files
committed
Added frame support for multi sites
1 parent 4f83113 commit 5dbc86b

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

lib/simplehar.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ var fs = require('fs'),
2929
}
3030

3131
if(args.return) {
32-
if(ilen > 1 && total.push(html) === ilen) {
33-
args.callback(total);
34-
}
32+
if(ilen > 1 && total.push(html) === ilen)
33+
args.callback(
34+
simplehar.multiFrame(total, args.frame, true)
35+
);
3536
else if(ilen < 2)
3637
args.callback(html);
3738
}
@@ -98,7 +99,7 @@ var fs = require('fs'),
9899
fs.writeFileSync(filename, html.html || html);
99100
}
100101
if(args.return)
101-
return htmls;
102+
return simplehar.multiFrame(htmls, args.frame, ilen > 1);
102103

103104
}
104105

@@ -360,6 +361,32 @@ simplehar.makeFrame = function(html, args) {
360361

361362
};
362363

364+
//Return multiple sites frames
365+
simplehar.multiFrame = function(htmls, frame, multi) {
366+
'use strict';
367+
368+
var i = 0,
369+
ilen = htmls.length,
370+
result;
371+
372+
if((htmls[0].js || htmls[0].css) && frame && multi) {
373+
result = {html:[]};
374+
for(;i<ilen;i++)
375+
result.html.push(htmls[i].html);
376+
377+
if(htmls[0].js)
378+
result.js = htmls[0].js;
379+
380+
if(htmls[0].css)
381+
result.css = htmls[0].css;
382+
383+
return result;
384+
}
385+
386+
return htmls;
387+
388+
};
389+
363390
//Copy the source to simpleharSrc folder
364391
simplehar.copySrc = function(dir) {
365392
'use strict';

0 commit comments

Comments
 (0)