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.calle e
if (callee.singlet on != undefined)
return callee.singleto n
if (this == window)
return new callee ( argument )
callee.singleto n = this
var myName = callee.toString ().replace (/\n/g, ' ').match(
/function\s(.*?) (\s|\()/ ) [1]
//alert ('my name is ' + myName)
installClassMet hods ()
doBunchOfStuff( )
return
function doBunchOfStuff () {
var id = '_' + Math.random(0). toString().subs tring(2)
document.write ('<TABLE ID="' + id + '"><TR><TD></TD></TR></TABLE>')
var table = document.getEle mentById (id)
table.deleteRow (0)
var row = table.insertRow (table.rows.len gth)
var cell = row.insertCell ( row.cells.lengt h )
cell.innerHTML = '<B>Provided</B> by <I>convenienc e</I> of innerHTML'
cell.style.bord erStyle = 'solid'
cell.style.bord erColor = 'Black'
cell.style.bord erWidth = '1px'
cell.onmouseove r = function ( E ) { callee.over (this) }
cell.onmouseout = function ( E ) { callee.out (this) }
}
//--------------------------------------------------------------
function installClassMet hods () {
//------------------------------------------------------------
callee.over = function (td) {
td.style.backgr oundColor = 'black'
}
callee.out = function (td) {
td.transition = new callee.transiti on (td)
td.transition.d oStart()
}
callee.transiti on = function (td) {
this.td = td
this.step = 0
this.interval = 10
}
callee.transiti on.prototype.do Start = function () {
thisObj = this
thisObj.doStep( )
this.timerId = setInterval ( function () { thisObj.doStep( ) },
this.interval )
}
callee.transiti on.prototype.do Step = function () {
this.step += 4
if (this.step > 255) this.step = 255
this.td.style.b ackgroundColor =
'rgb('+this.ste p+','+this.step +','+this.step+ ')'
if (this.step == 255) {
clearTimeout (this.timerId)
this.td.transit ion = null
}
}
}
} // end of Foo
Foo('Hi')
-----
Richard A. DeVenezia
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.calle e
if (callee.singlet on != undefined)
return callee.singleto n
if (this == window)
return new callee ( argument )
callee.singleto n = this
var myName = callee.toString ().replace (/\n/g, ' ').match(
/function\s(.*?) (\s|\()/ ) [1]
//alert ('my name is ' + myName)
installClassMet hods ()
doBunchOfStuff( )
return
function doBunchOfStuff () {
var id = '_' + Math.random(0). toString().subs tring(2)
document.write ('<TABLE ID="' + id + '"><TR><TD></TD></TR></TABLE>')
var table = document.getEle mentById (id)
table.deleteRow (0)
var row = table.insertRow (table.rows.len gth)
var cell = row.insertCell ( row.cells.lengt h )
cell.innerHTML = '<B>Provided</B> by <I>convenienc e</I> of innerHTML'
cell.style.bord erStyle = 'solid'
cell.style.bord erColor = 'Black'
cell.style.bord erWidth = '1px'
cell.onmouseove r = function ( E ) { callee.over (this) }
cell.onmouseout = function ( E ) { callee.out (this) }
}
//--------------------------------------------------------------
function installClassMet hods () {
//------------------------------------------------------------
callee.over = function (td) {
td.style.backgr oundColor = 'black'
}
callee.out = function (td) {
td.transition = new callee.transiti on (td)
td.transition.d oStart()
}
callee.transiti on = function (td) {
this.td = td
this.step = 0
this.interval = 10
}
callee.transiti on.prototype.do Start = function () {
thisObj = this
thisObj.doStep( )
this.timerId = setInterval ( function () { thisObj.doStep( ) },
this.interval )
}
callee.transiti on.prototype.do Step = function () {
this.step += 4
if (this.step > 255) this.step = 255
this.td.style.b ackgroundColor =
'rgb('+this.ste p+','+this.step +','+this.step+ ')'
if (this.step == 255) {
clearTimeout (this.timerId)
this.td.transit ion = null
}
}
}
} // end of Foo
Foo('Hi')
-----
Richard A. DeVenezia
Comment