JAVASCRIPT - HTML Nugget on Page

Creating and modifying plugins.
Post Reply
tedbone
Posts: 4
Joined: Mon Sep 18, 2006 3:48 am

JAVASCRIPT - HTML Nugget on Page

Post by tedbone »

Hello,
I am trying to add a JavaScript image fader to the head using the plugin.
Here are some specs to hopefully get the easy questions out of the way...

- I am clicking "<>" and adding the code.
- Nugget Placement: HEAD tag of the page
- I am selecting "NO" for Performing Markup Transformations
- Item to be displayed: All times

After I hit "Save" and I hit "<>" to look at the code here is what is reads:
<script type="text/javascript"></script><style type="text/css"></style>


Here is the JavaScript that I'm tyring to add:


<script type="text/javascript">
<!--
document.write("<style type='text/css'>.hideimg {visibility:hidden;}</style>");

function initImage() {

i = 1;

while (true) {

imageId = 'theimg' + i;
obj = document.getElementById(imageId);
if (obj == null) break;
setOpacity(imageId, 0);
obj.style.visibility = "visible";
fadeIn(imageId);
i++;

}

}
delay=15;

function fadeIn(objId) {

opacity = 1;
if (document.getElementById) {
while (opacity <= 100) {
window.setTimeout("setOpacity('"+objId+"',"+opacity+")", delay);
opacity += 1;
delay += 10; // modify to change fade speed
}
}
}

function setOpacity(objId, opacity) {
if (document.getElementById) {
obj = document.getElementById(objId);
opacity = (opacity == 100)?99.999:opacity;
// IE/Win
obj.style.filter = "alpha(opacity:"+opacity+")";
// Safari<1.2 Konqueror
obj.style.KHTMLOpacity = opacity/100;
// Older Mozilla and Firefox
obj.style.MozOpacity = opacity/100;
// Safari 1.2, newer Firefox and Mozilla, CSS3
obj.style.opacity = opacity/100;
}
}
window.onload = function() {initImage()}
// -->
</script>


I'm not sure if this is a bug, or if it's user error.
If anyone knows a better way to perform image fade-ins when the page loads, please help a brother out.

Thanks in Advance,
Ted
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I wonder if the WYSIWYG editor is stripping the comments out? That would result in the behavior you're seeing.

I'd try switching to the non-WYSIWYG editor temporarily to add the JavaScript to the nugget. Then I'd switch it back. You can make this change from Manage Users so it doesn't affect any other users of your blog.
Judebert
---
Website | Wishlist | PayPal
tedbone
Posts: 4
Joined: Mon Sep 18, 2006 3:48 am

Post by tedbone »

judebert,
You were correct - the WYSIWYG editor was stripping the comments out.
I switched to the non-WYSIWYG editor and the script remained intact.

However, the image did not fade in. I'll try a few more things with the script to see if this problem is not an error on my part.

Thank you,
Ted
Post Reply