theme.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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('li');
  40. // Remove the 'last' class from the last item.
  41. if (aItems.length > 0)
  42. {
  43. var oLastItem = aItems[aItems.length - 1];
  44. oLastItem.className = oLastItem.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. oNewButton.className = 'last';
  50. setInnerHTML(oNewButton, '<a href="' + oOptions.sUrl + '" ' + ('sCustom' in oOptions ? oOptions.sCustom : '') + '><span' + ('sId' in oOptions ? ' id="' + oOptions.sId + '"': '') + '>' + oOptions.sText + '</span></a>');
  51. oButtonStripList.appendChild(oNewButton);
  52. }
  53. // Adds hover events to list items. Used for a versions of IE that don't support this by default.
  54. var smf_addListItemHoverEvents = function()
  55. {
  56. var cssRule, newSelector;
  57. // Add a rule for the list item hover event to every stylesheet.
  58. for (var iStyleSheet = 0; iStyleSheet < document.styleSheets.length; iStyleSheet ++)
  59. for (var iRule = 0; iRule < document.styleSheets[iStyleSheet].rules.length; iRule ++)
  60. {
  61. oCssRule = document.styleSheets[iStyleSheet].rules[iRule];
  62. if (oCssRule.selectorText.indexOf('LI:hover') != -1)
  63. {
  64. sNewSelector = oCssRule.selectorText.replace(/LI:hover/gi, 'LI.iehover');
  65. document.styleSheets[iStyleSheet].addRule(sNewSelector, oCssRule.style.cssText);
  66. }
  67. }
  68. // Now add handling for these hover events.
  69. var oListItems = document.getElementsByTagName('LI');
  70. for (oListItem in oListItems)
  71. {
  72. oListItems[oListItem].onmouseover = function() {
  73. this.className += ' iehover';
  74. };
  75. oListItems[oListItem].onmouseout = function() {
  76. this.className = this.className.replace(new RegExp(' iehover\\b'), '');
  77. };
  78. }
  79. }
  80. // Add hover events to list items if the browser requires it.
  81. if (is_ie6down && 'attachEvent' in window)
  82. window.attachEvent('onload', smf_addListItemHoverEvents);