Dec 15, 2012

Website content management system – what is it all about?

CMS or the Content management system, in simple words can be explained as PC
software that helps you to amend, alter, make public and maintain the contents from
the central interface end. Initially CMS was designed with the purpose of simplifying
the complex task of writing codes of various versions and to ease up the development
process more flexible and handy. This type of software helps to manage system that
controls and manages the complete content with the help of a workflow procedure
including a collaborative environment.


CMS


CMS helps to centralize data edit, publish and modify at the single back end interface.
This web CMS technique is best used to be in charge of active set of web materials that
are made available online such as websites, media files and document.


Different types of CMS


We have three major types of Content Management System (CMS) namely, online
processing, offline processing and hybrid systems. These processes are being used
in the implementation procedure to describe the deployment pattern for Web CMS via
presentation templates that provide a structural content pattern for your web page.


Online processing system is all about implementing templates requisite condition.
Usually a web page HTML is being generated during a visitor’s entry or when the
page is being pulled off from web cache. It is known that most of the open source web
content management system has the capability to support add-ons that offers the
required support including blogs, forums, web stores, etc. It’s being referred to as add-
ons, widgets, modules, or extensions with open source of paid license model.


Offline processing system is something that is also termed as static site generators.
Pre-process all the content by implementing the right templates ahead of issuing to
generate your web pages. As pre-processing system does not call for server to make
use of the templates at the right time, they subsist as design-time tools.


Hybrid systems
There are systems where both online and offline techniques are being implemented.
Some systems write their exec codes to move on with dynamic HTML condition where
CMS is not deployed on all servers. While the other types of Hydrid systems are either
offline or online base on the functionality.

Nov 20, 2012

jQuery Form Validation Plugin

If you are developing websites then you will come across Form validation. I too and I was using jQuery Validation plugin. This is an awesome plugin but really buggy in IE7/8 browser with different jQuery versions. Its not stable and the developer of this plugin is not looking after the bugs. I reported several times but no response. So finally I decided to make my own validation plugin.

Before I start further let me tell you that currently this plugin only validates INPUT types with number, email and blank value fields. Its still in beta or under development mode.

GITHUB REPO : https://github.com/nirajmchauhan/jQuery-form-validation





Form-Validation



I ll explain you the usage of this plugin by a simple form example



HTML:



[html]
<section>
<form method="post" class="form-horizontal" id="loginForm" onsubmit="return false;">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" name="user" placeholder="Email" class="required email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" name="password" class="required" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button id="submit" type="submit" class="btn" onclick="javascript:ajaxThrow('#loginForm','#response');">Sign in</button>



</div>
</div>
<div class="alert alert-info" id="response"></div>
</form>
</section>
[/html]




To make a field mandatory, you need to add a class required.
Currently on input types will be accepted so to make if mandatory, use the following attributes :


















class Output
class="required email" This will check for blank field and whether the value is EMAIL ID
class="required number" This will check for blank field and whether the value is a NUMBER
class="required" This field will check for blank values


So now the final is the jQuery:



JS:


[js]
jQuery(function($) {
$(document).ready(function() {

$('#submit').click(function() {
val = $('#loginForm :input').validateForm();
if (val) {
var qstring = $('#loginForm').serialize();
$('#response').fadeIn().html('Form Validated successfully with following fields<br>' + qstring);
}
});

});
});
[/js]




To validate the form, you ll just need to add a line :
val = $('#loginForm :input').validateForm();

This will return a boolean value. And will also add a class error to the respective input field.

Check this in action here :





Oct 4, 2012

iPhone 5 Will Cost You at Least $1,800

You might have heard that

Buy an iPhone 5 From $199
Buy online and get free shipping.
Or visit your favorite Apple Retail Store.

Here's the Info-graphic which shows that iPhone 5 Can Cost You at Least $1,800!


iPhone 5 Infographic

Aug 27, 2012

JQuery Treeview List

JQuery Treeview List - Creates a nice expanding and collapsing tree view control using jQuery.

JQuery Treeview List

Tree view Displays a hierarchical collection of labeled items, each represented by a TreeNode. This you'll normally see in windows or MAC folder navigation.

Today I am making it in JQuery for ul, li list.



Basic HTML Markup


[html]
<ul>
<li><a>First Level</a>
<ul>
<li><a>Second Level</a></li>
<li><a>Second Level</a></li>
<li><a>Second Level</a></li>
</ul>
</li>
<li><a>First Level</a>
<ul>
<li><a>Second Level</a>
<ul>
<li><a>Third Level</a></li>
<li><a>Third Level</a></li>
<li><a>Third Level</a>
<ul>
<li><a>Fourth Level</a></li>
<li><a>Fourth Level</a></li>
<li><a>Fourth Level</a>
<ul>
<li><a>Fifth Level</a></li>
<li><a>Fifth Level</a></li>
<li><a>Fifth Level</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a>Second Level</a></li>
</ul>
</li>
<li><a>First Level</a>
<ul>
<li><a>Second Level</a></li>
<li><a>Second Level</a></li>
</ul>
</li>
</ul>
[/html]

We just created a normal list formation in hierarchical way.



Now lets add some styling - CSS


[css]
.tree {
-moz-border-bottom-colors: none;
-moz-border-image: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background: -moz-linear-gradient(center top , #E3E3E3, #FFFFFF 85px) repeat scroll 0 0 transparent;
border-color: #BFC0C2 #BFC0C2 #B6B7BA;
border-radius: 3px 3px 3px 3px;
border-style: solid;
border-width: 1px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.17), 0 -2px 0 rgba(0, 0, 0, 0.08) inset;
display: inline-block;
margin: 0 0 50px;
min-width: 300px;
padding: 10px 15px 15px;
}
.tree ul {
list-style: none outside none;
}
.tree li a {
line-height: 25px;
}
.tree > ul > li > a {
color: #3B4C56;
display: block;
font-weight: normal;
position: relative;
text-decoration: none;
}
.tree li.parent > a {
padding: 0 0 0 28px;
}
.tree li.parent > a:before {
background-image: url("../images/plus_minus_icons.png");
background-position: 25px center;
content: "";
display: block;
height: 21px;
left: 0;
position: absolute;
top: 2px;
vertical-align: middle;
width: 23px;
}
.tree ul li.active > a:before {
background-position: 0 center;
}
.tree ul li ul {
border-left: 1px solid #D9DADB;
display: none;
margin: 0 0 0 12px;
overflow: hidden;
padding: 0 0 0 25px;
}
.tree ul li ul li {
position: relative;
}
.tree ul li ul li:before {
border-bottom: 1px dashed #E2E2E3;
content: "";
left: -20px;
position: absolute;
top: 12px;
width: 15px;
}
[/css]


In css we are making tree nodes usinf :before

Last we will add jquery functionality to toggle the list on click events.



JQuery


[js]
$('.tree li').each(function(){
if($(this).children('ul').length > 0){
$(this).addClass('parent');
}
});

$('.tree li.parent > a').click(function(){
$(this).parent().toggleClass('active');
$(this).parent().children('ul').slideToggle('fast');
});
[/js]

Here first we search for all parent nodes and if found then we are adding a class named as .parent

Then on click of any parent elements, we just add a class .active and slide the li's in it.

This can be used to show the navigation of the website.

Aug 23, 2012

Collection of Special iPhone Meta Tags

I am not an iPhone developer nor a user but just found some special meta tags for developing iPhone webapps and iPhone prove websites. Hope this helps you.
 
Disable horizontal scrolling


[html]
<meta name="viewport" content="width=device-width, user-scalable=no" />
[/html]


  
When bookmarked the website runs in fullscreen, like a normal App.


[html]
<meta name="apple-mobile-web-app-capable" content="yes" />
[/html]


  
When bookmarked as fullscreen, set the color of the status bar


[html]
<meta name="apple-mobile-web-app-status-bar-style" content="black">
[/html]


  
When bookmarked, add an 57x57 Icon and the iPhone will add the shiny effect itself.


[html]
<link rel="apple-touch-icon" href="icon.png" />
[/html]


  
Prefer non glossy Icon or made the gloss yourself? Precomposed stops from adding the gloss on bookmarks


[html]
<link rel="apple-touch-icon-precomposed" href="icon" />
[/html]


  
Remove auto-recognition of Phone numbers


[html]
<meta name="format-detection" content="telephone=no">
[/html]


  
Forces the iPhone to use a number pad


[html]
<input type="number">
[/html]


  
Guess what? A phone number keypad


[html]
<input type="tel">
[/html]


  
Keyboard optimized for typing urls.


[html]
<input type="url">
[/html]


 

Credits : Robert

Aug 16, 2012

Forrst Invites Giveaway | CLOSED

Forrst.com A website for designers and also for developers. Here you will find a great resource of Web Development. Its a community where a developer and designers improve thier craft. Its just a invite based website so that only real people enter it.

Forrst

So you want it???? Then

  • Comment your latest or best work below with your actual EMAIL ID(Design or Development or both - Mandatory)

  • Share this post on twitter and other social sites(Advantage)


And just wait for results. I have total 2 invites so hurry up!!!

Results will be announced on 22 Aug 2012

 




We have selected two winners. TRAVIS and SUMON SELEEM Congratulations and welcome to forrst

Aug 8, 2012

Wordpress Bloginfo Shortcode

A small snippet for Wordpress Bloginfo. This will help you to add images directly without giving the entire path. Its a shortcode snippet

[php]
function get_bloginfo_shortcode( $atts ) {
extract(shortcode_atts(array(
'info' => '',
), $atts));
return get_bloginfo($info);
}
add_shortcode('bloginfo', 'get_bloginfo_shortcode');
[/php]

Usage :

[html]
<img src="[bloginfo info='template_url']/images/logo.jpg" alt="[bloginfo info='name'] logo" />
[/html]

Now you can easily call your images without giving actual path.

Credits Forrst

Aug 2, 2012

CSS3 Visiting Card 3D Transform

My friend Asif made a nice design on visiting card, so I decided to convert that into a 3D flipping Visiting Card

CSS3 Visiting Card

To rotate a div with 3D transform :-

  • transform-style: preserve-3d;

  • perspective: 800px;

  • transform: rotateY(180deg);

  • backface-visibility: hidden;


After setting the above CSS a div will transform.




Final Product

Visiting Card Front-Back

Visiting Card Back-Front




So lets start




[html]
<div id="card">
<div class="front">
<div class="strips">
<p class="strip red"></p>
<p class="strip orange"></p>
<p class="strip green"></p>
<p class="strip blue"></p>
<p class="strip lOrange"></p>
</div>
<div class="businessName">
Webs Tutorial
</div>
</div>
<div class="back">
<div class="strips">
<p class="strip red"><span>www.webstutorial.com</span></p>
<p class="strip orange"><span>Mumbai, India</span></p>
<p class="strip green"></p>
<p class="strip blue"><span>PHP, HTML5, CSS3</span></p>
<p class="strip lOrange"><span>niraj@webstutorial.com</span></p>
</div>
<div class="myName">
<p>Niraj Chauhan</p>
Developer
</div>
</div>
</div>
[/html]




Above we made a parent div and inside that two divs, one will be the front side and another will be the backside. When we :hover on the front facing div, it rotates in Y axis. As we have set the transform style to preserve-3d it will maintain its view and the transform will be displayed in 3D.




[css]
@font-face {
font-family: roboto;
src: url('../Roboto-Regular.ttf');
}

* {
font-family: roboto !important;
}

.container {
position: relative;
}

#card {
position: absolute;
z-index: 11;
-webkit-perspective: 800px;

-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
left: 30%;
}

#card .front,#card .back {
background: #000;
width: 480px;
height: 205px;
display: block;
position: absolute;
color: #fff;
border-radius: 8px;

-webkit-transition: -webkit-transform 1s ease-in-out;
-moz-transition: -moz-transform 1s ease-in-out;
-o-transition: -o-transform 1s ease-in-out;
-ms-transition: -ms-transform 1s ease-in-out;
transition: transform 1s ease-in-out;
}

#card .front {
-webkit-transform: rotateY(0deg);
-moz-transform: rotateY(0deg);
-o-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
transform: rotateY(0deg);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
z-index: 13;
}

#card:hover .front {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}

#card .back {
-webkit-transform: rotateY(-180deg);
-moz-transform: rotateY(-180deg);
-o-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
transform: rotateY(-180deg);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
z-index: 12;
background: #000;
}

#card:hover .back {
-webkit-transform: rotateY(0deg);
-moz-transform: rotateY(0deg);
-o-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
transform: rotateY(0deg);
z-index: 14;
}

/* Front Strips */
.strips {
clear: both;
margin: 0 auto;
position: relative;
width: 125px;
}

.strip {
float: left;
height: 140px;
margin-right: 12px;
position: relative;
width: 12px;
font-family: roboto;
}

.red {
background: #b70000;
color: #b70000;
border: 1px solid #890000;
border-top: 0px;
}

.orange {
background: #f25d07;
color: #f25d07;
border: 1px solid #b64605;
border-top: 0px;
}

.green {
background: #a69e33;
color: #a69e33;
border: 1px solid #837726;
border-top: 0px;
}

.blue {
background: #0092b2;
color: #0092b2;
border: 1px solid #006e86;
border-top: 0px;
}

.lOrange {
background: #ee913f;
color: #ee913f;
margin: 0 !important;
border: 1px solid #b36d2f;
border-top: 0px;
}

.businessName {
clear: both;
font-family: roboto;
font-size: 22px;
padding: 5px 0 0;
text-align: center;
}

/* Back strips */
.back .red {
height: 70px;
}

.back .orange {
height: 100px;
}

.back .green {
height: 140px;
}

.back .blue {
height: 100px;
}

.back .lOrange {
height: 70px;
}

.strip span {
position: absolute;
font-size: 15px;
}

.red span {
left: -162px;
top: 50px;
}

.orange span {
left: -102px;
top: 80px;
width: 100px;
}

.green span {
left: 0;
}

.blue span {
left: 20px;
top: 80px;
width: 140px;
}

.lOrange span {
left: 18px;
top: 50px;
}

.myName {
clear: both;
color: #999999;
font-family: roboto;
font-size: 20px;
padding: 0;
text-align: center;
}

.myName p {
color: #a69e33;
}

#designedBy {
border-radius: 5px 0 0 0;
bottom: 0;
color: #FFFFFF;
min-height: 10px !important;
padding: 10px;
position: fixed;
right: 0;
}
[/css]




Now in CSS we set the backface-visibility: hidden;. With this property the backside of the card will be hidden. When we hover on the front face of the card with the help of css transition we flip the card and now the backside of the card will be visible.

When we move away over mouse from the card it turns back to its original position.This way a 3D flip can be done using CSS3.

Now the latest Firefox also supports the 3D Transform. Previously it was only working on webkit browsers

Jul 25, 2012

AJAX Contact Form With Validation

Today I am going to share a simple tutorial on How to make a AJAX contact form with validation.

JQUERY-AJAX



What is AJAX?
AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.


The flow of the form is :


AJAX Process Diagram

So here I am using twitter bootstrap, so files which we need are :-

  • data.php - (here we will write our PHP code)

  • script.js - (here we will write our ajax jquery code)

  • validate.js - (jqueryvalidation plugin)

  • index.php and style.css



So the fields of our form will be Name, Email, Number, City, Area, Message, Submit

Here our city and area will also be using AJAX i.e. on city change area will also be changed.

index.php


[html]
<?php require_once('data.php'); ?>
<div class="hero-unit">
<h2>Contact Us</h2>

<form id="contactUs" name="contactUs" onsubmit="return false;">


<table cellspacing="5" cellpadding="5">
<tr>
<td><label for="name">Name:</label></td>
<td><input type="text" value="" name="name" id="name" class="required name"/></td>
</tr>
<tr>
<td><label for="email">Email:</label></td>
<td><input type="text" value="" name="email" id="email" class="required email"/></td>
</tr>
<tr>
<td><label for="number">Contact Number:</label></td>
<td><input type="text" value="" name="number" id="number" class="required number" minlength="8"/></td>
</tr>
<tr>
<td><label for="city">City:</label></td>
<td>
<select id="city" name="city" onchange="javascript:changeArea('#city', '#area');">
<option value="Any">Any</option>
<?php echo getCities();?>
</select>
</td>
</tr>
<tr>
<td><label for="area">Area:</label></td>
<td><select id="area" name="area" disabled="disabled"></select></td>
</tr>
<tr>
<td><label for="message">Message:</label></td>
<td><textarea id="message" name="message" class="required"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="contactFormSubmit" value="Yes" />
<input type="submit" value="Submit" class="btn" onclick="javascript:formSubmit('#contactUs','#responseText');"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<div id="responseText"></div>
</td>
</tr>

</form>
</div>
[/html]



Here we just made a simple html structure of form inside a table.

To make a field mandatory, just add class="required" to input.

If you want to validate it with only email or number then add class="required email" or class="required number"

If I add a attribute minlength="8" to the number field then that field should contain at least 8 digits of number.

data.php


[php]
<?php
$cities = array('1'=>'Mumbai',
'2'=>'Chennai',
'3'=>'Noida',
'4'=>'Bangalore');

$areas = array( 'Airoli' => '1',
'Andheri' => '1',
'Bandra' => '1',
'Bhandup' => '1',
'Bhayandar' => '1',
'Boisar' => '1',
'Borivali' => '1',
'Chembur' => '1',
'Gopalapuram' => '2',
'Mount Road' => '2',
'Noida Expressway' => '3',
'Sector 1' => '3',
' Sector 128' => '3',
'Sector 129' => '3',
'Yamuna Expressway' => '3',
'Anekal ' => '4',
'Banashankari ' => '4',
'Banasvadi ' => '4',
'Banaswadi ' => '4',
'Begur ' => '4',
'Bellary Road ' => '4',
'Dobespet ' => '4',
'Electronics City' => '4');


if(isset($_REQUEST['cityID']) && $_REQUEST['cityID'] != 'Any'){

getAreas($_REQUEST['cityID']);

}

if(isset($_REQUEST['contactFormSubmit'])){
if(!isValidEmail($_REQUEST['email'])){
echo 'Enter a valid email ID';
}elseif(!is_mobileNumber($_REQUEST['number'])){
echo 'Enter a valid number';
}elseif($_REQUEST['name'] == '' || $_REQUEST['message'] == ''){
echo 'Enter valid name or message';
}else{
?>
<p><b>Thank you for contacting us, your given information : </b></p>
<table cellspacing="5" cellpadding="5" border="1">
<tr>
<td>Name:</td>
<td><?php echo $_REQUEST['name']?></td>
</tr>
<tr>
<td>Email:</td>
<td><?php echo $_REQUEST['email']?></td>
</tr>
<tr>
<td>Contact Number:</td>
<td><?php echo $_REQUEST['number']?></td>
</tr>
<tr>
<td>City:</td>
<td><?php echo $_REQUEST['city']?></td>
</tr>

<?php if(isset($_REQUEST['area'])) : ?>
<tr>
<td>Area:</td>
<td><?php echo $_REQUEST['area']?></td>
</tr>
<?php endif; ?>

<tr>
<td>Message:</td>
<td><?php echo $_REQUEST['message']?></td>
</tr>
</table>
<?php
}
}



function getCities(){
global $cities;
foreach($cities as $Idx => $city){

echo '<option value="'.$Idx.'">'.$city.'</option>';

}
}

function getAreas($cityID = ''){
global $areas;
foreach($areas as $area => $Idx){

if($Idx == $cityID){

echo '<option value="'.$Idx.'">'.$area.'</option>';

}

}
}

function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

function is_mobileNumber($mobile) {
$regex1 = '123456789';
$regex2 = '1234567890';
$regex3 = '0123456789';

if(preg_match('/^([0-9])\1*$/', $mobile)){
return false;
}elseif($mobile == $regex1){
return false;
}elseif($mobile == $regex2){
return false;
}elseif($mobile == $regex3){
return false;
}elseif(preg_match("/[^0-9]/", $mobile)){
return false;
}else{
return true;
}
}
?>
[/php]



PHP code is simple, I am making an array of cities and area, made 2 functions to get areas and cities and getting the parameters from URL and passing it to functions.

Now the ajax function :

script.js


[js]
function changeArea(cityBox, areaBox) {
jQuery(function($) {

$(areaBox).attr('disabled','disabled');

$(areaBox).addClass('loading');
$.ajax({ //Starting the AJAX
url : 'data.php', //File to be called or pass the data
data : { //Extra paramters
"cityID" : $(cityBox+' option:selected').attr('value')
},
success : function(data) { // The result from data.php file comes as data
window.setTimeout(function(){
$(areaBox).removeAttr('disabled');

$(areaBox).removeClass('loading');

$(areaBox).html('');

$(areaBox).html(data);

}, 2000);
}
});
});
}
[/js]



The above function is is taking two parameters, the select id of City and area. Then I am saving the value of city in a variable, and inside ajax I am passing the value of city to data.php file.

Inside data.php I wrote a function to return areas according to the city ID. Inside success function I am inserting entire result into the area select box.

Simlarly I am going to make another function which will validate the form and if no error then ajax is called and mail is sent.

script.js


[js]
/* Submission of form */

function formSubmit(formID, displayMssgID) {
jQuery(function($) {

var qstring = $(formID).serialize();

var val = $(formID).validate().form();
if (val) {
$(displayMssgID).html('Registering your Request ... Please Wait ...');
$.ajax( {
url : "data.php",
data : qstring,
success : function(data) {

$(displayMssgID).html('');
$(displayMssgID).html(data);
window.setTimeout(function() {

$(displayMssgID).fadeOut();

}, 6000);

}
});
}
});
}
[/js]



This function takes two parameters, ID of the form and result message div. First I am serializing the form, which will take all the form data and store it in a variable. Then I am validating it, if validation is true then our AJAX is called and entire form data is passed to data.php file.

This is return will give some output which I am showing it in id="responseText"

This is a simple way to make AJAX forms, there might be many other tutorials on other websites but I find this very simple. This way you can make any AJAX form. Try out the demo.



Thanks to Jacob for server validation tip.

Jul 18, 2012

JQuery Allow Only Numbers

For a frontend developer when it is asked to do something unique that person will think of JQuery first. Today a simple jquery code to allow only numbers to a text-box. Below code will allow following key events :


  • Backspace

  • Delete

  • Tab

  • Escape

  • Enter

  • Ctrl+A

  • Home

  • end

  • left

  • right



Just add a class to textbox .onlyNumbers and paste the following jquery code :



[js]
$(document).ready(function() {

$(".onlyNumbers").keydown(function(event) {

if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || (event.keyCode == 65 && event.ctrlKey === true) || (event.keyCode >= 35 && event.keyCode <= 39)) {
return;
}
else {

if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
event.preventDefault();
}
}
});

});
[/js]



You can also apply this to textarea.

Demo:





Jul 11, 2012

Simple JQuery Tabs

JQuery tabs. Whenever I start any new project tabs is something which I have to use, so instead of using any external js library I created a small function.

JQuery Tabs



[html]
<div id="tabs">
<div class="divTabs"> <!-- divTabs class is important, this will be passed in function -->
<div id="tab_menu_1" class="tab selected first">PHP</div>
<div id="tab_menu_2" class="tab last">JQUERY</div>
</div>
<div class="divTabs-container">
<div id="divTabs_tab_content_1" class="tabcontent" style="display:block;">Content 1</div>
<div id="divTabs_tab_content_2" class="tabcontent">Content 2</div>
</div>
</div>
[/html]



First we are creating a div with a class name, this class name is really important. This class name will be passed in entire tabs, just check the class naming of the div in the above html. It is prefixed with other classes.

CSS is simple just make the .tabcontent{display:none;}

Now time for js function



[js]
function generateTabs(element) {
jQuery(function($) {
$("."+element+" .tab[id^=tab_menu]").click(function() {
var currentDiv=$(this);
$("."+element+" .tab[id^=tab_menu]").removeClass("selected");
currentDiv.addClass("selected");
var index=currentDiv.attr("id").split("tab_menu_")[1];
$("."+element+"-container .tabcontent").css('display','none');
$("."+element+"-container #"+element+"_tab_content_"+index).fadeIn();
});
});
}
[/js]



Now call this function by passing the classname.
generateTabs('divTabs');

Check the demo below




Jul 3, 2012

HTML5 Air Hockey Game Using Canvas

Air Hockey, my first HTML5 game

In this tutorial you will be learning the importance of canvas tag.


The canvas element is part of HTML5 and allows for dynamic, scriptable rendering of 2D shapes and bitmap images. It is a low level, procedural model that updates a bitmap and does not have a built-in scene graph.


Working : A puck(ball) will be freely moving in the table, we just need to stop it from touching the horizontal sides of table by using two mallets.

Let's break our game into pieces, which will help us to code easily. We will be using following javascripts

  • jquery.hotkeys.js - Helps for keyboard events

  • key_status.js - Helps to call required event for our game

  • util.js - Helps to define the mallet position

  • game.js - Our main file which will contain the game functionality



First we will make the canvas in our HTML document.



[html]
<canvas id="canvas" width="480" height="320" tabindex="1"></canvas>
[/html]



Now javascript - game.js


[js]
var canvasElement = document.getElementById("canvas");
var canvas = canvasElement.getContext("2d");

var canvas_width = canvasElement.width;
var canvas_height =canvasElement.height;
var botX = 2;
var botY = 2;
var mx = 2;
var my = 4;
var points = 0;

var init = {};
var FPS = {};

FPS.set = 30;
[/js]



Above, first we created a canvas in our HTML document, and then in game.js we are initializing it, storing its height and width in a variable, declaring some more constant variables.

Let's make our players(mallets) and our ball(puck).



[js]
var player = {
color: "#000",
x: 220,
y: 310,
width: 50,
height: 10,
draw: function() {
canvas.fillStyle = this.color;
canvas.fillRect(this.x, this.y, this.width, this.height);
}
};

var player2 = {
color: "#000",
x: 220,
y: 0,
width: 50,
height: 10,
draw: function() {
canvas.fillStyle = this.color;
canvas.fillRect(this.x, this.y, this.width, this.height);
}
};

var ball = {
x : 2,
y : 2,
r : 5,
draw: function() {
canvas.beginPath();
canvas.arc(this.x, this.y, this.r, 0, Math.PI*2, true);
canvas.fill();
}

};
[/js]



We are defining player1 and player2 and setting its height, width, default position and finally giving it a shape.

HTML5 Air hockey

At this stage if you run the code then you will just find a blank canvas element with no players and no ball. Because we just created the players and ball, we have not set them to do something in canvas. So let's do that now.




[js]

init.interval = setInterval(function(){
update();
draw();
}, 1000/FPS.set);


function update() {
if (keydown.left) {
player.x -= 5;
player2.x -= 5;
}

if (keydown.right) {
player.x += 5;
player2.x += 5;
}

player.x = player.x.clamp(0, canvas_width - player.width);

player2.x = player.x.clamp(0, canvas_width - player.width);

}

function draw() {
canvas.clearRect(0, 0, canvas_width, canvas_height);
player.draw();
player2.draw();
ball.draw();

}
[/js]



Now if you run the file then you'll find that in our canvas a ball and two players will present. If you try to press left and right arrow players will move left/right.

HTML5 Air hockey

In our init() function we call two functions draw() and update() in interval. Update function is used to check any movements or changes in our canvas and it sets the value of players and ball. Draw function will take those values and draw it on canvas.

So if suppose you pressed left arrow once, the update function will take the X position of the player, it will update the new position in the player parameters.

Then the draw function will take the new value from player's parameters and then it will update the canvas, so it appears that the player is actually moving.

And also we are limiting our players to go outside the canvas. We use clamp function to check whether the player has touched the boundaries of the canvas.

Now let's move the ball.



[js]
function draw() {
canvas.clearRect(0, 0, canvas_width, canvas_height);
player.draw();
player2.draw();
ball.draw();

if (ball.x + mx > canvas_width || ball.x + mx < 0){
mx = -mx;
}
if (ball.y + my > canvas_height || ball.y + my < 0){
my = -my;
}

ball.x += mx;
ball.y += my;

}

[/js]



We updated our draw function. Here we use if-else conditions to check the position of the ball. If its touching the boundary then throw it back. mx and my are the variables which helps the ball to give X, Y position. And with its help we change the X, Y co-ordinates of the ball every time.

Now if you run the code, the ball will be moving.

HTML5 Air hockey

But it won't be reacting with the players. Now we will update our draw function one more time to check whether our ball is colliding with player1 or player2.



[js]

function collides(a, b) {
if(a.y == b.y || a.y <= b.height){
if(a.x >= b.x && a.x <= b.x+b.width){
return true;
}else{
return false;
}
}

}

function draw() {
canvas.clearRect(0, 0, canvas_width, canvas_height);
player.draw();
player2.draw();
ball.draw();

if (collides(ball, player)) {

my = -my;

}else if (collides(ball, player2)) {

my = +my;

}else
{
if (ball.x + mx > canvas_width || ball.x + mx < 0){
mx = -mx;
}
if (ball.y + my > canvas_height || ball.y + my < 0){
my = -my;
}


}

ball.x += mx;
ball.y += my;

}


[/js]



As you can see we have created one more function collides(), which takes two parameters. In our draw function we are checking whether ball and player1, ball and player2 are colliding with each other. In our collides() function we are checking position of ball and players. If it returns true, then we change the mx and my value.

Now try running the game again, when the ball hits the players it will return back.

HTML5 Air hockey

Last we will code the game over section. If the ball touched the horizontal boundary of canvas then we end our game.



[js]
function gameOver(){
canvas.fillStyle = '#000';
canvas.font = '18px verdana';
canvas.textBaseline = 'top';
canvas.fillText('Game Over, refresh the page to restart game', 50, 150);

clearInterval(init.interval);

$('#level').removeAttr('disabled');
}

if (ball.y + my > canvas_height || ball.y + my < 0){
my = -my;
gameOver();
}
[/js]



We call gameover() function in our draw function. With help of clearInterval() function we stop the game.


HTML5 Air hockey


So this was the basic game, it can't be completely called Air Hockey but after creating it I found that word to be the best. Still there are many bugs. I just started learning HTML5 and this was my first attempt on a game. You can download this from github, suggestions are always welcomed and fork me if you liked it.

JQuery Slide Left Right | JQuery Toggle Left Right

Recently I completed a project where I had to show a panel to the left side using JQuery, on mouse hover it comes out and on mouse leave it goes back. Its seems to be easy but to maintain the functionality is not that easy.

Here's a small snippet on how to do it.

HTML


[html]
<div id="sidePanel">
<div id="panelContent">
<iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FWebsTutorial&amp;width=200&amp;height=258&amp;colorscheme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false&amp;appId=253401284678598" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:258px;" allowTransparency="true"></iframe>
</div>
<div id="panelHandle">
<p>Facebook</p>
</div>

</div>
[/html]




JQuery


[js]
jQuery(function($) {
$(document).ready(function() {
$('#panelHandle').hover(function() {
$('#sidePanel').stop(true, false).animate({
'left': '0px'
}, 900);
}, function() {
jQuery.noConflict();
});

jQuery('#sidePanel').hover(function() {
// Do nothing
}, function() {

jQuery.noConflict();
jQuery('#sidePanel').animate({
left: '-201px'
}, 800);

});
});
});
[/js]



Demo :





Jun 27, 2012

How to create a module in Drupal 7.x

What is a module in Drupal?
A module is nothing but a collection of functions that links into Drupal, providing all the additional functionality/behaviour for your Drupal installation or your Drupal site. After reading this tutorial, you will be able to create a basic block module and use it as a template for more advanced modules.


Things to be remember before we start:
This tutorial will not necessarily prepare you to write modules for public release it will only give you a step by step integration reagarding "How to create a module!". It does not cover caching, nor does it elaborate on permissions or security issues but you can simply use this tutorial as your starting point and extend your skills with other resources.


Our tutorial assumes you have:



  • Basic PHP knowledge, including syntax and the concept of PHP objects

  • Basic understanding of database tables, fields, records and SQL statements

  • A working Drupal 7 installation

  • Drupal administration access

  • Webserver access


Our tutorial does not assume you have any knowledge about the inner workings of a Drupal module.


Getting started


In this tutorial we'll create a module that lists links to content such as blog entries or forum discussions that were created recently (within the last week). This page in the tutorial describes how to create the initial module file and directory.


Name your module


The first step in creating a module is to choose a "short name" for it. This short name will be used in all file and function names in your module, so it must start with a letter, and it must contain only lower-case letters and underscores. For this example, we'll choose "current_posts" as the short name. Important note: Be sure you follow these guidelines and do not use upper case letters in your module's short name, since it is used for both the module's file name and as a function prefix. When you implement Drupal "hooks" (see later portions of tutorial), Drupal will only recognize your hook implementation functions if they have the same function name prefix as the name of the module file.


It's also important to make sure your module does not have the same short name as any theme you will be using on the site.


Create a folder and a module file


Given that our choice of short name is "current_posts" :



  1. Start the module by creating a folder in your Drupal installation at the path:

    • sites/all/modules/custom/current_posts



  2. Create the PHP file for the module :

    • Save it as current_posts.module in the directory sites/all/modules/custom/current_posts

    • As of Drupal 6.x, sites/all/modules is the preferred place for non-core modules (and sites/all/themes for non-core themes), because this places all site-specific files in the sites directory. This allows you to more easily update the core files and modules without erasing your customizations. Alternatively, if you have a multi-site Drupal installation and this module is for only one specific site, you can put it in sites/your-site-folder/modules.



  3. Add an opening PHP tag to the module :


    • <?php


    • Module files begin with the opening PHP tag. Do not place the CVS ID tag in your module. It is no longer needed with drupal.org's conversion to Git. If the coder module gives you error messages about it, then that module has not yet been updated to drupal.org's Git conventions.




The module is not operational yet: it hasn't been activated. We'll activate the module later in the tutorial.


Coding standards


As per the Coding standards, omit the closing ?> tag. Including the closing tag may cause strange runtime issues on certain server setups. (Note that the examples in documentation will show the closing tag for formatting reasons only and you should not include it in your real code.)


Telling Drupal about your module


All modules must have a 'modulename.info' file, which contains meta information about the module.


The general format is:


[php]name = Module Name<br />
description = A description of what your module does.<br />
core = 7.x[/php]



For our module, we will replace 'Module Name' in the example above with the name of our module, 'Current Posts'. Without this file, the module will not show up in the module listing. Here is our specific example:


[php]name = Current Posts<br />
description = A block module that lists links to recent posts.<br />
core = 7.x[/php]



Add the source above to a file named current_posts.info and save it into the module's directory at sites/all/modules/current_posts.


Note: If you copy and paste this code block, ensure that the description data does not contain a line break (turn off word-wrap on your text-editor to be sure). Otherwise, the .info file will not parse correctly.


.Info File Details


The details of what to put in a .info file can be found on the Writing .info files page.


Comments in Drupal modules


It's always a good idea to document how your module works in comments. Drupal uses Doxygen to draw documentation from source code, so contrib modules on drupal.org follow strict comment guidelines. See Doxygen and comment formatting conventions for more details. Following these guidelines is beneficial to anyone looking at your code even if it's not strictly necessary for your situation.


Your first comment:


[php]&lt;?php<br />
/**<br />
* @file<br />
* A block module that displays recent blog and forum posts.<br />
*/<br />
?&gt;[/php]



@file signifies that this comment pertains to the entire file. The doc block begins with a slash and two asterisks (/**) and ends with one asterisk and a slash (*/). Following Drupal guidelines, we will introduce each function in the module with such a comment.


Implementing your first hook


Hooks are fundamental to Drupal modules. They allow you to integrate your module into the actions of Drupal core.


[php]&lt;?php<br />
&lt;div&gt;<br />
&lt;pre&gt;function current_posts_help($path, $arg) {</p>
<p>}<br />
?&gt;[/php]


 


[php]&lt;?php<br />
/**<br />
* Implements hook_help.<br />
*<br />
* Displays help and module information.<br />
*<br />
* @param path<br />
*   Which path of the site we're using to display help<br />
* @param arg<br />
*   Array that holds the current path as returned from arg() function<br />
*/<br />
function current_posts_help($path, $arg) {<br />
switch ($path) {<br />
case &quot;admin/help#current_posts&quot;:<br />
return '&lt;p&gt;'.  t(&quot;Displays links to nodes created on this date&quot;) .'&lt;/p&gt;';<br />
break;<br />
}<br />
}<br />
?&gt;[/php]


(Note the closing ?> should not appear in your code.)


Declaring the block


To use this hook to define our block, go to your current_posts.module file and create the function current_posts_block_info() as follows:


[php]&lt;?php<br />
/**<br />
* Implements hook_block_info().<br />
*/<br />
function current_posts_block_info() {<br />
$blocks['current_posts'] = array(<br />
'info' =&gt; t('Current posts'), //The name that will appear in the block list.<br />
'cache' =&gt; DRUPAL_CACHE_PER_ROLE, //Default<br />
);<br />
return $blocks;<br />
}<br />
?&gt;[/php]



(Remember not to include the closing ?> in your code.)


Retrieving data


The function begins with getting the time numbers. Here's the first part:


[php]&lt;?php<br />
/**<br />
* Custom content function.<br />
*<br />
* Set beginning and end dates, retrieve posts from database<br />
* saved in that time period.<br />
*<br />
* @return<br />
*   A result set of the targeted posts.<br />
*/<br />
function current_posts_contents(){<br />
//Get today's date.<br />
$today = getdate();<br />
//Calculate the date a week ago.<br />
$start_time = mktime(0, 0, 0,$today['mon'],($today['mday'] - 7), $today['year']);<br />
//Get all posts from one week ago to the present.<br />
$end_time = time();<br />
?&gt;[/php]




Next we use Drupal's Database API to retrieve our list of current nodes. This is the second part of the custom function:


[php]&lt;?php<br />
//Use Database API to retrieve current posts.<br />
$query = db_select('node', 'n')<br />
-&gt;fields('n', array('nid', 'title', 'created'))<br />
-&gt;condition('status', 1) //Published.<br />
-&gt;condition('created', array($start_time, $end_time), 'BETWEEN')<br />
-&gt;orderBy('created', 'DESC') //Most recent first.<br />
-&gt;execute();<br />
return $query;<br />
}<br />
?&gt;[/php]



  1. We build the query using the db_select method, which takes a table name ('node') and alias ('n') as arguments.

  2. The fields method uses the table assigned the alias 'n' to select the fields listed in the array in the second argument.

  3. The condition method takes three arguments. The first is the field, the second the value, the third the operator. If no operator is specified, as in 'status' above, = is assumed.

  4. The orderBy method sorts according to the field in the first argument, in the order specified by the second argument.

  5. The execute method compiles and runs the query and returns a result set/statement object.


Here's the complete function:


[php]&lt;?php<br />
/**<br />
* Custom content function.<br />
*<br />
* Set beginning and end dates, retrieve posts from database<br />
* saved in that time period.<br />
*<br />
* @return<br />
*   A result set of the targeted posts.<br />
*/<br />
function current_posts_contents(){<br />
//Get today's date.<br />
$today = getdate();<br />
//Calculate the date a week ago.<br />
$start_time = mktime(0, 0, 0,$today['mon'],($today['mday'] - 7), $today['year']);<br />
//Get all posts from one week ago to the present.<br />
$end_time = time();</p>
<p>//Use Database API to retrieve current posts.<br />
$query = db_select('node', 'n')<br />
-&gt;fields('n', array('nid', 'title', 'created'))<br />
-&gt;condition('status', 1) //Published.<br />
-&gt;condition('created', array($start_time, $end_time), 'BETWEEN')<br />
-&gt;orderBy('created', 'DESC') //Most recent first.<br />
-&gt;execute();<br />
return $query;<br />
}<br />
?&gt;[/php]



(Remember not to include the closing ?> in your code.)


Generating block content


Access check


Here's the first part of the code:


[php]&lt;?php<br />
function current_posts_block_view($delta = '') {<br />
switch($delta){<br />
case 'current_posts':<br />
$block['subject'] = t('Current posts');<br />
if(user_access('access content')){<br />
//Retrieve and process data here.<br />
}<br />
?&gt;[/php]






Coding the data as links


Here's the next bit of code:


[php]&lt;?php<br />
//Use our custom function to retrieve data.<br />
$result = current_posts_contents();<br />
//Array to contain items for the block to render.<br />
$items = array();<br />
//Iterate over the resultset and format as links.<br />
foreach ($result as $node){<br />
$items[] = array(<br />
'data' =&gt; l($node-&gt;title, 'node/' . $node-&gt;nid),<br />
);<br />
}<br />
?&gt;[/php]






Theming the data


Here's the last section of code for current_posts_block_view:


[php]&lt;?php</p>
<p>if (empty($items)) { //No content in the last week.<br />
$block['content'] = t('No posts available.');<br />
} else {<br />
//Pass data through theme function.<br />
$block['content'] = theme('item_list', array(<br />
'items' =&gt; $items));<br />
}<br />
}<br />
}<br />
return $block;<br />
}<br />
?&gt;[/php]





The Final Steps


Testing and troubleshooting the module


It's time to enable and fully test your module!


Enable the module


Go to Modules, or http://example.com/admin/modules, and scroll down to the bottom of the list in the 'Other' category. You should see the module 'Current posts.' Click the checkbox to enable Current posts, and save your configuration. Now you should see a link to Help beside the module name. Click it to see the help text you entered in current_posts_help.


Enable the block


Next, navigate to Structure > Blocks, or http://example.com/admin/structure/block. Scroll down to the bottom of the list. Among the disabled blocks, you should find the name, 'Current posts'. Set its location for one of the page regions and save. Navigate to another page like your homepage to see your block. Congratulations! You have written a working module.


Troubleshooting


If you get a "white screen" or a PHP error when you enable this module, it probably means you have a syntax error in your .module file. Be sure all your punctuation is correct, semi-colons, commas, etc. all in the right places, and that you have all the hook names and module short names spelled correctly. (In the case of a white screen, you may be able to find out what the PHP error was by looking in your Apache error log. Or you can try changing PHP's error reporting level.)


If you cannot find and fix the syntax error, nothing on your site will display, because Drupal will try to load your module on every page request. The easiest way to get your site working again is to delete the module's folder or move it out of the site, in which case Drupal will figure out that it shouldn't load this module after all, and your site should work again.


Clear caches


Drupal caches a lot of data, and if you are not seeing changes appear, that could be why. In this phase of the module, the caches shouldn't be an issue, but they will be as we proceed. To get all the troubleshooting instructions in one place, we'll give you the instructions here that you'll need later.


To clear the caches, go to Configuration > Performance or http://example.com/admin/config/development/performance, and click the Clear all cachesbutton.

Jun 18, 2012

CSS3 UI Buttons Set

I just saw the amazing art work by Alessio Atzeni for creating UI Buttons Design. I just converted the PSD to HTML5 and CSS3, so lets start with it. This tut will be having two set of buttons blue and black.

Each button has three states: normal, hover and active.

CSS3-UI-BUTTONS

The css selectors will be :hover and :active.

I will be using Foundation-Icons font for getting the icon image instead of using an image.



Blue Set



CSS3-UI-BUTTONS

HTML :
[html]
<a class="blue">a</a>
[/html]


CSS:
[css]
.blue{
background-image:-moz-linear-gradient(top,transparent,rgba(0,0,0,0.2));
background-image:-webkit-linear-gradient(top,transparent,rgba(0,0,0,0.2));
background-image:-o-linear-gradient(top,transparent,rgba(0,0,0,0.2));

-webkit-transition:all 0.1s linear;
-moz-transition:all 0.1s linear;
-o-transition:all 0.1s linear;
-ms-transition:all 0.1s linear;
transition:all 0.1s linear;

background-color: #5683b1;
/*font-family:icons;*/
border-top:1px solid #8bbfd7;
border-radius: 50% 50% 50% 50%;
font-size: 15px;
font-weight: bold;
color:#24272a;
text-shadow:0 1px 0 #5a92ba;
box-shadow: 0 5px 6px #1C1F22;
cursor: default;
text-align: center;
width: 33px;
height: 33px;
float: left;
margin: 10px;
font-family:icons;
}

.blue:hover{
background-color: #5f94bc;
}

.blue:active{
background-color: #3a6a9b;
box-shadow: 0 0 3px #323638 inset;
border: 1px solid #3c4246;
}
[/css]



Black Set



CSS3-UI-BUTTONS

HTML:
[html]
<p class="blackMask">
<a class="black">a</a>
</p>
[/html]

CSS:
[css]
.black{
background-image:-moz-linear-gradient(top,transparent,rgba(0,0,0,0.2));
background-image:-webkit-linear-gradient(top,transparent,rgba(0,0,0,0.2));
background-image:-o-linear-gradient(top,transparent,rgba(0,0,0,0.2));
-webkit-transition:all 0.1s linear;
-moz-transition:all 0.1s linear;
-o-transition:all 0.1s linear;
-ms-transition:all 0.1s linear;
transition:all 0.1s linear;


background-color: #464d53;
/*font-family:icons;*/
border-top:1px solid #626c74;
border-radius: 50% 50% 50% 50%;
font-size: 15px;
font-weight: bold;
color:#191919;
text-shadow:0 1px 0 #485258;
box-shadow: 0 3px 6px #1f2225;
cursor: default;
text-align: center;
width: 33px;
height: 33px;
float: left;
margin: 7px;
font-family:icons;
}

.black:hover{
background-color: #4b575f;
color:#00b7fb;
text-shadow:0 0 5px #39748c;
}

.black:active{
background-color: #2f383d;
box-shadow: 0 0 3px #323638 inset;
border: 1px solid #20292e;
color:#191919;
text-shadow:0 1px 0 #485258;
}

.blackMask{
background-image:-moz-linear-gradient(top,transparent,rgba(0,0,0,0.2));
background-image:-webkit-linear-gradient(top,transparent,rgba(0,0,0,0.2));
background-image:-o-linear-gradient(top,transparent,rgba(0,0,0,0.2));
background-color:#30363a;
border-radius: 50% 50% 50% 50%;
float: left;
width:47px;
position: relative;
height:47px;
margin: 10px;
border-top:1px solid #3c4247;
border-bottom:1px solid #4a5155;
}

.black:before {
background: none repeat scroll 0 0 transparent;
border-bottom: 1px solid #4F555A;
border-radius: 50% 50% 50% 50%;
border-top: 1px solid #373C40;
content: "";
height: 50px;
left: -2px;
position: absolute;
top: -3px;
width: 50px;
}
[/css]


These buttons can be used widely and advantages of using it, no images, fully flexible and customizable and it can be applied to any container a, button, span, p etc.

Thanks to Alessio, for creating the buttons Design.

Jun 13, 2012

Give away - Google Adwords of $100 by WebsTutorial

 


Give Away
 

What is Give Away?


WebsTutorial feels proud to announce that we have launched Give Away for this week which is of $100 Google AdWords credit for free!

Do I need to sign up to enter the Give Away contest?


No, not at all. Simply you only have to mention @WebsTutorial or follow us on Twitter to be on topchart of the Give Away contest.

How are winners notified?


Winners will be notified via mail & also will be declared on the WebsTutorial website i.e. www.webstutorial.com

What is Google AdWords?


AdWords is Google's flagship advertising product and main source of revenue.

How does Google AdWords work?


Here is a great infographic by pulpmedia.at which describes the working of Google Adwords.

Give AwayGive Away
*Note:
1. This give away is valid for 7 days only.
2. Winner will be randomly selected on the basis of his/her activity.

May 29, 2012

CSS3 Gradient Textures

A snippet share just to show the power of CSS3 gradient, I just follow some free PSD's texture and try it to code in CSS3. So its time to share with you all.

CSS3 Gradient Texture

[css]
/* Gradient */

#texture1{
background-image: -moz-linear-gradient(90deg, #9fc9d7, #9fc9d7 2px, #a3dcf0 2px, #a3dcf0 4px, #9fc9d7 4px);
background-image: -webkit-linear-gradient(90deg, #9fc9d7, #9fc9d7 2px, #a3dcf0 2px, #a3dcf0 4px, #9fc9d7 4px);
background-repeat: repeat;
background-size: 2px 4px;
}

#texture2{
background-image: -moz-linear-gradient(0deg, #202125, #202125 2px, #292a2e 2px, #292a2e 4px, #202125 4px);
background-image: -webkit-linear-gradient(0deg, #202125, #202125 2px, #292a2e 2px, #292a2e 4px, #202125 4px);
background-repeat: repeat;
background-size: 5px 10px;
}

#texture3{
background-image: -moz-linear-gradient(90deg, #9dd9da, #9dd9da 15px, #a6dcde 15px, #a6dcde 30px, #9dd9da 30px);
background-image: -webkit-linear-gradient(90deg, #9dd9da, #9dd9da 15px, #a6dcde 15px, #a6dcde 30px, #9dd9da 30px);
background-repeat: repeat;
background-size: 15px 30px;
}

#texture4{
background-image: -moz-linear-gradient(45deg, rgba(0, 0, 0, 0.25) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.25) 75%, rgba(0, 0, 0, 0.25)), -moz-linear-gradient(45deg, rgba(0, 0, 0, 0.25) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.25) 75%, rgba(0, 0, 0, 0.25));
background-image: -webkit-linear-gradient(45deg, rgba(0, 0, 0, .25) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, .25) 75%, rgba(0, 0, 0, .25)), -webkit-linear-gradient(45deg, rgba(0, 0, 0, .25) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, .25) 75%, rgba(0, 0, 0, .25));
background-position: 0 0pt, 2px 2px;
background-size: 4px 4px;
background-color: #202125;
}
[/css]

 

May 26, 2012

HTML5 CSS3 Admin Panel | Dashboard Template

Now a days I go to dribble and see the amazing designs created by users. From their I get amazing ideas and today I ll share my HTML5 and CSS3 coded Admin panel with you all.

This tutorial will consist with :-

Here's the final output of our template:

HTML5-CSS3 Template
Fixed Menubar

Menu bar code is simple, li list with a drop down in it. We will be using box-shadow to give the gradient effect.

[html]
<ul id="admin-bar">
<li title="Home">H</li>
<li title="Users">A</li>
<li title="Add New Post">D</li>
<li title="Settings">G</li>
<li title="Videos">V</li>
<li title="Stats" class="active">v</li>
<li title="More">d
<ul id="drop-down">
<li title="Media Gallery">m<span>Media Gallery</span></li>
<li title="Comments">b<span>Comments</span></li>
<li title="Plugins">C<span>Plugins</span></li>
</ul>
</li>
</ul>
[/html]

Like my previous CSS3 tutorials here also I ll be using fonts instead of images to show the correct icons in menu.

[css]
#menu{
position:fixed;
top:0;
left:0;
width:100%;
background-color: #151515;
background-size: 6px 6px;
border-radius: 2px;
box-shadow: 0 25px 0 0 rgba(255, 255, 255, 0.15) inset;
height: 50px;
z-index: 1;
}

#admin-bar {
float: left;
margin: 0 auto;
padding: 0;
position: relative;
}

#admin-bar li {
color: #FFFFFF;
cursor: default;
display: inline;
float: left;
font-family: icons;
font-size: 25px;
list-style-type: none;
padding: 7px 10px 14px;
position: relative;
}

#admin-bar li:hover, .active{
text-shadow:0 0 5px #fff;
background:-moz-linear-gradient(center top , #1B1B1B 0%, #262626 100%) repeat scroll 0 0 transparent;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1b1b1b), color-stop(100%,#262626));
}

#admin-bar li ul {
-webkit-transition: all 1s ease 0s;
-moz-transition: all 1s ease 0s;
-o-transition: all 1s ease 0s;
-ms-transition: all 1s ease 0s;
transition: all 1s ease 0s;

background: -moz-linear-gradient(center top , #1B1B1B 0%, #262626 100%) repeat scroll 0 0 transparent;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1b1b1b), color-stop(100%,#262626)); /* Chrome,Safari4+ */
border-radius: 0 0 10px 10px;
display: block;
height: 0;
left: 0;
margin: 0;
opacity: 0;
overflow: hidden;
padding: 0;
position: absolute;
top: 50px;
width: 135px;
}

#admin-bar li:hover ul{
height:auto;
overflow:visible;
opacity:1;
}

#drop-down li {
display: block;
float: none;
background-image:url(divider.png);
background-repeat:no-repeat;
}

#drop-down li:hover{
background: -moz-linear-gradient(center top , #1B1B1B 0%, #262626 100%) repeat scroll 0 0 transparent;
}

#drop-down li:last-child {
border-radius: 0 0 10px 10px;
}
[/css]

To show the menu gradient I am using box-shadow: 0 25px 0 0 rgba(255, 255, 255, 0.15) inset; and for drop down menu the logic is really simple. By default overflow to be set as hidden, opacity as 0 and height to 0 and on mouse hover we change these values as visible, 1, auto.

The icons are not images but fonts. And using text-shadow they appear to glow on mouse hover.




Search Box

Its really simple if you have knowledge in CSS3 gradients. A textbox with black blackground color and CSS3 gradient effect to change the looks.

[html]
<input type="text" placeholder="Search" id="df">
[/html]

 

[css]
input[type="text"] {
background: -moz-linear-gradient(center top , #1B1B1B 0%, #262626 100%) repeat scroll 0 0 transparent;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1b1b1b), color-stop(100%,#262626)); /* Chrome,Safari4+ */
border: 1px solid #000000;
border-radius: 5px 5px 5px 5px;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 0 rgba(0, 0, 0, 0.5) inset;
color: #FFFFFF;
float: left;
font-size: 11px;
height: 26px;
padding-left: 10px;
padding-right: 65px;
text-shadow: 0 0 3px #FFFFFF;
width: 130px;
margin-left: 50px;
margin-top: 10px;
}
input[type="text"]:hover, input[type="text"]:active{
background:#1B1B1B;
}
[/css]




Log out Button
Using the search box idea here also we will make use of CSS3 gradients.

[html]
<input type="submit" id="logout" value="Logout" />
[/html]

 

[css]
#logout {
background: -moz-linear-gradient(center top , #CD2525 0%, #B11B1C 50%, #940F10 50%, #861213 100%) repeat scroll 0 0 #CD2525;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#CD2525), color-stop(50%,#B11B1C), color-stop(50%,#940F10), color-stop(100%,#861213)); /* Chrome,Safari4+ */

border-radius: 3px;
color: #FFFFFF;
float: right;
font-family: arial;
font-size: 14px;
margin: 12px;
padding: 5px 15px;
text-decoration: none;
border:0px;
}

#logout:active{
background:#861213;
}
[/css]




Animated Graphs
The logic to design the graph is really simple, make 6-7 div's with same height and width. The height should be longer and width to be thin so that it looks like a standing pole. Then with the help of simple CSS3 gradients and CSS3 animations we have the make it animated so that it looks like animated bar graph.

[html]
<div id="graph">
<div class="progress">
<div style="height: 40%;" class="bar"></div>
<p class="stats-info"><span class="tooltip"></span>Monday</p>
</div>
<div class="progress">
<div style="height: 70%;" class="bar"></div>
<p class="stats-info"><span class="tooltip"></span>Tuesday</p>
</div>
<div class="progress">
<div style="height: 72%;" class="bar"></div>
<p class="stats-info"><span class="tooltip"></span>Wednesday</p>
</div>
<div class="progress">
<div style="height: 80%;" class="bar"></div>
<p class="stats-info"><span class="tooltip"></span>Thursday</p>
</div>
<div class="progress">
<div style="height: 75%;" class="bar"></div>
<p class="stats-info"><span class="tooltip"></span>Friday</p>
</div>
<div class="progress">
<div style="height: 65%;" class="bar"></div>
<p class="stats-info"><span class="tooltip"></span>Saturday</p>
</div>
<div class="progress">
<div style="height: 45%;" class="bar"></div>
<p class="stats-info"><span class="tooltip"></span>Sunday</p>
</div>
</div>
[/html]

To show the tooltip we are using the same logic as drop down menu. Here the tooltip is the class stats-info. On hover we are changing the opacity to give the fade in effect with the help of css3 transition effect

To show the graph animation we will be using animation effect and the css3 gradient:

[css]
.bar {
animation: 2s linear 0s normal none infinite progress-bar-stripes;
background-image: -moz-linear-gradient(-134deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
}

@keyframes "progress-bar-stripes" {
from {
background-position: 0 0;
}
to {
background-position: 40px 0;
}

}

[/css]

Tooltip hover effect

[css]
.stats-info {
-webkit-transition: all 0.3s linear 0s;
-moz-transition: all 0.3s linear 0s;
-o-transition: all 0.3s linear 0s;
-ms-transition: all 0.3s linear 0s;
transition: all 0.3s linear 0s;

background-image: -moz-linear-gradient(center top, #CD2525 0%, #B11B1C 50%, #940F10 50%, #861213 100%);
background-image: -webkit-linear-gradient(-90deg, #CD2525 0%, #B11B1C 50%, #940F10 50%, #861213 100%);

background-repeat:repeat;
background-color:#CD2525;
border-radius: 5px 5px 5px 5px;
bottom: -45px;
color: #FFFFFF;
left: -18px;
opacity: 0;
padding: 5px;
position: absolute;
font-size: 12px;
}

.bar:hover + .stats-info{
opacity:1;
}

.tooltip {
border-bottom: 10px solid #C02020;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
display: block;
height: 0;
left: 17px;
position: absolute;
top: -9px;
width: 0;
z-index: 1;
}
[/css]




Notification messages
If you have gone through all the above parts then I am sure you can guess how the notification messages are coded.

By using CSS3 gradients and fonts we can make it.

[html]
<div id="messages">

<div class="error">Error</div>
<div class="notification">Notification</div>
<div class="success">Success</div>

</div>
[/html]

 

[css]
/* messages */
#messages{
float:left;
}

#messages div{
display:block;
margin:20px;
cursor: pointer;
}

/* Error */
.error {
background-image: -moz-linear-gradient(center top , #CB1634 0%, #C41330 50%, #BC102C 50%, #B70D2A 100%);
background-image: -webkit-linear-gradient(-90deg , #CB1634 0%, #C41330 50%, #BC102C 50%, #B70D2A 100%);
background-color:#CB1634;
background-repeat:repeat;
border-radius: 8px 8px 8px 8px;
color: #FFFFFF;
display: block;
font-size: 18px;
padding: 5px 30px;
position: relative;
width: 200px;
}

.error:before {
content: "X";
font-family: icons;
left: 4px;
position: absolute;
font-size: 18px;
}

/* Notification */

.notification {
background-image: -moz-linear-gradient(center top , #e4b023 0%, #e0ab1b 50%, #dca512 50%, #d79f08 100%);
background-image: -webkit-linear-gradient(-90deg , #e4b023 0%, #e0ab1b 50%, #dca512 50%, #d79f08 100%);
background-color:#e4b023;
background-repeat:repeat;
border-radius: 8px 8px 8px 8px;
color: #FFFFFF;
display: block;
font-size: 18px;
padding: 5px 30px;
position: relative;
width: 200px;
}

.notification:before {
content: "l";
font-family: icons;
font-size: 28px;
left: 0;
position: absolute;
top: -1px;
}

/* Success */

.success {
background-image: -moz-linear-gradient(center top , #6da920 0%, #62991b 50%, #558614 50%, #4d7a10 100%);
background-image: -webkit-linear-gradient(-90deg , #6da920 0%, #62991b 50%, #558614 50%, #4d7a10 100%);
background-color:#6da920;
background-repeat:repeat;
border-radius: 8px 8px 8px 8px;
color: #FFFFFF;
display: block;
font-size: 18px;
padding: 5px 30px;
position: relative;
width: 200px;
}

.success:before {
content: "O";
font-family: icons;
left: 4px;
position: absolute;
}

[/css]




Dialog box

[html]
<div id="dialogbox">

<div id="box-header">Are You Sure?<a id="close">X</a></div>
<div id="box-content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>

<p style="position: relative; left: 20%; margin: 12px 0pt;">
<a class="yes">Yes</a>
<a class="no">No</a>
</p>
</div>

</div>
[/html]

We are using the div structure to build the dialog box. Again with the help of CSS3 gradients, fonts and other effects we will be making it to look like a Dialog Box.

[css]
/* Modal box */

#dialogbox{
float:left;
width:344px;
padding:5px;
background:rgba(255, 255, 255, 0.2);
border-radius:10px;
}

#box-header {
background-image: -moz-linear-gradient(center top , #D2DEE3 0%, #C7D6DB 50%, #B8CBD1 50%, #BBCDD3 100%);
background-image: -webkit-linear-gradient(-90deg , #D2DEE3 0%, #C7D6DB 50%, #B8CBD1 50%, #BBCDD3 100%);
background-color:#D2DEE3;
background-repeat:repeat;
border-radius: 5px 5px 0 0;
color: #324044;
font-size: 17px;
padding: 15px;
position: relative;
display: block;
cursor: default;
}

#close {
color: #314248;
cursor: pointer;
font-family: icons;
font-size: 26px;
position: absolute;
right: 5px;
top: 10px;
}

/* */
#box-content{
text-align:center;
background:#fff;
color:#7c7c7c;
font-size:13px;
float:left;
padding: 10px 5px;
}

.yes{
background-image: -moz-linear-gradient(center top , #c1e087 0%, #c3e092 50%, #bbdd83 50%, #b7db7a 100%);
background-image: -webkit-linear-gradient(-90deg , #c1e087 0%, #c3e092 50%, #bbdd83 50%, #b7db7a 100%);
background-color:#c1e087;
background-repeat:repeat;
font-size:12px;
padding:10px 35px;
border:1px solid #81aa3c;
border-radius:5px;
margin:2px 5px;
float:left;
cursor:pointer;
}

.yes:hover{
box-shadow: 0 0 5px #a7bc84;
}

.no{
background-image: -moz-linear-gradient(center top , #f6b2b2 0%, #f7bfbf 50%, #f7c1c1 50%, #f5b1b1 100%);
background-image: -webkit-linear-gradient(-90deg , #f6b2b2 0%, #f7bfbf 50%, #f7c1c1 50%, #f5b1b1 100%);
background-repeat:repeat;
background-color:#f6b2b2;
font-size:12px;
padding:10px 35px;
border:1px solid #d38e8e;
color:#582121;
cursor:pointer;
border-radius:5px;
float:left;
margin:2px 5px;
}

.no:hover{
box-shadow: 0 0 5px #B98B8B;
}
[/css]

I hope that with the help of this tutorial you learned a lot, you can use this for free in any of your creative work(don't forget to give me a back-link :P). Tweet, FB Shares and other suggestions are always welcomed at WT.

May 23, 2012

Working of Drupal theme system

Ok, we can do this the hard way or we can do this the Drupal way!

In the below section I've tried to define the theme structure of Drupal 7.x. Always remember "Never hack core!"

Why you shouldn't modify core files


No matter how easy it is to modify core files to make Drupal do what you want it to do, resist the temptation.

  • Doing so will make it complicated,difficult or near impossible to apply site updates such as Security and bug fixes.

  • You will make it difficult for those that come after to maintain the site.

  • You could possibly leave your site vulnerable to exploits.


The Drupal core has been designed to be modular, so there should be no reason to hack it. If there is a feature you want and it cannot be accomplished outside of modifying core, consider submitting your hack as a patch. Create an issue and tell the community the feature you want to accomplish. It will then be tested and your feature may become a part of the Drupal core.

Exceptions


Are there exceptions to this rule?

Nope.

Okay, maybe. But this is generally for specific sites or implementations by people who are extremely familiar with the Drupal code base, development practices and security model. Those who properly document their changes and practice proper revision control with their code. If you have to ask, chances are you shouldn't.

Overview of theme files

A theme is a collection of files that define the presentation layer. You can also create one or more "sub-themes" or variations on a theme. Only the .info file is required, but most themes and sub-themes will use other files as well. The following diagram illustrates the files that are found in a typical theme and sub-theme.

Drupal 7 - Theme Anatomy

.info (required)

 

All that is required for Drupal to see your theme is a ".info" file. Should the theme require them, meta data, style sheets, JavaScripts, block regions and more can be defined here. Everything else is optional.

The internal name of the theme is also derived from this file. For example, if it is named "drop.info", then Drupal will see the name of the theme as "drop". Drupal 5 and below used the name of the enclosing folder of the theme.

Info files for themes are new in Drupal 6. In version 5, .info files were used solely for modules.

template files (.tpl.php)

These templates are used for the (x)HTML markup and PHP variables. In some situations they may output other types of data --xml rss for example. Each .tpl.php file handles the output of a specific themable chunk of data, and in some situations it can handle multiple .tpl.php files through suggestions. They are optional, and if none exists in your theme it will fall back to the default output. Refrain from having complex logic in these files. In most cases, it should be straight (x)HTML tags and PHP variables. A handful of these templates exist in directories where core and contributed modules exist. Copying them to your theme folder will force Drupal to read your version.

Note: The theme registry caches information about the available theming data. You must reset it when adding or removing template files or theme functions from your theme.

template.php

For all the conditional logic and data processing of the output, there is the template.php file. It is not required, but to keep the .tpl.php files tidy it can be used to holdpreprocessors for generating variables before they are merged with the markup inside .tpl.php files. Custom functions, overriding theme functions or any other customization of the raw output should also be done here. This file must start with a PHP opening tag "<?php", but the close tag is not needed and it is recommended that you omit it.

 Sub-themes

On the surface, sub-themes behave just like any other theme. The only differences is that they inherit the resources from their parent themes. To create one, a "base theme" entry inside the .info file is needed. From there it will inherit the resources from its parent theme. There can be multiple levels of inheritance; i.e., a sub-theme can declare another sub-theme as its base. There are no hard set limits to this.

Drupal 5 and below required sub-themes to be in sub-directories of the parent theme. This is no longer the case.

Others

  • The logo and screen shot are not absolutely necessary for the theme to function, but they are recommended, especially if you are contributing your theme to the Drupal repository. Screenshots will show inside the theme administration page and the user account settings for selecting themes when the appropriate permissions are set. See the screenshot guidelines for more information.

  • To supply administrative UI settings or "features" beyond logo, search, mission, etc., a "theme-settings.php" file can be used. This is an advanced feature. More information can be found in the Advanced settings handbook page.

  • For color module support, a "color" directory with a "color.inc" file is needed along with various support files.


Remember

  • If you want to base your work on a core theme, use sub-theming or make a copy and rename the theme. Directly modifying Bartik, Garland or Minnelli is strongly discouraged, since they are used for the install and upgrade process.

  • All non-Core or modifications to Core themes should be installed under the "sites/all/themes" directory to keep them separate from core files. If you plan to run multiple sites from a single Drupal code base, you can make a theme available to a specific site rather than all sites; read about how to set this up in Multi-site installations.


Hope it might help you understanding the theme structure of Drupal 7.x