annotate forum/Themes/default/scripts/theme.js @ 76:e3e11437ecea website

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