Javascript Examples
By placing custom javascript code in Footer JS placement you can extend the application functionality.
Note that you should not place <script></script> tag in the Footer JS. The code you put there is directly inserted within the script block.
Place your code within an anonymous function and we also suggest to add try...catch to not cause any accidental javascript error which would prevent the LMS pages to render completely. In case you break the script and are unable to edit the content back, here is how to rectify it.
- Open accounts.edubrite.com and use site owner's credential to login
- You would see the sites you own there
- Edit the site details where you were working for customization, and add DISABLE_PLACEMENTS=true in the customization tab, and save
- Now reopen the original microsite, you would notice your customizations done via placements are not visible anymore. Fix the javascript and then when ready, remove the DISABLE_PLACEMENTS=true property
Here are some examples of using javascript Ajax calls from the footer JS
1. Fetching the groups in which current user is a member
(function (){
var dataObj = { "dispatch": "list", "json": "true", "searchIn": "GROUP", "pageSize": 20 };
$.post( "../site/search.do",
dataObj,
function( data ) {
//Do something
}, "json"
);
myGroupsFetched = true;
})();
Check the response in your site by entering this URL in browser
http://<<your-site-url>>/oltpublish/site/search.do?dispatch=list&searchIn=GROUP&pageSize=20&json=true
2. Fetch courses enrolled by the current user
(function (){
var dataObj = { dispatch: "listCourseSessions", fullDetails:true, json: true, view: "USER", pageSize: 10, award: false };
/*optional parameters - group id, course name to search, course session name to search
dataObj.groupId = "...";
dataObj.courseName = "...";
dataObj.sessionName = "..."; */
$.post( "../site/program.do",
dataObj,
function( data ) {
//Do something
}, "json"
);
})();
Check the response in your site by entering this URL in browser
http://<<your-site-url>>/oltpublish/site/program.do?dispatch=listCourseSessions&fullDetails=true&view=USER&pageSize=10&award=false&json=true
3. Adding custom content in Dashboard
(function(){
if(location.href.indexOf('homeNew.do') != -1){
$("#maincenter").prepend("<div style=''>Hello</div>");
}
})();
4. In the above example, checking if the current user is learner, instructor or admin
(function(){
if(eb_IsGuest){
//Not logged in
}else if(eb_IsAdminSiteAdmin){
//Site admin or owner
}else if(eb_IsTeacher){
//Instructor
}else{
//Learner
if(location.href.indexOf('homeNew.do') != -1){
$("#maincenter").prepend("<div style=''>Hello</div>");
}
}
})();
Related Pages
Group Management
Javascript
- Customization On Payment Page
- Validate IP Address while accessing the course
- UI Customization JavaScript Functions
- Verify Custom properties during Test Taking
- Verifying User Properties During Test
- JS Example
- example_custom_scripts
- Test Taking - Customization using callback mechanism
- Cms Calendar Example
Reports
Enrollment Management
- API - Update Event Subscription
- API - Create ExamTestInstance
- Update Program Member - via Program Session Id
- Update Program Member
- API - Self Enroll in Course Session
- Update Course Session Member
- API - Self Enroll in Program Session
- API - Self Enroll in Event
- API - Enroll Users in Course Session
- API - Enroll Users in Program Session
- API - Enroll Users in Event
- API - Enroll Users in Program
Other
Introduction
Report
- Get Sites Metadata
- Get Open Learning Items List
- API - Program Enrollment Summary
- API - Course Enrollment Summary
- Get Catalog Items List
- API - Course Session Members list
- API - Program Members List
- Event participants list
- Api - Test Attempts (Test Instances) List
- Test instance details list
- Api - Non Subscribed Event List
- Api - Subscribed Event List
- API - List All Report Schedules
- API - Get Latest Report Content For A Given Schedule ID
- API - Get Report Content For A Given Report ID
- API - List Reports For A Given Schedule
User Management
- API - User list
- API - Get user details
- Api - User Creation
- API - Create User (With Custom Properties)
- API - Update User
- API - Rename User
- API - Add user to group(s)
- API - Remove user from group(s)
- Merge User Accounts
- API - Activate User
- API - Deactivate User
- API - Change User's Origin Site
- Api - User Login (Creating User Session)
eCommerce
API Documentation
Examples
- User Creation
- User Update
- User List
- Get User Details
- Add User to Group(s)
- Remove User from Group(s)
- User Activate
- User Deactivate
- User Login
- Group List
- Group Membership
- Course Subscription(Coupon Code)
- Subscribed Events List
- Non Subscribed Events List
- Test Instances in Microsite
- Forum APIs
- Javascript Example
Client Example
Quick Links
- Home
- Getting Started
- Knowledgebase
- Video Tutorials
- Google Apps Integration
- Gilly (Plugin for Atlassian Confluence)
Group Management
Javascript
- Customization On Payment Page
- Validate IP Address while accessing the course
- UI Customization JavaScript Functions
- Verify Custom properties during Test Taking
- Verifying User Properties During Test
- JS Example
- example_custom_scripts
- Test Taking - Customization using callback mechanism
- Cms Calendar Example
Reports
Enrollment Management
- API - Update Event Subscription
- API - Create ExamTestInstance
- Update Program Member - via Program Session Id
- Update Program Member
- API - Self Enroll in Course Session
- Update Course Session Member
- API - Self Enroll in Program Session
- API - Self Enroll in Event
- API - Enroll Users in Course Session
- API - Enroll Users in Program Session
- API - Enroll Users in Event
- API - Enroll Users in Program
Other
Introduction
Report
- Get Sites Metadata
- Get Open Learning Items List
- API - Program Enrollment Summary
- API - Course Enrollment Summary
- Get Catalog Items List
- API - Course Session Members list
- API - Program Members List
- Event participants list
- Api - Test Attempts (Test Instances) List
- Test instance details list
- Api - Non Subscribed Event List
- Api - Subscribed Event List
- API - List All Report Schedules
- API - Get Latest Report Content For A Given Schedule ID
- API - Get Report Content For A Given Report ID
- API - List Reports For A Given Schedule
User Management
- API - User list
- API - Get user details
- Api - User Creation
- API - Create User (With Custom Properties)
- API - Update User
- API - Rename User
- API - Add user to group(s)
- API - Remove user from group(s)
- Merge User Accounts
- API - Activate User
- API - Deactivate User
- API - Change User's Origin Site
- Api - User Login (Creating User Session)
eCommerce
API Documentation
Examples
- User Creation
- User Update
- User List
- Get User Details
- Add User to Group(s)
- Remove User from Group(s)
- User Activate
- User Deactivate
- User Login
- Group List
- Group Membership
- Course Subscription(Coupon Code)
- Subscribed Events List
- Non Subscribed Events List
- Test Instances in Microsite
- Forum APIs
- Javascript Example
Client Example
Quick Links
- Home
- Getting Started
- Knowledgebase
- Video Tutorials
- Google Apps Integration
- Gilly (Plugin for Atlassian Confluence)