Here’s my presentation at DevCamp event on 28th August 2010. It’s an introduction to Titanium Mobile framework, developed by Appcelerator. With Titanium Mobile, we can use fully JavaScript (optional HTML & CSS) to build a native application running on Android & iPhone.
Recently, I’ve upgraded to use Ubuntu 10.04. It seems that by default, I can’t just use “sudo apt-get install sun-java6-bin” to download the java package. After doing Google for the solution, I’ve come across a working solution. I need to add apt repository first, before I can download the java package:
Here’s a littile progress bar I’ve created using JavaScript. I’ve use JavaScript setInterval() to increase the progress bar & clearInterval() to stop progress bar.
//Create dom
var bar = document.createElement("div");
progressBar = document.createElement("div");
with(bar.style){
width = "200px";
height = "10px";
position = "absolute";
border = "1px solid #949DAD";
};
with(progressBar.style){
width = "0px";
height = "100%";
background = "#D4E4FF none repeat scroll 0 0";
};
bar.appendChild(progressBar);
document.body.appendChild(bar);
//start setInterval
var x = window.setInterval(
function(){
progressBar.style.width = parseInt(progressBar.style.width) + 5 + "px";
//stop interval when progress bar width = 200
if(parseInt(progressBar.style.width) == 200) clearInterval(x);
},
40
);
The tabIndex property sets or returns the tab index for a text field. The tab order defines the order the elements appear if you navigate the page using the “tab” button on the keyboard.
Given the scenario that we have a webpage which has many links & a form for users to complete. In this case we see that the main focus is the form not the links before the form. If users were to use tabkey to browse to the form, it would take many keypress before users are able to go to form. We can solve our problem by specifying the tabindex property.
In the following code, there’s a problem which is faced when we’re using inheritance through prototype.
Now, we have a parent class Person, and we have a child class Student which inherit from Person. As a default, we want to set gender to “Male”.
var Person = function(){
this.object = {"name": "", "gender": "Male"};
}
Person.prototype.sayHi = function(){
console.log ("Hi! I am " + this.object.name);
}
Person.prototype.sayGender = function(){
console.log ("I am " + this.object.gender);
}
var Student = function(){}
Student.prototype = new Person();
var victoria = new Student();
victoria.object.name = "Vitoria";
victoria.object.gender = "Female"
victoria.sayHi();
victoria.sayGender();
var sam = new Student();
sam.object.name = "Sam";
sam.sayHi();
sam.sayGender();
here’s the result:
Hi! I am Votoria
I am Female
Hi! I am Sam
I am Female
As we see, the default gender “Male” has been alter to “Female”. we can prevent the default gender in the Person class to be altered by adding “Person.apply(this);” Student class.
After added, the code will look like this:
var Person = function(){
this.object = {"name": "", "gender": "Male"};
}
Person.prototype.sayHi = function(){
console.log ("Hi! I am " + this.object.name);
}
Person.prototype.sayGender = function(){
console.log ("I am " + this.object.gender);
}
var Student = function(){
Person.apply(this);
}
Student.prototype = new Person();
var victoria = new Student();
victoria.object.name = "Vitoria";
victoria.object.gender = "Female"
victoria.sayHi();
victoria.sayGender();
var sam = new Student();
sam.object.name = "Sam";
sam.sayHi();
sam.sayGender();
here’s the result:
Hi! I am Votoria
I am Female
Hi! I am Sam
I am Male
Here’s how we create javascript object using Javascript Object Notation (JSON). After the code below is executed, it would show alert windows with text “Borey Lim”
//script to demonstrate creating object in javascript using JSON
var objectDemo = {
firstName: "",
lastName: "",
displayName : function(){
alert(this.firstName + " " + this.lastName);
}
}
objectDemo.firstName = "Borey";
objectDemo.lastName = "Lim";
objectDemo.displayName();