Skip to content

Commit 8fea920

Browse files
committed
Removed function loadFromUrl and added loadFromUrls (gnab#573)
1 parent 6384a3e commit 8fea920

File tree

1 file changed

+53
-20
lines changed

1 file changed

+53
-20
lines changed

src/remark/models/slideshow.js

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Slideshow (events, dom, options, callback) {
2222
Navigation.call(self, events);
2323

2424
self.loadFromString = loadFromString;
25-
self.loadFromUrl = loadFromUrl;
25+
self.loadFromUrls = loadFromUrls;
2626
self.update = update;
2727
self.getLinks = getLinks;
2828
self.getSlides = getSlides;
@@ -61,7 +61,10 @@ function Slideshow (events, dom, options, callback) {
6161
});
6262

6363
if (options.sourceUrl) {
64-
loadFromUrl(options.sourceUrl, callback);
64+
loadFromUrls([ options.sourceUrl ], callback);
65+
}
66+
else if (options.sourceUrls){
67+
loadFromUrls(options.sourceUrls, callback);
6568
}
6669
else {
6770
loadFromString(options.source);
@@ -88,27 +91,57 @@ function Slideshow (events, dom, options, callback) {
8891
events.emit('slidesChanged');
8992
}
9093

91-
function loadFromUrl (url, callback) {
92-
var xhr = new dom.XMLHttpRequest();
93-
xhr.open('GET', options.sourceUrl, true);
94-
xhr.onload = function (e) {
95-
if (xhr.readyState === 4) {
96-
if (xhr.status === 200) {
97-
options.source = xhr.responseText.replace(/\r\n/g, '\n');
98-
loadFromString(options.source);
99-
if (typeof callback === 'function') {
100-
callback(self);
101-
}
94+
function loadFromUrls(urls, callback) {
95+
96+
function xhrOnload(e) {
97+
if (this.readyState === 4) {
98+
if (this.status === 200) {
99+
options.sources[this.index] = this.responseText.replace(/\r\n/g, '\n') ;
100+
options.loadingCompleted++;
101+
if(options.loadingCompleted === urls.length)
102+
xhrLoadSlides();
102103
} else {
103-
throw Error(xhr.statusText);
104+
throw Error(this.statusText);
104105
}
105106
}
106-
};
107-
xhr.onerror = function (e) {
108-
throw Error(xhr.statusText);
109-
};
110-
xhr.send(null);
111-
return xhr;
107+
}
108+
109+
function xhrOnerror(e) {
110+
options.loadingCompleted++;
111+
throw Error(this.statusText);
112+
}
113+
114+
function xhrLoadSlides() {
115+
for (var j = 0; j < urls.length; j++) {
116+
if (j === 0) {
117+
options.source = options.sources[j];
118+
}
119+
else {
120+
options.source += '\n---\n' + options.sources[j];
121+
}
122+
}
123+
124+
loadFromString(options.source);
125+
if (typeof callback === 'function') {
126+
callback(self);
127+
}
128+
}
129+
130+
var xhrs = [];
131+
options.loadingCompleted = 0;
132+
options.sources = [];
133+
134+
for (var i =0 ; i < urls.length; i++) {
135+
var url = urls[i];
136+
xhrs[i] = new dom.XMLHttpRequest();
137+
xhrs[i].index = i;
138+
xhrs[i].open('GET', url, true);
139+
xhrs[i].onload = xhrOnload;
140+
xhrs[i].onerror = xhrOnerror;
141+
xhrs[i].send(null);
142+
}
143+
144+
return xhrs;
112145
}
113146

114147
function update () {

0 commit comments

Comments
 (0)