Pages

Friday, November 18, 2011

1

Combined CSS and image comment bubbles

This article concludes my three part comment bubble article series. If you want comment bubbles in your Blogspot blog, you can pick one these three hacks.

1. Comment bubbles using only CSS
2. Comment bubbles using an image
3. Combined solution, which uses CSS whenever possible (installed in this blog)

As I explained in the CSS only comment bubble hack article, Internet Explorer does not support all CSS needed for rounded comment bubbles with gradient background. And the support varies from version to version.

Internet Explorer 8 and lower

I start with the "CSS only" hack installed, and then add there stuff for different Internet Explorer versions.

IE8 and lower don't have rounded corners and IE7 does not support :after, so I decided simply to use a comment bubble image, when IE version is lower than 9. First I thought that I'll use conditional comments like this:

<!--[if lt IE 9]>
..stuff for ie versions below 9..
<![endif]-->

But after trial and error I found out that it was not so easy. I learned that the browser version number does not actually determine the CSS capabilities, but the document mode (compatibility mode) instead. Well at least in Blogspot blogs, and that's where I'm targeting with my code.

I finally came up with this solution for IE (documentMode) < 9:

<!--[if IE]><script type='text/javascript'>
if(typeof document.documentMode == 'undefined' || document.documentMode < 9)
document.write('<style type="text/css"> a.comment-bubble { background:url(http://lh6.googleusercontent.com/-IVVxPuuguig/Tr_NWRIN3HI/AAAAAAAAAWs/weLvk3eWQtM/s800/comment_bubble.jpg) no-repeat;width:36px;height:26px;border:0;padding-top:3px;} a.comment-bubble:after { border:0; };</style>');
</script><![endif]-->

That code is placed somewhere after template stylesheet and before </body>. The javascript is seen and runs only on IE. If documentMode < 9 (IE8, IE7, ...), new style definitions are written: bubble background uses an image, set width and height, no border and right padding, and for a:after remove the border that made the triangle. Basically make comment-bubble use same styles as in the image comment bubble hack.

Internet Explorer 9

As we saw in the CSS only comment bubble hack, IE9 does quite well with the comment bubble CSS: only the gradient background is missing. There is a filter provided by Microsoft to make gradients, but that messes the rounded corners. There are workarounds for that, too, but I chose another way: I made a gradient background image and encoded it in base64 to make a data URI, so it could be directly embedded in CSS without external file. Background image is correctly clipped by the rounded corners.

So the comment bubble CSS became:

Data provided by Pastebin.com - Download Raw

Line 15 is new (compared to CSS only solution) and contains the gradient for IE9. Because it is before the background gradient definitions, they override it on browsers that support gradients. And on IE8 and below the background is later reset to use an image (see previous chapter).

The discovery of data URIs base64 gradient PNG lead me do a simple linear gradient tool for making embeddable gradient backgrounds.

Complex solution?

So, is there any point in this complex solution, one might ask. Well, to be honest, I don't know :) You might prefer to use either CSS only or image only solution, for simplicity. I could also have used either, but this way I learned more. In a year or two Internet Explorer will do CSS comment bubbles, too, and then these browser version dependend hacks won't be needed anymore.

Thursday, November 17, 2011

10

Comment bubbles for Blogger using an image

Similar hacks have been available before, this one adds nothing new or special to them, except the CSS code may be a bit tidier. Some might want to use this in their Blogspot blog for its simplicity: the same version gives same results in all browsers, and the CSS code is not long.

In this blog I use a combined method that uses CSS3 whenever supported, so this image comment bubble hack is not installed in this blog, instead a combination of this hack and the CSS3 comment bubble hack, more about that in this post.

Add comment count code

First we will add the link to "post.url#comments" next to the post title. Open your template html, and expand widget templates. Find lines:
<b:includable id='post' var='post'>
  <div class='post hentry'>
    <a expr:name='data:post.id'/>
    <b:if cond='data:post.title'>
      <h3 class='post-title entry-title'>
After those lines add (doubleclick to select for copying):
<b:if cond='data:post.allowComments'><a class='comment-bubble' expr:href='data:post.url + &quot;#comments&quot;' expr:title='&quot;Comments to &amp;quot;&quot; + data:post.title + &quot;&amp;quot;&quot;'><data:post.numComments/></a></b:if>
Save the template.

Add CSS for comment bubbles

If you want to have own bubble image, first you need to upload the comment bubble image to some server, to your Picasa web album, for example, and get its url address. I use this image uploaded to my Picasa web album, its url is http://lh6.googleusercontent.com/-IVVxPuuguig/Tr_NWRIN3HI/AAAAAAAAAWs/weLvk3eWQtM/s800/comment_bubble.jpg.

Then go to Template designer, choose Advanced, Add CSS. Add the following simple CSS definition:

Data provided by Pastebin.com - Download Raw

Change image url, if you want, and image width and height. Paddings can be changed to change text position inside the comment bubble image. Apply to blog – comment bubbles are installed.

0

Pure CSS3 comment bubbles for Blogger

A week ago or so I implemented the comment bubbles for this blog. There are some comment bubble hacks for Blogger that use image, but I found none with CSS3 bubbles, so that is what I started from. I show in this article, how you can make CSS3 comment bubbles like this for Blogger.

"Pure" in this context means that I don't use images. I really don't know much CSS so I don't know if the product-dependent -webkit-, -moz- and -o- style settings are "pure CSS3" or not.

Browsers like Firefox, Opera and Chome already support CSS3, and soon also Internet Explorer will, so you might already want to have this clean CSS only solution in your blog. It also loads a bit quicker without external images that cause http request. This CSS solution degrades to quite nice looking and usable element on Internet Explorers (version 9 and below), too, see the end of this article.

Because CSS3 is not fully supported by Internet Explorer versions below 10, in this blog I expanded this CSS only solution to use image in IE8 and below, and CSS + gradient data URI in IE9. So this CSS only hack is not installed in this blog. I'll tell you about "pure image comment bubbles" and the combined solution in later articles.

Add comment count code

First we add the link to "post.url#comments" next to the post title, where link's text is the number of comments in that post. Open your template html, and expand widget templates. Find lines:
<b:includable id='post' var='post'>
  <div class='post hentry'>
    <a expr:name='data:post.id'/>
    <b:if cond='data:post.title'>
      <h3 class='post-title entry-title'>
After those lines add (doubleclick to select for copying):
<b:if cond='data:post.allowComments'><a class='comment-bubble' expr:href='data:post.url + &quot;#comments&quot;' expr:title='&quot;Comments to &amp;quot;&quot; + data:post.title + &quot;&amp;quot;&quot;'><data:post.numComments/></a></b:if>
Save the template.

Add CSS for comment bubbles

I chose the colors for my bubbles like this, you might want to use some other colors that suit your template:


Go to Template designer, choose Advanced, Add CSS. Add the following CSS:

Data provided by Pastebin.com - Download Raw

Apply to blog. And you have your CSS comment bubbles!

This hack and Internet Explorer

In IE7 and below the bubble is only a rectangle with borders and solid background color.
In IE8 the comment bubble has solid background color and no rounded borders.
IE9 does quite well, only the gradient background is missing (background is solid color).

Wednesday, November 16, 2011

0

Gradient PNG data URI maker reference

As I mentioned when I posted the new version of my AppEngine application, I also added a new feature to the application. When I was implementing the comment bubbles, I learned about data URIs (or data: URIs). Data URI is a Uniform Resource Identifier. URLs are URIs, too, only data URIs do not contain address to the data, but instead the data itself. For example, small images! Data URIs are supported by all major browsers and by Internet Explorer version 8 and higher.

Read more, blog article: Data URIs explained.
Convert any data to data URI: The data: URI kitchen.

I implemented the button gradient for IE9 using gradient PNG data URI. I made the PNG with GIMP, saved without any extra data, run "base64 gradient.png", added "data:image/png;base64," in front of the output and there was my data URI for CSS. Still, quite a lot of work, for example if you change colors, you have to do this all over again. I tried to find a tool to automate this, but did not find, so I implemented it in my Google AppEngine application.

The gradient tool uses url parameters, although I have also made a front end tool for it. Url parameters work like this:

http://avafavico.appspot.com/?c1=C1C1C1&c2=C2C2C2&h=H&w=W

C1C1C1 is top color (or left color in horizontal gradient), 000000-FFFFFF
C2C2C2 is bottom color (or right color in horizontal gradient), 000000-FFFFFF
H is gradient image height, integer 1-4096
W is gradient image width, integer 1-4096

Example: http://avafavico.appspot.com/?c1=ff0000&c2=0000ff&h=10&w=30
Gradient:
Data URI: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAKCAYAAACjd+4vAAAABHNCSVQICAgIfAhkiAAAACVJREFUOI1j/M/A8P8HAyfDdwYOBnrSTAwDBEYtHrV41OKhbzEAzUMfE4HBrHkAAAAASUVORK5CYII=

Usually either H or W is 1 to optimize png size, and image is repeated to make it fill the whole background of an element, in the example h=10 so the image can be seen better, but in production version you would use h=1. H x W cannot be more than 4096, but this should be sufficient.

You don't and cannot embed the call to gradient tool into your template or page. Instead, you use the tool, get the data URI and put that in your template/page.

Tuesday, November 15, 2011

0

My Google App Engine Python application evolved

Couple of weeks ago I made my first Google App Engine application, using a new language for me, Python. It is made to fetch Blogger user avatars using Blogger userID. It worked/works ok, but I did some improvements to code, some structuring and formatting, generalized tag searching from html, etc.

Yesterday, as a deviation of making the comment bubbles, I added a completely new function to that application: a tool to make gradient PNG data URIs, which can be used in CSS, for example. The avatar part of the application functions just like before. I will tell you more about the gradient PNG data URI tool later in another article, and the comment bubbles, too, but here's the revised code (in my versioning it is version number 4):

Data provided by Pastebin.com - Download Raw

Again, if you have any ideas for the code, please comment. There was a minor html bug (which did not affect functionality) in the previous version, also one "None" comparison made with "==", unnecessary parenthesis, etc, and nobody told me! :)

Updates:
2011 Dec 14th, v4.01: Load also the new default icon from "www.blogger.com"
2011 Dec 18th, v4.02: Increased timeout from 5 to 15 in loading blogger profile pages, also handle download errors.
2012 March 14th, newest version 5 here.

Tuesday, November 8, 2011

11

Welcome to YABTB

Welcome to my Blogger tips and hacks blog. This is a real sticky post, without date hassling. Learn how you can make real sticky posts in your Blogspot blog. See also these hacks and tips of interest:

50

Real Sticky posts for Blogger

Sticky post(s) can be useful in a blog, as a featured post, as a notification of an upcoming event, some general info about blog, etc. Again, Wordpress, from where I migrated to Blogger, has this feature. And Blogger does not.

There has been two "hacks" around, until now, to make kind of sticky posts in Blogger, but both have big problems. But maybe one of them suits you, so I'll tell you about these shortly.

Date hack - not good

Publish your post. Edit the post after publishing, under Post Options set post date to somewhere in the future (for example year 2020). Now this post will be the first post in your blog, until 2020 or until you edit the date.

Problem: Messes blog's RSS feed. Your sticky post will be the latest post in the feed until 2020, and so people won't see updates from your blog in services that use RSS. This is bad.
Problem: Your post shows that it is published in the future. You can make code to hide the date but it gets complicated.

Gadget hack - not good

Go to Design, Page Layout, add HTML/Javascript gadget to page, and move it to just above the posts section. Don't give the gadget a title, write your sticky "post" in HTML to look as a post. One variation of this is to edit template html and put the "post" there.

Problem: It is not a post. You cannot comment it. You cannot see it in blog archives. And it does not appear in your Blog RSS feed, either. So for example, if you announce some upcoming event this way, your feed followers won't see it, unless they open your blog page.
Problem: your gadget/template html is shown on every page in your blog, unless you add some code to show it only on the first page, and this gets complicated.

Here is my gadget sticky post hack, with the latter problem solved. It may be a good solution for some blogs, so check it out, here's a demo.

Real sticky posts - excellent!

Sticky post should be a post, with normal publishing date, appearing in Blog feed. It should be easy to make a post sticky, and make a sticky post normal. Sticky posts should have a way to look different from normal posts.

My solution fulfills these requirements. Script pulls the sticky posts from the blog feed, so blog feed must be enabled in blog's settings. And also because blog feed is needed, my sticky posts hack don't unfortunately work in private blogs. You can control posts' sticky state simply by giving post a label, default is "sticky" but you can change that if you want. You can set how many sticky posts are shown at most, and if more "sticky" labels are found than this amount, then the newest posts are shown.

Installation

Edit template html. Put this code just before </body>.

Data provided by Pastebin.com - Download Raw

Normally posts posted in same day are grouped together in Blogger layout templates, into same div element. Because of this, if you post a sticky post and a normal post with same date, also the normal post is removed from the page when sticky post is removed and placed on top of the page. To prevent this, you may want to install a simple hack to show dates on all posts, which breaks down the "daily groups". But if you never post two posts in the same day, or edit the sticky posts' dates to be different from any other post, then it is not necessary.

Configuration

You may edit the CSS styles for stickies-container and sticky-post, and configure the following javascript variables:

stickyLabel: the label which turns a post into a sticky post
maxStickies: maximum number of posts displayed as sticky, 1-20 (don't overdo it)
showDate: show date or not, you may want to hide it
showTitle: show post title or not
showFooter: you may want to hide the whole footer
showPostedBy: show Posted By text in footer
showCommentLink: show link to comments in footer
showLabels: show post labels in footer
showStickyLabel: show also the sticky label in the labels list, or hide it
showEmailPost: show Email Post button
showShareButtons: show the sharebuttons group or not
showShareEmail: show email button in sharebuttons
showShareBlog: show blog button in sharebuttons
showShareTwitter: show twitter button in sharebuttons
showShareFacebook: show facebook button in sharebuttons
showSharePlusone: show plus one button in sharebuttons
widthPlusone: you may want to limit this, small enough and text disappears
txtComment: singular form, used in sentence "1 comment", just the text, without number
txtComments: plural form, used in sentence "# comments", just the text, without number
txtPostedBy: text in Posted by, can have variables [user] and [time]
txtLabels: text preceding the labels list
txtMore: "Read more »" text for posts with a jump break.
dynamicMore: if true, jump break text (after "more link") is revealed dynamically
txtHideMore: text of the link to hide "more text", if dynamicMore is used (true)

Using a jump break in a sticky post may be a good idea, so that the sticky post don't become too tall. With variable setting dynamicMore=true the rest of the sticky post is revealed dynamically, which looks great and is faster than a full page load.

You can move the CSS style declarations to body section of the template, if you want, and add more styles to style the sticky posts (know your way around).
See the hack
for this dynamic
views icon: