2
0

theme.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // The purpose of this code is to fix the height of overflow: auto blocks, because some browsers can't figure it out for themselves.
  2. function smf_codeBoxFix()
  3. {
  4. var codeFix = document.getElementsByTagName('code');
  5. for (var i = codeFix.length - 1; i >= 0; i--)
  6. {
  7. if (is_webkit && codeFix[i].offsetHeight < 20)
  8. codeFix[i].style.height = (codeFix[i].offsetHeight + 20) + 'px';
  9. else if (is_ff && (codeFix[i].scrollWidth > codeFix[i].clientWidth || codeFix[i].clientWidth == 0))
  10. codeFix[i].style.overflow = 'scroll';
  11. else if ('currentStyle' in codeFix[i] && codeFix[i].currentStyle.overflow == 'auto' && (codeFix[i].currentStyle.height == '' || codeFix[i].currentStyle.height == 'auto') && (codeFix[i].scrollWidth > codeFix[i].clientWidth || codeFix[i].clientWidth == 0) && (codeFix[i].offsetHeight != 0))
  12. codeFix[i].style.height = (codeFix[i].offsetHeight + 24) + 'px';
  13. }
  14. }
  15. // Add a fix for code stuff?
  16. if ((is_ie && !is_ie4) || is_webkit || is_ff)
  17. addLoadEvent(smf_codeBoxFix);
  18. // Toggles the element height and width styles of an image.
  19. function smc_toggleImageDimensions()
  20. {
  21. var oImages = document.getElementsByTagName('IMG');
  22. for (oImage in oImages)
  23. {
  24. // Not a resized image? Skip it.
  25. if (oImages[oImage].className == undefined || oImages[oImage].className.indexOf('bbc_img resized') == -1)
  26. continue;
  27. oImages[oImage].style.cursor = 'pointer';
  28. oImages[oImage].onclick = function() {
  29. this.style.width = this.style.height = this.style.width == 'auto' ? null : 'auto';
  30. };
  31. }
  32. }
  33. // Add a load event for the function above.
  34. addLoadEvent(smc_toggleImageDimensions);
  35. // Adds a button to a certain button strip.
  36. function smf_addButton(sButtonStripId, bUseImage, oOptions)
  37. {
  38. var oButtonStrip = document.getElementById(sButtonStripId);
  39. var aItems = oButtonStrip.getElementsByTagName('span');
  40. // Remove the 'last' class from the last item.
  41. if (aItems.length > 0)
  42. {
  43. var oLastSpan = aItems[aItems.length - 1];
  44. oLastSpan.className = oLastSpan.className.replace(/\s*last/, 'position_holder');
  45. }
  46. // Add the button.
  47. var oButtonStripList = oButtonStrip.getElementsByTagName('ul')[0];
  48. var oNewButton = document.createElement('li');
  49. setInnerHTML(oNewButton, '<a href="' + oOptions.sUrl + '" ' + ('sCustom' in oOptions ? oOptions.sCustom : '') + '><span class="last"' + ('sId' in oOptions ? ' id="' + oOptions.sId + '"': '') + '>' + oOptions.sText + '</span></a>');
  50. oButtonStripList.appendChild(oNewButton);
  51. }
  52. // Adds hover events to list items. Used for a versions of IE that don't support this by default.
  53. var smf_addListItemHoverEvents = function()
  54. {
  55. var cssRule, newSelector;
  56. // Add a rule for the list item hover event to every stylesheet.
  57. for (var iStyleSheet = 0; iStyleSheet < document.styleSheets.length; iStyleSheet ++)
  58. for (var iRule = 0; iRule < document.styleSheets[iStyleSheet].rules.length; iRule ++)
  59. {
  60. oCssRule = document.styleSheets[iStyleSheet].rules[iRule];
  61. if (oCssRule.selectorText.indexOf('LI:hover') != -1)
  62. {
  63. sNewSelector = oCssRule.selectorText.replace(/LI:hover/gi, 'LI.iehover');
  64. document.styleSheets[iStyleSheet].addRule(sNewSelector, oCssRule.style.cssText);
  65. }
  66. }
  67. // Now add handling for these hover events.
  68. var oListItems = document.getElementsByTagName('LI');
  69. for (oListItem in oListItems)
  70. {
  71. oListItems[oListItem].onmouseover = function() {
  72. this.className += ' iehover';
  73. };
  74. oListItems[oListItem].onmouseout = function() {
  75. this.className = this.className.replace(new RegExp(' iehover\\b'), '');
  76. };
  77. }
  78. }
  79. // Add hover events to list items if the browser requires it.
  80. if (is_ie7down && 'attachEvent' in window)
  81. window.attachEvent('onload', smf_addListItemHoverEvents);