Header
From Phonology
| (One intermediate revision not shown) | |||
| Line 84: | Line 84: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
//Feel free to add your javascript code here. | //Feel free to add your javascript code here. | ||
| - | function | + | //Behaviour |
| - | { | + | var Behaviour = { |
| - | var | + | list : new Array, |
| - | var | + | |
| - | // | + | register : function(sheet){ |
| - | var | + | Behaviour.list.push(sheet); |
| - | if( | + | }, |
| + | |||
| + | start : function(){ | ||
| + | Behaviour.addLoadEvent(function(){ | ||
| + | Behaviour.apply(); | ||
| + | }); | ||
| + | }, | ||
| + | |||
| + | apply : function(){ | ||
| + | for (h=0;sheet=Behaviour.list[h];h++){ | ||
| + | for (selector in sheet){ | ||
| + | list = document.getElementsBySelector(selector); | ||
| + | |||
| + | if (!list){ | ||
| + | continue; | ||
| + | } | ||
| + | |||
| + | for (i=0;element=list[i];i++){ | ||
| + | sheet[selector](element); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | }, | ||
| + | |||
| + | addLoadEvent : function(func){ | ||
| + | var oldonload = window.onload; | ||
| + | |||
| + | if (typeof window.onload != 'function') { | ||
| + | window.onload = func; | ||
| + | } else { | ||
| + | window.onload = function() { | ||
| + | oldonload(); | ||
| + | func(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Behaviour.start(); | ||
| + | |||
| + | |||
| + | |||
| + | function getAllChildren(e) { | ||
| + | // Returns all children of element. Workaround required for IE5/Windows. Ugh. | ||
| + | return e.all ? e.all : e.getElementsByTagName('*'); | ||
| + | } | ||
| + | |||
| + | document.getElementsBySelector = function(selector) { | ||
| + | // Attempt to fail gracefully in lesser browsers | ||
| + | if (!document.getElementsByTagName) { | ||
| + | return new Array(); | ||
| + | } | ||
| + | // Split selector in to tokens | ||
| + | var tokens = selector.split(' '); | ||
| + | var currentContext = new Array(document); | ||
| + | for (var i = 0; i < tokens.length; i++) { | ||
| + | token = tokens[i].replace(/^\\s+/,'').replace(/\\s+$/,'');; | ||
| + | if (token.indexOf('#') > -1) { | ||
| + | // Token is an ID selector | ||
| + | var bits = token.split('#'); | ||
| + | var tagName = bits[0]; | ||
| + | var id = bits[1]; | ||
| + | var element = document.getElementById(id); | ||
| + | if (tagName && element.nodeName.toLowerCase() != tagName) { | ||
| + | // tag with that ID not found, return false | ||
| + | return new Array(); | ||
| + | } | ||
| + | // Set currentContext to contain just this element | ||
| + | currentContext = new Array(element); | ||
| + | continue; // Skip to next token | ||
| + | } | ||
| + | if (token.indexOf('.') > -1) { | ||
| + | // Token contains a class selector | ||
| + | var bits = token.split('.'); | ||
| + | var tagName = bits[0]; | ||
| + | var className = bits[1]; | ||
| + | if (!tagName) { | ||
| + | tagName = '*'; | ||
| + | } | ||
| + | // Get elements matching tag, filter them for class selector | ||
| + | var found = new Array; | ||
| + | var foundCount = 0; | ||
| + | for (var h = 0; h < currentContext.length; h++) { | ||
| + | var elements; | ||
| + | if (tagName == '*') { | ||
| + | elements = getAllChildren(currentContext[h]); | ||
| + | } else { | ||
| + | elements = currentContext[h].getElementsByTagName(tagName); | ||
| + | } | ||
| + | for (var j = 0; j < elements.length; j++) { | ||
| + | found[foundCount++] = elements[j]; | ||
| + | } | ||
| + | } | ||
| + | currentContext = new Array; | ||
| + | var currentContextIndex = 0; | ||
| + | for (var k = 0; k < found.length; k++) { | ||
| + | if (found[k].className && found[k].className.match(new RegExp('\\\\b'+className+'\\\\b'))) { | ||
| + | currentContext[currentContextIndex++] = found[k]; | ||
| + | } | ||
| + | } | ||
| + | continue; // Skip to next token | ||
| + | } | ||
| + | // Code to deal with attribute selectors | ||
| + | if (token.match(/^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$/)) { | ||
| + | var tagName = RegExp.$1; | ||
| + | var attrName = RegExp.$2; | ||
| + | var attrOperator = RegExp.$3; | ||
| + | var attrValue = RegExp.$4; | ||
| + | if (!tagName) { | ||
| + | tagName = '*'; | ||
| + | } | ||
| + | // Grab all of the tagName elements within current context | ||
| + | var found = new Array; | ||
| + | var foundCount = 0; | ||
| + | for (var h = 0; h < currentContext.length; h++) { | ||
| + | var elements; | ||
| + | if (tagName == '*') { | ||
| + | elements = getAllChildren(currentContext[h]); | ||
| + | } else { | ||
| + | elements = currentContext[h].getElementsByTagName(tagName); | ||
| + | } | ||
| + | for (var j = 0; j < elements.length; j++) { | ||
| + | found[foundCount++] = elements[j]; | ||
| + | } | ||
| + | } | ||
| + | currentContext = new Array; | ||
| + | var currentContextIndex = 0; | ||
| + | var checkFunction; // This function will be used to filter the elements | ||
| + | switch (attrOperator) { | ||
| + | case '=': // Equality | ||
| + | checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); }; | ||
| + | break; | ||
| + | case '~': // Match one of space seperated words | ||
| + | checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\\\b'+attrValue+'\\\\b'))); }; | ||
| + | break; | ||
| + | case '|': // Match start with value followed by optional hyphen | ||
| + | checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); }; | ||
| + | break; | ||
| + | case '^': // Match starts with value | ||
| + | checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); }; | ||
| + | break; | ||
| + | case '$': // Match ends with value - fails with "Warning" in Opera 7 | ||
| + | checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); }; | ||
| + | break; | ||
| + | case '*': // Match ends with value | ||
| + | checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); }; | ||
| + | break; | ||
| + | default : | ||
| + | // Just test for existence of attribute | ||
| + | checkFunction = function(e) { return e.getAttribute(attrName); }; | ||
| + | } | ||
| + | currentContext = new Array; | ||
| + | var currentContextIndex = 0; | ||
| + | for (var k = 0; k < found.length; k++) { | ||
| + | if (checkFunction(found[k])) { | ||
| + | currentContext[currentContextIndex++] = found[k]; | ||
| + | } | ||
| + | } | ||
| + | // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); | ||
| + | continue; // Skip to next token | ||
| + | } | ||
| + | |||
| + | if (!currentContext[0]){ | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | // If we get here, token is JUST an element (not a class or ID selector) | ||
| + | tagName = token; | ||
| + | var found = new Array; | ||
| + | var foundCount = 0; | ||
| + | for (var h = 0; h < currentContext.length; h++) { | ||
| + | var elements = currentContext[h].getElementsByTagName(tagName); | ||
| + | for (var j = 0; j < elements.length; j++) { | ||
| + | found[foundCount++] = elements[j]; | ||
| + | } | ||
| + | } | ||
| + | currentContext = found; | ||
| + | } | ||
| + | return currentContext; | ||
| + | } | ||
| + | /////Behaviour over | ||
| + | var clickRules={ | ||
| + | '.collation':function(e){ | ||
| + | e.onclick=function(){ | ||
| + | //To fold/unfold particular child element(annotation etc) of current element--the collation element | ||
| + | var folder=this; | ||
| + | var folded; | ||
| + | var mark; | ||
| + | //find 'folded' and 'mark' | ||
| + | //U must give the folded element a class name including "hidden" | ||
| + | //And give the mark elenent a class name including "mark" | ||
| + | for(i=0;i<folder.childNodes.length;i++) | ||
{ | { | ||
| - | + | var chld=folder.childNodes[i]; | |
| - | + | var classname=String(chld.className); | |
| + | classname=classname.toLowerCase(); | ||
| + | if(classname.indexOf("mark")!=-1)mark=chld; | ||
| + | if(classname.indexOf("hidden")!=-1)folded=chld; | ||
} | } | ||
| - | + | //To check folding mark of hidden element,to show or to hide | |
| - | folded.style.display="none"; | + | var toshow=(folded.style.display=="none")?true:false; |
| - | + | if(toshow)//If true,show the hidden content,and hide the Sign,otherwise,hide the content and re-show the Sign | |
| + | { | ||
| + | folded.style.display=""; | ||
| + | if(!(mark==undefined))mark.style.display="none"; | ||
| + | } | ||
| + | else{ | ||
| + | folded.style.display="none"; | ||
| + | if(!(mark==undefined))mark.style.display=""; | ||
| + | } | ||
} | } | ||
} | } | ||
| - | + | } | |
| - | + | Behaviour.register(clickRules); | |
| + | </script> | ||
Current revision as of 18:11, 29 April 2007
<style type="text/css">
/*
Notes:
-You must log as admin to edit this page
-Whatever you enter in this page will be added to the html in the header after the standard style sheet, so you can override styles.
-if you want your code to look nice on this page, put a space at the beginning of each line
-This is the default style sheet that you can override : http://editthis.info/wiki/skins/monobook/main.css
For example uncomment this next section to turn all the text green:
*/
- column-content {
background: #f9f9f9 url("
") 0px 0px repeat;
width: 100%; float: right; margin: 0 0 0.6em -12.2em; padding:0; background-color: #DEE4D6; }
- article,#dicussion,#edit,#history,#protect,#delect,#move,#watch {
ackground-color: #DEE4D6;
}
- content {
margin: 2.8em 0 0 12.2em; padding: 0em 1em 1.5em 1em; border: 1px solid #aaaaaa; border-right: none; line-height: 1.5em; position: relative; z-index: 2; background-color: #EDECE2; }
- p-cactions li a {
background-color: #EDECE2; color: #002bb8; border: none; padding: 0 0.8em 0.3em 0.8em; text-decoration: none; text-transform: lowercase; position: relative; z-index: 0; margin: 0;
} .portlet h5{
color: #993366; }
body {
font: x-small sans-serif; color: Black; margin: 0; padding: 0;
} /* wikitable/prettytable class for skinning normal tables */
table.wikitable, table.prettytable {
margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaaaaa solid; border-collapse: collapse;
}
table.wikitable th, table.wikitable td, table.prettytable th, table.prettytable td {
border: 1px #aaaaaa solid; padding: 0.2em;
}
table.wikitable th, table.prettytable th {
background: #f2f2f2; text-align: center;
}
table.wikitable caption, table.prettytable caption {
margin-left: inherit; margin-right: inherit;
}
</style>
<script type="text/javascript"> //Feel free to add your javascript code here.
//Behaviour var Behaviour = { list : new Array,
register : function(sheet){ Behaviour.list.push(sheet); },
start : function(){ Behaviour.addLoadEvent(function(){ Behaviour.apply(); }); },
apply : function(){ for (h=0;sheet=Behaviour.list[h];h++){ for (selector in sheet){ list = document.getElementsBySelector(selector);
if (!list){ continue; }
for (i=0;element=list[i];i++){ sheet[selector](element); } } } },
addLoadEvent : function(func){ var oldonload = window.onload;
if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } }
Behaviour.start();
function getAllChildren(e) {
// Returns all children of element. Workaround required for IE5/Windows. Ugh.
return e.all ? e.all : e.getElementsByTagName('*');
}
document.getElementsBySelector = function(selector) {
// Attempt to fail gracefully in lesser browsers
if (!document.getElementsByTagName) {
return new Array();
}
// Split selector in to tokens
var tokens = selector.split(' ');
var currentContext = new Array(document);
for (var i = 0; i < tokens.length; i++) {
token = tokens[i].replace(/^\\s+/,).replace(/\\s+$/,);;
if (token.indexOf('#') > -1) {
// Token is an ID selector
var bits = token.split('#');
var tagName = bits[0];
var id = bits[1];
var element = document.getElementById(id);
if (tagName && element.nodeName.toLowerCase() != tagName) {
// tag with that ID not found, return false
return new Array();
}
// Set currentContext to contain just this element
currentContext = new Array(element);
continue; // Skip to next token
}
if (token.indexOf('.') > -1) {
// Token contains a class selector
var bits = token.split('.');
var tagName = bits[0];
var className = bits[1];
if (!tagName) {
tagName = '*';
}
// Get elements matching tag, filter them for class selector
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (found[k].className && found[k].className.match(new RegExp('\\\\b'+className+'\\\\b'))) {
currentContext[currentContextIndex++] = found[k];
}
}
continue; // Skip to next token
}
// Code to deal with attribute selectors
if (token.match(/^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$/)) {
var tagName = RegExp.$1;
var attrName = RegExp.$2;
var attrOperator = RegExp.$3;
var attrValue = RegExp.$4;
if (!tagName) {
tagName = '*';
}
// Grab all of the tagName elements within current context
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
var checkFunction; // This function will be used to filter the elements
switch (attrOperator) {
case '=': // Equality
checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
break;
case '~': // Match one of space seperated words
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\\\b'+attrValue+'\\\\b'))); };
break;
case '|': // Match start with value followed by optional hyphen
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
break;
case '^': // Match starts with value
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
break;
case '$': // Match ends with value - fails with "Warning" in Opera 7
checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
break;
case '*': // Match ends with value
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
break;
default :
// Just test for existence of attribute
checkFunction = function(e) { return e.getAttribute(attrName); };
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (checkFunction(found[k])) {
currentContext[currentContextIndex++] = found[k];
}
}
// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
continue; // Skip to next token
}
if (!currentContext[0]){
return;
}
// If we get here, token is JUST an element (not a class or ID selector)
tagName = token;
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements = currentContext[h].getElementsByTagName(tagName);
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = found;
}
return currentContext;
} /////Behaviour over var clickRules={ '.collation':function(e){ e.onclick=function(){ //To fold/unfold particular child element(annotation etc) of current element--the collation element var folder=this; var folded; var mark; //find 'folded' and 'mark' //U must give the folded element a class name including "hidden" //And give the mark elenent a class name including "mark" for(i=0;i<folder.childNodes.length;i++) { var chld=folder.childNodes[i]; var classname=String(chld.className); classname=classname.toLowerCase(); if(classname.indexOf("mark")!=-1)mark=chld; if(classname.indexOf("hidden")!=-1)folded=chld; } //To check folding mark of hidden element,to show or to hide var toshow=(folded.style.display=="none")?true:false; if(toshow)//If true,show the hidden content,and hide the Sign,otherwise,hide the content and re-show the Sign { folded.style.display=""; if(!(mark==undefined))mark.style.display="none"; } else{ folded.style.display="none"; if(!(mark==undefined))mark.style.display=""; } } } } Behaviour.register(clickRules); </script>
