1
// Miscellaneous core Javascript functions for Moodle
3
function popUpProperties(inobj) {
5
op.document.open('text/plain');
6
for (objprop in inobj) {
7
op.document.write(objprop + ' => ' + inobj[objprop] + '\n');
12
function fillmessagebox(text) {
13
document.form.message.value = text;
16
function copyrichtext(textname) {
17
/// Legacy stub for old editor - to be removed soon
23
void(el=d.getElementsByTagName('INPUT'));
24
for(i=0;i<el.length;i++)
28
function checknone() {
30
void(el=d.getElementsByTagName('INPUT'));
31
for(i=0;i<el.length;i++)
35
function lockoptions(form, master, subitems) {
36
// subitems is an array of names of sub items
37
// requires that each item in subitems has a
38
// companion hidden item in the form with the
39
// same name but prefixed by "h"
40
if (eval("document."+form+"."+master+".checked")) {
41
for (i=0; i<subitems.length; i++) {
42
unlockoption(form, subitems[i]);
45
for (i=0; i<subitems.length; i++) {
46
lockoption(form, subitems[i]);
52
function lockoption(form,item) {
53
eval("document."+form+"."+item+".disabled=true");/* IE thing */
54
eval("document."+form+".h"+item+".value=1");
57
function unlockoption(form,item) {
58
eval("document."+form+"."+item+".disabled=false");/* IE thing */
59
eval("document."+form+".h"+item+".value=0");
62
function submitFormById(id) {
63
var theform = document.getElementById(id);
67
if(theform.tagName != 'FORM') {
70
if(!theform.onsubmit || theform.onsubmit()) {
71
return theform.submit();
75
function select_all_in(elTagName, elId, elClass) {
76
var inputs = document.getElementsByTagName('INPUT');
77
inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elId, elClass);});
78
for(var i = 0; i < inputs.length; ++i) {
79
if(inputs[i].type == 'checkbox') {
80
inputs[i].checked = 'checked';
85
function deselect_all_in(elTagName, elId, elClass) {
86
var inputs = document.getElementsByTagName('INPUT');
87
inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elId, elClass);});
88
for(var i = 0; i < inputs.length; ++i) {
89
if(inputs[i].type == 'checkbox') {
90
inputs[i].checked = '';
95
function confirm_if(expr, message) {
99
return confirm(message);
104
findParentNode (start, elementName, elementClass, elementID)
106
Travels up the DOM hierarchy to find a parent element with the
107
specified tag name, class, and id. All conditions must be met,
108
but any can be ommitted. Returns the BODY element if no match
111
function findParentNode(el, elName, elClass, elId) {
112
while(el.nodeName != 'BODY') {
114
(!elName || el.nodeName == elName) &&
115
(!elClass || el.className.indexOf(elClass) != -1) &&
116
(!elId || el.id == elId))
126
elementToggleHide (element, elementFinder)
128
If elementFinder is not provided, toggles the "hidden" class for the specified element.
129
If elementFinder is provided, then the "hidden" class will be toggled for the object
130
returned by the function call elementFinder(element).
132
If persistent == true, also sets a cookie for this.
134
function elementToggleHide(el, persistent, elementFinder) {
139
var obj = elementFinder(el);
141
if(obj.className.indexOf('hidden') == -1) {
142
obj.className += ' hidden';
146
obj.className = obj.className.replace(new RegExp(' ?hidden'), '')
150
if(persistent == true) {
151
new cookie('hide:' + obj.id, 1, (shown ? -1 : 356), '/').set();
156
function elementCookieHide(id) {
157
var obj = document.getElementById(id);
158
var cook = new cookie('hide:' + id).read();
160
elementToggleHide(obj, false);
164
function filterByParent(elCollection, parentFinder) {
165
var filteredCollection = [];
166
for(var i = 0; i < elCollection.length; ++i) {
167
var findParent = parentFinder(elCollection[i]);
168
if(findParent.nodeName != 'BODY') {
169
filteredCollection.push(elCollection[i]);
172
return filteredCollection;
176
All this is here just so that IE gets to handle oversized blocks
177
in a visually pleasing manner. It does a browser detect. So sue me.
180
function fix_column_widths() {
181
var agt = navigator.userAgent.toLowerCase();
182
if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) {
183
fix_column_width('left-column');
184
fix_column_width('right-column');
188
function fix_column_width(colName) {
189
if(column = document.getElementById(colName)) {
190
if(!column.offsetWidth) {
191
setTimeout("fix_column_width('" + colName + "')", 20);
196
var nodes = column.childNodes;
198
for(i = 0; i < nodes.length; ++i) {
199
if(nodes[i].className.indexOf("sideblock") != -1 ) {
200
if(width < nodes[i].offsetWidth) {
201
width = nodes[i].offsetWidth;
206
for(i = 0; i < nodes.length; ++i) {
207
if(nodes[i].className.indexOf("sideblock") != -1 ) {
208
nodes[i].style.width = width + 'px';