Various - Maybe useful


/ Published in: JavaScript
Save to your folder(s)

old stuff floating around my system. trying to get organized. might not be worth keeping. I'll weed it out later


Copy this code and paste it in your HTML
  1. function setActiveStyleSheet(title)
  2. {
  3. var i, a, main;
  4.  
  5. // find an loop through all the <link> elements in the document
  6. for (i = 0; (a = document.getElementsByTagName("link")[i]); i++)
  7. {
  8. // disable all the stylesheet
  9. if (a.getAttribute("rel").indexOf("style") != -1
  10. && a.getAttribute("title"))
  11.  
  12. a.disabled = true;
  13.  
  14. // if it is the stylesheet requested, then enable it
  15. if (a.getAttribute("title") == title)
  16. a.disabled = false;
  17. }
  18. }
  19.  
  20.  
  21. // Jumble addresses
  22. function decryptEmail() {
  23. for(i=0; i<= document.links.length-1; i++) {
  24. var str = new String(document.links[i].href);
  25. document.links[i].href =
  26. str.replace(/^mail:([^\?]+)(\?.+)?$/,"mailto:[email protected]$2");
  27. }
  28. }
  29.  
  30.  
  31. var __PNGReplace = "png.gif";
  32.  
  33. function changePngForIEWin()
  34. {
  35.  
  36. imgs = document.getElementsByTagName("img");
  37.  
  38. for (var i = imgs.length; i-- > 0;)
  39. {
  40. if(imgs[i].src.indexOf(".png") > 0)
  41. {
  42. imgs[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + imgs[i].src + ",sizingMethod=scale)";
  43.  
  44. imgs[i].width = imgs[i].width;
  45. imgs[i].height = imgs[i].height;
  46.  
  47. imgs[i].src = __PNGReplace;
  48. }
  49.  
  50. }
  51. }
  52.  
  53. function setCookie(name, value, expires, path, domain, secure)
  54. {
  55.  
  56. document.cookie= name + "=" + escape(value) +
  57. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  58. ((path) ? "; path=" + path : "") +
  59. ((domain) ? "; domain=" + domain : "") +
  60. ((secure) ? "; secure" : "");
  61. }
  62.  
  63. /*
  64. Gets the value of the specified cookie.
  65.  
  66.  
  67. name Name of the cookie to get the value of.
  68.  
  69. Returns a string containing value of specified cookie, or null if cookie does not exist.
  70. */
  71.  
  72. function getCookie(name)
  73. {
  74.  
  75. var dc = document.cookie;
  76. var prefix = name + "=";
  77. var begin = dc.indexOf("; " + prefix);
  78.  
  79.  
  80. if (begin == -1)
  81. {
  82. begin = dc.indexOf(prefix);
  83. if (begin != 0) return null;
  84. }
  85. else
  86. {
  87. begin += 2;
  88. }
  89.  
  90.  
  91. var end = document.cookie.indexOf(";", begin);
  92.  
  93.  
  94. if (end == -1)
  95. {
  96. end = dc.length;
  97. }
  98.  
  99. return unescape(dc.substring(begin + prefix.length, end));
  100. }
  101.  
  102. function PreloadImages()
  103. {
  104. //alert("number of images to load: " + PreloadImages.arguments.length);
  105.  
  106. // var arr = new Array(PreloadImages.arguments.length);
  107. for(var c = PreloadImages.arguments.length; c -- > 0;)
  108. {
  109. _img = new Image();
  110. _img.src = PreloadImages.arguments[c];
  111. }
  112.  
  113. }
  114.  
  115. function setLinkedStyleSheet(title)
  116. {
  117. var linkNodes = document.getElementsByTagName("link");
  118. for ( i = 0; i < linkNodes.length; i++ )
  119. {
  120. linkNode = linkNodes[i];
  121. relAttr = linkNode.getAttribute('rel');
  122. if ( relAttr && ( relAttr.indexOf("style") != -1 ) && linkNode.getAttribute("title") )
  123. {
  124. linkNode.disabled = true;
  125.  
  126. if ( linkNode.getAttribute("title") == title )
  127. linkNode.disabled = false;
  128. }
  129. }
  130. }
  131.  
  132. // function for changing stylesheets using document.styleSheets
  133. function setStyleSheet(theme)
  134. {
  135. for ( i = 0; i < document.styleSheets.length; i++ )
  136. {
  137. if ( document.styleSheets[i].title )
  138. {
  139. document.styleSheets[i].disabled = true;
  140.  
  141. if ( document.styleSheets[i].title == theme )
  142.  
  143. document.styleSheets[i].disabled = false;
  144. }
  145. }
  146. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.