Html5 Tutorial - Future Technology

Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Monday, 2 December 2013

Node.js Video Tutorial



Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.



Current Version: v0.10.22


I am posting all node.js video tutorials here please check and subscribe.

Node.js Tutorial Videos:



Node js A Jumpstart for Devs 01 Installing Node js Part -1





Node js A Jumpstart for Devs 02 Building our Project Part - 2





Node js A Jumpstart for Devs 03 Handlebars Switching the Template Engine HD Part 3





Node js Jumpstart for Devs 04 Adding our First Template Part - 4





Node js A Jumpstart for Devs 05 Geolocation A Usable HTML5 API HD





Node js A Jumpstart for Devs 06 Geolocations Making it Human Friendly HD





Node js A Jumpstat for Devs 07 Dynamic HTML Making Use of Our Templates HD Part - 7





Node js A Jumpstart for Devs 08 Simple Persistence w SQLite & an ORM Package HD Part- 8





Node js A Jumpstart for Devs 09 Tracking Ourselves Part - 9





Node js A Jumpstart for Devs 10 Displaying Places We've Been HD Part- 10





HTML5 Tutorial - Html5 tutorial two chat programs using node.js

In this tutorial we will learn how to use HTML5 WebSockets. We need a server that supports this protocol. We will use the NodeJS server, a very popular server for writing web applications that use WebSockets or for writing HTML5 games. It's a small, powerful server, that embeds the V8 JavaScript interpreter (the one in Chrome), enablind server side JavaScript. We will look at two versions of a small chat application, that use the socket.io and express modules for NodeJS. Socket.io brings weNotice that socket.io has also implementations server side for Java, C#, Android, etc). Installation of NodeJS and of the express and socket.io modules Go to http://www.nodejs.org and install the last version of NodeJS. Click on the install button on the web page. Check the installation. Open a terminal window, type "node --version", this should print something like: "node 0.10.x". Test of a first NodeJS application Create somewhere a file names test.js, with this content
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
Save and run this command from the terminal: node test.js You just ran your first nodeJS application, try it with a Web browser by opening: http://localhost:8124 You should see this in your web browser: The test.js file contains ultra minimal code for creating and configuring an HTTP web server. This ultra minimal server answers requests by sending string responses on the fly. If we want to serve HTML files, images, JS files, CSS files, we need a more complete web server. This is what the "express" module will bring to NodeJS. And we will also need the socket.io module for using WebSockets. NodeJS module installation We will use the "npm" (node package manager) command from the nodeJS installation Create a directory named "chatWithSocketIO" somewhere cd in it, run "npm install express", run "npm install socket.io". You should see a subdir named "node_modules" that contains the new modules you just downloaded/installed locally to your project. Simple chat application that uses express and socket.io This part is an updated/fixed version of this tutorial , that explains how to write a small chat application with nodeJS, express and socket.io. We cleaned the code and adapted it so it works with the last version of express (v3), and socket.io. Get this archive : chatSocketIO.rar Unarchive it in your working dir. You should get this; Now run this command "node simpleChatServer.js" and open "http://localhost:8080", in your browser. Open th URL in two different tabs. Enter two different names, try to chat, look at what happens in the different tabs.Open Chrome dev tools, you should find how to trace data exchanged over web sockets. Now, study the code of simpleChatServer.js, of simpleChat.html, and read : http://psitsmike.com/2011/09/node-js...chat-tutorial/, forget the beginning about the nodeJS installation, just read the code explanations. socket.io basic principles socket.on(event_name, callback) : executes the callback when an event with a given name is fired. (event_name = user defined). Some events like 'connection' or 'disconnect' are predefined. All event processing is performed in the io.sockets.on('connection', function (socket) {...}, call. socket.emit(event_name, data1, data2): sends only to the connected client the event and two parameters with data io.sockets.emit(event_name, data1, data2): same but sends to all connected clients socket.broadcast.emitevent_name, data1, data2): same but sends to all connected clients except the emitter simpleChatServer.js:
// We need to use the express framework: have a real web server that knows how to send mime types etc.
var express=require('express');

// Init globals variables for each module required
var app = express()
  , http = require('http')
  , server = http.createServer(app)
  , io = require('socket.io').listen(server);

// Indicate where static files are located  
app.configure(function () {  
    app.use(express.static(__dirname + '/'));  
});  

// launch the http server on given port
server.listen(8080);

// routing
app.get('/', function (req, res) {
  res.sendfile(__dirname + '/simpleChat.html');
});

// usernames which are currently connected to the chat
var usernames = {};

io.sockets.on('connection', function (socket) {

 // when the client emits 'sendchat', this listens and executes
 socket.on('sendchat', function (data) {
  // we tell the client to execute 'updatechat' with 2 parameters
  io.sockets.emit('updatechat', socket.username, data);
 });

 // when the client emits 'adduser', this listens and executes
 socket.on('adduser', function(username){
  // we store the username in the socket session for this client
  socket.username = username;
  // add the client's username to the global list
  usernames[username] = username;
  // echo to client they've connected
  socket.emit('updatechat', 'SERVER', 'you have connected');
  // echo globally (all clients) that a person has connected
  socket.broadcast.emit('updatechat', 'SERVER', username + ' has connected');
  // update the list of users in chat, client-side
  io.sockets.emit('updateusers', usernames);
 });

 // when the user disconnects.. perform this
 socket.on('disconnect', function(){
  // remove the username from global usernames list
  delete usernames[socket.username];
  // update list of users in chat, client-side
  io.sockets.emit('updateusers', usernames);
  // echo globally that this client has left
  socket.broadcast.emit('updatechat', 'SERVER', socket.username + ' has disconnected');
 });
});
And simpleChat.html:



USERS
Multiroom chat: several groups of clients can chat together This version enable clients to be in groups called "rooms". The Socket.io API has a complete set of functions for joining/leaving a room, sending messages to all people in a room, to all people except the emitter, etc. socket.join(room_name) and socket.leave(room_name) : when joining a non existing room it creates it, socket.broadcast.to(room_name).emit(...): similar to socket.broadcast.emit, sends a message to all clients in the room except the emitter. io.sockets.inroom_name).emit(...) : sends to all clients in the room. Complete documentation of the room API: https://github.com/LearnBoost/socket.io/wiki/Rooms multiRoomChatServer.js
// We need to use the express framework: have a real web server that knows how to send mime types etc.
var express=require('express');

// Init globals variables for each module required
var app = express()
  , http = require('http')
  , server = http.createServer(app)
  , io = require('socket.io').listen(server);

// Indicate where static files are located. Without this, no external js file, no css...
app.configure(function () {  
    app.use(express.static(__dirname + '/'));  
});  

// launch the http server on given port
server.listen(8080);

// routing with express, mapping for default page
app.get('/', function (req, res) {
  res.sendfile(__dirname + '/multiRoomChat.html');
});

// usernames which are currently connected to the chat
var usernames = {};

// rooms which are currently available in chat
var rooms = ['room1','room2','room3'];

io.sockets.on('connection', function (socket) {
 
 // when the client emits 'adduser', this listens and executes
 socket.on('adduser', function(username){
  // store the username in the socket session for this client
  socket.username = username;
  // store the room name in the socket session for this client
  socket.room = 'room1';
  // add the client's username to the global list
  usernames[username] = username;
  // send client to room 1
  socket.join('room1');
  // echo to client they've connected
  socket.emit('updatechat', 'SERVER', 'you have connected to room1');
  // echo to room 1 that a person has connected to their room
  socket.broadcast.to('room1').emit('updatechat', 'SERVER', username + ' has connected to this room');
  socket.emit('updaterooms', rooms, 'room1');
 });
 
 // when the client emits 'sendchat', this listens and executes
 socket.on('sendchat', function (data) {
  // we tell the client to execute 'updatechat' with 2 parameters
  io.sockets.in(socket.room).emit('updatechat', socket.username, data);
 });
 
 socket.on('switchRoom', function(newroom){
  socket.leave(socket.room);
  socket.join(newroom);
  socket.emit('updatechat', 'SERVER', 'you have connected to '+ newroom);
  // sent message to OLD room
  socket.broadcast.to(socket.room).emit('updatechat', 'SERVER', socket.username+' has left this room');
  // update socket session room title
  socket.room = newroom;
  socket.broadcast.to(newroom).emit('updatechat', 'SERVER', socket.username+' has joined this room');
  socket.emit('updaterooms', rooms, newroom);
 });
 

 // when the user disconnects.. perform this
 socket.on('disconnect', function(){
  // remove the username from global usernames list
  delete usernames[socket.username];
  // update list of users in chat, client-side
  io.sockets.emit('updateusers', usernames);
  // echo globally that this client has left
  socket.broadcast.emit('updatechat', 'SERVER', socket.username + ' has disconnected');
  socket.leave(socket.room);
 });
});
multiRoomChat.html



ROOMS
Code explanations here: http://psitsmike.com/2011/10/node-js-and-socket-io-multiroom-chat-tutorial/ (we made small updates to the code) Node.js Tutorial Videos: Part - 1 Part - 2 Part - 3 Part - 4 Part - 5 Part - 6 Part - 7 Part- 8 Part - 9 Part - 10

Thursday, 3 October 2013

HTML5 Tutorial - Advantages of HTML5

Top 10 Advantages of HTML5

Basically HTML5 has it’s many new syntactical features, which include the video, audio, and canvas elements, as well as the integration of SVG content. Due to these new elements, it will be very easy to integrate multimedia and graphical content to web without using flash and third party plugins. There are also another new elements like section, article, header and nav which enrich the semantic value of the document. Other major advantages of HTML5 are described below. -

  • 1. Mutuality
    Due to usability purpose the web sites made by developers are highly interactive nowadays and for this developers need to include fluid animations, stream video, play music and Social Network sites like Facebook and Twitter into the websites. Till now they have only the option to integrate it with the help of Flash or Silverlight, Flex or javascript like tools. But these consume so much time to develop and even the complexity of web application also increased. But now with the help of HTML5 it is possible to embed video and audio, high quality drawings, charts and animation and many other rich content without using any plugins and third party programmas as the functionality is built into the browser.

  • 2. Cleaner markup / Improved Code
    HTML 5 will enable web designers to use cleaner, neater code, we can remove most div tags and replace them with semantic HTML 5 elements.

  • 3. Improved Semantics
    Now it is easy to see which parts of the page are headers, nav, footers, aside, etc as the tags are specific for these all and most importantly know what their meaning and purpose is in whole the format. By using HTML5 elements we can increase the semantic value of the web page as the codes are very standardized.

  • 4. Elegant forms
    HTML5 enables designer to use more fancier forms. Even it makes form validation native to HTML, User interface enhancements and reduced need for JavaScript (only needed in browsers that don’t support form types). There will be different type of text inputs, search and different fields for different purpose.

  • 5. Consistency
    As websites adopt the new HTML5 elements we will see more greater consistency in terms of the HTML used to code a web page on one site compared to another. This will make it more easier for designers and developers to immediately understand how a web page is structured.

  • 6. Improved Accessibility
    Different technologies can elaborate on the features with the help of HTML5, as they can Immediately make more detailed understanding of the structure of a page by take a look at HTML5 elements it has.

  • 7. Fulfill the need of Web application
    Many new features and standards have emerged as part of HTML 5. Once you detect the available features in today’s browsers, you can take advantage of those features in your application. Main focus of HTML5 is to make easier application with easy front-ends, drag and drop tools, discussion boards, wikis and other useful elements.

  • 8. Offline Application cache
    All browsers have some kind of caching m After a sometime, you open up your laptop and click the Back button in the browser hoping to see the previous page that was opened. However, as you are not connected to the internet and the browser didn’t cache the page properly, you are unable to view that page. You then click the Forward button thinking that at least that page will load, but it doesn’t. You need to reconnect to the internet to be able to view the pages. HTML 5, thankfully, provides a smarter solution. While building the site, the developer can specify the files that the browser should cache. So, even if you refresh the page when you are offline, the page will still load correctly. This sort of caching has several advantages like offline browsing, files load much faster and reduced load on server

  • 9. Client-side database
    While cookies have been used to track unique user data for years, they have serious disadvantages. The largest flaw is that all of your cookie data is added to every HTTP request header. This can end up having a measurable impact on response time. So a best practice is to reduce cookie size. With HTML5 we can do better by using sessionStorage and localStorage(two different storage in HTML5) in place of cookies. It is not a permanent database, but enables you to store structured data, temporarily.

  • 10. Geolocation support
    With help of Geolocation any one can find out where you are in the world and sharing that information with people. There is different ways to figure out where you are — your IP address, your wireless network connection, which cell tower your phone is talking to, or dedicated GPS hardware that calculates latitude and longitude from information sent by satellites in the sky. But The new HTML5 geolocation APIs make location, whether generated via GPS or other methods, directly available to any HTML5-compatible browser-based application. This is only the overview of the HTML5 advantages, actually there is lots more to know about HTML5. In the near future HTML5 will become a online development language. It is assumed that it will not completely finished before 2022.So just keep it in your mind and start using HTML5 in your designs right now!

Wednesday, 26 June 2013

HTML5 Tutorial - Drag and Drop

Title: HTML5 Tutorial - Drag and Drop example.

Description : I am going to explain how to drag an item and drop the item at required position.

In The above image i am going to move all right side boxes to trash i.e to left side dust bin. CSS Code for above App


JavaScript and html5 Code



HTML5 Powered with Connectivity / Realtime, Device Access, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage

     

Fork me on GitHub






HTML5 Code

Drag and drop

Drag the list items over the dustbin, and drop them to have the bin eat the item

Original Source

Wednesday, 2 January 2013

HTML5 Tutorial - Sections and Outlines of an HTML5 Document


Title : Sections and Outlines of an HTML5 Document.

Details:Technology : HTML5/JavaScript

Completion Time: 1 Hour

Difficulty : easy

Description :
    
                   I am going to explain some new elements in HTML5 allowing web developers to describe the web document with standard semantics.

Problems solved in HTML5 compared to HTML 4 

1)HTML5 removes the need for <br />
<div>
elements from the outlining algorithm by introducing     a new element,<br />
<section>,the Html Section element.

2)Merging several documents is hard: inclusion of a sub-document in a main document     means changing the level of the HTML Headings Element so that the outline is kept. This  is solved in HTML5 as the newly introduced sectioning elements (<article>, <section>, <nav> and <aside>) are always subsections of their nearest ancestor section, regardless of what sections are created by internal headings.

3)Because each HTML Heading Element is part of the outline, it is not possible to describe a subtitle or secondary title (e.g., <h1>
Justine</h1>
<h2>
Les Malheurs de la Vertu</h2>
creates the outline 1. Justine 1.1 Les Malheurs de la Vertu). HTML5 introduces the <hgroup> element that hides all the heading elements except the first one of the highest rank (e.g., <hgroup><h1>
Justine</h1>
<h2>
Les Malheurs de la Vertu</h2>
</hgroup> creates the outline 1. Justine).

4)In HTML4, every section is part of the document outline. But documents are often not that linear. A document can have special sections containing information that is not part of, though it is related to, the main flow, like an advertisement block or an explanation box. HTML5 introduces the <aside> element allowing such sections to not be part of the main outline.

5)Again, in HTML4, because every section is part of the document outline, there is no way to have section containing information related not to the document but to the whole site, like logos, menus, table of contents, or copyright information and legal notices. For that purpose, HTML5 introduces three specific sections elements: <nav> for collections of links, such as a table of contents, <footer> and <header> for site-related information.

Here is an Example for Showing Basic Html5 Elements(<section>,<article>,<header>,<nav>,<footer>,<aside>):

<section>  : Our Home page has been divided into number of sections which consisits of header,article 1,article 2 and footer.we have innersections also where we can embed animations inside section , we can write articles inside section element for more details , please go through the code , demo and image below.






From , the above image we can see <header>,<nav,<article>,<aside>,<footer> and some animations where a girl rides a bicycle,birds flies in the sky.

All this elements are aligned with particular space looking the code our body of the page starts with <section> tag with id="wrapper" for style and this section consists <header>,<nav>,<article>,<aside>,<footer> elements.
<header> : Next going through code we have <header> element where place some logo there.
<article>  : We have article tag for writing some articles like some tutorials,stories etc.
<aside>    : We have this element for writing some notes side to our articles or displaying some
                    advertisements.
<footer>  : We have this tag for writing some copy write notices or linking up some back links for              our sitemap index.
animation : I have included some sections which wraps css3 elements or style elements using id's assigned in the css style sheet.

Index.html












 
 
 
         HTML5 Semantics Example
 

 


    

HTML5 Semantics Example

What We Provide?

Posted on by Alex Jones
We Provide All Domestic academic admissions for B.Tech,M.tech,Mca,Mba,Bds,Mbbs through out the country.we provide admissions for councilling fee only with out any donations,we look after accomdation along with career guidence.we are developing mobile app for colleges and students to communicate with each others and get admissions online from your mobile only.we provide online tutorials for students who want to learn new technologies with out any fee

Technologies

Posted on by Alex Jones
We Provide online courses for the following : JAVA HTML5 JavaScript Mobile Development
SS Educational Consultancy
Here is the code for css
@charset "utf-8";
/* CSS Document

Name: Vivek Kumar
Email: vivekwebmaker@gmail.com
Company:IDS Infotech Ltd.
 */

* {
	margin:0px;
	padding:0px;
}
body {
	overflow-x:hidden;
}

/*
//////////////////////////////////////////////////
				CLOUD
//////////////////////////////////////////////////
*/
#clouds {
	padding:100px 0px 0px;
	background:#c9dbe9;
	background:-webkit-linear-gradient(top, #c9dbe9 0%, #fff 100%);
	background:-linear-gradient(top, #c9dbe9 0%, #fff 100%);
	background:-moz-linear-gradient(top, #c9dbe9 0%, #fff 100%);
}
.cloud {
	width:200px;
	height:60px;
	background:#fff;
	border-radius:200px;
	-moz-border-radius:200px;
	-webkit-border-radius:200px;
	position:relative;
}
.cloud:before, .cloud:after {
	content:'';
	position:absolute;
	width:100px;
	height:80px;
	background:#fff;
	position:absolute;
	top:-15px;
	left:10px;
	border-radius:100px;
	-moz-border-radius:100px;
	-webkit-border-radius:100px;
	-webkit-transform:rotate(30deg);
	transform:rotate(30deg);
	-moz-transform:rotate(30deg);
}
.cloud:after {
	width:120px;
	height:120px;
	top:-55px;
	left:auto;
	right:15px;
}

/*
//////////////////////////////////////////////////
				CLOUD Animation Code
//////////////////////////////////////////////////
*/

.x1 {
	-webkit-animation:moveclouds 18s ease-in-out infinite;
	-moz-animation:moveclouds 18s ease-in-out infinite;
	-o-animation:moveclouds 18s ease-in-out infinite;
	top:-10px;
	
}
.x2 {
	left:200px;
	top:-50px;
	-webkit-transform:scale(0.6);
	-mox-transform:scale(0.6);
	transform:scale(0.6);
	opacity: 0.6; /*opacity proportional to the size*/
	-webkit-animation:moveclouds 25s ease-in-out infinite;
	-moz-animation:moveclouds 25s ease-in-out infinite;
	-o-animation:moveclouds 25s ease-in-out infinite;
	}
.x3 {
	left:0px;
	top:-175px;
	-webkit-transform:scale(0.8);
	-mox-transform:scale(0.8);
	transform:scale(0.8);
	opacity: 0.6; /*opacity proportional to the size*/
	-webkit-animation:moveclouds 30s ease-in-out infinite;
	-moz-animation:moveclouds 30s ease-in-out infinite;
	-o-animation:moveclouds 30s ease-in-out infinite;
	
}
.x4 {
	left:470px;
	top:-195px;
	-webkit-transform:scale(0.75);
	-mox-transform:scale(0.75);
	transform:scale(0.75);
	opacity: 0.75; /*opacity proportional to the size*/
	-webkit-animation:moveclouds 15s ease-in-out infinite;
	-moz-animation:moveclouds 15s ease-in-out infinite;
	-o-animation:moveclouds 15s ease-in-out infinite;
	
}
.x5 {
	left:-100px;
	top:-150px;
	-webkit-transform:scale(0.8);
	-mox-transform:scale(0.8);
	transform:scale(0.8);
	opacity: 0.8; /*opacity proportional to the size*/
	-webkit-animation:moveclouds 35s ease-in-out infinite;
	-moz-animation:moveclouds 35s ease-in-out infinite;
	-o-animation:moveclouds 35s ease-in-out infinite;
	
}
.x6 {
	left:50px;
	top:-280px;
	opacity: 0.4; /*opacity proportional to the size*/
	-webkit-animation:moveclouds 22s ease-in-out infinite;
	-moz-animation:moveclouds 22s ease-in-out infinite;
	-o-animation:moveclouds 22s ease-in-out infinite;
	
}
.x7 {
	left:-80px;
	top:-255px;
	-webkit-transform:scale(0.8);
	-mox-transform:scale(0.8);
	transform:scale(0.8);
	opacity: 0.8; /*opacity proportional to the size*/
	-webkit-animation:moveclouds 40s ease-in-out infinite;
	-moz-animation:moveclouds 40s ease-in-out infinite;
	-o-animation:moveclouds 40s ease-in-out infinite;
	
}
@-webkit-keyframes moveclouds {
	0% {
		margin-left:110%;
	}
 	100% {
		margin-left:-110%;
	}
}
@-moz-keyframes moveclouds {
	0% {
		margin-left:110%;
	}
	100% {
		margin-left:-110%;
	}
}
@-o-keyframes moveclouds {
	0% {
		margin-left:110%;
	}
100% {
		margin-left:-110%;
	}
}

/*
//////////////////////////////////////////////////
				GRASS
//////////////////////////////////////////////////
*/
.grass {
	background:url(grass.png) bottom center no-repeat;
	height:295px;
	width:100%;
	bottom:0px;
	position:absolute;
}
.cycle {
	/*background:url(cycle-2.png) no-repeat;*/
	width:279px;
	height:260px;
	position:absolute;
	right:0px;
	bottom:-2px;
	
}
.bycycle {
	background:url(cycle-2.png) no-repeat;
	width:279px;
	height:260px;
	position:absolute;
	z-index:1;
}
/*
//////////////////////////////////////////////////
				Cycle Animation Code
//////////////////////////////////////////////////
*/
.cycle-ride {
	-webkit-animation:movecycle 25s ease-in-out infinite;
	-moz-animation:movecycle 25s ease-in-out infinite;
	-o-animation:movecycle 25s ease-in-out infinite;
}
@-webkit-keyframes movecycle {
	0% {
		margin-right:100%;
	}
	100% {
		margin-right:-100%;
	}
}
@-moz-keyframes movecycle {
	0% {
		margin-right:100%;
	}
	100% {
		margin-right:-100%;
	}
}
@-o-keyframes movecycle {
	0% {
		margin-right:100%;
	}
	100% {
		margin-right:-100%;
	}
}

/*
//////////////////////////////////////////////////
				BIRD
//////////////////////////////////////////////////
*/
.bird {
	background:url(birds.png) no-repeat;
	width:376px;
	height:191px;
	position:absolute;
}
/*
//////////////////////////////////////////////////
				BIRD Animation Code
//////////////////////////////////////////////////
*/
.fly {
	-webkit-animation:birdfly 20s ease-in-out infinite;
	-moz-animation:birdfly 20s ease-in-out infinite;
	-o-animation:birdfly 20s ease-in-out infinite;
}
@-webkit-keyframes birdfly {
	0% {
		margin-left:100%;
		top:300px
	}
	20% {
		top:200px;
	}
	40% {
		top:150px;
	}
	50% {
		top:100px;
	}
	60% {
		top:50px;
	}
	70% {
		top:-300px;
	}
	80% {
		top:-50px;
	}
	100% {
		margin-left:-100%;
		top:-70px;
		opacity:.4;
		-webkit-transform:scale(0.4);
		-moz-transform:scale(0.4);
		transform:scale(0.4);
	}
}
@-moz-keyframes birdfly {
	0% {
		margin-left:100%;
		top:300px
	}
	20% {
		top:200px;
	}
	40% {
		top:150px;
	}
	 50% {
		top:100px;
	}
	60% {
	 	top:50px;
	}
	70% {
		top:-300px;
	}
	80% {
		top:-50px;
	}
	100% {
		margin-left:-100%;
	 	top:-70px;
	 	opacity:.4;
	 	-webkit-transform:scale(0.4);
	 	-moz-transform:scale(0.4);
	 	transform:scale(0.4);
	}
}
@-o-keyframes birdfly {
	0% {
		margin-left:100%;
		top:200px
	}
	20% {
		top:150px;
	}
	40% {
		top:100px;
	}
	50% {
		top:500px;
	}
	60% {
		top:0px;
	}
	70% {
		top:-50px;
	}
	80% {
		top:-70px;
	}
	100% {
		margin-left:-100%;
	 	top:-100px;
	 	opacity:.4;
	 	-webkit-transform:scale(0.4);
	 	-mox-transform:scale(0.4);
	 	transform:scale(0.4);
	}
}

.name{
	font-size:30px;
	color: transparent;
	right:20px;
	position:absolute;
	bottom:0px;
	
	-webkit-animation:name 25s ease-in-out infinite;
	-moz-animation:name 25s ease-in-out infinite;
	-o-animation:name 25s ease-in-out infinite;
}

@-webkit-keyframes name {
	0% {
		text-shadow: 0 0 0px rgba(0,0,0,1);
	}
	100% {
		text-shadow: 0 0 10px rgba(0,0,0,0.5);
	}
}
@-moz-keyframes name {
	0% {
		text-shadow: 0 0 0px rgba(0,0,0,1);
	}
	100% {
		text-shadow: 0 0 10px rgba(0,0,0,0.5);
	}
}
@-o-keyframes name {
	0% {
		text-shadow: 0 0 0px rgba(0,0,0,1);
	}
	100% {
		text-shadow: 0 0 10px rgba(0,0,0,0.5);
	}
}





/* Create the animation blocks */


/* Spinning, gradient circle; CSS only! */
.cycle-front, .cycle-back {
  width: 108px;
  height: 107px;
  position:absolute;
  bottom:8px;
  right:8px;

  background:url(wheel-front.png) no-repeat;  
 
  -webkit-animation:spin 3s ease-in-out infinite;
  -moz-animation:spin 3s ease-in-out infinite;
  -o-animation:spin 3s ease-in-out infinite;
 
}

.cycle-back{
	background:url(wheel-back.png) no-repeat;
	bottom:8px;
  	left:8px;
}

@-webkit-keyframes spin {
  from {  
    -webkit-transform: rotate(0deg);  
}  
to {  
    -webkit-transform: rotate(360deg);  
    }  
}
@-moz-keyframes spin {
  from {  
    -moz-transform: rotate(0deg);  
}  
to {  
    -moz-transform: rotate(360deg);  
    }  
}
@-o-keyframes spin {
  from {  
    -o-transform: rotate(0deg);  
}  
to {  
    -o-transform: rotate(360deg);  
    }  
}

Friday, 28 December 2012

Html5 local storage example

Title : Html5 local storage example - a small tutorial.


User can enter the contact details , store the contact details in a table , can modify them, can retrive them and can remove them when he wanted.
Html5 comes with a new feature local storage that can add an item with key value pair and can retrive,modify,delete them when he wants.
Here is the code for the above example.

<!
doctype html>
<
html>
<
head>
<meta charset="utf-8" />
<title>Contacts</title>
<style>
a { color: #0068D2; cursor: pointer; }
a:link, a:visited { text-decoration: none; color: #0068D2; }
a:hover, a:active { text-decoration: underline; color: #0068D2; }
body { font: 12px/18px "Lucida Grande", "Lucida Sans Unicode", sans-serif; }
#contacts-table { border-collapse: collapse; }
#contacts-table, #contacts-table th, #contacts-table td { padding: 8px 16px; text-align: left; border: 0px solid #B9BABE; }
#contacts-table th { font-weight: bold; font-size: 14px; color: #29344B; }
#contacts-table td { color: #000; }
#contacts-table tr:nth-child(2n) { background: #E8EDFF; }
#contacts-form { padding: 10px; }
.text input, .button input { padding: 5px; margin: 0; border: 1px solid #ccc; -moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px; }
#contacts-form .item { margin: 3px 0; }
#contacts-form label, #contacts-form .field { display: inline-block; color: #0C0B07; }
#contacts-form label { width: 110px; font-weight: bold; text-align: right; color: #666; }
#contacts-form .text input { width: 176px; padding: 3px; }
#contacts-form .button { display: inline-block; }
#contacts-form .button-wrapper { padding-left: 113px; }
.button input { padding: 4px 8px; color: #343434; background-color: #fdfdfd; background: -moz-linear-gradient(#fdfdfd, #e1e1e1); background: -webkit-gradient(linear, 0 0, 0 100%, from(#fdfdfd), to(#e1e1e1)); }
.button-default input { font-weight: bold; color: #fff; background-color: #7ca0c7; background: -moz-linear-gradient(#acc6e1, #7ca0c7); background: -webkit-gradient(linear, 0 0, 0 100%, from(#acc6e1), to(#7ca0c7)); border-color: #5b80b2; }
</style>
</
head>
<
body>
<h1>Contacts</h1>
<table id="contacts-table">
<tr id="contacts-head">
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Actions</th>
</tr>
</table>
<form id="contacts-form">
<div class="item text">
<label>First name:</label>
<div class="field"><input type="text" name="first_name" /></div>
</div>
<div class="item text">
<label>Last name:</label>
<div class="field"><input type="text" name="last_name" /></div>
</div>
<div class="item text">
<label>Email:</label>
<div class="field"><input type="text" name="email" /></div>
</div>
<div class="button-wrapper">
<div class="item button">
<div class="field"><input type="button" id="contacts-op-discard" value="Discard" /></div>
</div>
<div class="item button button-default">
<div class="field"><input type="submit" id="contacts-op-save" value="Save" /></div>
</div>
</div>
<input type="hidden" name="id_entry" value="0" />
</form>
<script>
var Contacts = {
index: window.localStorage.getItem(
"Contacts:index"),
$table: document.getElementById(
"contacts-table"),
$form: document.getElementById(
"contacts-form"),
$button_save: document.getElementById(
"contacts-op-save"),
$button_discard: document.getElementById(
"contacts-op-discard"),
init:
function() {
// initialize storage index
if (!Contacts.index) {
window.localStorage.setItem(
"Contacts:index", Contacts.index = 1);
}
// initialize form
Contacts.$form.reset();
Contacts.$button_discard.addEventListener(
"click", function(event) {
Contacts.$form.reset();
Contacts.$form.id_entry.value = 0;
},
true);
Contacts.$form.addEventListener(
"submit", function(event) {
var entry = {
id: parseInt(
this.id_entry.value),
first_name:
this.first_name.value,
last_name:
this.last_name.value,
email:
this.email.value
};
if (entry.id == 0) { // add
Contacts.storeAdd(entry);
Contacts.tableAdd(entry);
}
else { // edit
Contacts.storeEdit(entry);
Contacts.tableEdit(entry);
}
this.reset();
this.id_entry.value = 0;
event.preventDefault();
},
true);
// initialize table
if (window.localStorage.length - 1) {
var contacts_list = [], i, key;
for (i = 0; i < window.localStorage.length; i++) {
key = window.localStorage.key(i);
if (/Contacts:\d+/.test(key)) {
contacts_list.push(JSON.parse(window.localStorage.getItem(key)));
}
}
if (contacts_list.length) {
contacts_list
.sort(
function(a, b) {
return a.id < b.id ? -1 : (a.id > b.id ? 1 : 0);
})
.forEach(Contacts.tableAdd);
}
}
Contacts.$table.addEventListener(
"click", function(event) {
var op = event.target.getAttribute("data-op");
if (/edit|remove/.test(op)) {
var entry = JSON.parse(window.localStorage.getItem("Contacts:"+ event.target.getAttribute("data-id")));
if (op == "edit") {
Contacts.$form.first_name.value = entry.first_name;
Contacts.$form.last_name.value = entry.last_name;
Contacts.$form.email.value = entry.email;
Contacts.$form.id_entry.value = entry.id;
}
else if (op == "remove") {
if (confirm('Are you sure you want to remove "'+ entry.first_name +' '+ entry.last_name +'" from your contacts?')) {
Contacts.storeRemove(entry);
Contacts.tableRemove(entry);
}
}
event.preventDefault();
}
},
true);
},
storeAdd:
function(entry) {
entry.id = Contacts.index;
window.localStorage.setItem(
"Contacts:index", ++Contacts.index);
window.localStorage.setItem(
"Contacts:"+ entry.id, JSON.stringify(entry));
},
storeEdit:
function(entry) {
window.localStorage.setItem(
"Contacts:"+ entry.id, JSON.stringify(entry));
},
storeRemove:
function(entry) {
window.localStorage.removeItem(
"Contacts:"+ entry.id);
},
tableAdd:
function(entry) {
var $tr = document.createElement("tr"), $td, key;
for (key in entry) {
if (entry.hasOwnProperty(key)) {
$td = document.createElement(
"td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement(
"td");
$td.innerHTML =
'<a data-op="edit" data-id="'+ entry.id +'">Edit</a> | <a data-op="remove" data-id="'+ entry.id +'">Remove</a>';
$tr.appendChild($td);
$tr.setAttribute(
"id", "entry-"+ entry.id);
Contacts.$table.appendChild($tr);
},
tableEdit:
function(entry) {
var $tr = document.getElementById("entry-"+ entry.id), $td, key;
$tr.innerHTML =
"";
for (key in entry) {
if (entry.hasOwnProperty(key)) {
$td = document.createElement(
"td");
$td.appendChild(document.createTextNode(entry[key]));
$tr.appendChild($td);
}
}
$td = document.createElement(
"td");
$td.innerHTML =
'<a data-op="edit" data-id="'+ entry.id +'">Edit</a> | <a data-op="remove" data-id="'+ entry.id +'">Remove</a>';
$tr.appendChild($td);
},
tableRemove:
function(entry) {
Contacts.$table.removeChild(document.getElementById(
"entry-"+ entry.id));
}
};
Contacts.init();
</script>
</
body></
html>
I  willl explain the line by line code with in this week so, please follow this blog.