Wednesday, April 30, 2008

AjaxForm

Having my new web project started, I'm thinking about an agile solution for posting forms in an Ajax way with minimized JavaScript code.
Using prototype, my former solution was a functional approach...but now I'm thinking for a better OO approach.
Let see what can I do! I will put my solution here in next days.

Wednesday, March 12, 2008

Javascript Import / Include

We can load JS files in the HEAD part of a HTML document, but have you ever needed to load a JS file from another script?

you can use this code:

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'snip.js';
document.getElementsByTagName('head')[0].appendChild(script);



And if you don't want to write it again and again, and prefer to prevent loading a JS file more than one time you can use this clean function:


function $import(path){
var
i, base, src = "grid.js", scripts = document.getElementsByTagName("script");
for (
i=0; i<scripts.length; i++){if (scripts[i].src.match(src)){ base = scripts[i].src.replace(src, "");break;}}
document.write("<" + "script src=\"" + base + path + "\">+ "script>");
}


// example

$import("controls/grid.js");
$import("http/request.js");

But I strongly recommend you to use the AjaxCSSJS calss instead.

Friday, February 22, 2008

Gmail in Thunderbird 2

Thunderbird 2 is offering a default configuration for Gmail POP service!





Sunday, January 6, 2008

Oh all those cats!!!

Amir Hossein has posted about a book written by Hank Rainwater here which is about leading software teams.
You can download the eBook here! :)

Goodbye Dubai

...it is my last day in office, I'm not supposed to come to office today but I'm here to solve some problems in the live version of portal...I will go home by end of the week. :) The company has some plans for bringing me back to Dubai to work for them 6 months more...and if they can provide me the visa I should come here since I've promised them to do that due to their high level of flexibility during my final examinations. But I hope that they don't bring me back again ;)...



View Larger Map

Monday, December 31, 2007

non-UTF8 characters in XML

Have you ever used an Ajax tool which is very sensitive to the non-UTF characters in the XML data which is coming back from the server-side script??? I mean those tools which are using the responseXML field of XMLHttpRequest instead of its responseText! Taconite is one of this kind of tools.
It is a big headache when you couldn't see the result due to only one invalid character which is there because you (or the operator) have copy paste the text in your DB from MS Word or any other applications which are not supporting Unicode by default!
Some standard browsers are not so sensitive to these invalid characters and do the correction automatically, Firefox, Opera and Safari do this but the most popular one (it's a pity) which is MS IE doesn't do that! And is 100% sensitive to all kind of these characters! :(
In the company everyday one of us reports the others that
Oh shit! search results of the ... part of the portal are not coming in IE!!! Ehsuuuuuuuuuuuuuun!!!
- Oh who entered data for ...part??? Have you copied them from Word?!!! Oh one of you should go through the records and find that invalid character which is 99% a comma!

Tiered of this lengthy solution, I've decided to find a way that convert invalid characters in an string to their corresponding UTF8 character! After some research in the PHP resources I found this nice function here!

$text = iconv("UTF-8","UTF-8//IGNORE",$text);

Tuesday, December 25, 2007

XSLT or Template Engines

Having a nice separation between business logic and presentation logic in web development is a really beneficial and important functionality to be obtained. There are many template engines for any server-side technology out there such as: Smarty, Heyes Template Class, FastTemplate, ShellPage, STP Simple Template Parser, OO Template Class, SimpleTemplate, bTemplate for PHP scripting language and Velocity, FreeMarker, SiteMesh, Better Templates for Everybody, WebMacro, Transformica, Tea, Jamon, StringTemplate, jxp for JSP. There are lots of them but there are many common features in all of them.
Usually 2 goals are achieved by using a template engine:
  1. Separation of the business logic and presentation logic
  2. Separation of the server-side scripts and HTML code. (logic and content)

The former is the right goal! and the latter shouldn't be a direct goal. The separation of HTML and Scripting language will achieve in some extent but we shouldn't go deliberately for gaining it! For example assume that we want to display a table-based report of all customers who have bought something in the last month in 3 columns. Executing the query and fetching the result should be happened in the business logic and separated from HTML code. But dividing the customers in 3 groups in the business logic is a wrong solution! Because in a new layout (template design) we may want the customers in 4 columns, so we should achieve this without amending the business layer. So our template engine should have the features to let us have some logic in the templates (presentation logic) in this example we need to have FOR loops or similar structures in order to display the group of customers in 3 columns. This is exactly what is done by Smarty and XSLT. But there are some problems with using the template engines which are:
  1. They usually have complex process and documents.
  2. Some of them are replacing the standard and popular scripting language e.g. PHP with a more complex and non-standard conventional language
  3. The business layer usually produce a non-standard and non-structured data which is totally useless to other websites or applications
  4. They usually (NOT always) bring some security risks if we have untrusted template developers.



Using XSLT realize the main goal which is separating the business logic from presentation logic. We can have powerful logical structures in the presentation layer which could not be malicious as well. Generally XSLT will bring the following benefits:
  1. The XSLT documents are not more than some XML files and HTML files.
  2. XSLT could be as complex as some of the template engines but there are lots of books and resources out there due to its standard and support from W3C.
  3. The data which is produced by business layer i.e. XML is 100% standard and reusable by other programming technologies.
  4. The XSLT logical structures could not be used in a malicious fashion.





Download the e-book: Beginning XSLT 2.0 from Novice to Professional

Saturday, December 22, 2007

Firefox 3 Beta


You can download Firefox 3 beta here.
Let's check it out.

Google Suggest Tutorial

In the web sites and web applications most of the users are not aware of the exact and complete name of terms they are searching for! So it is a good idea to give them suggestion while they are trying to write the name of the desired words. Similar to what is happening in Google suggest.

In this tutorial we will do the same thing for a search in a group of people whose information are stored in a table of database. The same as the previous tutorials we use prototype.js as Ajax/DOM framework.

Since the steps are too simple and so similar to the previous tutorials, I let you download it and check it out by yourself! ;)

Good Luck!

Tuesday, December 18, 2007

Prototype and Scriptaculous Ebook


The first book about prototype.js framework and scriptaculous animation library!
Download the book here!