forked from atutor/ATutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATutorCourse.js
153 lines (132 loc) · 5.06 KB
/
ATutorCourse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/************************************************************************/
/* ATutor */
/************************************************************************/
/* Copyright (c) 2002 - 2010 */
/* Inclusive Design Institute */
/* http://atutor.ca */
/* */
/* This program is free software. You can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation. */
/** ********************************************************************* */
// $Id: $
var ATutor = ATutor || {};
ATutor.course = ATutor.course || {};
(function() {
var element_collapse_icon;
var element_expand_icon;
var setExpandIcon = function (clickedElement, title) {
clickedElement.attr("src", element_expand_icon)
clickedElement.attr("alt", ATutor.course.show + " " + title);
clickedElement.attr("title", ATutor.course.show + " " + title);
ATutor.setcookie("m_"+title, 0, 1);
};
var setCollapseIcon = function (clickedElement, title) {
clickedElement.attr("src", element_collapse_icon);
clickedElement.attr("alt", ATutor.course.hide + " " + title);
clickedElement.attr("title", ATutor.course.hide + " " + title);
ATutor.setcookie("m_"+title, null, 1);;
};
// toggle elements in side menu (via the +/- icon in each side menu element)
function showHideSubmenu()
{
var clickedElement = jQuery(this);
var title = jQuery("span", clickedElement.parent()).html();
if (clickedElement.attr("src") == element_collapse_icon) {
setExpandIcon(clickedElement, title);
}
else {
setCollapseIcon(clickedElement, title);
}
clickedElement.parent().next().slideToggle();
}
//modifies the menu html to add title, expand/collapse image, alt text.
var printSubmenus = function () {
var sideMenuBoxHeadings = jQuery("h2.box");
for (var titleIndex = 0; titleIndex < sideMenuBoxHeadings.length; titleIndex++) {
var heading = jQuery(sideMenuBoxHeadings[titleIndex]);
var title = jQuery("span", heading).html();
var inputElement = jQuery("input", heading);
var menu = jQuery(heading.next());
if (ATutor.getcookie("m_" + title) == "0") {
setExpandIcon(inputElement, title);
menu.hide();
} else {
setCollapseIcon(inputElement, title);
menu.show();
}
inputElement.click(showHideSubmenu);
}
};
var menu_show_icon;
var menu_hide_icon;
//Initialize the submenus
ATutor.course.doSideMenus = function () {
element_collapse_icon = ATutor.customized_data_dir + "themes/" + ATutor.course.theme + "/images/mswitch_minus.gif";
element_expand_icon = ATutor.customized_data_dir + "themes/" + ATutor.course.theme + "/images/mswitch_plus.gif";
printSubmenus();
};
var hideMenu = function (effect) {
var menuImage = jQuery("#menutoggle > a > img");
menuImage.attr("src", menu_show_icon);
menuImage.attr("alt", ATutor.course.show);
menuImage.attr("title", ATutor.course.show);
if (effect) {
jQuery("#side-menu").slideUp("slow");
} else {
jQuery("#side-menu").hide();
}
ATutor.setcookie("side-menu", "none", 1);
};
var showMenu = function (effect) {
var menuImage = jQuery("#menutoggle > a > img");
menuImage.attr("src", menu_hide_icon);
menuImage.attr("alt", ATutor.course.hide);
menuImage.attr("title", ATutor.course.hide);
if (effect) {
jQuery("#side-menu").slideDown("slow");
} else {
jQuery("#side-menu").show();
}
ATutor.setcookie("side-menu", "", 1);
};
var showHideMenu = function () {
var clickedElement = jQuery("img", this);
if (clickedElement.attr("src") == menu_hide_icon) {
hideMenu(true);
}
else {
showMenu(true);
}
};
var printMenuToggle = function (effect) {
var state = ATutor.getcookie("side-menu");
if (state && state=="none") {
hideMenu(effect);
} else {
showMenu(effect);
}
var menuLink = jQuery("#menutoggle > a");
menuLink.click(showHideMenu);
};
ATutor.course.doMenuToggle = function (effect) {
menu_show_icon = ATutor.customized_data_dir + "themes/" + ATutor.course.theme + "/images/showmenu.gif";
menu_hide_icon = ATutor.customized_data_dir + "themes/" + ATutor.course.theme + "/images/hidemenu.gif";
printMenuToggle();
};
ATutor.course.toggleFolder = function (cid, expand, collapse, course_id) {
if (jQuery("#tree_icon"+cid).attr("src") == ATutor.course.collapse_icon) {
jQuery("#tree_icon"+cid).attr("src", ATutor.course.expand_icon);
jQuery("#tree_icon"+cid).attr("alt", expand);
jQuery("#tree_icon"+cid).attr("title", expand);
ATutor.setcookie("c"+course_id+"_"+cid, null, 1);
}
else {
jQuery("#tree_icon"+cid).attr("src", ATutor.course.collapse_icon);
jQuery("#tree_icon"+cid).attr("alt", collapse);
jQuery("#tree_icon"+cid).attr("title", collapse);
ATutor.setcookie("c"+course_id+"_"+cid, "1", 1);
}
jQuery("#folder"+cid).slideToggle();
};
})();