Home > Monthly Archives: November 2011
Page 1

Designing a Clean Website: Navigation

There is one design style that can withstand the fluctuating trends that come and go in the design world, and that is to have a clean, simple, minimalist site.

Think of sites like Apple, Amazon, and The New York Times. One thing you will notice that they all have in common is perfectly executed use of white space. However, there are some very subtle guidelines to follow or tips that you should consider when designing your own clean website.

This tutorial will take you through the development process and point out things to consider along the way to keep your site looking like a modern, polished, professional website, and not something that was made back in the 90’s.

The single most important aspect of a website is its navigation. If a viewer is not able to easily navigate through your site and find the information they’re looking for quickly and easily, they’re going to leave. When you’re striving for minimalism, your navigation is an excellent source to add some character to your site. The first part of our tutorial will focus on developing an accordion-style navigation system that is powered entirely by CSS3.

Let’s begin with the simple part, setting up the HTML for our navigation. Typically I like to create the navigation in its own HTML file and then pull it in to each page with a simple PHP include. Doing it this way allows you to easily add or subtract links from your navigation menu throughout your entire site by only having to modify one file, rather than every page. Let’s go ahead and make an unordered list of what we want our main navigation links to be. We’re also going to wrap those in a paragraph tag so that we’re able to handle those links differently than our sub-navigation links. You’ll also notice that I’ve left the “Home” link out of the list and assigned the class “first” to it, that’s because there will be no sub-links under home. The same goes for “Contact” but there will be nothing underneath that link so it’s OK to leave it in the list.

<div class="slider"> <p class="first"><a href="index.php">Home</a></p> <ul> <li><a href="about.php">About</a></li> <li><a href="services.php">Services</a></li> <li><a href="portfolio.php">Portfolio</a></li> <li><a href="contact.php">Contact</a></li> </ul> </div>

Now let’s go ahead and add in our sub-navigation links, and we’ll wrap those in a div tag so that we can add different behaviors to them.

<div class="slider"> <p class="first"><a href="index.php">Home</a></p> <ul> <li><a href="about.php">About</a> <div> <a href="philosophy.php">Philosophy</a> <a href="vision.php">Vision</a> <a href="history.php">History</a> </div>...
more →
Andrew says: I just wrote an article with research references talking about how a http://thepsychof.com/2012/03/07/clean-website/"...

PHP User Survey: Setting Variable Values and Reading from Tables

In Part I of this series, we started the process of creating user polls for a business web site. Part I gave the layout of the data layer and began the construction of the class file. 

In this part we will continue with adding methods to the class file that will enable the administrator to set the variable values and read from the database tables.

The setPollId($iPollId) method sets the value for the _iPollId variable.  Since the constructor method calls the setPollId($iPollId) method, we must define that method as well:

function setPollId($iPollId) { // set the _iPollId variable for the class if (is_int($iPollId)) { $this->_iPollId = $iPollId; } }

The setAnswerId($iAnswerId) method sets the value for the _iAnswerId variable.

function setAnswerId($iAnswerId) { // set the _iAnswerId variable for the class if (is_int($iAnswerId)) { $this->_iAnswerId = $iAnswerId; } }

The class will also contain several methods for reading from and writing to the two database tables.

The getPollsCount method returns the number of polls in the poll table.

function getPollsCount($iStatus=false) { // get polls count for paging // set sql filter $iStatus ? $sFilter .= " AND status=1" : $sFilter .= ""; $sql = "SELECT count(poll_id) AS poll_cnt FROM devdrive_polls WHERE deleted=0".$sFilter; if (DB::isError($iCnt = $this->_oConn->getOne($sql))) { catchExc($iCnt->getMessage()); return false; } return $iCnt; }

The getPolls method returns all the poll data from the poll table into an associative array and sorts it by the sort key.

function getPolls($sSort, $iPage=0) {// get polls list $sql = "SELECT poll_id, poll_vote_cnt, poll_question, status, created_dt, modified_dt FROM devdrive_polls...
more →

J2EE 1.4 and Web Services

The J2EE platform is designed to provide server-side and client-side support for developing Web services and distributed, multi-tier enterprise applications. Web Services can provide unlimited functionalities by connecting with an existing service API or creating your own.

If you can efficiently develop and deploy distributed applications and Web services for use on both corporate intranets and over the Internet, you will gain competitive advantage.

J2EE

The J2EE platform is architected to facilitate the deployment of multi-tier distributed applications and Web services. The platform defines different tiers, including a client tier, one or more middle tiers, and a back-end tier. The J2EE platform supports component-based development of applications and services. The portions of application logic that reside on separate tiers can make use of the different components provided by the platform for each tier. To ensure that the components interact in a standard way, the platform introduces the concept of container-based component management. Components run within containers, which are standardized runtime environments that provide specific services to components and thus ensure application portability across platform implementations.

I assume that you already have J2EE platform on your servers, if not you can access it on with downloadable link and installation guide http://www.oracle.com/technetwork/java/javaee/download-141771.html

Web Services

As Web services can be used with any application or technology, the services should be written in such a way that it can communicate with any software, application and technology. The four basic standards required in web services are:

Who make services available, and service requestors, who use services, must be able to write Web services using Extensible Markup Language (XML). Simple Object Access Protocol (SOAP) provides a common message format for Web services. All service providers need to have a common format to specify service details, such as the service type, how to access the service, and so forth, which is written in Web Services Description Language (WSDL). Service requestors must have a common way to look up and obtain details of a service. This is accomplished by having common, well-known locations where providers can register their service specifications and where requestors know to go to find services. Universal Description, Discovery, and Integration (UDDI) specification defines a common means for looking up Web services.

Communication between Java Client and Java Web Services on J2EE Platform

In a Web service scenario, a client makes a request to a particular Web service, such as asking for the weather at a certain location, and the service, after processing the request, sends a response to the client to fulfill the request. When both the client and the Web service are implemented in a Java environment, the client makes the call to the service by invoking a Java method, along with setting up and passing the required parameters, and receives as the response the result of the method invocation.

Once the client knows how to access the service, the client makes a request to the service by invoking a Java method, which is passed with its parameters to the client-side JAX-RPC runtime. With the method call, the client is actually invoking an operation on the service. These operations represent the different services of interest to clients. The JAX-RPC runtime maps the Java types to standard XML types and forms a SOAP message that encapsulates the method call and parameters. The runtime then passes the SOAP message through the SOAP handlers, if there are any, and then to the server-side service port.

Java API

Java API for XML-based RPC (JAX-RPC) supports XML-based RPC for Java and J2EE platforms. It enables a traditional client-server remote procedure call (RPC) mechanism using an XML-based protocol. JAX-RPC enables Java technology developers to develop SOAP-based interoperable and portable Web services. Developers use the JAX-RPC programming model to develop SOAP-based Web service endpoints, along with their corresponding WSDL descriptions, and clients. A JAX-RPC-based Web service implementation can interact with clients that are not based on Java. Similarly, a JAX-RPC-based client can interact with a non-Java-based Web service implementation.

Implementation of JAX-RPC Service Endpoint Interface for the weather service interface using a Web component will be like:

public interface WeatherService extends Remote { public String getWeather(String city) throws RemoteException; }

JAX-RPC Service Implementation will be like:

WeatherService, ServiceLifecycle { public void init(Object context) throws JAXRPCException {} public String getWeather(String city) { return ("Early morning fog clearing midday; " + "over all great day expected in " + city); } public void destroy() {} }

A Java/J2EE Client Accessing the Weather Service will be:

Context ic = new InitialContext(); Service svc = (Service) ic.lookup("java:comp/env/service/WeatherService"); WeatherSvcIntf port = (WeatherSvcIntf) svc.getPort(WeatherSvcIntf.class); String info = port.getWeather("San Francisco");

This way you need to code very less and yet you can use lot of functionalities in your applications. The equivalent EJB service endpoint implementation for the same weather service.

public class HelloService implements SessionBean { private SessionContext sc; public WeatherService(){} public void ejbCreate() {} public String getWeather(String city) { return ("Early morning fog...
more →
Bart says: Ehmz... Are you aware that J2EE 1.4 was released in 2003? And that since then Java EE 5 has been released in 2006, and Java EE 6...

Developing With The HTML5 Element

Videos have been a great way to attract viewers to a website long before YouTube launched back in 2005.  But it wasn’t until the release of HTML5 that web developers have had a lightweight solution to playing the video.  In the past, displaying a video on your site meant your viewer was required to have a Flash or Java-based player installed on their system in order to watch the video.  This was one more thing that would weigh down your site, causing pages to load slower, and be one more thing you’d have to trust the viewer to download and install.

Handling a video with HTML5 can be as simple as this.

<video src=”videos/myMovie.mp4” controls></video>

You’ve got the source and have added the browsers native controls.  That’s approximately 41 less lines of code than a site I recently worked on that was using a Flash player, not to mention the player itself had a fairly bulky file size.

Flash and Java Video Players

One big advantage that Flash and Java video players have over the new HTML5 video element is that they’re able to stream live video.  The HTML5 video element is still in its infancy and as of now is not able to stream any sort of live video feed.  Another major advantage that a Flash of Java video player has over HTML5 is that they can handle 3D effects.  This could be a major factor in preventing HTML5 video players from taking away a large amount of market share from Flash and Java players.  As we’re seeing an influx of films coming out in 3D, as well as major sporting events being broadcast in 3D, the ability to handle 3D and streaming content is becoming a more crucial requirement for a video player.  Add the growing number of people who choose to stream movies or TV shows from sites like Netflix, Hulu, or YouTube, and the demand for a powerful, robust video player grows even more.

One of the downsides to having a Flash video player, aside from file sizes and it being an add-on that the viewer must install, is that Flash is not compatible with Apple tablets and mobile devices.  With Net Applications announcing iOS grew to owning 61.6% of the mobile market share in the month of October, that appears to be a big down side.  Especially when you consider more people opt to browse websites from their mobile device or tablets instead of using their computer.

Java players gain their biggest edge over Flash players by being compatible with the iPhone, iPad, and iPod touch. The reason behind Apple’s decision not to support Flash stems from Flash being a “closed” system, meaning that Adobe Flash products are only available from Adobe and Adobe controls the future of the product in regards to upgrades and pricing.  This is opposed to Java, which is an “open” programming language.  Downsides to a Java video player are very similar to that of Flash as well, larger file sizes, and the need for the viewer to install a plug-in for their browser to display the video.

HTML5 Video Element

We’ve already established that an HTML5 video player can mean you have a substantially smaller file size, but as with Flash and Java, HTML5 has its advantages and disadvantages.  An HTML5 video player will also be cross-browser friendly and work on Apple products.  However, just because you’ve implemented an HTML5 video player on your site does not mean that the video will play on an Apple product.  This is an issue I pointed out with a recent client; they wanted to switch their site from a Flash video player to HTML5 so that it would play on an iPhone or iPad.  It was at this point I had to point out that their video formats were in FLV, a video compressed with Flash.

To accommodate anyone who might be viewing your site from an Apple mobile device or tablet there are some video compression guidelines you will want to follow.  An iPhone will play MPEG-4 videos or QuickTime videos that were compressed with MPEG-4, meaning H.264 video and AAC audio.  It’s also worth noting that the iPhone does not support B-Frames.  If you’re given the option of encoding your video in a multi-pass or single-pass mode, choose single, even though you will most likely be encouraged to do multi-pass for best quality.  I’ve found that 480×360 dimensions is a nice median to accommodate full screen on a computer without distorting the image too much, and not ending up with a file so large it takes too long to load on an iPhone.

HTML5 will also allow you to name multiple video sources, OGG, MPEG-4, and WebM.  OGG is compatible with Firefox 3.5+, Opera 10.5+, and Chrome 5.0+, but not IE or Safari.  MPEG-4 is supported by IE 9.0+, Chrome 5.0+, and Safari 3.0+, but not Firefox, or Opera.  While WebM is supported by Firefox 4.0+, Opera 10.6+, and Chrome 6.0+, but not IE or Safari.  Being able to point to multiple sources will ensure that your video is able to play on any major browser, with the only downside being you to have multiple formats of your video.

Pointing to multiple video sources is as easy as one might think, “just include the source for each”.

<video controls> <source src=”videos/myMovie.mp4” type=”video/mp4” /> <source src=”videos/myMovie.ogg” type=”video/ogg” /> <source src=”videos/myMovie.webm” type=”video/webm” /> </video>

Moving Forward With <video>

Some might say that the <video> element is too little too late, but using HTML5 to display a simple static video on your site is a perfect way to ensure viewers to your site will be able to see it, whether it’s on a mobile device or a desktop computer.  It’s lightweight and requires no additional plug-in to work.  As with all new technologies you have to start somewhere, and from there you begin to see areas in which it can be improved.  Being someone who strives to develop as lightweight of sites as possible, I am excited to see what direction the new HTML5 video element goes.

...
more →
UK Logo Design says: Very well shared, this is nice to read this article. i am learning web designing and development, so this element will be more...

Creating a PHP User Survey: Writing to Database Tables

In the first two parts of this series, we created the data layer that will hold the polling data and established methods for setting the variable values and reading from the database tables.

In this part, we will build the methods that will write new polls and answers to the tables.

The addPoll method adds a new record to the devdrive_polls table and returns a Boolean value that signals if the record was added successfully.

function addPoll($aArgs) { // add a poll record $sql = "LOCK TABLES devdrive_polls WRITE"; // lock tables to capture unique identifier if (DB::isError($rsTmp = $this->_oConn->query($sql))) { catchExc($rsTmp->getMessage()); return false; } $sql = "INSERT INTO devdrive_polls ( // add new record poll_question, status, created_dt, modified_dt ) values ( '".$aArgs["Question"]."', 1, (NOW()), (NOW()) )"; if (DB::isError($rsTmp = $this->_oConn->query($sql))) { catchExc($rsTmp->getMessage()); return false; } $sql = "SELECT MAX(poll_id) FROM devdrive_ polls"; // get last unique identifier from entry if (DB::isError($iPollId = $this->_oConn->getOne($sql))) { catchExc($iPollId->getMessage()); return false; } $sql = "UNLOCK TABLES"; if (DB::isError($rsTmp = $this->_oConn->query($sql)))...
more →
Logo Design Contest says: Excellent tips, using database is much tough to be organized according to its content but the coding provided makes it easy to...

An Introduction to HTML5′s Video API Part 2

This is the second part in our introduction to HTML5′s video API. In part 1 of this series, I introduced you to the basic markup we’ll be using to play the video, then I helped set up a simple script with which we were able to make the controls visible, while ensuring that the native controls will still be visible when JavaScript is disabled.

We also touched on the use of JavaScript’s addEventListener method, along with our first look at the video API — the canplaythrough event. Let’s dig a little deeper into the API and start giving some functionality to our play/pause and mute/unmute buttons.

Playing and Pausing

With our controls visible, we’ll allow the user to play and subsequently pause the video. Here’s how we’ll do it:

playPause.bind('click', function () { if (video.paused) { video.play(); } else { video.pause(); } return false; });

Using jQuery’s bind() method, we’ve attached a click handler to the play/pause button. Then, in response to the click, we use a simple if statement to decide what to do. The video API’s paused attribute will be set to true if the video is in the “paused” state. So in that case, we can safely play the video. This is done by calling the play() method.

If the video is not in the paused state, then that must mean it’s in the “playing” state, so we can safely pause it. This is done using the video API’s pause() method. Finally, we return false on the click event, so the click isn’t registered within the page itself.

But what about the visual state of our play button? If the video is playing, then we want the play/pause button to look like a pause button. Let’s add some code that will do this in a rudimentary fashion:

video.addEventListener('play', function () { playPause.html('||'); }, false); video.addEventListener('pause', function () { playPause.html('▶'); }, false);

Here we have two new events from the video API. First we’re listening for the firing of the “play” event. In response to that, we change the button’s text to a double pipe (“||” – which kind of looks like a pause button).

Next we listen for the pause event. When this fires, we change it back to a right-pointing triangle (“▶” – which kind of looks like a play button).

But you’re probably wondering: Why not just change the button’s visual state in the previous code block, where we responded to the click event? Well, clicking the button is not the only way to play or pause the video. The user also has the option to bring up a context menu from the video element itself, shown below:

By changing the button’s state in response to the video element’s native events, we ensure that the button will always accurately represent the proper state. It’s a little extra code, but it ensures a more usable experience.

Muting and Unmuting

The code to allow muting and unmuting of the video’s sound is somewhat similar to the code we’ve already introduced. Except this time we’ll be using two new API features: The muted attribute and the volumechange event:

muteUnmute.bind('click', function () { if (video.muted) { video.muted = false; } else { video.muted = true; } return false; }); video.addEventListener('volumechange', function () { if (video.muted) { muteUnmute.html('⊕'); } else { muteUnmute.html('⊗'); } }, false);

The reason we listen for the “volumechange” event and not a “mute” or “unmute” event is that there are no “mute” or “unmute” events – only a “muted” attribute.

Now our video can be played, paused, muted and unmuted – all by means of our custom controls.

When the Video Ends Playback

Finally, we’ll add an event that listens for the end of video playback then sends the video back to frame one so it’s ready to be played again:

video.addEventListener('ended', function () { video.currentTime = 0; video.pause(); }, false);

Here we listen for the “ended” event, which means the video has come to the end of playback. When that fires, we set the video back to the first frame by setting its currentTime attribute to zero. Then we pause the video at this spot, so it will be ready to play again when the user desires.

Other Events and Attributes

In this two-part series, we’ve only briefly scratched the surface of the events and attributes available via HTML5′s media elements API. And in fact, what we’ve done here is just one basic way to create custom video controls. There are other events and attributes that we can utilize to have a more fine-grained approach to our media resource’s custom controls.

For example, the API includes events like progress (which fires when the browser is getting media data), stalled (when the browser unexpectedly can’t fetch the data), error (when an error occurs), loadedmetadata (when the duration and dimensions of the resource are loaded), and durationchange (when the duration of the video has been updated).

There are also attributes like seeking (which indicates whether or not the user is “scrubbing” through the video), videoTracks (which is an object containing any tracks associated with the video), duration (the length of the video), and loop (indicating whether or not the video will repeat once it ends).

As support for the video API improves, more and more developers will start using it in various ways in their projects. In fact, with the fallback solutions available, it’s ready to use today. Check out the links below for further info on the different parts of the media elements API.

Further Reading

HTML5 Video Events and API Media Elements API on WHATWG

...
more →

Creating OpenSocial Gadgets

There are two things which look and act similar but are different, gadgets and widgets.

Widgets can be referred to any icons or graphical interface element that is operated by a computer or internet use to execute a preferred function online or on the computer. You can add a widget in all kind of web pages.

A gadget acts just like a widget, often fulfilling the same purpose, but it is proprietary or called to be self-contained. It only works on a certain website or a specific set of websites. For example, OpenSocial Gadgets can look and act like widgets. But they only work on OpenSocial enabled web pages.

You can use gadgets to make your web pages even more interesting and useful to your visitors. People can add your gadget to their personalized profile pages or to their other pages.

OpenSocial gadgets also work in very similar way like a normal gadget plus the gadgets have unlimited ways to bring new functionalities through incorporating customized code into service classes of Shindig. In this tutorial, we will explore more about OpenSocial gadgets. Please note that I am assuming that either you have a OpenSocial integrated website where you would like to use gadgets or you want to contribute the gadget to the gadget directory. The gadgets will not work on any website.

OpenSocial Gadgets

Gadgets are applications and you can build gadgets according to your unique requirements. Otherwise just use existing gadget from reliable directories and customize it for the field names etc. to make it work on your website.

At their core, social gadgets are XML files, sometimes known as gadget specifications. Here is a simple “Hello World” gadget (helloworld.xml) that illustrates the basic sections of a specification:

<?xml version="1.0" encoding="UTF-8" ?> <Module> <ModulePrefs title="Hello World!"> <Require feature="opensocial-0.8" /> </ModulePrefs> <Content type="html"> <![CDATA[ Hello, OpenSocial Gadget world! ]]> </Content> </Module>

In the “Hello OpenSocial Gadget world ” example, you can see several sections which control the features and design of the gadget. A gadget is hosted in a server infrastructure to provide its data.

<Module> indicates that this XML file contains a gadget. It is a root tag. This root tag contains a <ModulePrefs> and a <Content> section. <ModulePrefs> is in XML format. It specifies characteristics of the gadget, such as title, author, preferred sizing, and so on. <Require feature=”opensocial-0.8″ /> denotes a required feature of the gadget — in this case, the OpenSocial API (v0.8). <Content type=”html”> indicates that the gadget’s content type is HTML. This is the recommended content type for OpenSocial containers, but gadgets for other containers such as iGoogle support other content types. <![ CDATA[a:...]]> contains the bulk of the gadget, including all of the HTML, CSS, and JavaScript (or references to such files). The content of this section should be treated like the content of the body tag on a generic HTML page.

We usually have one more tag of <UserPrefs> section, which defines controls that allow users to specify settings for the gadget. For example, a personalized greeting gadget might provide a text field for users to specify their names. The gadgets API consist of a few simple building blocks: XML, HTML, and JavaScript. So writing your own gadgets are not difficult once we understand few basics.

Giving Gifts Gadget Description

One example to access your friend’s list is below, let’s build to complete virtual gift giving functionality for your website. To access the example, visit the link http://opensocial-resources.googlecode.com/svn/samples/tutorial/tags/api-0.8/gifts_2_send_gifts.xml

Explanation of the above link code is follows:

The JavaScript function will allow you to select a friend to receive a virtual gift. Please check that using variable like “viewerFriends” is an undefined standard followed in the gadget community. OpenSocial defines two personas, the owner and the viewer. The owner is the user that owns the content on a particular page while the viewer is the logged in user looking at a page.

For example, if Alice is logged into a social network and she’s viewing Bob’s profile page, then Alice is the viewer and Bob is the owner. If Alice is viewing her own profile page then she is the owner and the viewer.

It’s also possible for Alice to view Bob’s instance of an application. Suppose Alice is viewing an app on Bob’s profile and clicks a link that takes her to the canvas view. In this case, Alice is the viewer of the canvas view, and Bob is the owner. If Alice is viewing her own instance of an app’s canvas page, then she is the owner and the viewer. The latter case, where owner == viewer, is often used to let the user configure the settings of an app.

Also note that to use this gadget you need to have a website where friend’s functionality exists. Not every information oriented website has making friends online functionality, so they can use some other type of gadgets.

function onLoadFriends(data) { var viewer = data.get('viewer').getData(); var viewerFriends = data.get('viewerFriends').getData(); html = new Array(); html.push('<select id="person">'); viewerFriends.each(function(person) { if (person.getId()) { html.push('<option value="', person.getId(), '">', person.getDisplayName(), '</option>'); } }); html.push('</select>'); document.getElementById('friends').innerHTML = html.join(''); }

Next, you’ll need to create another selection menu of gifts you can give. The sample uses a selection of different types of nuts, but you can feel free to use whatever you like. A small update to the initialization function calls this function when the page loads.

var globalGiftList = ['a cashew...
more →
says: Amazing Work!! this gadgets coding really works, thanks you so much for sharing with us!