Wednesday, 26 January 2011

The missing event when the mouse stays in a place

Hello everybody,

I just released a jquery plugin which detects if the mouse stays in a place for more than the specified period of millisecs.
I was missing this functionality and I also needed more than twice and :) I needed also in the past so finally I decided to extract as a reusable plugin.

You can download it from here:
or here:

It is easy to use as any other jquery thing.

Enjoy :)

Sunday, 17 October 2010

Unobtrusive In PlaceEditor for Rails3

Hello everyone,

It's been one and half month since Rails3 came out and it evolvolved a lot if we compare it to Rails2. This direction of evolution makes me happy.
The topic I want to write about is related to the Rails3 way of unobtrusive Javascript. To be more specific I want to show you a way how to make the scriptaculous' in place editor unobtrusive.
The idea: wouldn't it be nice if by adding some extra attributes to some html tag the displayed entity fields would become spontaneously editable?


<p id="<%= project.id %>_project_content"
data-in-place-editable="true"
data-entity="project"
data-field="content"
><%= project.content %></p>

I think it definitely would.

So let's start with it.

Let's suppose that we have a restfull resource called project and we want an in place editor in our view which is bind to the update method of our ProjectsController.
First thing you need to do is to check out the http://github.com/orbanbotond/Fast-In-Place-Editor. into your public/javascript directory of your project.
This file contains the generic repetitive mundane line's of code which would otherwise been repeated field by field in your view.

In your layout file you need to include this javascript:

<%= javascript_include_tag "myextensions/fast_in_place_editor.js" %>


In your view add some extra attributes to the tag which displays your entity's fields. Let's say this is how you were displaying the content of a project:

<p id="<%= project.id %>_project_content"><%= project.content %></p>

In order to make the content in place editable do this:

<p id="<%= project.id %>_project_content"
data-in-place-editable="true"
data-entity="project"
data-field="content"
data-url="<%= project_path(project, :authenticity_token => form_authenticity_token) %>"
data-cols="60"
data-rows="6"
><%= project.content %></p>


And that's all you need to do.
Enjoy :)



Sunday, 6 December 2009

A Click Heat Map plugin for ruby on rails applications

Hi Rubysts,

I've just finished my first contribution to the Ruby on Rails community this evening.
This contribution is actually the repackaging of the click heat map generator included within cannoli into an easy-to-install and deploy ruby on rails plugin.

If you take a look at cannoli you observe that it is based on ruwa web analytic ruby on rails app. I didn't need all of these together.
So... Did I manage to do something better? I believe that it is only rarely the case for something to be in every aspects better than something different. In this particular case I would say that I have made a piece of ruby on rails building block which is less than cannoli but it can be extremely easily incorporated in your Rails ( >2.3.2 ) application.

It has it's own requirements:
  • you need Rmagick installed
  • you must have Rails 2.3.2

Maybe you want to improve your sites web usability.
In order to install the plugin:
  • ./script/plugin install git://github.com/orbanbotond/click_heat_map.git
From the click_heat_map plugin directory (not from rails root)
  • rake db:migrate:click_heat_map
Then you need to put and adapt this code into your templates:
< src="'/javascripts/overlay.js'" type="'text/javascript'">
< src="'/javascripts/clickmap.js'" type="'text/javascript'">


put this html code into your templates you want to measure:
< id="prova" style="margin:auto;width:800px;height:1px;">

And finally, you reached the point where you want to deploy your rails app using capistrano.
Maybe you ask yourself how capistrano knows how to migrate your plugin to the remote server.
Well...
In my case I put the installed plugin under version control and Capistrano just copied to the remote server.
I also created a file named
20091130000000_create_heat_map_clicks.rb:
require 'vendor/plugins/click_heat_map/lib/db/migrate/20091130000000_create_heat_map_clicks.rb'
This way capistrano creates the tables needed by the plugin on the remote server by running "cap deploy:migrations".

Finally the result makes me happy :)

Wednesday, 4 November 2009

A quick fix for swfir and prototype incompatibility



Hi,

Some of you might know about a small and smart library called swfir. This library intends to extend some of the limitations of classic html images. It can rotate the images and it can draw some fancy borders and fancy shadows around the borders and so on. I like the library despite the fact that it's not perfect. It's not compatible with prototype. :(

Here is a small patch that I posted to the authors and hopefully a new release will come out which will support prototype :)

Untill then you can use the patch from here:

@@ -569,7 +569,11 @@
Flash Vars
*/
var varString = "";
- for(va
r key in this.params){ varString += ("&"+key+'='+ this.params[key]); }
+ for(var key in this.params){
+ if("function" != typeof(this.params[key])){
+ varString += ("&"+key+'='+ this.params[key]);
+ }
+ }
Rendering before:

Rendering after: