theme.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }