Saturday, July 27, 2013

Notes on the Bluebird Template, Part 5

It's way past time that we got to the post part of the Bluebird template, and we'll do that today. The template's <BlogDateHeader> ... </BlogDateHeader> node, which we discussed two entries ago, is followed by a Post div

.Post { margin-bottom: 20px; font-size: 15px; padding-right: 15px; line-height: 22px; font-family: arial, helvetica; color: black; }
...
<div class="Post"> ... </div>


that contains the post title, the post itself, and a byline for the post.

The post title

Blogger assigns a multidigit ID to each of my posts; this ID serves as a fragment identifier for an anchor that precedes the post title.

<div class="Post">
<a name="<$BlogItemNumber$>"> </a><br />
...the post title...


FWIW, 7217738745400984168 is a typical <$BlogItemNumber$>. If there's a link somewhere to this anchor, I can't find it. Keep the anchor if you want, but I'd throw it out.

The anchor is followed by a somewhat-confusing block of code:

<BlogItemTitle>
<span class="PostTitle">
<BlogItemURL><a href="<$BlogItemURL$>"></BlogItemURL>
<$BlogItemTitle$>
<BlogItemURL></a></BlogItemURL>
</span><br />
</BlogItemTitle>


As you would guess, the post title is the replacement text for the <$BlogItemTitle$> reference. But what about the rest of it? The <BlogItemURL> ... </BlogItemURL> nodes and the link markup they contain are/were related to a "Link field" feature that Blogger has evidently abandoned. Moreover, the <BlogItemTitle> ... </BlogItemTitle> node seems to have a purely descriptive purpose, i.e., it doesn't do anything to the post title as far as I can tell.

The title is styled as follows:

.PostTitle { font-size: 16px; font-weight: bold; font-family: arial, helvetica; }

The post

...
</BlogItemTitle>
<$BlogItemBody$><br />


The post is the replacement text for a <$BlogItemBody$> reference that immediately follows the BlogItemTitle node. The post text is styled by the font-size, line-height, font-family, and color property declarations in the .Post { ... } style rule given earlier.

The post and its title are taken from their respective input fields at the "Create post" or "Edit post" page.

The post byline

Here is a typical reptile7's JavaScript blog post byline:

The post byline

The byline is held by a PostFooter span:

.PostFooter { margin-bottom: 10px; margin-left: 0px; color: gray; font-size: 10px; }
...
<span class="PostFooter"> ... </span>


The byline begins with a
- posted by <$BlogItemAuthorNickname$>
string; the <$BlogItemAuthorNickname$> reference returns the author's Display Name as set in the Identity section of the Edit User Profile page.

Next we have the post's 'permalink':

@ <a href="<$BlogItemPermalinkURL$>" title="permanent link"><$BlogItemDateTime$></a>

<$BlogItemPermalinkURL$> returns the URL of the post's individual post page; as for the link text, <$BlogItemDateTime$> returns a value based on the selected option of the Timestamp Format selection list in the Formatting subsection of the Dashboard Settings zone.

(A timestamp is not meant to be a dynamic feature and should not be created via a client-side script. If you want to append a timestamp to a block of content, then you should look at your watch, say "It's 2:53 in the afternoon," and type 2:53 PM into a suitable element - at least that's what I would do.)

If we're at the main page or one of the archive pages and if comments on the post are allowed, then the post's permalink is followed by another link that points to a separate "Post a Comment" page and whose text indicates the number of published comments the post has.

<MainOrArchivePage><BlogItemCommentsEnabled>
<a href="<$BlogItemCommentCreate$>"<$BlogItemCommentFormOnclick$>><$BlogItemCommentCount$> comments</a>
</BlogItemCommentsEnabled></MainOrArchivePage>


<MainOrArchivePage> </MainOrArchivePage> are "conditional tags" à la the <ItemPage> </ItemPage> construct we encountered in Part 2 of this series.

• The <BlogItemCommentsEnabled> ... </BlogItemCommentsEnabled> node is turned on or off if comments on the post are enabled or not, respectively:

Post settings

<$BlogItemCommentCreate$> returns the URL of the "Post a Comment" page. Bizarrely, <$BlogItemCommentFormOnclick$> returns a JavaScript statement that sets location.href to the <$BlogItemCommentCreate$> URL:

location.href = post-a-comment-pageURL;

According to Blogger's "Comments Tags" page, <$BlogItemCommentFormOnclick$> includes the code that opens the link in a popup window, if you have that option selected - an option that Blogger seems to have abandoned. In practice, the browser ignores the location.href assignment (no errors are thrown): in the Notes on invalid documents section of the HTML 4.01 Specification, the W3C stipulates, If a user agent encounters an attribute it does not recognize, it should ignore the entire attribute specification (i.e., the attribute and its value). You can alternatively give the link a target="_blank" attribute in order to open it in a new window.

• As for the <$BlogItemCommentCount$> in the link text, I trust you can figure that one out.

The PostFooter span concludes with a <$BlogItemControl$> reference, which is replaced by
(1) a Email Post image-link to an "Email Post to a Friend" page and
(2) a Edit Post image-link to the "Edit post" page via which the post can be edited.

I am not inclined to discuss the Comments part of the Bluebird template; as noted in Part 1 of this series, my concern here is in applying the Bluebird template to the creation of normal Web pages vis-à-vis reproducing the template's blog-centric features. But then I thought, "Is it really that difficult to add a simple comments facility to an ordinary Web page?" As a matter of fact, it isn't - I'll show you what I came up with in the following entry.

Monday, July 15, 2013

Notes on the Bluebird Template, Part 4

A sidebar adorns the right side of the Bluebird template.

The Bluebird template sidebar

The sidebar is framed by a <div id="menu"> ... </div> div. The menu div is the second-in-source-order div in the template and the first child of the main div; both on the page and in the source, the menu div appears where it does because it is floated right. Here's the menu div's CSS:

#menu { border-left: 1px solid #000; border-bottom: 1px solid #000;
float: right; padding: 10px; width: 160px;
margin: 0px 0px 10px 10px; background-color: #eee; }


The menu div has an #eeeeee background color, which I do not particularly care for but has never bothered me to the point that I felt a burning need to change it.

The sidebar content can be divided into three sections: a description section, a profile section, and an archives section.

Description

The Basic subsection of the Dashboard Settings zone features a Description field for describing the blog.

The Basic subsection of the Settings zone

As shown by the preceding screen shot, the Description field's value can contain textual markup (for two paragraphs and a link in my case).

The menu div's first child is a Description div that holds the Description field value, which is the replacement text for a <$BlogDescription$> reference.

#Description { padding: 0px; padding-top: 10px; font-size: 12px; font-weight: normal; }
...
<div id="menu">
<div id="Description"><$BlogDescription$></div> ...


All of the padding properties have an initial value of 0 and therefore the padding:0px; style declaration can be removed. The font-weight property's initial value is normal and therefore the font-weight:normal; declaration can also be thrown out.

Profile

(N.B. Some versions of the Bluebird template do not have a SideBar div and wrap the archives section in an Archives div. What I describe in this and the next sections was true of the Bluebird template in March 2005, when I began blogging.)

#SideBar { font-size: 12px; margin-top: 15px; }
...
<div id="SideBar">
<!-- The profile section: -->
<$BlogMemberProfile$>
<!-- The archives section: -->
...
</div>


The menu div's second child is a SideBar div that holds both the profile and archives sections of the sidebar. I access my Blogger profile via a widget in the upper-right-hand corner of the Dashboard; if at my Edit User Profile page I
(a) upload a myPhoto.jpg Profile Photo,
(b) enter a Display Name in the Identity section (as is required),
(c) complete the Location section, and
(d) provide an Introduction in the Extended Info section, then
the <$BlogMemberProfile$> reference in the SideBar div is replaced by the following code:

<div id="profile-container">
<h2 class="sidebar-title">About Me</h2>
<dl class="profile-datablock">
<dt class="profile-img">
<a href="http://www.blogger.com/profile/10603056373768030580">
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJm5Hz5bzABaho0GwcfwRK0uTTAKpSlE4uUZt0cKBFevzwfqT-Rr2l6OGLZOM21qhiFhnUsqeWw0N_7w57C0LWrgHeeSJ8ZcuCIH7fPrEaXAJ0VQc_iNow5HhQDMr6WjuTJ379qWZSYF-W/s1600/myPhoto.jpg" width="80" height="58" alt="My Photo">
</a>
</dt>
<dd class="profile-data">
<strong>Name:</strong>
<a rel="author" href="http://www.blogger.com/profile/10603056373768030580"> A. Peak </a>
</dd>
<dd class="profile-data">
<strong>Location:</strong>
New Orleans, LA, United States </dd>
</dl>
<p class="profile-textblock">Introduction text...</p>
<p class="profile-link"><a rel="author" href="http://www.blogger.com/profile/10603056373768030580">View my complete profile</a></p></div>


In-source-order commentary

• The sidebar-title h2 inherits a font-size of 12px from the SideBar div -
h2.sidebar-title { font-size: inherit; }
- pretty small for an h2, whose default font-size is 24px.

• The HTML dl, dt, and dd elements are detailed here.

• The profile-img dt is given an inline rendering (the dl, dt, and dd elements normally have a block-level rendering), but its only content is an image-link whose image component - the myPhoto.jpg photo - is floated left:
.profile-img { display: inline; }
.profile-img img { float: left; margin: 0 10px 5px 0; }

The former rule serves no purpose, whereas the latter declaration set should be applied to the profile-img dt:
.profile-img { float: left; margin: 0 10px 5px 0; }

• The Name: and Location: labels are given a block-level rendering by:
.profile-data strong { display: block; }

• The margin-left of the profile-textblock and profile-link p(aragraph)s is set to 0 (with respect to the SideBar div, their containing block):
.profile-textblock, .profile-link { margin-left: 0px; }
These settings are not overridden by the subsequent
p { margin: 0px 10px 10px 10px; }
rule in the style block.

The profile code contains not one, not two, but three links to my 10603056373768030580 User Profile page - a bit overkill, wouldn't you say? The link is fair enough but I would lose the first two of these links.

Archives

<!-- The archives section: -->
<strong>Archives</strong><br />
<BloggerArchives>
<a href="<$BlogArchiveURL$>"><$BlogArchiveName$></a><br />
</BloggerArchives>
<script type="text/javascript" language="Javascript">
if (location.href.indexOf("archive") != -1)
    document.write("<strong><a href=\"<$BlogURL$>\">Current Posts</a></strong>");
</script>


The <BloggerArchives> ... </BloggerArchives> node is a container for links to the blog's archive pages. The <$BlogArchiveURL$> reference is replaced by a URL for an archive page. The replacement text for the <$BlogArchiveName$> reference is based on the selected option of the Archive Index Date Format selection list in the Formatting subsection of the Dashboard Settings zone.

<a href="http://reptile7.blogspot.com/2005_03_01_archive.html">March 2005</a><br>
<a href="http://reptile7.blogspot.com/2005_04_01_archive.html">April 2005</a><br>
<a href="http://reptile7.blogspot.com/2005_05_01_archive.html">May 2005</a><br>
<a href="http://reptile7.blogspot.com/2005_06_01_archive.html">June 2005</a><br> <!-- Etc. -->


If we're at an archive page, then a script appends to the link list a Current Posts link that points to the main page (we previously encountered the <$BlogURL$> reference in our discussion of the Title div).

Script notes
(1) The language attribute of the script element is deprecated, but you knew that, right?
(2) If you're going to validate the page, then be sure to escape the </ character sequences in the a(nchor) and strong element end-tags, i.e., document.write("...Current Posts<\/a><\/strong>");.

One last point:
When my Archives link list began getting unwieldy, I capped the height of the SideBar div at 300px and set the div's overflow to auto so as to clip but provide scrollbar access to the beyond-the-div part of the list - this is not part of the template but I thought I'd give it a quick mention.

We'll discuss the template's Post div in our next installment.

Thursday, July 4, 2013

Notes on the Bluebird Template, Part 3

Having covered the Bluebird template's Title div in the previous post, we move on today to the template's date header.

The date header sits between the blog title and the post title

Proceeding in source order:
• The Title div element's next sibling* is a <Blogger> ... </Blogger> node (for lack of a better word).
• The Blogger node's first child* is a <BlogDateHeader> ... </BlogDateHeader> node.
• The BlogDateHeader node contains a class="DateHeader" div element that holds the date header, which is the replacement text for a <$BlogDateHeaderDate$> reference.
(*I am ignoring inter-tag white space for my use of these terms.)

<div id="Title"> ... </div>
<Blogger>
<BlogDateHeader>
<div class="DateHeader"><$BlogDateHeaderDate$></div>
</BlogDateHeader> ... </Blogger>


The DateHeader div is styled as follows:

.DateHeader { border-bottom: solid 1px #c3cfe5;
font-size: 18px; text-align: left; margin-top: 30px; width: 300px;
margin-bottom: 0px; color: gray; font-weight: bold; }


If more than one post is published on a given date, the date header
(a) is displayed at each individual post page but
(b) only appears once for those posts at the main page or at an archive page.

How to configure the date header

At the www.blogger.com/home Dashboard, go to the Settings zone

Blogger Dashboard zones

and then to the zone's Language and formatting section.

The Setting zone's Language and formatting section

The Formatting subsection features a Date Header Format selection list of 16 date header options from which to choose.

Coding the default date header

As shown by the preceding screen shot, the default Blogger date header has a Day, Month Date (preceded by a 0 if in the 1-9 range), Year format:



Creating this format with JavaScript is not at all difficult:

<div id="dateDiv" class="DateHeader"></div>
<script type="text/javascript">
var now = new Date( );
var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var date = ((now.getDate( ) < 10) ? "0" : "") + now.getDate( );
var today = days[now.getDay( )] + ", " + months[now.getMonth( )] + " " + date + ", " + now.getFullYear( );
document.getElementById("dateDiv").textContent = today;
</script>


Quick script deconstruction

(1) We begin by creating a now Date object.
(2) We set up a days array of day names that maps onto the 0-6 returns of the Date object's getDay( ) method.
(3) We set up a months array of month names that maps onto the 0-11 returns of the Date object's getMonth( ) method.
(4) We get the date of the month; if the date is in the 1-9 range, we prepend a 0 to it.
(5) We piece together the various parts of the date header and assign the resulting string to a today variable.
(6) We load today into the DateHeader div.

Mozilla's current Date object page is here; go here for links to pages for the getDay( ), getMonth( ), getDate( ), and getFullYear( ) methods of the Date object; go here if you are unfamiliar with the ?: conditional operator.

It is left to the reader to adapt the above code to other Blogger date header formats.

Link styling, take two

In the previous post I neglected to mention that the Bluebird template's style block also contains a
a { text-decoration: none; }
rule that will de-underline all links on the page even if we throw out the style block's
#Title a { text-decoration: inherit; color: inherit; }
rule. To ensure that all of our links are blue and underlined, we should throw out the latter rule and change the former rule to
a { color: blue; text-decoration: underline; }.

We'll discuss the template's sidebar in our next installment.