Skip to content

Commit 27d580c

Browse files
committed
MOBILE-1160 media: Fix media in book, page and resource
1 parent 969c927 commit 27d580c

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

www/addons/mod_book/services/book.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ angular.module('mm.addons.mod_book')
262262

263263
// Promise handling when we are in a browser.
264264
promise = (function() {
265-
var deferred;
266265
if (!indexUrl) {
267266
// If ever that happens.
268267
$log.debug('Could not locate the index chapter');
@@ -272,9 +271,7 @@ angular.module('mm.addons.mod_book')
272271
return $mmFilepool.downloadUrl($mmSite.getId(), indexUrl, false, mmaModBookComponent, moduleId);
273272
} else {
274273
// We return the live URL.
275-
deferred = $q.defer();
276-
deferred.resolve($mmSite.fixPluginfileURL(indexUrl));
277-
return deferred.promise;
274+
return $q.when($mmSite.fixPluginfileURL(indexUrl));
278275
}
279276
})();
280277

@@ -286,12 +283,16 @@ angular.module('mm.addons.mod_book')
286283
} else {
287284
// Now that we have the content, we update the SRC to point back to
288285
// the external resource. That will be caught by mm-format-text.
289-
var html = angular.element('<div>');
286+
var html = angular.element('<div>'),
287+
media;
290288
html.html(response.data);
291-
angular.forEach(html.find('img'), function(img) {
292-
var src = paths[decodeURIComponent(img.getAttribute('src'))];
289+
290+
// Treat img, audio, video and source.
291+
media = html[0].querySelectorAll('img, video, audio, source');
292+
angular.forEach(media, function(el) {
293+
var src = paths[decodeURIComponent(el.getAttribute('src'))];
293294
if (typeof src !== 'undefined') {
294-
img.setAttribute('src', src);
295+
el.setAttribute('src', src);
295296
}
296297
});
297298
// We do the same for links.
@@ -301,6 +302,7 @@ angular.module('mm.addons.mod_book')
301302
anchor.setAttribute('href', href);
302303
}
303304
});
305+
304306
return html.html();
305307
}
306308
});

www/addons/mod_page/services/page.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ angular.module('mm.addons.mod_page')
164164
return $mmFilepool.downloadUrl($mmSite.getId(), indexUrl, false, mmaModPageComponent, moduleId);
165165
} else {
166166
// We return the live URL.
167-
deferred = $q.defer();
168-
deferred.resolve($mmSite.fixPluginfileURL(indexUrl));
169-
return deferred.promise;
167+
return $q.when($mmSite.fixPluginfileURL(indexUrl));
170168
}
171169
})();
172170

@@ -177,13 +175,17 @@ angular.module('mm.addons.mod_page')
177175
return $q.reject();
178176
} else {
179177
// Now that we have the content, we update the SRC to point back to
180-
// the external resource. That will be caught by mm-format-text.
181-
var html = angular.element('<div>');
178+
// the external resource. That will b caught by mm-format-text.
179+
var html = angular.element('<div>'),
180+
media;
182181
html.html(response.data);
183-
angular.forEach(html.find('img'), function(img) {
184-
var src = paths[decodeURIComponent(img.getAttribute('src'))];
182+
183+
// Treat img, audio, video and source.
184+
media = html[0].querySelectorAll('img, video, audio, source');
185+
angular.forEach(media, function(el) {
186+
var src = paths[decodeURIComponent(el.getAttribute('src'))];
185187
if (typeof src !== 'undefined') {
186-
img.setAttribute('src', src);
188+
el.setAttribute('src', src);
187189
}
188190
});
189191
// We do the same for links.
@@ -193,6 +195,7 @@ angular.module('mm.addons.mod_page')
193195
anchor.setAttribute('href', href);
194196
}
195197
});
198+
196199
return html.html();
197200
}
198201
});

www/addons/mod_resource/services/resource.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,16 @@ angular.module('mm.addons.mod_resource')
227227
} else {
228228
// Now that we have the content, we update the SRC to point back to
229229
// the external resource. That will be caught by mm-format-text.
230-
var html = angular.element('<div>');
231-
html.append(response.data);
232-
233-
angular.forEach(html.find('img'), function(img) {
234-
var src = paths[decodeURIComponent(img.getAttribute('src'))];
230+
var html = angular.element('<div>'),
231+
media;
232+
html.html(response.data);
233+
234+
// Treat img, audio, video and source.
235+
media = html[0].querySelectorAll('img, video, audio, source');
236+
angular.forEach(media, function(el) {
237+
var src = paths[decodeURIComponent(el.getAttribute('src'))];
235238
if (typeof src !== 'undefined') {
236-
img.setAttribute('src', src);
239+
el.setAttribute('src', src);
237240
}
238241
});
239242
// We do the same for links.

0 commit comments

Comments
 (0)