Fancy Archive Page

Ages ago, I wrote about how to (a) pass Pages through the Post template, and (b) use Smarty Tags in special Pages. I had an Archives page, that had a list of every Post I’d ever made. It’s getting kind of long, so I wrote a script that parses this list, and creates a structured list, dividing the posts up according to the month they were published. It then makes this list so that you can hide/show a whole month’s worth of posts in one go. In the Posts Template, I have the following lines:

    {elseif $smarty.server.REQUEST_URI == '/archives/' || $smarty.server.REQUEST_URI == '/archives'}
        <ul>{get_archives type='postbypost' limit='' format='html'}</ul>{$content}

Note that this is out of context: see my whole Posts template file for details. This is in the actual Page:

    <script type="text/javascript">
    var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December")
    function getYear(li){
        return li.innerHTML.split("/")[3]*1;
    }
    function getMonth(li){
        return li.innerHTML.split("/")[4]*1;
    }
    
    function showKids(id){
        var unit = getById(id);
        for (var i=1;i<unit.childNodes.length;i++){
            unit.childNodes[i].style.display="block";
        }
    }
    function hideKids(id){
        var unit = getById(id);
        for (var i=1;i<unit.childNodes.length;i++){
            unit.childNodes[i].style.display="none";
        }
    }
    function toggleKids(id){
        var unit = getById(id);
        if (unit.childNodes[1].style.display == "none")
            showKids(id)
        else
            hideKids(id)
    }
       
    function Restructure(){
        var pc = getByClass("post-content")[0];
        var items = pc.getElementsByTagName("li");
        var list = items[0].parentNode;
        var month_nodes = document.createElement("ul");
        
        var month_node = document.createElement("li");
        month_node.className = "month";
        month_node.innerHTML = months[getMonth(items[0])] + " " + getYear(items[0]);
        month_node.id = month_node.innerHTML.replace(" ","_");
        month_node.innerHTML = "<h3><a onclick='toggleKids(\""+ month_node.id +"\");'>" + month_node.innerHTML + "</a></h3>";
        month_nodes.appendChild(month_node);
        
        var this_month;
        var next_month;
        
        while (items.length) {
            this_month = items[0];
            next_month = items[1];
            month_node.appendChild(this_month);
            if (next_month && (getMonth(this_month) != getMonth(next_month))){
                month_node = document.createElement("li");
                month_node.className = "month";
                month_node.innerHTML = months[getMonth(next_month)] + " " + getYear(next_month);
                month_node.id = month_node.innerHTML.replace(" ","_");
                month_node.innerHTML = "<h3><a onclick='toggleKids(\""+ month_node.id +"\");'>" + month_node.innerHTML + "</a></h3>";
                month_nodes.appendChild(month_node);
            }
        }
        
        pc.replaceChild(month_nodes,list);
        
        var all = getByClass("month")
        for (var i=0;i<all.length;i++) hideKids(all[i].id);
    }
    
    Restructure();
    </script>

You’ll notice a couple of strange comments, and what looks to be a closing all tag: these are because the Blogsome post editor kindly closes tags for me, even when they aren’t tags!

Movin' Out (Anthony’s Song)Billy JoelGreatest Hits ★★

I’m off to Karaoke now, I might have to sing that song!

Better Display of HTML as Source

I spent hours last night working on this, and a fair bit of time today. I think I’ve got it pretty good, now. See my Templates page for an example. Now, instead of trying to get the data to appear immediately, which I could not do, I have four buttons that the user can select between the various template files, and it shows them in the <textarea> underneath.

 1     <script type="text/javascript">
 2         var req1 = new XMLHttpRequest(); 
 3         req1.open("GET", "/templates/index.html",true); 
 4         req1.send(""); 
 5         var req2 = new XMLHttpRequest(); 
 6         req2.open("GET", "/templates/post.html",true); 
 7         req2.send(""); 
 8         var req3 = new XMLHttpRequest(); 
 9         req3.open("GET", "/templates/comments.html",true); 
10         req3.send(""); 
11         var req4 = new XMLHttpRequest(); 
12         req4.open("GET", "/templates/wp-layout.css",true); 
13         req4.send(""); 
14     
15     function Display(text){
16         document.getElementById('template').innerHTML = text;
17     }
18     </script>
19     
20     <p>This is the current, up to date version of my conversion of Patricia Müller's Connections Template for Blogsome.</p>
21     
22     <p>There are four files that Blogsome uses, you need to ensure that the correct data goes into each.  Each one also has, by default some features enabled.  There is commenting throughout that will enable you to disable that which you do not want.</p>
23     
24     <p><a class="button" onclick="Display(req1.responseText);">Main Page</a> 
25     <a class="button" onclick="Display(req2.responseText);">Post</a> 
26     <a class="button" onclick="Display(req3.responseText);">Comments</a> 
27     <a class="button" onclick="Display(req4.responseText);">Style Sheet</a></p>
28     
29     <p><textarea id="template" wrap="off"  style='width:95%;height:500px;'>Click on a button above to display the template contents.</textarea></p>

I probably could have saved the data to variables, and reused the XMLHttpRequest item, but then I would have had to find some way to wait for the response code, and that kept failing for me.

Kissing YouDes'ree ★★★½

Missing Sync Lists

I bought Missing Sync for PalmOS – probably a bad decision as it’s not really that much better than the standard Palm Syncing software. Oh, it claims to be heaps better, but there are just too many things that don’t quite work right. For instance, it makes duplicate entries on my Palm of Read-Only calendars. I use but one of these, that has all of the Australian Public Holidays in it. However, I’ve stopped syncing, as by the end of a month I have 30 copies of each holiday in the database. Not cool. So, surely there’s a way (a-la iTunes/iPod syncing) to only choose some of the items. As it turns out, there is. If you select the Conduit (Events) and then Choose Settings…, you can choose to only sync selected calendars. Except you can’t get at anything other than the first 4 calendars. The scroll bar in this window is broken. Makes it pretty hard to deselect the ones you don’t want. I got around this by renaming my Holidays calendar to Aus Holidays, but I shouldn’t have to do this.

Displaying HTML as Source in a Web Page

Now, I’m not talking here about using the “Show Source” feature of a Web Browser. Anyone worth even a quarter of a pinch of salt knows how to do that. What I’m trying to do is display the source of a web page as text/plain within another web page. This is so I can have a current version of my template available on a page of my blog. I’ve put a version up that I need to update, and I make so many changes to the template this is unsustainable.

Under Blogsome, the template files can be found in the /templates/ directory, and there are four of them: index.html, wp-layout.css, post.html and comments.html. Of these, only wp-layout.css is a plain text document, the rest are (naturally) text/html.

Now, HTML has a nice little feature called <object>, which should be able to display anything the browser can render. For example:

<object data=“/templates/index.html”> </object>

Will display a rendering of the Main Page template. It looks somewhat ugly, since it’s not been pre-processed by the Smarty Templating engine, so is somewhat useless – it’s neither the source nor the full result:

This element also has an attribute that should allow you to choose the content type: codetype.

<object data=“/templates/index.html” codetype=“text/plain”> </object>

This to me should be now rendering the object as a plain text document. But no, it still renders the HTML:

1 <object data="/templates/index.html"codetype="text/plain"></object>

I fiddled around with this for about an hour or so last night, trying to get it to work. The DOM tells me it’s text/plain, but the browser won’t render it as such.

So, after much more rooting around, I finally figured out a way to get the source to display: use XMLHttpRequest() to grab the data, and DOM manipulation to put it into the required location. This is what my page looks like:

 1     <h3 class="comments">Main Page (index.html)</h3>
 2     <textarea id="index.html" wrap="off"  style='width:95%;height:200px;'>
 3     </textarea>
 4 
 5     <h3 class="comments">Style Sheet (wp-layout.css)</h3>
 6     <textarea id="wp-layout.css" wrap="off" style='width:95%;height:200px;'>
 7     </textarea>
 8 
 9     <h3 class="comments">Post (post.html)</h3>
10     <textarea id="post.html" wrap="off" style='width:95%;height:200px;'>
11     </textarea>
12 
13     <h3 class="comments">Comments (comments.html)</h3>
14     <textarea id="comments.html" wrap="off" style='width:95%;height:200px;'>
15     </textarea>
16 
17     <script type="text/javascript">
18 
19     var div1 = document.getElementById("index.html");
20     var req1 = new XMLHttpRequest();
21     req1.open("GET", "/templates/index.html",true);
22     req1.send(""); 
23 
24     var div2 = document.getElementById("post.html");
25     var req2 = new XMLHttpRequest();
26     req2.open("GET", "/templates/post.html",true);
27     req2.send(""); 
28 
29     var div3 = document.getElementById("comments.html");
30     var req3 = new XMLHttpRequest();
31     req3.open("GET", "/templates/comments.html",true);
32     req3.send(""); 
33 
34     var div4 = document.getElementById("wp-layout.css");
35     var req4 = new XMLHttpRequest();
36     req4.open("GET", "/templates/wp-layout.css",true);
37     req4.send(""); 
38 
39     function Source(){
40         if (req1.status+req2.status+req3.status+req4.status == "800"){
41             div1.innerHTML = req1.responseText
42             div2.innerHTML = req2.responseText
43             div3.innerHTML = req3.responseText
44             div4.innerHTML = req4.responseText
45         } else
46             setTimeout("Source();",500);
47     }
48 
49     Source();
50     </script>

It’s not quite perfect: there are still some issues with the timings, but I’ll get there. At least it works, now. You may need to type javascript:Source() into the address bar to get it to work.

All I need to do now is some syntax styling!

Stupid Young Folk

Don’t even get me started on the inanity of young people these days. The latest, and stupidest thing I just heard during an ad break in Video Hits (I despise their latest look, btw):

Get your personal Chinese symbol sent directly to your phone! Just SMS “c” plus your year of birth, for example 1980, to 19 XX XX.

This is just wrong on so many levels. For christ’s sake, every person born in the same year as you, which is probably most of your stupid little friends from school, has the same symbol as you. That’s hardly a personal symbol. Secondly, is the company seriously suggesting that it’s customers are so stupid as to require an example of what a year looks like? But then, these people will quite happily pay $4 to send a text message, and receive in return a sampled down version of a song on their mobile phone, rather than pay $1 to download it legally, and then use some simple software to convert it to a format suitable for use on said phone. And then probably only use it as their ringtone for about a week, before repeating the process.