CSS Sprites are working in the HTML of the page, but not in Javascript?
I am trying to install http://www.spyka.net/scripts/javascript/easy-social-bookmarks and add CSS Sprites to minimise the server calls.
I created the style sheet like this:
<style type="text/css">
<!--
.i_blinklist
{
width:21px;
height:21px;
background-repeat: no-repeat;
background-image: url(img_socialsprites.jpg);
background-position: 0 0;
}
.i_blogmarks
//-->
</style>
This code works in the HTML of the page like this:
<div class=i_blinklist></div>
When I add it to the javascript like this, it doesn't work:
sites[0] = new Array('http://blinklist.com/index.php?Action=Blink/addblink.php&Url={url}', 'Blinklist', '<div class=i_blinklist></div>');
Here is the main workings of the script which may also affect it:
function swgbookmarks()
{
for(i = 0; i < sites.length; i++)
{
var g = sites[i];
var u = g[0];
u = u.replace('{url}', escape(window.location.href));
u = u.replace('{title}', escape(window.document.title));
var img = (imagepath == '0') ? '' : '<img src="'+g[2]+'" alt="'+g[1]+'" /> ';
var k = '<a href="'+u+'">'+img+g[1]+'</a> ';
window.document.write(html_before+k+html_after);
}
}
Any ideas or help is very much appreciated.
Thank you.
UPDATE:
I've been playing around with this, and finally got it working :o)
Here are the changes I have made.
The social bookmark and image JS code:
sites[0] = new Array('http://blinklist.com/index.php?Action=Blink/addblink.php&Url={url}', 'Blinklist', 'socialsprite social blinklist');
Here is the JS code from the base of the script:
function swgbookmarks()
{
for(i = 0; i < sites.length; i++)
{
var g = sites[i];
var u = g[0];
u = u.replace('{url}', escape(window.location.href));
u = u.replace('{title}', escape(window.document.title));
var img = (imagepath == '0') ? '' : '<img src="transparent1x1.gif" class="'+g[2]+'" alt="'+g[1]+'" /> ';
var k = '<a href="'+u+'">'+img+g[1]+'</a> ';
window.document.write(html_before+k+html_after);
}
}
Here is the CSS Style Sheet code:
<style type="text/css">
<!--
.socialsprite {background:url(img_socialsprites.jpg);}
.social {height:22px;}
.social {width:22px;}
/* Social Images */
.blinklist {background-position:0px 0px;}
.blogmarks {background-position:0px -22px;}
This seems to be working.
I now have this working.
See main post Update at the bottom.
I wrote the update there, as the site wouldn't let me post my own answer for several hours, and I didn't want to waste anyone's time.
Thank you for the constructive comments, they helped a lot.