/**
* Register event listeners for the module.
*/
- var registerEventListeners = function() {
- var root = $(SELECTORS.ROOT);
-
+ var registerEventListeners = function(root) {
// Bind click events to event links.
root.on('click', SELECTORS.EVENT_ITEM, function(e) {
e.preventDefault();
};
return {
- init: function() {
- CalendarViewManager.init();
- registerEventListeners();
+ init: function(root) {
+ root = $(root);
+
+ CalendarViewManager.init(root);
+ registerEventListeners(root);
}
};
});
root.on('click', SELECTORS.CALENDAR_NAV_LINK, function(e) {
var courseId = $(root).find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('courseid');
var link = $(e.currentTarget);
- changeMonth(link.attr('href'), link.data('time'), courseId);
+ changeMonth(root, link.attr('href'), link.data('time'), courseId);
e.preventDefault();
});
* @param {Number} courseid The id of the course whose events are shown
* @return {promise}
*/
- var refreshMonthContent = function(time, courseid) {
- var root = $(SELECTORS.ROOT);
-
+ var refreshMonthContent = function(root, time, courseid) {
startLoading(root);
return CalendarRepository.getCalendarMonthData(time, courseid)
return Templates.render('core_calendar/month_detailed', context);
})
.then(function(html, js) {
- return Templates.replaceNode(SELECTORS.CALENDAR_MONTH_WRAPPER, html, js);
+ return Templates.replaceNode(root.find(SELECTORS.CALENDAR_MONTH_WRAPPER), html, js);
})
.always(function() {
return stopLoading(root);
* @param {Number} courseid The id of the course whose events are shown
* @return {promise}
*/
- var changeMonth = function(url, time, courseid) {
- return refreshMonthContent(time, courseid)
+ var changeMonth = function(root, url, time, courseid) {
+ return refreshMonthContent(root, time, courseid)
.then(function() {
window.history.pushState({}, '', url);
return arguments;
if (!courseId) {
courseId = root.find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('courseid');
}
- return refreshMonthContent(time, courseId);
+ return refreshMonthContent(root, time, courseId);
};
/**
};
return {
- init: function() {
- registerEventListeners(SELECTORS.ROOT);
+ init: function(root) {
+ registerEventListeners(root);
},
reloadCurrentMonth: reloadCurrentMonth,
changeMonth: changeMonth,