Saturday, September 24, 2011

Some Notes on Best Practices and concepts

* The MIME standard can be used to tell the browsers about the automatic identification and handling of files. 

* We can mention the MIME type in a HTML page by using META tag. for example,
<meta http-equiv='Content-Type' content='application/xhtml+xml; charset=UTF-8' />

* Yellow Screen of Death (YSOD) occurs when a XHTML document is having any markup errors like missing tags, improper closing tags etc..

* As long as we are using XHTML1.0 we no need to worry about the MIME type, but if we are using XHTML1.1, must and should we have to mention the MIME Type(Typically application/xhtml+xml).

* Namespacing  is the concept of making our code to follow certain naming conventions thereby making our programs more portable, easy to maintain, avoiding the conflicts if we include our code in other documents of similar type.

* Unobtrusive JavaScript is the practice of separating out any JavaScript behavior code from your content structure(HTML) and presentation(CSS). With Unobtrusive JavaScript, only <script> tags that include external JavaScript files are allowed within your document. The goal is to eliminate the use of any <script> tags with inline JavaScript and the use of any HTML behavioral/event attributes, like onclick, onmouseover, etc, that make use of JavaScript from within the content markup itself, and externalize this code in a separate JavaScript file which gets included by a <script> tag with a "src" attribute. The idea here is that these externalized behaviors will get programmatically attached to the elements at some point during the document loading process, most likely after the window onload event fires, with the use of the DOM APIs which allow you to add/remove event handlers programmatically. For guidelines refer this URL : The 7 rules of Unobtrusive JavaScript.


Friday, September 23, 2011

Example1.1 - Test jQuery configuration

This is the example for for testing whether the jQuery configured properly or not
1. As i mentioned in my previous blog, Download the jQuery java script file latest version.
2. Create a sample HTML file and include the following code.

3. Save the HTML and open the file on any browser to see the output.

if we see the code, we can clearly observe three  sections of code.
one is plain HTML code which defines the view or structure.
second is the JavaScript code. Actually, this is the jQuery code. In jQuery, functions are the first class objects. We can move this code to a java script file and we can mention the source in the script tag. This script defines the behavior.
third part is the styling part.This defines the presentation.
Actually, this is one of the best practice to separate these parts.

the symbol $ indicates the query object. As i said, we can use this object as function also. See this sample code (source: Wrox publications)

the ready function is equivalent to onLoad event in Java Script.

jQuery - A Quick Review

JQuery is nothing but another framework for JavaScript. Of-course, there are many frameworks available in the internet. But this is very simple and it is capable of doing anything. 

Few advantages are
i.  Iterating and traversing through DOM becomes very easy.
ii. It works across all the browsers and can work with all development environments.
iii.It provides a standard Event API, a standard selectors API, useful traversal and enumeration methods, and a very useful UI library that work across all the browsers.

To Download jQuery, please go here