R
Richard A. DeVenezia
I hope this is the end of my present 'discovery' phase. I've learned alot
about JavaScript in a short time and my head hurts. The following is what
came out of all my questions and all the excellent answers (thanks!). It
will be the basis of a slightly more complicated function for rendering a
two-level navigation bar ( Don't have time to get into design of a
multi-styletype renderer for n-level hierarchies. )
This is a single function that will perform color transitioning.
If Foo is an unavailable identifier, change it to whatever you want, nothing
else needs to be changed (except the invocation of it)
----
function Foo (argument) {
// Simpleton singleton
var callee = arguments.callee
if (callee.singleton != undefined)
return callee.singleton
if (this == window)
return new callee ( argument )
callee.singleton = this
var myName = callee.toString().replace (/\n/g, ' ').match(
/function\s(.*?)(\s|\()/ ) [1]
//alert ('my name is ' + myName)
installClassMethods ()
doBunchOfStuff()
return
function doBunchOfStuff () {
var id = '_' + Math.random(0).toString().substring(2)
document.write ('<TABLE ID="' + id + '"><TR><TD></TD></TR></TABLE>')
var table = document.getElementById (id)
table.deleteRow (0)
var row = table.insertRow (table.rows.length)
var cell = row.insertCell ( row.cells.length )
cell.innerHTML = '<B>Provided</B> by <I>convenience</I> of innerHTML'
cell.style.borderStyle = 'solid'
cell.style.borderColor = 'Black'
cell.style.borderWidth = '1px'
cell.onmouseover = function ( E ) { callee.over (this) }
cell.onmouseout = function ( E ) { callee.out (this) }
}
//--------------------------------------------------------------
function installClassMethods () {
//------------------------------------------------------------
callee.over = function (td) {
td.style.backgroundColor = 'black'
}
callee.out = function (td) {
td.transition = new callee.transition (td)
td.transition.doStart()
}
callee.transition = function (td) {
this.td = td
this.step = 0
this.interval = 10
}
callee.transition.prototype.doStart = function () {
thisObj = this
thisObj.doStep()
this.timerId = setInterval ( function () { thisObj.doStep() },
this.interval )
}
callee.transition.prototype.doStep = function () {
this.step += 4
if (this.step > 255) this.step = 255
this.td.style.backgroundColor =
'rgb('+this.step+','+this.step+','+this.step+')'
if (this.step == 255) {
clearTimeout (this.timerId)
this.td.transition = null
}
}
}
} // end of Foo
Foo('Hi')
about JavaScript in a short time and my head hurts. The following is what
came out of all my questions and all the excellent answers (thanks!). It
will be the basis of a slightly more complicated function for rendering a
two-level navigation bar ( Don't have time to get into design of a
multi-styletype renderer for n-level hierarchies. )
This is a single function that will perform color transitioning.
If Foo is an unavailable identifier, change it to whatever you want, nothing
else needs to be changed (except the invocation of it)
----
function Foo (argument) {
// Simpleton singleton
var callee = arguments.callee
if (callee.singleton != undefined)
return callee.singleton
if (this == window)
return new callee ( argument )
callee.singleton = this
var myName = callee.toString().replace (/\n/g, ' ').match(
/function\s(.*?)(\s|\()/ ) [1]
//alert ('my name is ' + myName)
installClassMethods ()
doBunchOfStuff()
return
function doBunchOfStuff () {
var id = '_' + Math.random(0).toString().substring(2)
document.write ('<TABLE ID="' + id + '"><TR><TD></TD></TR></TABLE>')
var table = document.getElementById (id)
table.deleteRow (0)
var row = table.insertRow (table.rows.length)
var cell = row.insertCell ( row.cells.length )
cell.innerHTML = '<B>Provided</B> by <I>convenience</I> of innerHTML'
cell.style.borderStyle = 'solid'
cell.style.borderColor = 'Black'
cell.style.borderWidth = '1px'
cell.onmouseover = function ( E ) { callee.over (this) }
cell.onmouseout = function ( E ) { callee.out (this) }
}
//--------------------------------------------------------------
function installClassMethods () {
//------------------------------------------------------------
callee.over = function (td) {
td.style.backgroundColor = 'black'
}
callee.out = function (td) {
td.transition = new callee.transition (td)
td.transition.doStart()
}
callee.transition = function (td) {
this.td = td
this.step = 0
this.interval = 10
}
callee.transition.prototype.doStart = function () {
thisObj = this
thisObj.doStep()
this.timerId = setInterval ( function () { thisObj.doStep() },
this.interval )
}
callee.transition.prototype.doStep = function () {
this.step += 4
if (this.step > 255) this.step = 255
this.td.style.backgroundColor =
'rgb('+this.step+','+this.step+','+this.step+')'
if (this.step == 255) {
clearTimeout (this.timerId)
this.td.transition = null
}
}
}
} // end of Foo
Foo('Hi')