Return to Snippet

Revision: 12846
at May 19, 2009 11:41 by pdswan


Updated Code
var CSSLoader = {
	addStylesheets: function(sheets, elm){
		var l = sheets.length;
		if( !l ) return;
		elm = $(elm) || $$('head')[0];
		if( !elm ) return;
		
		for( var i=0; i<l; i++){
			var sheet = sheets[i];
			var info = {
				rel: 'stylesheet',
				type: 'text/css',
				media: 'screen'
			}
                        if( Object.isString(sheet)){
                            Object.extend(info, {href: sheet});
                        }else{
                            try{
                                Object.extend(info, sheet);
                            }catch(e){
                                continue;
                            }
                        }
			var temp = new Element('link', info);
			elm.insert(temp);
		}
	}
};

Revision: 12845
at March 30, 2009 16:45 by pdswan


Initial Code
var CSSLoader = {
	addStylesheets: function(sheets, elm){
		var l = sheets.length;
		if( !l ) return;
		elm = $(elm) || $$('head')[0];
		if( !elm ) return;
		
		for( var i=0; i<l; i++){
			var sheet = sheets[i];
			var info = {
				rel: 'stylesheet',
				type: 'text/css',
				media: 'screen'
			}
                        // woops, this is wrong
			if( Object.isArray(sheet)){
				Object.extend(info, sheet);
			}else{
				Object.extend(info, {
					href: sheet
				});
			}
			var temp = new Element('link', info);
			elm.insert(temp);
		}
	}
};

Initial URL

                                

Initial Description
changed to detect sring sheet first, then to try object extension.

Initial Title
Load Css Files Dynamically Via Javascript

Initial Tags
css

Initial Language
JavaScript