# HG changeset patch # User Christian Urban # Date 1319280843 -3600 # Node ID a1add930f3a196d37d1eda2172b3e85d809b14f0 # Parent 38568b07bfefeb9dfe5622f51ab927f7d0699f8f tuned diff -r 38568b07bfef -r a1add930f3a1 striper.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/striper.js Sat Oct 22 11:54:03 2011 +0100 @@ -0,0 +1,43 @@ +// Splintered striper 1.3 +// reworking of Zebra Tables and similar methods which works not only for tables and even/odd rows, +// but as a general DOM means of assigning any number of classes to children of a parent element. +// Patrick H. Lauke aka redux / www.splintered.co.uk +// Distributed under the Creative Commons Attribution-ShareAlike license - http://creativecommons.org/licenses/by-sa/2.0/ + + +/* + * Summary: Core experiment function that applies any number of classes to all child elements + * contained in all occurences of a parent element (either with or without a specific class) + * Parameters: parentElementTag - parent tag name + * parentElementClass - class assigned to the parent; if null, all parentElementTag elements will be affected + * childElementTag - tag name of the child elements to apply the styles to + * styleClasses - comma separated list of any number of style classes (using 2 classes gives the classic "zebra" effect) + * Return: none + */ +function striper(parentElementTag, parentElementClass, childElementTag, styleClasses) +{ + var i=0,currentParent,currentChild; + // capability and sanity check + if ((document.getElementsByTagName)&&(parentElementTag)&&(childElementTag)&&(styleClasses)) { + // turn the comma separate list of classes into an array + var styles = styleClasses.split(','); + // get an array of all parent tags + var parentItems = document.getElementsByTagName(parentElementTag); + // loop through all parent elements + while (currentParent = parentItems[i++]) { + // if parentElementClass was null, or if the current parent's class matches the specified class + if ((parentElementClass == null)||(currentParent.className == parentElementClass)) { + var j=0,k=0; + // get all child elements in the current parent element + var childItems = currentParent.getElementsByTagName(childElementTag); + // loop through all child elements + while (currentChild = childItems[j++]) { + // based on the current element and the number of styles in the array, work out which class to apply + k = (j+(styles.length-1)) % styles.length; + // add the class to the child element - if any other classes were already present, they're kept intact + currentChild.className = currentChild.className+" "+styles[k]; + } + } + } + } +} diff -r 38568b07bfef -r a1add930f3a1 travelling.html --- a/travelling.html Sat Oct 22 11:49:14 2011 +0100 +++ b/travelling.html Sat Oct 22 11:54:03 2011 +0100 @@ -2,6 +2,7 @@ Christian Urban + @@ -9,7 +10,8 @@ BGCOLOR="#4169E1" LINK="#0000EF" VLINK="#51188E" - ALINK="#FF0000"> + ALINK="#FF0000" + ONLOAD="striper('ul','striped','li','first,second')"> @@ -62,7 +64,7 @@
2011
-

Talks and Travel Plans

-
    +
    • Talk at Dyckhoff Fest (18 - 19 November)

-Last modified: Sat Oct 22 11:49:00 BST 2011 +Last modified: Sat Oct 22 11:53:32 BST 2011 [Validate this page.]