Tuesday, March 27, 2007

Going offline for a while

I'll be in Seoul ( South Korea, for the geographically challenged ) on holiday from 29.03.07 - 15.04.07.

Maybe I'll post a photo or two, if I randomly drop by an Internet Café.

Tuesday, March 20, 2007

(mis?)Using $$ReturnGeneralError as a shortcut for search

Lets the users search like this:
Everything in regard to Tokyo

Hotels in tokyo

Restaurants that serve sushi

In the HTTP Head Content of $$ReturnGeneralError, add a little JavaScript to extract what is typed after the path to the database (application if you're using N8 beta ;) ).

var db='"+@WebDbName+"';
var loc=document.location.href;
var viewToSearchIn = '($People)'; //if not specified
var newloc;

//if searchview->error, return general error

var query=loc.split(db)[1].replace('/','');
viewToSearchIn = query.split('/')[0];
var tmpquery = query.split('/')[1];

query=query.replace(/s/g,'+and+');//replace whitespace with +and+

//avoid the back-button pointing to the erroneous url

Above I'm using a view called ($People), to search in. You can pass the "query" to whatever you want.

Demo application
You have to create the full-text index on the db yourself to searh on the web.

This is the same as Jake's FakeNames.nsf, but I changed the $$ReturnGeneralError form.

Tested URLs:
Searches in the default view, ($People)

Searches in the peoplecat view

Searches in the holidays view

With the last view, you can also write: http://localhost/fakenames.nsf/holidays/austria
which opens the austria document (sorted view).

You can of course take this even further, with per-application mapping-documents for particular searches.

Saturday, March 17, 2007

Simple way to check if a Domino Server is online

This is a small one, but I thought it was a nice example how nice and powerful events in JavaScript are.

The images (<img> tag) on the web has an onerror-event that fires if the image in the src is either an invalid image, or the image is not found (404). Every Domino server has an icons-folder. The most used icon/image is ecblank.gif, which Notes uses in many nasty ways on the web.

To check if a notes-server is online, you simply make an image tag with src=http://serverdomain.com/icons/ecblank.gif
onerror, change some text, pop an alertbox up etc.

In my simple demo, I add a css class to a a div, and replace() innerHTML with a status.

Demo (view source to see how it is done)

If you want to automate the testing of online-status on your company's servers, you can use the Windows API's UrlDownloadToFile ( example ) to download ecblank.gif. OnError - log error, send mail etc.

Sunday, March 11, 2007

Bookmarklet to animate the clouds on Twitter.com

javascript:(function(){_c=0;d_=document; d_.styleSheets[0].insertRule("div, h1{opacity:0.7}",2);d_.body.style.backgroundRepeat="repeat-x"; setInterval(function(){ d_.body.style.backgroundPosition=(_c++)+"px top"; },40);})()

javascript:(function(){_c=0; d_=document;d_.styleSheets[0].addRule("div","filter:alpha(opacity=70)}",2); d_.body.style.backgroundRepeat="repeat-x";setInterval(function(){ d_.body.style.backgroundPosition=(_c++)+"px top";},40);})()

Test it out on http://www.twitter.com

It makes the content partly transparent, and the clouds flow towards the right.

The reason that I made this useless bookmarklet is that I liked the clouds when they were positionary, but I wanted to see how they looked moving about.

The animation is quite CPU-intensive.. Not sure how to optimize this..

Thursday, March 8, 2007

Breaking the count-limit in views on the web

Show n' Tell Thursday
I thought I'd sit this Thursday out, but too much free time I guess.

First, open the demo-db in notes.
Click Create test-documents (creates 5001 documents).
Open the view on the web.
A counter will tell how many "documents" currently fetched

The parsing of the HTML is quite CPU-intensive.
On my PC it takes IE7 about 15 seconds, and FF about 20 seconds to get all 5001 items.

There are more elegant ways of getting more documents than the server-limit. With this method, you can control the layout from the view, and you don't have to mess about with XML or JSON.

If someone can provide me with a more complex database with 1500+ (non-sensitive) documents, I can try to add browser-side click-to-sort columns.

Demo-db: NoCountLimit.zip




Wednesday, March 7, 2007

Greasemonkey script: Select text to make temporary link

Not the most impressive code (I still don't understand closures in JS fully), but it works with what I've tested it on..

Select a text-link, and a temporary pop-up with a real link is created from the selection. Se picture at the end.

Tested in Opera 9.x (download/put it in the user-script folder) and FireFox 2.0.

The script

Example URLs:

Opera - User JS
About greasemonkey

Update 1: I've found some sites it doesn't work on. I will try to find out the difference between sites that work, and sites that don't. Probably JS-libs used on the sites messing with my script. :8

Update2: I've no rewritten the script so that is doesn't add any symbols to the global namespace.

Result of running the script through JSLint:
Global: document (?), setTimeout (?), window (?)

Monday, March 5, 2007

Tip about tables

Today, I was rewriting a search-agent at work.

The agent is used to search for unbooked cabins. First it searches for the cabins matching some criteria. Using the collection that is returned, It then looks for bookings (which are made from another form than the cabin-documents) on the cabins that are found. When a cabin is found, the HTML for that cabin is printed.

The counter of found cabins, which I had to print, is not available until all the HTML for the cabins is printed.

I considered adding line-breaks at the top of the table containing the result, and absolutely positioning the count at the top. I then remembered reading something about thead, tfoot and tbody being "non-chronological". The solution was putting all the cabins from the result in a tbody tag. Then printing the thead-tag with the number of results at the bottom.

<tr><td>Cabin at the mountains.</td></tr>
<tr><td>Cabin at the tundra.</td></tr>
<td colspan="2">Found 2 cabins matching the search criteria:</td>

Result (faked with div, because of blogspot escaping code):

Found 2 cabins matching the search criteria:

Cabin at the mountains.

Cabin at the tundra.