Archive for August, 2008

Facebook Style Image Cropping (Javascript Preview)

Tuesday, August 26th, 2008

While others are sun bathing somewhere on the shores of Black Sea I received another interesting task – to¬† implement cropping for user uploaded profile images. My first idea was to port MooCrop to Mootools 1.2 and apply couple of modifications, but the customer wanted the cropping to be exactly like in Facebook. For those who don’t know it is plain old boring mouse drag.

Instead of generating thumbnail and then cropping it (like in Facebook) I take the original (uploaded) image and resize it with CSS (yes I know it is not the right thing to do but for a quick preview IMO it is ok and we skip one resizing operation). Then I use the Drag Class to create a drag to scroll container (like in Adobe Acrobat) and finally with two hidden input fields I send the coordinates to the server side part which takes care of the resizing and cropping of the image.

Enough mumbojumbo – the cropping example and the pic

FaceBook cropping

Javascript Dynamic Paging (MooTools Pager)

Saturday, August 16th, 2008

Couple of days ago I had to create a content pager which can dynamically insert page numbers including previous and next buttons.

The reason why I had to use Javascript and not any server side solution is quite interesting – the paging method should not really divide the content into different web pages. This is needed because if the text we want to split contains any XHTML markup and we divide it into separate web pages the markup will be broken (invalid). Just imagine having opening <div> tag in the first page and closing in the second – not cool! Other break point is if we just split some tag in two.

Using my favourite Javascript Framework – Mootools and with couple of XHTML/CSS tricks I could get it working with the following code:

// This Javascript is written by Peter Velichkov (
// and is distributed under the following license :
// Use and modify all you want just keep this comment. Thanks
var pagerPageHeight = $('warper').getSize().y;
var contentArea = $('content');
var pagerCurPage = 1;
var pagerPagesCount = 1;
var pagerPages = $('pager');
var pagerInit = function(){
	var contentHeight = contentArea.getSize().y ;
	pagerPagesCount = (contentHeight / pagerPageHeight).toInt();
	if (contentHeight % pagerPageHeight != 0 ) pagerPagesCount++;
	if (pagerPagesCount === 1) return;
	var prev = new Element('a', {
			'class': 'cust-pager-prev',
			'html': '&amp;lt',
			'id': 'cust-pager-prev',
			'events': {
				'click': function(){
					pagerChangePage(pagerCurPage - 1);
	var next = new Element('a', {
			'class': 'cust-pager-next',
			'html': '&amp;gt',
			'id': 'cust-pager-next',
			'events': {
				'click': function(){
					pagerChangePage(pagerCurPage + 1);
	for (var i=1; i&lt;=pagerPagesCount; i++){
		var anchor = new Element('a', {
			'class': 'cust-pager-item',
			'id': 'cust-pager-item-'+ i,
			'html': i,
			'events': {
				'click': pagerChangePage.pass(i)
var pagerChangePage = function(page){
	$('cust-pager-item-' + pagerCurPage).set('class', 'cust-pager-item');
	$('cust-pager-item-' + page).set('class', 'cust-pager-item-sel');
	pagerCurPage = page;
	if (pagerCurPage === 1) {
		$('cust-pager-prev').setStyle('display', 'none');
		$('cust-pager-prev').setStyle('display', 'inline');
	if (pagerCurPage === pagerPagesCount) {
		$('cust-pager-next').setStyle('display', 'none');
		$('cust-pager-next').setStyle('display', 'inline');
	contentArea.setStyle('top', (-1) * pagerPageHeight * (page - 1));

The example and the picture as usual.

Custom Pager

How-to Install VMware Player / Workstation on 2.6.26 Kernel

Monday, August 11th, 2008

Following the series about VMware troublesome installation here is a short tip for having VMware Player or Workstation up and running on your linux box.

  1. Download latest patch from the Google VMKernelNewbies Group (currently 117d)
  2. Extract it to some tmp directory
  3. Execute

It could not get any easier than this (well maybe VMware can update more often)