{"id":2903,"date":"2005-09-12T09:17:00","date_gmt":"2005-09-12T09:17:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/heaths\/2005\/09\/12\/blog-customizations\/"},"modified":"2005-09-12T09:17:00","modified_gmt":"2005-09-12T09:17:00","slug":"blog-customizations","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/setup\/blog-customizations\/","title":{"rendered":"Blog Customizations"},"content":{"rendered":"<p>In my seemingly never-ending quest to provide a simple, compact,&nbsp;yet stylish design for this blog I have recently made a customization based on what <a href=\"\/jledgard\/\">Josh Ledgard<\/a> did sometime back to make collapsible panels, though I wanted something more easily reusable. I whipped together an ECMAScript &mdash; that is, ECMA-compliant JScript and JavaScript &mdash; class as you can see below:<\/p>\n<pre><font color=\"blue\">function<\/font> CollapsiblePanel(elem) {\n  <font color=\"blue\">if<\/font> (!elem) {\n    <font color=\"blue\">return null<\/font>;\n  }\n  <font color=\"green\">\/\/ Close 'this'.<\/font>\n  <font color=\"blue\">var<\/font> self = <font color=\"blue\">this<\/font>;\n  <font color=\"blue\">this<\/font>.toggle = <font color=\"blue\">function<\/font>() {\n    <font color=\"blue\">if<\/font> (self.sibling.style.display == \"none\") {\n      self.elem.innerHTML = self.collapseHTML + self.title;\n      self.sibling.style.display = \"block\";\n    } <font color=\"blue\">else<\/font> {\n      self.elem.innerHTML = self.expandHTML + self.title;\n      self.sibling.style.display = \"none\";\n    }\n  }\n  <font color=\"blue\">this<\/font>.elem = elem;\n  <font color=\"blue\">this<\/font>.title = elem.innerHTML;\n  <font color=\"blue\">this<\/font>.expandHTML = '&lt;img src=\"expand.gif\" width=\"9\" height=\"9\"&gt;&amp;nbsp;';\n  <font color=\"blue\">this<\/font>.collapseHTML = '&lt;img src=\"collapse.gif\" width=\"9\" height=\"9\"&gt;&amp;nbsp;';\n  <font color=\"blue\">this<\/font>.elem.style.cursor = \"pointer\";\n  <font color=\"blue\">this<\/font>.sibling = elem.nextSibling;\n  <font color=\"blue\">if<\/font> (<font color=\"blue\">this<\/font>.sibling.nodeType == 3) {\n    <font color=\"green\">\/\/ Get second sibling if text node is next.<\/font>\n    <font color=\"blue\">this<\/font>.sibling = <font color=\"blue\">this<\/font>.sibling.nextSibling;\n  }\n  elem.onclick = <font color=\"blue\">this<\/font>.toggle;\n  <font color=\"blue\">this<\/font>.toggle();\n}<\/pre>\n<p>Since I&#8217;m defining an event handler to handle toggling the CSS <code>display<\/code> attribute, I need to create a closure around the class instance, which is why the private variable <code>self<\/code> is defined. Had I used <code>this<\/code> in the event handler, when the <code>onclick<\/code> event was fired <code>this<\/code> would refer to the item that was clicked &#8211; the H3 element.<\/p>\n<p>To create the <code>CollapsiblePanel<\/code> instances, I needed to handle the <code>window.onload<\/code> event. Since the only place <a href=\"http:\/\/www.gotdotnet.com\/Community\/Workspaces\/workspace.aspx?id=e99fccb3-1a8c-42b5-90ee-348f6b77c407\">.Text<\/a> or <a href=\"http:\/\/communityserver.org\/\">Community Server<\/a> lets us add our own script is in the News section, several headers are not parsed and displayed until after the script is processed synchronously:<\/p>\n<pre>window.onload = <font color=\"blue\">function<\/font>() {\n  <font color=\"green\">\/\/ Enumerate headers after document is loaded.<\/font>\n  <font color=\"blue\">var<\/font> i, h3s = document.body.getElementsByTagName(\"h3\");\n  <font color=\"blue\">for<\/font> (i = 0; i &lt; h3s.length; i++) {\n    <font color=\"blue\">var<\/font> elem = h3s.item(i);\n    <font color=\"blue\">if<\/font> (elem.innerHTML == \"Archives\" ||\n        elem.innerHTML == \"Common Tasks\" ||\n        elem.innerHTML == \"Navigation\") {\n      <font color=\"blue\">new<\/font> CollapsiblePanel(elem);\n    }\n  }\n}<\/pre>\n<p>Since Josh&#8217;s blog gave me the idea to collapse a few of the longer or less interesting panels, I shared the code with him that you can find on his blog now, too. Feel free to use it yourself. You can easily customize the view by changing the <code>expandHTML<\/code> and <code>collapseHTML<\/code> public fields, though you&#8217;re free to change anything. Please keep in mind that this is not Microsoft-supported code, but if you have questions feel free to ask on this particular blog.<\/p>\n<p>When a get I little time I will create a cookie collection class to hold state for each individual <code>CollapsiblePanel<\/code> so that your preference for what is and is not displayed is persisted across pages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my seemingly never-ending quest to provide a simple, compact,&nbsp;yet stylish design for this blog I have recently made a customization based on what Josh Ledgard did sometime back to make collapsible panels, though I wanted something more easily reusable. I whipped together an ECMAScript &mdash; that is, ECMA-compliant JScript and JavaScript &mdash; class as [&hellip;]<\/p>\n","protected":false},"author":389,"featured_media":3843,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[11,14,29,34],"class_list":["post-2903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-customizations","tag-development","tag-personal","tag-script"],"acf":[],"blog_post_summary":"<p>In my seemingly never-ending quest to provide a simple, compact,&nbsp;yet stylish design for this blog I have recently made a customization based on what Josh Ledgard did sometime back to make collapsible panels, though I wanted something more easily reusable. I whipped together an ECMAScript &mdash; that is, ECMA-compliant JScript and JavaScript &mdash; class as [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/users\/389"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/comments?post=2903"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2903\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media\/3843"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media?parent=2903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/categories?post=2903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/tags?post=2903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}