Dynamically Resize Text

No Comments


CSS, combined with little JavaScript, offers great flexibility to web designers. For instance, let say you want to allow visitors to change text size on your website. Now how do you do it? Using CSS is the easiest solution.
All you need is few style sheets and a JS script to dynamically enable those style sheets. Sounds daunting? Believe me it is very simple and easy to implement. Let me walk you through the process.

In this tutorial we’ll create a simple web page with options to select one of the three text sizes.
Let’s start with creating a simple HTML page.

<HTML>
<BODY>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Sed a risus eu dolor viverra volutpat.In a tellus ut augue dignissim nonummy.
</BODY>
</HTML>

Assuming that we have three CSS files named style.css, sStyle.css and lStyle.css.
In mStyle.css and lStyle.css you only need one line if all you want is to change the text size.
So sStyle.css may have .body {font-size:small;}
and lStyle.css may have .body{font-size:large;}
By default the font-size value is medium. To reference these style sheets from our HTML,

we add them to the “head” section of our HTML. So our code will become:

<HTML>
<HEAD>
<link rel=”stylesheet” type=”text/css” href=”mystyles.css” media=”screen” />
<link rel=”alternate stylesheet” type=”text/css”
href=”mystyle_xl.css” media=”screen” title=”medium” />
<link rel=”alternate stylesheet” type=”text/css” href=”mystyle_xxl.css” media=”screen” title=”large”/>
</HEAD>
<BODY>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed a risus eu dolor viverra volutpat.In a tellus ut augue dignissim nonummy.
</BODY>
</HTML>

To associate the style sheets to our web page we added the link elements in the header section. Style sheets can be added to a web page in one of the following three ways.

  1. Persistent: This is the default style sheet and is always ‘on’. You just need to set rel attribute to ‘stylesheet’ to make a style sheet persistent for your web page. You can use this style sheet for common rules shared by all style sheets.
  2. Preferred: This type of style sheet is enabled by default and can be ‘turned-off’ if the user selects an
    alternate style sheet. To make a style sheet preferred you need to include a title attribute in the link element.
  3. Alternate: This type of style sheet can be selected by the user as alternative to the default or preferred style sheet. This is the type that we will use in this example. To declare a style sheet as alternative set the rel attribute to ‘alternate stylesheet’ and give a title to the style sheet. (See lines 2 and 3 in the header section above.)

When our web page loads the rules in the persistent style sheet will be applied to the page. Now let us add links to our page to allow user to change text size.

<HTML>
<HEAD>
<link rel=”stylesheet” type=”text/css” href=”mystyles.css” media=”screen” />
<link rel=”alternate stylesheet” type=”text/css” href=”mystyle_xl.css” media=”screen” title=”medium” />
<link rel=”alternate stylesheet” type=”text/css” href=”mystyle_xxl.css” media=”screen” title=”large”/>
</HEAD>
<BODY>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed a risus eu dolor viverra volutpat.In a tellus ut augue dignissim nonummy.
<a href=”#” onClick=”enableSelectedStyle(‘default’); return false;”>Small</a>
<a href=”#” onClick=”enableSelectedStyle(‘medium’); return false;”>Medium</a>
<a href=”#” onClick=”enableSelectedStyle(‘large’); return false;”>Large</a>
</BODY>
</HTML>

We added three links to our page and each link invokes a Javascript method to swap the style sheet. Here is the JavaScript code.

function enableSelectedStyle(title){
var i, linkSheets, ss, title;
linkSheets = document.getElementsByTagName(“link”);
for(i=0; i<linkSheets.length;i++){
ss = linkSheets[i];
var b = ss.getAttribute(“title”);
if(b == null) continue;
if(b == title) ss.disabled = false;
else ss.disabled = true;
}
}

Script Explained:

The script retrieves all “link” elements of the document and then loop through them. If the element has a title attribute and its value is same as the input value, it activates that style. If the title value is different from the input value it disables that style sheet. Since the default style sheet link does not have ‘title’ attribute the script will not change it.

Here is the final code

<HTML><HEAD>
<script language=”JavaScript”>
function enableSelectedStyle(title){
var i, linkSheets, ss, title;
linkSheets = document.getElementsByTagName(“link”);
for(i=0; i<linkSheets.length;i++){
ss = linkSheets[i];
var b = ss.getAttribute(“title”);
if(b == null) continue;
if(b == title) ss.disabled = false;
else ss.disabled = true;
}
}
</script>
<link rel=”stylesheet” type=”text/css” href=”mystyles.css” media=”screen” />
<link rel=”alternate stylesheet” type=”text/css” href=”mystyle_xl.css” media=”screen” title=”medium” />
<link rel=”alternate stylesheet” type=”text/css” href=”mystyle_xxl.css” media=”screen” title=”large”/>
</HEAD>
<BODY>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed a risus eu dolor viverra volutpat.In a tellus ut augue dignissim nonummy.
<a href=”#” onClick=”enableSelectedStyle(‘default’); return false;”>Small</a>
<a href=”#” onClick=”enableSelectedStyle(‘medium’); return false;”>Medium</a>
<a href=”#” onClick=”enableSelectedStyle(‘large’); return false;”>Large</a>
</BODY>
</HTML>

article clipper vert Dynamically Resize Text
 

Best free software

2 Comments

Thanks to Open source movement there are plenty of free software available for our day to day computing needs. Here is a partial list of my favorite software.

  • Mozilla Firefox: Firefox is considered by many as the best web browser. Everyday hoards of people converting to Firefox. The features include Tabs, pop-up blocking, themes, and extensions. Download Firefox
  • Mozilla Thunderbird: Another powerful software from Mozilla. This free email client has everything you need. To me it is better than Outlook. You can safely replace Outlook with Thunderbird. Download Thunderbird.
  • GIMP: A solid image and photo editing software. A good alternative to Photoshop. Download GIMP.
  • Paint.NET: Paint.NET is free image and photo editing software for computers that run Windows. It features an intuitive and innovative user interface with support for layers, unlimited undo, special effects, and a wide variety of useful and powerful tools. An active and growing online community provides friendly help, tutorials, and plugins.Download Paint.Net
  • Inkscape: An Open Source vector graphics editor, with capabilities similar to Illustrator, CorelDraw, or Xara X, using the W3C standard Scalable Vector Graphics (SVG) file format. Download Inkscape.
  • FileZilla: FileZilla is a fast FTP and SFTP client for Windows with a lot of features. Download FileZilla.
  • OpenOffice.org: OpenOffice.org is a multiplatform and multilingual office suite. Compatible with all other major office suites (including Microsoft Office), the product is free to download, use, and distribute. Download OpenOffice.org
  • Notepad++: A much better text editor than Notepa. Features include tabbed interface, configurable syntax highlighting, syntax folding, line numbering, multi-view, bookmarks and regular expression search, brace and indent guideline highlighting and much more. Download Notepad++
  • WinMerge: WinMerge is a visual text file differencing and merging tool. It is highly useful for comparing versions of projects, and then merging changes between versions. Download WinMerge.

Do you have a list of your own free software? Let’s hear from you.

article clipper vert Best free software
 

Automatically Sort Vector Elements

1 Comment

Vector class in java.util package is very easy to use. You can add objects of any type in a vector.

You don’t have to worry about declaring the size of the vector. You can just keep adding elements to your object and the vector will dynamically adjust the size. The vector will add elements one after other and will keep them in the order in which your insert them. It means that the elements in the vector are not sorted. Sometimes you need to sort elements in a vector. The Vector class does not offer any sorting mechanism. I created a subclass to sort elements in a vector.
It works with any class that implements Comparable interface or has a Compartor method. If you want elements of your own class sorted in a vector you will need to either make your class implement Comparable or create a Comparator method.


public class SortedVector extends Vector{
public SortedVector(){
super();
}
public void addElement(Object o){
super.addElement(o);
Collections.sort(this);
}
}

Here is a sample program showing how to use this class.

public static void main(String args[]){
SortedVector v =new SortedVector();
v.addElement(new Double(12));
v.addElement(new Double(320));
v.addElement(new Double(21));
System.out.println(v);
}

The output from this program is [12.0, 21.0, 320.0].

article clipper vert Automatically Sort Vector Elements
 

Pakistan vs India – 2007 complete schedule

No Comments

Pakistan Tour of India, 2007
1-day ± Nov 2nd, 2007 Delhi vs Pakistan Feroz Shah Kotla Stadium, Delhi 09:00 IST; 03:30 GMT
1st ODI Nov 5th,2007 India vs Pakistan Jawaharlal Nehru Stadium, Guwahati 09:00 IST; 03:30 GMT
2nd ODI * Nov 8th,2007 India vs Pakistan Punjab Cricket Association Stadium, Mohali 14:30 IST; 09:00 GMT
3rd ODI Nov 11th,2007 India vs Pakistan Green Park, Kanpur 09:00 IST; 03:30 GMT
4th ODI * Nov 15th2007 India vs Pakistan Captain Roop Singh Stadium, Gwalior 14:30 IST; 09:00 GMT
5th ODI * Nov 18th India vs Pakistan Sawai Mansingh Stadium, Jaipur 14:30 IST; 09:00 GMT
1st Test Nov 22nd-26th, 2007 India vs Pakistan Feroz Shah Kotla, Delhi 09:30 IST; 04:00 GMT
2nd Test Nov 30th – Dec 4th, 2007 India vs Pakistan Eden Gardens, Kolkata 09:30 IST; 04:00 GMT
3rd Test Dec 8th-12th,2007 India vs Pakistan M. Chinnaswamy Stadium, Bangalore 09:30 IST; 04:00 GMT

*: Day and night matches.

±:Warm-up matchIST: India Standar TimeGMT: Greenwich Mean Time


article clipper vert Pakistan vs India   2007 complete schedule
 

#1 Programming Language – Java

No Comments

According to TIOBE Programming Community Index Java is still the #1 programming language. TIOBE Index gives an indication of the popularity of a programming language and is updated monthly.
The ratings are calculated by counting hits of the most popular search engines.
Ruby moved up from 13th to 10th position.

Following is the list of top 10 programming languages.
1. Java
2. C
3. (Visual) Basic
4. C++
5. PHP
6. Perl
7. C#
8. Python
9. JavaScript
10. Ruby

For complete results visit TIOBE website

article clipper vert #1 Programming Language   Java
 

Newer Entries