Using JavaScript to override ObjMedia

susanmacnab
Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 44 ☆ Superstar ☆
Is it possible to override ObjMedia using javascript?
We want to modify the path to media files because we have many users who access our modules from remote sites that have poor connectivity. Until now we have been manually editing the html files after publishing but that is a tedious and error-prone task.
I've seen a few suggesitons on StackOverflow but they only seem to be overriding functions that have no arguments.
This is generally what I want to do:
function ObjMedia(n,a,x,y,w,h,v,z,m,l,p,rol,sPlay,eKey,vol,c,d,fb,cl) {
// Update m to point to localContent folder
if (Var_localContent.getValue() != "") {
m = m.replace("media/", Var_localContent.getValue());
}
// End of update
// *** CALL ORIGINAL ObjMedia HERE ***
}
Any thoughts/suggestions would be helpful.
Thanks!
We want to modify the path to media files because we have many users who access our modules from remote sites that have poor connectivity. Until now we have been manually editing the html files after publishing but that is a tedious and error-prone task.
I've seen a few suggesitons on StackOverflow but they only seem to be overriding functions that have no arguments.
This is generally what I want to do:
function ObjMedia(n,a,x,y,w,h,v,z,m,l,p,rol,sPlay,eKey,vol,c,d,fb,cl) {
// Update m to point to localContent folder
if (Var_localContent.getValue() != "") {
m = m.replace("media/", Var_localContent.getValue());
}
// End of update
// *** CALL ORIGINAL ObjMedia HERE ***
}
Any thoughts/suggestions would be helpful.
Thanks!
Best Answer
-
wheels Florida USACommunity Member, Administrator, Moderator, Rockstar Manager Posts: 665 eLearning ROCKSTAR Admin TeamI tested the following code, it worked for me. You'll need to still add in your conditional.
Hope this gives you some good direction. Add this as a HTML Extension of type Header Scripting
var objMediaConstruct = ObjMedia.prototype.constructor;
var objMediaProto = ObjMedia.prototype;
ObjMedia = function()
{// calls the original method
objMediaConstruct.apply(this,arguments);
// do your override here
this.src = this.src.replace("media/", "https://external.com/");
}
ObjMedia.prototype = objMediaProto;
Answers
-
-
-
susanmacnab Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 44 ☆ Superstar ☆Thanks pjackson.
Sorry - it's taken me a while to get back to this. I see where you are going with your suggestion but it doesn't quite work the way you have it written. I'm running into problems with the middle line...
I'll keep playing with it and see what I can come up with. Your technique seems a lot safer than my original one was.
Susan -
Hi @susanmacnab, can you create a single page title with my code plus your external source file and I will test my code in your content.
-
susanmacnab Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 44 ☆ Superstar ☆Hi @pjackson2462.
Thank you for the offer but I will continue to look at this myself for the time being. We are working within a closed/secure network so sharing isn't so simple.
I'm sure I'll get it - I just need to find the time to work on it! -
susanmacnab Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 44 ☆ Superstar ☆Also - I forgot to mention. It doesn't look like the class name that you put in the Appearance window ever shows up in the html for media objects. Not sure if this is by design or a bug.
This means I'm going to have to do a bit more manipulation in the DOM to find the actual object. -
susanmacnab Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 44 ☆ Superstar ☆
Categories
- 35.8K All Categories
- 109 ✫ Announcements
- 33.1K Lectora®
- 31.1K Lectora Discussions
- 28.9K Lectora Desktop
- 2K Lectora Online
- 2K Lectora Feature Requests
- 71 Lectora User Groups
- 36 Lectora Accessibility User Group (LAUG)
- 22 ELB Learning Content
- 22 ELB Learning Content Discussions
- 321 CenarioVR®
- 188 CenarioVR Discussions
- 133 CenarioVR Feature Requests
- 41 Rockstar Learning Platform®
- 38 Rockstar Learning Platform Discussions
- 108 CourseMill®
- 108 CourseMill Discussions
- 47 ReviewLink®
- 47 ReviewLink Discussions
- 5 The Training Arcade®
- 5 The Training Arcade Discussions
- 934 All Things eLearning
- 36 eLearning Development
- 546 Learning Management System (LMS) Integration
- 332 Web Accessibility
- 1.2K ♪ The Green Room
- 9 Additional Learning Products