weboholic.de

random rant-o-rama

Archive for the ‘Development’ Category

nofollow Bookmarklet

with one comment

Here is a smallish bookmarklet that highlights all links that are marked with the nofollow attribute. Just drag and drop it to your bookmarks bar.

show nofollow

In its current version the bookmarklet is very very simple: it just highlights nofollow-links and reports back the total number. However it only works on frameless documents.

Here’s the code in a readable <code>-block:

  1. javascript:(function(){
  2.   for (var i = 0, a = document.getElementsByTagName('a'), b = a.length, c = b; i < b; i++) {
  3.     a[i].rel.match(/nofollow/i) ? a[i].style.backgroundColor = '#ff0066' : c–;
  4.   }
  5.   alert(c);
  6. })();

That’s the shortest I could get. Have fun :).

P.S. You can test-drive it right away on this page: the about-link in the footer is a nofollow-link.

P.P.S. It’s the browser that turns a double minus into a single long dash.

Written by Никола

June 14th, 2008 at 12:39 pm

Unobtrusive Smilies :)

without comments

I don’t know whether you may find use for this, it might be a complete overhaul, but anyway.

Smilies are small inline images that represent a mood like being sad :( or help enrich the context with some emotion like winking after a joke ;). Everybody uses them but no one actually puts down those img-tags: we rely on our smart CMS’s to the job. Smilies are accessible since screen readers use either the title or the alternative text attributes of the img-tag. The problem is that such inline images aren’t semantically correct: they should be part of the text as text and not as images.

I’ve put down a small (~2KB minified) mixture which filters all smilies and replaces them with images in an unobtrusive way.

Download uns v. 0.2

What is the basic?

Default behavior is to query the document for span-tags that have the class smiley. Each one option is customizable.

What’s the compatibility?

It’s known to work with Firefox 2, Firefox 3, IE5.5, IE6, IE7, Safari 3 and Opera 9 under Windows, Safari 3 under Mac OS X and Konqueror 3.5 under Kubuntu.

How to trigger it?

Use it just as any other unobtrusive JavaScript out there:

  1. window.onload = function() {
  2.   uns.parse();
  3. };

Or gain performance by providing a node where smilies are to be found, like the main content div-block:

  1. window.onload = function() {
  2.   uns.parse({node: document.getElementById('content')});
  3. };

You can also provide an onfinish callback:

  1. window.onload = function() {
  2.   uns.parse({
  3.     node: document.getElementById('content'),
  4.     onfinish: function() {
  5.       alert('finished');
  6.     }
  7.   });
  8. };

Or you can add additional smilies:

  1. window.onload = function() {
  2.   uns.smilies({
  3.     ':cska:': 'images/cska.gif'
  4.   });
  5.   uns.parse();
  6. };

You can also AJAX load new content into some poor div and run the parser afterwards:

  1. xhr.onreadystatechange = function() {
  2.   if (xhr.readyState == 4) {
  3.     var comments = document.getElementById('comments');
  4.     comments.innerHtml = xhr.responseText;
  5.     uns.parse({node: comments});
  6.   }
  7. };

Where can it be seen?

I’ve put down a small demo.

Log

20.02.2008: 0.1 Initial release.
22.02.2008: 0.2 Added support for native getElementsByClassName and tested with Firefox 3, added support for IE5.5 and IE6.

Written by Никола

February 20th, 2008 at 11:01 am

Posted in Development

Tagged with , ,

TOCoholic

without comments

I’ve had the other day some referrers from a site listing a bunch of WordPress plugins about TOCoholic. So I decided to dig it out. Here it is:

What’s new about the plugin? Nothing. I’ve just dropped it in the plugins directory and … it worked. This tells me two things:

  1. WordPress’ developers had made some nice efforts to make it backwards compatible and this is great, kudos
  2. I’ve been more than a decent developer 18 months ago :roll:

I have plans to make some changes to plugin’s features and to optimize it a bit, but for now it’s fine just as it is. So stay tuned.

Written by Никола

January 1st, 2008 at 10:19 am

Posted in Development

Tagged with , , ,

Clicky Web Analytics