lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
Nifty Cube: css file autoloader
Nifty Cube is a nifty corner-rounding script for web pages written by Alessandro Fulciniti. One small drawback I discovered in it is that it requires the CSS file it uses to be in the same directory as the calling script. I wrote the following function to overcome this and make it a little easier to use:

function niftyAutoDetectCssPath()
{
var _debug = 0;
var _regex = 'niftycube.js';
var _SCRIPTS = new Array();
var nifty_path = ""; // return

// Get Script Tag Array
_SCRIPTS = document.getElementsByTagName('script');

// Loop Search for Nifty Tag
for ( i=0; i<_SCRIPTS.length; i++ )
{
var _src = _SCRIPTS[i].src
if ( _debug ) alert(_src);
if ( _src.search(_regex) != -1 )
{
if ( _debug ) alert('nifty path [' + _src + '] found!');
nifty_path = _src.substr(0, _src.lastIndexOf('/') + 1);
break;
}
}

if ( _debug ) alert('returning niftyPath [' + nifty_path + ']');
return nifty_path;
}


I tested it in my current version of Firefox and IE (6?) and it worked.

The modified package with demo is available here:

NiftyCubeAuto
Css autoloader seems interesting so I will give it a whirl.

I was trying the cube out as a trial and found problems with css location. My temporary fix is messy and involves dumping files in directories and changing file paths to suit. So If this works thanks in advance.
Thanks for your work. It solved the problem .

I am trying to find a solution that improves the quality of the corners. Something to do with anti-aliasing functions.
I am new to all of this so a little behind the development of web techniques.
Hi Tom(?), thank you very much for the insight and code that I need to solve the autoloading of css in nifty cube. You rock!
I've been needing something like this for a long time. Thank you very much.