Re-arranged static Javascript a bit

This commit is contained in:
moodler 2005-04-16 12:30:48 +00:00
parent d6bf473ec2
commit 47aa42e211
3 changed files with 104 additions and 100 deletions

View file

@ -1,96 +0,0 @@
/*
findParentNode (start, elementName, elementClass, elementID)
Travels up the DOM hierarchy to find a parent element with the
specified tag name, class, and id. All conditions must be met,
but any can be ommitted. Returns the BODY element if no match
found.
*/
function findParentNode(el, elName, elClass, elId) {
while(el.nodeName != 'BODY') {
if(
(!elName || el.nodeName == elName) &&
(!elClass || el.className.indexOf(elClass) != -1) &&
(!elId || el.id == elId))
{
break;
}
el = el.parentNode;
}
return el;
}
/*
elementToggleHide (element, elementFinder)
If elementFinder is not provided, toggles the "hidden" class for the specified element.
If elementFinder is provided, then the "hidden" class will be toggled for the object
returned by the function call elementFinder(element).
If persistent == true, also sets a cookie for this.
*/
function elementToggleHide(el, persistent, elementFinder) {
if(!elementFinder) {
var obj = el;
}
else {
var obj = elementFinder(el);
}
if(obj.className.indexOf('hidden') == -1) {
obj.className += ' hidden';
var shown = 0;
}
else {
obj.className = obj.className.replace(new RegExp(' ?hidden'), '')
var shown = 1;
}
if(persistent == true) {
new cookie('hide:' + obj.id, 1, (shown ? -1 : 356), '/').set();
}
}
function elementCookieHide(id) {
var obj = document.getElementById(id);
var cook = new cookie('hide:' + id).read();
if(cook != null) {
elementToggleHide(obj, false);
}
}
function filterByParent(elCollection, parentFinder) {
var filteredCollection = [];
for(var i = 0; i < elCollection.length; ++i) {
var findParent = parentFinder(elCollection[i]);
if(findParent.nodeName != 'BODY') {
filteredCollection.push(elCollection[i]);
}
}
return filteredCollection;
}
/*
Is there some specific reason for this function? I think pretty
much every browser worth considering supports getElementById() [Jon]
function getObj(id)
{
if (document.getElementById)
{
this.obj = document.getElementById(id);
this.style = document.getElementById(id).style;
}
else if (document.all)
{
this.obj = document.all[id];
this.style = document.all[id].style;
}
else if (document.layers)
{
this.obj = document.layers[id];
this.style = document.layers[id];
}
}
*/

View file

@ -1,3 +1,5 @@
// Miscellaneous core Javascript functions for Moodle
function popUpProperties(inobj) { function popUpProperties(inobj) {
op = window.open(); op = window.open();
op.document.open('text/plain'); op.document.open('text/plain');
@ -96,3 +98,101 @@ function confirm_if(expr, message) {
} }
return confirm(message); return confirm(message);
} }
/*
findParentNode (start, elementName, elementClass, elementID)
Travels up the DOM hierarchy to find a parent element with the
specified tag name, class, and id. All conditions must be met,
but any can be ommitted. Returns the BODY element if no match
found.
*/
function findParentNode(el, elName, elClass, elId) {
while(el.nodeName != 'BODY') {
if(
(!elName || el.nodeName == elName) &&
(!elClass || el.className.indexOf(elClass) != -1) &&
(!elId || el.id == elId))
{
break;
}
el = el.parentNode;
}
return el;
}
/*
elementToggleHide (element, elementFinder)
If elementFinder is not provided, toggles the "hidden" class for the specified element.
If elementFinder is provided, then the "hidden" class will be toggled for the object
returned by the function call elementFinder(element).
If persistent == true, also sets a cookie for this.
*/
function elementToggleHide(el, persistent, elementFinder) {
if(!elementFinder) {
var obj = el;
}
else {
var obj = elementFinder(el);
}
if(obj.className.indexOf('hidden') == -1) {
obj.className += ' hidden';
var shown = 0;
}
else {
obj.className = obj.className.replace(new RegExp(' ?hidden'), '')
var shown = 1;
}
if(persistent == true) {
new cookie('hide:' + obj.id, 1, (shown ? -1 : 356), '/').set();
}
}
function elementCookieHide(id) {
var obj = document.getElementById(id);
var cook = new cookie('hide:' + id).read();
if(cook != null) {
elementToggleHide(obj, false);
}
}
function filterByParent(elCollection, parentFinder) {
var filteredCollection = [];
for(var i = 0; i < elCollection.length; ++i) {
var findParent = parentFinder(elCollection[i]);
if(findParent.nodeName != 'BODY') {
filteredCollection.push(elCollection[i]);
}
}
return filteredCollection;
}
/*
Is there some specific reason for this function? I think pretty
much every browser worth considering supports getElementById() [Jon]
function getObj(id)
{
if (document.getElementById)
{
this.obj = document.getElementById(id);
this.style = document.getElementById(id).style;
}
else if (document.all)
{
this.obj = document.all[id];
this.style = document.all[id].style;
}
else if (document.layers)
{
this.obj = document.layers[id];
this.style = document.layers[id];
}
}
*/

View file

@ -9,11 +9,11 @@
echo '<script language="JavaScript" type="text/javascript" src="'.$CFG->wwwroot.'/lib/speller/spellChecker.js"></script>'."\n"; echo '<script language="JavaScript" type="text/javascript" src="'.$CFG->wwwroot.'/lib/speller/spellChecker.js"></script>'."\n";
} }
?> ?>
<script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/overlib.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/javascript-static.js"></script> <script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/javascript-static.js"></script>
<script language="JavaScript" type="text/javascript" <script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/javascript-mod.php"></script>
src="<?php echo "$CFG->wwwroot/lib/container.js" ?>"></script><script language="JavaScript" type="text/javascript" <script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/overlib.js"></script>
src="<?php echo "$CFG->wwwroot/lib/cookies.js" ?>"></script> <script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/cookies.js"></script>
<script language="JavaScript" type="text/javascript"> <script language="JavaScript" type="text/javascript">
<!-- // Non-Static Javascript functions <!-- // Non-Static Javascript functions