theme.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. $(document).ready(function() {
  2. // menu drop downs
  3. $('ul.dropmenu').superfish();
  4. // tooltips
  5. $('.preview').SMFtooltip();
  6. // find all nested linked images and turn off the border
  7. $('a.bbc_link img.bbc_img').parent().css('border', '0');
  8. });
  9. // The purpose of this code is to fix the height of overflow: auto blocks, because some browsers can't figure it out for themselves.
  10. function smf_codeBoxFix()
  11. {
  12. var codeFix = document.getElementsByTagName('code');
  13. for (var i = codeFix.length - 1; i >= 0; i--)
  14. {
  15. if (is_webkit && codeFix[i].offsetHeight < 20)
  16. codeFix[i].style.height = (codeFix[i].offsetHeight + 20) + 'px';
  17. else if (is_ff && (codeFix[i].scrollWidth > codeFix[i].clientWidth || codeFix[i].clientWidth == 0))
  18. codeFix[i].style.overflow = 'scroll';
  19. 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))
  20. codeFix[i].style.height = (codeFix[i].offsetHeight + 24) + 'px';
  21. }
  22. }
  23. // Add a fix for code stuff?
  24. if (is_ie || is_webkit || is_ff)
  25. addLoadEvent(smf_codeBoxFix);
  26. // Toggles the element height and width styles of an image.
  27. function smc_toggleImageDimensions()
  28. {
  29. var oImages = document.getElementsByTagName('IMG');
  30. for (oImage in oImages)
  31. {
  32. // Not a resized image? Skip it.
  33. if (oImages[oImage].className == undefined || oImages[oImage].className.indexOf('bbc_img resized') == -1)
  34. continue;
  35. oImages[oImage].style.cursor = 'pointer';
  36. oImages[oImage].onclick = function() {
  37. this.style.width = this.style.height = this.style.width == 'auto' ? null : 'auto';
  38. };
  39. }
  40. }
  41. // Add a load event for the function above.
  42. addLoadEvent(smc_toggleImageDimensions);
  43. // Adds a button to a certain button strip.
  44. function smf_addButton(sButtonStripId, bUseImage, oOptions)
  45. {
  46. var oButtonStrip = document.getElementById(sButtonStripId);
  47. var aItems = oButtonStrip.getElementsByTagName('span');
  48. // Remove the 'last' class from the last item.
  49. if (aItems.length > 0)
  50. {
  51. var oLastSpan = aItems[aItems.length - 1];
  52. oLastSpan.className = oLastSpan.className.replace(/\s*last/, 'position_holder');
  53. }
  54. // Add the button.
  55. var oButtonStripList = oButtonStrip.getElementsByTagName('ul')[0];
  56. var oNewButton = document.createElement('li');
  57. setInnerHTML(oNewButton, '<a href="' + oOptions.sUrl + '" ' + ('sCustom' in oOptions ? oOptions.sCustom : '') + '><span class="last"' + ('sId' in oOptions ? ' id="' + oOptions.sId + '"': '') + '>' + oOptions.sText + '</span></a>');
  58. oButtonStripList.appendChild(oNewButton);
  59. }