Posted By

pdswan on 03/30/09


Tagged

css prototype injection unobtrusive stylesheet


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

nickelstar
rickfu
legacye


Load Css Files Dynamically Via Javascript


 / Published in: JavaScript
 

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

  1. var CSSLoader = {
  2. addStylesheets: function(sheets, elm){
  3. var l = sheets.length;
  4. if( !l ) return;
  5. elm = $(elm) || $$('head')[0];
  6. if( !elm ) return;
  7.  
  8. for( var i=0; i<l; i++){
  9. var sheet = sheets[i];
  10. var info = {
  11. rel: 'stylesheet',
  12. type: 'text/css',
  13. media: 'screen'
  14. }
  15. if( Object.isString(sheet)){
  16. Object.extend(info, {href: sheet});
  17. }else{
  18. try{
  19. Object.extend(info, sheet);
  20. }catch(e){
  21. continue;
  22. }
  23. }
  24. var temp = new Element('link', info);
  25. elm.insert(temp);
  26. }
  27. }
  28. };

Report this snippet  

You need to login to post a comment.