Tuesday, December 16, 2008
Ajax Islands Tutorial - AjaxCSSJS Class (Part 1)
Sunday, December 14, 2008
Ajax Islands Tutorial - AjaxContent Class
Friday, December 12, 2008
AjaxImageReflection
Something like this:
Go ahead and take a look at examples here. You can download it too.
Thursday, December 11, 2008
Thursday, December 4, 2008
AjaxContent
Monday, November 17, 2008
Google Chrome
I've just installed Google Chrome web browser. I can say it's a Google product indeed: simple, powerful and elegant.
Sunday, November 16, 2008
JavaScript Object Model - OO Programming
OO languages are either class based or prototype based. JavaScript is one of prototype based languages out there.
There are lots of references and tutorials about OO programming in JavaScript in the Net. Most of them are so useful and explain a single aspect of OO programming in the language. Some are based on a particular framework such as Prototype, JQuery ... while some explain the pure JavaScript rules.If you are curious to read yet another nice article about JavaScript Object Model, I strongly suggest you to spend 15 minutes to read JavaScript's class-less objects by Stoyan Stefanov.
The article explains the dynamic features of the JavaScript and explains different ways to implement inheritance in the language and then compare them with Java's way.
Monday, November 10, 2008
Friday, November 7, 2008
AjaxCSSJS - JavaScript and CSS on-demand
Ajax Islands Solution
Download AjaxCSSJS here.
You can load JavaScript and CSS files dynamically (on-demand) by means of AjaxCSSJS which is the 4th class of AjaxIslands (the 2nd and 3ed classes are not released yet!).
You can load your CSS or JavaScript files this way:
new AjaxCSSJS('css/grid.css', 'css'); new AjaxCSSJS('js/ajaxform.js', 'js');
You load a JavaScript to use it! don't you?
I mean usually you call a function or make an object after loading a JavaScript file. In this example you are going to make an AjaxForm object like this:
new AjaxCSSJS('js/ajaxform.js', 'js'); var af = new AjaxForm("frmProfile", "profile.act.php", "loader1.gif", "profileBoard");
But your second line of code will fail!
The browser try to load the ajaxform.js asynchronously! It means that the browser won't wait for the file to be loaded and will continue executing the rest of the code. So the second line which is trying to instantiate the AjaxForm will run before the file is loaded!!!
Don't worry! AjaxCSSJS class has a nice feature to solve this problem too!
You can pass a function as 3ed argument to the constructor of the class. This function will be executed as soon as the browser loads the file. So we should change the code this way:
new AjaxCSSJS('js/ajaxform.js', 'js', function() { var af = new AjaxForm("frmProfile", "profile.act.php", "loader1.gif", "profileBoard"); });
Wednesday, November 5, 2008
Trick in AjaxForm
In the case of AjaxForm, it is possible that the user click submit button while the AjaxForm or Prototype is not loaded.
Solution is to prevent the user to submit the form before the libraries (JS files are loaded). So you must hide the submit button by setting its CSS attribute visibility to hidden. The AjaxForm object will make it visible automatically as soon as it is created.
So you should write the form this way:
Monday, November 3, 2008
AjaxForm methods
Method | Description |
submit() | You can submit the form by calling this function, but it is not necessary to use it usually, for example you can set the last field onBlure event to a function which calls this method. |
reset() | You can reset the form and clear the message board by calling this method, but it is not necessary usually and it is called from other methods of the class. |
resetForm() | You can reset the form but not clear the message board by calling this method. |
hideForm() | This method will hide the form element (form tag). You may call this function when the server script has processed the data and the process was successful and user won't need the form anymore, similar to the login forms after successful login. |
showMessage(msg, color) | This method let you show a message to the user such as data validation messages. The firs parameter is the message itself which is string and the second one is the color of message which is string too and could contain a color name e.g. "red" or a color value e.g. "#FF0000" |
focusForm() | By calling this method the first input of the form will receive the focus. You may call this method after creating the object in order to make form ready to receive user's data. |
Saturday, November 1, 2008
AjaxForm
e.g.
ajaxForm.focusForm();
But don't forget that all of these components which I'm working on are based on Prototype.js framework.
So in all examples I assume that you have the following line in your document's head section.
<script type="text/javascript" src="prototype.js"></script>
You can download the current version of AjaxForm here.
The design is based on the idea that each form has 4 main elements to be working as an web 2.0 form. (it is my idea, you may disagree with that)
- The form itself - HTML element (tag) of form, so we need to pass the ID of the form element to the AjaxForm object.
- The server side script which the forms's data will be sent to, so we pass the URL of the script to the object.
- The image that should be displayed as a loading animation while the user is waiting to receive the server result. We need to pass the URL of the image file to the AjaxForm object.
- The exact portion of the page that the animation image should be displayed, and also the place that other potential messages to the users should be displayed. So we pass the ID of an HTML element to the object.
Example1
First add the followings to the head section of your page:
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="ajaxform.js"></script>
The HTML form.
The place-holder for messages and the animation image.
Main part (instantiating the object)
<script type="text/javascript">
<!--
var ajaxForm = new AjaxForm("form1", "action1.php", "loader1.gif", "board");
ajaxForm.focusForm();
//-->
</script>
Don't forget to locate the following files in the same directory as your page directory:
- prototype.js - you can download it here.
- ajaxform.js - download it here.
- loader1.gif - any gif animation
- action1.php - a php file that will handle the request data
Now it's time to write the server side code. The server side script could be developed in any technology such as Java servlet, JSP, PHP, PERL, Python, ASP, ASP .NET and ...
In this example I write it using PHP (action1.php).
action1.php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$login = false;
if (empty($username)) {
$message = "You should enter your username!";
$color = "red";
} else if (empty($password)) {
$message = "You should enter your password!";
$color = "#FF7000";
} else if($username == 'ehsun' && $password == '7') {
$login = true;
$message = "You have logged in successfully.";
$color = "#335599";
} else {
$message = "Your username or password is incorrect!";
$color = "#9F9000";
}
echo "<script>";
echo "ajaxForm.showMessage('$message', '$color');";
if ($login) {
echo "ajaxForm.hideForm();";
} else {
echo "ajaxForm.focusForm();";
}
echo "</script>";
sleep(3);
?>
The sleep command is for simulating the delay! you don't need it in the real codes.
As you may noticed you have access to the AjaxForm object which has been created in the client side from the JavaScript code which is coming from server side script, that is very useful feature!
The AjaxForm has some other methods that I will explain in the next posts. Please give me your suggestions.
Friday, October 31, 2008
Galileo - Java Plug-in for RIA
I was reading an article titled "Can the Java Plug-in Compete?" that first lines of it really fascinated me...
It is about a RIA framework - actually the client side part - which is using Java Plug-in, and Java programming language. Looks very interesting, even imagination of having those nice features of the language which we use in the server side, at the client side too. You can download and read more about the framework here! But remember that you need a Java-enabled browser.
Tuesday, July 29, 2008
Monday, May 12, 2008
My first Java program in Linux
Please write your similar experiences on this topic.
Sunday, May 11, 2008
Pronunciation of Linux
Saturday, May 10, 2008
Sudo is older than me!
Wednesday, April 30, 2008
AjaxForm
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
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
Sunday, January 6, 2008
Oh all those cats!!!
You can download the eBook here! :)
Goodbye Dubai
View Larger Map