Using JavaScript to override ObjMedia

susanmacnab
Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 16 ♪ Opening Act ♪
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: 635 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: 16 ♪ Opening Act ♪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: 16 ♪ Opening Act ♪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: 16 ♪ Opening Act ♪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: 16 ♪ Opening Act ♪
Categories
- 4.7K All Categories
- 3 New Feature Releases
- The Training Arcade®
- Arcades™
- 57 ✫ Announcements
- 6 ✪ Contests
- 34.1K eLearning Brothers® Products
- 33.6K Lectora®
- 31.5K Lectora Discussions
- 1.9K Lectora Feature Requests
- 64 Lectora User Groups
- 16 Asset Library
- 10 AssetLibrary Discussions
- 6 AssetLibrary Feature Requests
- 293 CenarioVR®
- 171 CenarioVR Discussions
- 122 CenarioVR Feature Requests
- 29 Rockstar Learning Platform®
- 20 Rockstar Learning Platform Discussions
- 9 Rockstar Learning Platform Feature Requests
- 4 Off-the-Shelf Course Library
- 3 Off-the-Shelf Course Library Discussions
- 1 Off-the-Shelf Course Library Feature Requests
- 114 CourseMill®
- 107 CourseMill Discussions
- 43 ReviewLink®
- 31 ReviewLink Discussions
- 12 ReviewLink Suggestions
- 2 The Training Arcade®
- 1 The Training Arcade Discussions
- 1 The Training Arcade Feature Requests
- 10 Additional Learning Products
- 2 Adobe®
- 4 Articulate®
- 2 Camtasia®
- Docebo®
- 1 iSpring®
- 1 Microsoft® PowerPoint®
- 912 All Things eLearning
- 5 Course Development Showcase
- 1 eLearning Brothers® Downloads
- 1 Compliance Training
- 11 eLearning Development
- eLearning Game Design
- 7 Instructional Design
- 545 Learning Management System (LMS) Integration
- 2 Mobile Learning
- 5 Visual Design
- 329 Web Accessibility
- 1.2K ♪ The Green Room
- 7 ♡ Community Feedback
- 7 Community Tips