Installing an external javascript

  • oblongintellect
  • Novice
  • Novice
  • oblongintellect
  • Posts: 28

Post 3+ Months Ago

I've got a script for a cell color transition I want to embed into my site could you tell me what I am doing wrong I keep getting script errors. This is the code I want to embed
Code: [ Select ]
function makearray(n) {
    this.length = n;
    for(var i = 1; i <= n; i++)
        this[i] = 0;
    return this;
}
function hex(i) {
    if (i < 0)     return "00";
    else if (i > 255) return "ff";
    else         return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}
function hexnumtodec(hexchar) {
    if (parseInt(hexchar) == hexchar) return Number(hexchar)
    hexchar = hexchar.toUpperCase()
    switch (hexchar) {
        case 'A': return 10; break;
        case 'B': return 11; break;
        case 'C': return 12; break;
        case 'D': return 13; break;
        case 'E': return 14; break;
        case 'F': return 15; break;
    }
}
function hextodec(daHex) {
    var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
    return daDec
}

function setColor(r,g,b) {
    var hr = hex(r); var hg = hex(g); var hb = hex(b);
    var daColor = "#"+hr+hg+hb
    daEl.style.backgroundColor = daColor
    if (daColor == colorend.toLowerCase()) {
        clearInterval(iId)
        iId = null
        timerRunning = false
    }
}

function fade() {
    i++
    setColor(
        Math.floor(sr * ((step-i)/step) + er * (i/step)),
        Math.floor(sg * ((step-i)/step) + eg * (i/step)),
        Math.floor(sb * ((step-i)/step) + eb * (i/step)));
}
hexa = new makearray(16);
for(var i = 0; i < 10; i++)
    hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

var i
var iId = null
var sr, sg, sb
var er, eg, eb
var interval = 1
var step = 16
var colorstart
var colorend
var daEl
var timerRunning = false

function myfade(el,cs,ce,iv,st) {
    daEl = el
    colorstart = cs
    colorend = ce
    interval = iv
    step = st
    i = 0
    if (timerRunning) {
        clearInterval(iId)
        iId = null
    }
    var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
    if (colorstart.match(myRe)) {
        sr = hextodec(RegExp.$1)
        sg = hextodec(RegExp.$2)
        sb = hextodec(RegExp.$3)
    }
    if (colorend.match(myRe)) {
        er = hextodec(RegExp.$1)
        eg = hextodec(RegExp.$2)
        eb = hextodec(RegExp.$3)
    }
    timerRunning = false;
    iId = setInterval("fade()",interval)
    timerRunning = true;
}
function cellover(table_cell) {
    // play around with these values
    // element, from_color, to_color, interval(milliseconds), transition steps
    myfade(table_cell,'#B9D4E6','#eeeee0',20,32)
}
function cellout(table_cell) {
    if (timerRunning) {
        clearInterval(iId)
        iId = null
    }
    table_cell.style.backgroundColor = '#B9D4E6'
}
  1. function makearray(n) {
  2.     this.length = n;
  3.     for(var i = 1; i <= n; i++)
  4.         this[i] = 0;
  5.     return this;
  6. }
  7. function hex(i) {
  8.     if (i < 0)     return "00";
  9.     else if (i > 255) return "ff";
  10.     else         return "" + hexa[Math.floor(i/16)] + hexa[i%16];
  11. }
  12. function hexnumtodec(hexchar) {
  13.     if (parseInt(hexchar) == hexchar) return Number(hexchar)
  14.     hexchar = hexchar.toUpperCase()
  15.     switch (hexchar) {
  16.         case 'A': return 10; break;
  17.         case 'B': return 11; break;
  18.         case 'C': return 12; break;
  19.         case 'D': return 13; break;
  20.         case 'E': return 14; break;
  21.         case 'F': return 15; break;
  22.     }
  23. }
  24. function hextodec(daHex) {
  25.     var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
  26.     return daDec
  27. }
  28. function setColor(r,g,b) {
  29.     var hr = hex(r); var hg = hex(g); var hb = hex(b);
  30.     var daColor = "#"+hr+hg+hb
  31.     daEl.style.backgroundColor = daColor
  32.     if (daColor == colorend.toLowerCase()) {
  33.         clearInterval(iId)
  34.         iId = null
  35.         timerRunning = false
  36.     }
  37. }
  38. function fade() {
  39.     i++
  40.     setColor(
  41.         Math.floor(sr * ((step-i)/step) + er * (i/step)),
  42.         Math.floor(sg * ((step-i)/step) + eg * (i/step)),
  43.         Math.floor(sb * ((step-i)/step) + eb * (i/step)));
  44. }
  45. hexa = new makearray(16);
  46. for(var i = 0; i < 10; i++)
  47.     hexa[i] = i;
  48. hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
  49. hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
  50. var i
  51. var iId = null
  52. var sr, sg, sb
  53. var er, eg, eb
  54. var interval = 1
  55. var step = 16
  56. var colorstart
  57. var colorend
  58. var daEl
  59. var timerRunning = false
  60. function myfade(el,cs,ce,iv,st) {
  61.     daEl = el
  62.     colorstart = cs
  63.     colorend = ce
  64.     interval = iv
  65.     step = st
  66.     i = 0
  67.     if (timerRunning) {
  68.         clearInterval(iId)
  69.         iId = null
  70.     }
  71.     var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
  72.     if (colorstart.match(myRe)) {
  73.         sr = hextodec(RegExp.$1)
  74.         sg = hextodec(RegExp.$2)
  75.         sb = hextodec(RegExp.$3)
  76.     }
  77.     if (colorend.match(myRe)) {
  78.         er = hextodec(RegExp.$1)
  79.         eg = hextodec(RegExp.$2)
  80.         eb = hextodec(RegExp.$3)
  81.     }
  82.     timerRunning = false;
  83.     iId = setInterval("fade()",interval)
  84.     timerRunning = true;
  85. }
  86. function cellover(table_cell) {
  87.     // play around with these values
  88.     // element, from_color, to_color, interval(milliseconds), transition steps
  89.     myfade(table_cell,'#B9D4E6','#eeeee0',20,32)
  90. }
  91. function cellout(table_cell) {
  92.     if (timerRunning) {
  93.         clearInterval(iId)
  94.         iId = null
  95.     }
  96.     table_cell.style.backgroundColor = '#B9D4E6'
  97. }
It's name is table.js . I've been trying to embed it like this
Code: [ Select ]
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<link rel="stylesheet" type="text/css" href="../templates/test.css">

<script type="text/javascript" src="fader.js"></script>
<script type="text/javascript" src="jsfunctions.js"></script>
<script type="text/javascript" src="table.js"></script>
</head>
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  6. <meta name="ProgId" content="FrontPage.Editor.Document">
  7. <link rel="stylesheet" type="text/css" href="../templates/test.css">
  8. <script type="text/javascript" src="fader.js"></script>
  9. <script type="text/javascript" src="jsfunctions.js"></script>
  10. <script type="text/javascript" src="table.js"></script>
  11. </head>
Could someone please tell me what I'm doing wrong?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Starting with the lines
Code: [ Select ]
var i
var iId = null
var sr, sg, sb
  1. var i
  2. var iId = null
  3. var sr, sg, sb

The mandatories semicolons are missing.
Code: [ Select ]
var i;
var iId = null;
var sr, sg, sb;
  1. var i;
  2. var iId = null;
  3. var sr, sg, sb;
  • oblongintellect
  • Novice
  • Novice
  • oblongintellect
  • Posts: 28

Post 3+ Months Ago

I tried but still no workie. This is what I now have.

Code: [ Select ]
function makearray(n) {
    this.length = n;
    for(var i = 1; i <= n; i++)
        this[i] = 0;
    return this;
}
function hex(i) {
    if (i < 0)     return "00";
    else if (i > 255) return "ff";
    else         return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}
function hexnumtodec(hexchar) {
    if (parseInt(hexchar) == hexchar) return Number(hexchar)
    hexchar = hexchar.toUpperCase()
    switch (hexchar) {
        case 'A': return 10; break;
        case 'B': return 11; break;
        case 'C': return 12; break;
        case 'D': return 13; break;
        case 'E': return 14; break;
        case 'F': return 15; break;
    }
}
function hextodec(daHex) {
    var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
    return daDec
}

function setColor(r,g,b) {
    var hr = hex(r); var hg = hex(g); var hb = hex(b);
    var daColor = "#"+hr+hg+hb;
    daEl.style.backgroundColor = daColor;
    if (daColor == colorend.toLowerCase()) {
        clearInterval(iId)
        iId = null;
        timerRunning = false;
    }
}

function fade() {
    i++
    setColor(
        Math.floor(sr * ((step-i)/step) + er * (i/step)),
        Math.floor(sg * ((step-i)/step) + eg * (i/step)),
        Math.floor(sb * ((step-i)/step) + eb * (i/step)));
}
hexa = new makearray(16);
for(var i = 0; i < 10; i++)
    hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

var i;
var iId = null;
var sr, sg, sb;
var er, eg, eb;
var interval = 1;
var step = 16;
var colorstart;
var colorend;
var daEl;
var timerRunning = false;

function myfade(el,cs,ce,iv,st) {
    daEl = el;
    colorstart = cs;
    colorend = ce;
    interval = iv;
    step = st;
    i = 0;
    if (timerRunning) {
        clearInterval(iId)
        iId = null;
    }
    var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i;
    if (colorstart.match(myRe)) {
        sr = hextodec(RegExp.$1)
        sg = hextodec(RegExp.$2)
        sb = hextodec(RegExp.$3)
    }
    if (colorend.match(myRe)) {
        er = hextodec(RegExp.$1)
        eg = hextodec(RegExp.$2)
        eb = hextodec(RegExp.$3)
    }
    timerRunning = false;
    iId = setInterval("fade()",interval)
    timerRunning = true;
}
function cellover(table_cell) {
    // play around with these values
    // element, from_color, to_color, interval(milliseconds), transition steps
    myfade(table_cell,'#B9D4E6','#eeeee0',20,32)
}
function cellout(table_cell) {
    if (timerRunning) {
        clearInterval(iId)
        iId = null;
    }
    table_cell.style.backgroundColor = '#B9D4E6'
}
  1. function makearray(n) {
  2.     this.length = n;
  3.     for(var i = 1; i <= n; i++)
  4.         this[i] = 0;
  5.     return this;
  6. }
  7. function hex(i) {
  8.     if (i < 0)     return "00";
  9.     else if (i > 255) return "ff";
  10.     else         return "" + hexa[Math.floor(i/16)] + hexa[i%16];
  11. }
  12. function hexnumtodec(hexchar) {
  13.     if (parseInt(hexchar) == hexchar) return Number(hexchar)
  14.     hexchar = hexchar.toUpperCase()
  15.     switch (hexchar) {
  16.         case 'A': return 10; break;
  17.         case 'B': return 11; break;
  18.         case 'C': return 12; break;
  19.         case 'D': return 13; break;
  20.         case 'E': return 14; break;
  21.         case 'F': return 15; break;
  22.     }
  23. }
  24. function hextodec(daHex) {
  25.     var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
  26.     return daDec
  27. }
  28. function setColor(r,g,b) {
  29.     var hr = hex(r); var hg = hex(g); var hb = hex(b);
  30.     var daColor = "#"+hr+hg+hb;
  31.     daEl.style.backgroundColor = daColor;
  32.     if (daColor == colorend.toLowerCase()) {
  33.         clearInterval(iId)
  34.         iId = null;
  35.         timerRunning = false;
  36.     }
  37. }
  38. function fade() {
  39.     i++
  40.     setColor(
  41.         Math.floor(sr * ((step-i)/step) + er * (i/step)),
  42.         Math.floor(sg * ((step-i)/step) + eg * (i/step)),
  43.         Math.floor(sb * ((step-i)/step) + eb * (i/step)));
  44. }
  45. hexa = new makearray(16);
  46. for(var i = 0; i < 10; i++)
  47.     hexa[i] = i;
  48. hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
  49. hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
  50. var i;
  51. var iId = null;
  52. var sr, sg, sb;
  53. var er, eg, eb;
  54. var interval = 1;
  55. var step = 16;
  56. var colorstart;
  57. var colorend;
  58. var daEl;
  59. var timerRunning = false;
  60. function myfade(el,cs,ce,iv,st) {
  61.     daEl = el;
  62.     colorstart = cs;
  63.     colorend = ce;
  64.     interval = iv;
  65.     step = st;
  66.     i = 0;
  67.     if (timerRunning) {
  68.         clearInterval(iId)
  69.         iId = null;
  70.     }
  71.     var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i;
  72.     if (colorstart.match(myRe)) {
  73.         sr = hextodec(RegExp.$1)
  74.         sg = hextodec(RegExp.$2)
  75.         sb = hextodec(RegExp.$3)
  76.     }
  77.     if (colorend.match(myRe)) {
  78.         er = hextodec(RegExp.$1)
  79.         eg = hextodec(RegExp.$2)
  80.         eb = hextodec(RegExp.$3)
  81.     }
  82.     timerRunning = false;
  83.     iId = setInterval("fade()",interval)
  84.     timerRunning = true;
  85. }
  86. function cellover(table_cell) {
  87.     // play around with these values
  88.     // element, from_color, to_color, interval(milliseconds), transition steps
  89.     myfade(table_cell,'#B9D4E6','#eeeee0',20,32)
  90. }
  91. function cellout(table_cell) {
  92.     if (timerRunning) {
  93.         clearInterval(iId)
  94.         iId = null;
  95.     }
  96.     table_cell.style.backgroundColor = '#B9D4E6'
  97. }
Can you see anything else wrong?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Let's see the page calling the scripts source, I just tried the above code, added cellover(this) and cellout(this) to a TD tag and It works like a charm.

EDIT: I just noticed that your using fader.js as well, I'd really like to know if you can get fader.js to work with this cell fader. I tinkered with trying to get fader and a cell fader to work together awhile ago with no success.
  • oblongintellect
  • Novice
  • Novice
  • oblongintellect
  • Posts: 28

Post 3+ Months Ago

I figured it out, Thanks for your help guys :D .
  • oblongintellect
  • Novice
  • Novice
  • oblongintellect
  • Posts: 28

Post 3+ Months Ago

Here's an example of the finished product. The colors will be reworked. This is only a working example. I still want to try and incorporate Nunzio's cellfader script but I gotta go to work soon and I'm currently still getting script errors.

http://www.ghosthacker.org/test.html

Thanks again for all the help.

-OI
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

:( I was hoping to see the link fade one way while the cell faded the other, all at the same time.
  • oblongintellect
  • Novice
  • Novice
  • oblongintellect
  • Posts: 28

Post 3+ Months Ago

Well, I have the script for the cellfader but embedding it is where I'm having problems. I'll work on it some more whenever I get off work. I have some ideas so if I'm successful I'll post a link.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: Liamw411 and 41 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.