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