diff --git a/javascript/highlight.js b/javascript/highlight.js new file mode 100755 index 00000000..cfc0b0c2 --- /dev/null +++ b/javascript/highlight.js @@ -0,0 +1,236 @@ +/* +highlightImages_over * common/js/highlight.js + * Behaviour-abstracted highligher modul + * + * Usage: + * - include in the header of your file + * - set the class of the container to "highlight". The class will have ' over' appended to it on mouseover + * - set the overSrc attribute on any images inside that, if you want them to be changed + */ + +/* + * Initialise all items that have a highlight or highlightImages class with the appropriate event handlers + */ + + +function onload_init_highlight() { + var allElements = getAllElements(); + var tester,j,overSrc; + + for(var i = 0;i 0) { + overSrc = allImages[j].src; + for(k=0;k<_IMAGE_HIGHLIGHT_REWRITING.length;k++) + overSrc = overSrc.replace(_IMAGE_HIGHLIGHT_REWRITING[k].norm,_IMAGE_HIGHLIGHT_REWRITING[k].over); + if(overSrc != allImages[j].src) { + allImages[j].normSrc = allImages[j].src; + allImages[j].overSrc = overSrc; + } + } + } + } + } + } +} + +/* + * Highlight handlers + */ +function highlightImages_over() { + var el = this; +// if(el.id) document.getElementById('SearchField').document.getElementById('SearchField').innerHTML += "Over: " + el.id + "
"; + + // Reset any timer that may exist + if(el.timer != null) { + clearTimeout(el.timer); + try { + delete el.timer; + } catch(er) {} + } + + // Class + if(el) { + addClass(el, 'over'); + removeClass(el, 'stale'); + + if(el.parentNode) { + el.parentNode.highlightedChild = el; + addClass(el.parentNode,'childOver'); + } + } + + // Images + var allImages = el.getElementsByTagName('img'); + for(var j=0;j 0) { + var el = _HIGHLIGHTED_OBJECTS[idx]; + delete _HIGHLIGHTED_OBJECTS[idx]; + unhighlightDelay = null; + + } else { + var el = this; + if(el && el.getAttribute) { + unhighlightDelay = el.getAttribute("unhighlightDelay"); + if(unhighlightDelay == null) { + if(_DEFAULT_UNHIGHLIGHT_DELAY[el.parentNode.className]) unhighlightDelay = _DEFAULT_UNHIGHLIGHT_DELAY[el.parentNode.className]; + else if(_DEFAULT_UNHIGHLIGHT_DELAY[el.parentNode.id]) unhighlightDelay = _DEFAULT_UNHIGHLIGHT_DELAY[el.parentNode.id]; + else if(_DEFAULT_UNHIGHLIGHT_DELAY['default']) unhighlightDelay = _DEFAULT_UNHIGHLIGHT_DELAY['default']; + } + } + } + + if(unhighlightDelay) { + nextIdx = _HIGHLIGHTED_OBJECTS.length; + if(nextIdx == 0) nextIdx = 1; + _HIGHLIGHTED_OBJECTS[nextIdx] = el; + el.timer = setTimeout("highlightImages_out(" + nextIdx + ")", unhighlightDelay); + + } else { + // Class + if(el) { + removeClass(el, 'over'); + removeClass(el, 'stale'); + + + if(el.parentNode) { + if(!el.parentNode.highlightedChild || el == el.parentNode.highlightedChild) { + removeClass(el.parentNode,'childOver'); + el.parentNode.highlightedChild = null; + } + } + + // Images + var allImages = document.getElementsByTagName('img'); + for(var j=0;j 0) { + nextIdx = _HIGHLIGHTED_OBJECTS.length; + _HIGHLIGHTED_OBJECTS[nextIdx] = el; + el.timer = setTimeout("highlightImages_makeStale(" + nextIdx + ")", staleDelay); + } + } + + if(el.old_onmouseout) el.old_onmouseout(); + + } + } + +} + +// Add the stale class to the given item +function highlightImages_makeStale(idx) { + var el = _HIGHLIGHTED_OBJECTS[idx]; + delete _HIGHLIGHTED_OBJECTS[idx]; + addClass(el, 'stale'); +} + +/* + * Preload the given image + */ + +var _PRELOADED_IMAGES = Array(); +function preload(filename) { + var i = new Image; + i.src = filename; + _PRELOADED_IMAGES[_PRELOADED_IMAGES.length] = i; +} + +//go to the specified page. +//Works for nested elements. Always calls the most nested. +//Includes Bubble hack for mozilla + +var pagelocation; +function go(url){ + if(pagelocation == null){ + window.location=url; + pagelocation = url; + } +} + + + +/* + * This function will show or hide a div when you + * pass it a element ID + * Created by sgow added @ 16-09-2004 + */ + +/* variables needed */ +var showDiv; +var oldDiv = 1; + +function toggleDiv( el ){ + if(oldDiv == 1){ + //the first time you call this function + if(showDiv = document.getElementById(el)) { + showDiv.style.display = "block"; + oldDiv = showDiv; + } + } + else{ + showDiv = document.getElementById(el); + if( showDiv && showDiv == oldDiv ){ + if(oldDiv.style.display == "none"){ showDiv.style.display = "block";} + else { showDiv.style.display = "none";} + oldDiv = showDiv; + // if its the same div as before, hide the same div, unless its the first time you use the function + }else{ + oldDiv.style.display = "none"; + showDiv.style.display = "block"; + oldDiv = showDiv; + // if its a different div, hide the first one, and show the second one + } + } +} + +var _IMAGE_HIGHLIGHT_REWRITING = Array(); +function setImageHighlightRewriting(normVal, overVal) { + _IMAGE_HIGHLIGHT_REWRITING[_IMAGE_HIGHLIGHT_REWRITING.length] = { + 'norm' : normVal, 'over' : overVal + } +} + + +appendLoader(onload_init_highlight);