Ajax Updates

Ajax Updates


Fancy Apple.com Style Search Suggestion

Posted: 29 Sep 2009 11:38 AM PDT

Apple is known to create beautiful products (next to the needed functionality of course). I already wrote several articles on how you can transfer some amazing iPhone designs to your webbrowser, I own a MacBook Pro (which also looks pretty sleek) and many other products from Apple are well known for their amazing design.

The website from Apple isn’t less: The layout is simple yet beautiful. Yet, one of the most awesome things about the website is the search functionality. It gives you suggestions (with images) about the several products they offer, making it really user-friendly.

Today, we’re trying to recreate the effect from that website by creating a fancy apple.com-style search suggestion. Make sure you check out the demo (or visit Apple.com) to see this awesome effect work.

This example makes use of several techniques: MySQL (for the database), HTML/CSS for styling, PHP for retrieving the data and jQuery for the AJAX request. How about that for some nice way of combining powerful techniques to create something nice like this. You do need some basic knowledge about these techniques to fully understand this tutorial.

IMPORTANT NOTE:
As you can see, the demo is located on another server. The reason for this is, that every time a user presses on his keyboard, a call is made to the MySQL database. When loads of users do loads of calls (at the same time), this could result in slowing down the database. The answer for this would that the results should be cached – Something that isn’t implemented right now.

Safari, Chrome and Opera are currently the only webbrowsers that support the drop shadow effect around the the search results. Other browsers will simply display the results without the drop shadow.

This technique would be great if it were converted to a plugin for a CMS (WordPress/Joomla/Drupal etc.), but also just very cool to have on your website.

The SQL dump looks like this:

 CREATE TABLE IF NOT EXISTS `categories` (   `cid` int(11) NOT NULL AUTO_INCREMENT,   `cat_name` varchar(255) NOT NULL,   `cat_url` text NOT NULL,   PRIMARY KEY (`cid`) );  CREATE TABLE IF NOT EXISTS `search` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `cat_id` int(11) NOT NULL,   `name` varchar(255) NOT NULL,   `img` varchar(255) NOT NULL,   `desc` text NOT NULL,   `url` text NOT NULL,   PRIMARY KEY (`id`) ); 

I assume the names of the columns are pretty straight forward. You’ll need to fill in the data yourself (in the download, you can find all the INSERTS that can be found in the demo). Also, take note of the AUTO_INCREMENT from both id’s.

Now that we have the data stored, we’ll need a front-end to place the data in. On to the next part!
HTML:
The HTML from the page isn’t the spectecular: It simply holds one form element with an input box. Take note that no action is defined to the form. If you actually want to pass the data to the search page, you should add it. Also, no input-submit was added.

  <div>    <form id="searchform">       <div>          What are you looking for? <input type="text" size="30" value="" />       </div>       <div id="suggestions"></div>    </form> </div> 

More interesting in the code above, is the (empty) divider with an id suggestions. We’ll fill up this divider later on with jQuery to place the actual found search results in.
Search results

Even more interesting is the searchresults that we’re going to display. Here’s the HTML, I’ll explain it below.

 <p id="searchresults">    <span class="category">[CATEGORY_FROM_DATABASE]</span>       <a href="[URL_FROM_DATABASE]">          <img alt="" src="search_images/[IMG_FROM_DATABASE]"/>          <span class="searchheading">[HEADING_FROM_DATABASE]</span>          <span>[TEXT_FROM_DATABASE]</span>       </a>       <a href="[URL_FROM_DATABASE]">          <img alt="" src="search_images/[IMG_FROM_DATABASE]"/>          <span class="searchheading">[HEADING_FROM_DATABASE]</span>          <span>[TEXT_FROM_DATABASE]</span>       </a>       <!-- more items -->    <span class="category">Webdesign</span>       <a href="[URL_FROM_DATABASE]">          <img alt="" src="search_images/[IMG_FROM_DATABASE]"/>          <span class="searchheading">[HEADING_FROM_DATABASE]</span>          <span>[TEXT_FROM_DATABASE]</span>       </a>    <!-- more categories -->    <span class="seperator">       <a href="http://www.marcofolio.net/sitemap.html">Nothing interesting here? Try the sitemap.</a>    </span> </p>  

* #searchresults – Main container to place the search results in.
* .category – When a new category is displayed, simply use this span to differ it from the actual links.
* .seperator – This is used at the bottom of the suggestion, linking to another page (in this case: the sitemap).
* As you can expect, all values between the [] and written in capitals needs to be data from the database.

On to some CSS styling and make it look a lot more pretty!

CSS:
First, we’ll fancy-up the page (looks pretty boring now, right?). I used the same background as in the polaroid viewer (hey, it looks pretty nice) and wrote the following CSS.

  /* HTML ELEMENTS */ body { font-family:"Lucida Grande","Lucida Sans Unicode",Arial,Verdana,sans-serif;    background-color:#efefef; background-image:url(../images/bg.jpg); }  /* SEARCH FORM */ #searchform { margin:50px 200px; font-size:18px; } #searchform div { color:#eeeeee; } #searchform div input { font-size:18px; padding:5px; width:320px; } #suggestions{ position: relative; left:235px; width:320px; display:none; } 

Nothing really fancy going on over here, except for the #suggestions. As you can see, the display is set to none. Like I said, we’ll fill that container using jQuery but we’ll also show it (fade it in) using the javascript framework. We’ll get to that later.



Demo:
Download:
Source:

Related Listings:

  1. Ajax Suggestions Script JAX Suggestions is pretty much what you might have seen...
  2. Spry Auto Suggest Search Script This page will highlights the capabilities of the Spry Auto...
  3. Ajax Script for Domain Search Ajax Domain Search Script is an open source domain...

MooTools Dropdown Menus With MenuMatic

Posted: 29 Sep 2009 10:42 AM PDT

MenuMatic is a MooTools 1.2 class that takes a sematic ordered or unordered list of links and turns it into a dynamic drop down menu system. For users without javascript, it falls back on a CSS menu system.

<link rel="stylesheet" href="css/MenuMatic.css" type="text/css" media="all" /> ... <ul id="nav"> 	<li><a href="#" >Link 1</a></li> 	<li><a href="#" >Link 2</a> 		<ul> 			<li><a href="#" >Link3</a></li> 			<li><a href="#" >Link4</a></li> 		</ul> 	</li> 	<li><a href="#" >Link 5</a></li> </ul> ... <script type="text/javascript" src="http://www.google.com/jsapi" ></script> <script type="text/javascript" > google.load("mootools", "1.2.1"); </script> <script type="text/javascript" src="js/MenuMatic_0.68.3.js" ></script>   

Javascript:

 var myMenu = new MenuMatic({/*options here*/});  

Features:
* Search Engine Friendly: Only manipulates existing links, does not generate links with javascript.
* Usable: Adjust hide delay to keep menus from disappearing to quickly.
* Accessible: Tab through main menu links with tab key. Navigate through drop down menus with arrow keys.
* Fails Gracefully: Falls back to suckerfish CSS based drop down menu system in the absence of javascript.
* Stylish: Control how menu looks with CSS, add flair with some effects.
* Flexible: With plenty of options (and more coming down the road) and the open source code, make it do your bidding.



Demo: http://greengeckodesign.com/?q=menumatic
Download:
Source: http://greengeckodesign.com/?q=menumatic

Related Listings:

  1. Digg Like Menus Using CSS Navigation bar with rounded corners an sliding doors technique for...
  2. 10 incredible JQuery navigation menus JQuery is a lightweight, cross-browser compliant, and extremely powerful Javascript...
  3. Ajax Prototype Vertical Menus A simple and lightweight prototype-based solution for vertical menu. Features:...

Captions and Sliding Boxes using jQuery

Posted: 29 Sep 2009 09:37 AM PDT

All of these sliding box animations work on the same basic idea. There is a div tag (.boxgrid in my css) that essentially acts as a window where two other items of your choosing "peek" through.

From this basic idea we can play around with animations of the sliding element to either show or cover up the viewing area, thus creating the sliding effect.
Step 1 – CSS Foundation Work

Given the basic structure outlined in the helpful image above, we will need to use a little bit of CSS to make it work as intended. The following will make it functional – review my complete stylesheet in the downloadable file.

The following defines the viewing window (.boxgrid) and sets the default position for images within it to the top left. This is important to make the overlap while sliding work. Dont' forget that overflow:hidden makes this all possible.

  .boxgrid{ 	width: 325px; 	height: 260px; 	margin:10px; 	float:left; 	background:#161613; 	border: solid 2px #8399AF; 	overflow: hidden; 	position: relative; } .boxgrid img{ 	position: absolute; 	top: 0; 	left: 0; 	border: 0; } 

If you aren't using the semi-transparent captions you are done with CSS – move to Step 2.

   .boxcaption{ 	float: left; 	position: absolute; 	background: #000; 	height: 100px; 	width: 100%; 	opacity: .8; 	/* For IE 5-7 */ 	filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80); 	/* For IE 8 */ 	-MS-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";  	}

Opacity that plays nice in all browsers is a rough topic, educate yourself if you need to.

Now we'll need to set up the default starting point for the caption box. If you want it fully hidden initially, you will want the distance from the top or left to match the height or width of the window (.boxgrid), depending on which direction it will be sliding. You can also have it partially visible initially, as .caption .boxcaption illustrates.

   .captionfull .boxcaption {  	top: 260;  	left: 0;  }  .caption .boxcaption {  	top: 220;  	left: 0;  } 

Step 2 – Adding the Sliding Animations

This next stage is a matter of choosing which animation suites you, I have included a bunch of pre-formatted potentials to help you along. Play around with them to find one that fits your needs and style.

 $(document).ready(function(){ 	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute 	//Vertical Sliding 	$('.boxgrid.slidedown').hover(function(){ 		$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300}); 	}, function() { 		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300}); 	}); 	//Horizontal Sliding 	$('.boxgrid.slideright').hover(function(){ 		$(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300}); 	}, function() { 		$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300}); 	}); 	//Diagnal Sliding 	$('.boxgrid.thecombo').hover(function(){ 		$(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300}); 	}, function() { 		$(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300}); 	}); 	//Partial Sliding (Only show some of background) 	$('.boxgrid.peek').hover(function(){ 		$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160}); 	}, function() { 		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160}); 	}); 	//Full Caption Sliding (Hidden to Visible) 	$('.boxgrid.captionfull').hover(function(){ 		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160}); 	}, function() { 		$(".cover", this).stop().animate({top:'260px'},{queue:false,duration:160}); 	}); 	//Caption Sliding (Partially Hidden to Visible) 	$('.boxgrid.caption').hover(function(){ 		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160}); 	}, function() { 		$(".cover", this).stop().animate({top:'220px'},{queue:false,duration:160}); 	}); });

Step 3 – The HTML

There are a few classes that we created simply as selectors for JQuery. Keep these rules in mind:

* The div class ".cover" should be assigned to whatever is doing the sliding/movement.
* Within the div .boxgrid, the img should always come first.

Here's an example of the HTML I would use for the .captionfull animation:

<div class="boxgrid captionfull"> 	<img src="jareck.jpg"/> 	<div class="cover boxcaption"> 		<h3>Jarek Kubicki</h3> 		<p>Artist<br /><a href="<a class="linkification-ext" title="Linkification: http://www.nonsensesociety.com/2009/03/art-by-jarek-kubicki/" href="http://www.nonsensesociety.com/2009/03/art-by-jarek-kubicki/">http://www.nonsensesociety.com/2009/03/art-by-jarek-kubicki/</a>" target="_BLANK">More Work</p> 	</div> </div>   

Go Forth and Create

I've only touched upon a few options you have, these boxes are your canvases, create away. I would encourage you to download the attached files, as it may be easiest to just copy-paste the parts relevant to your project.



Demo: http://buildinternet.com/live/boxes/
Download: http://buildinternet.com/live/boxes/slidingboxes.zip
Source: http://buildinternet.com/2009/03/sliding-boxes-and-captions-with-jquery/

Related Listings:

  1. Sliding Menu for script.aculo.us It's been a while since the original post Sexy sliding...
  2. jQuery Link Nudge Plugin A while back I debuted a tasteful mouseover/mouseout technique called...
  3. Sliding Tabs using Mootools Sliding Tabs is a mootools 1.11 plugin which adds a...

uploadify – A file upload plugin using jQuery

Posted: 29 Sep 2009 08:56 AM PDT

This plugin allows you to change any element with an ID on your page into a single or multiple file upload tool. The plugin uses a mix of JQuery, Flash, and a backend upload script of your choice to send files from your local computer to your website ser
uploadify - A file upload plugin for jQuery

Latest Features and Functions:

  • Function changed to uploadify()
    • fileUpload()                       – uploadify()
    • fileUploadStart()              - uploadifyUpload()
    • fileUploadSettings()        - uploadifySettings()
    • fileUploadCancel()          - uploadifyCancel()
    • fileUploadClearQueue() – uploadifyClearQueue()
  • queueID option added
  • method option added
  • uploadifySettings getter added
  • queueSizeLimit option added
  • onQueueFull event trigger added
  • Server-side file type validation added (commented out), requires fileExt
  • SWFObject integration
  • Example folder added to zip package
  • "All Glyphs" version of SWF file added to zip package
  • Moved error styling to css
  • Errored queue items can now be cancelled
  • Files process in order of adding to queue
  • errorObj returned by onError now only uses two parameters
  • Updating scriptData is now performed by passing an array of key/value pairs
  • hideButton can now be used to hide the browse button with uploadifySettings()
  • Added compatibility for noConflict() and for use with other api's ie prototype

Implementation:
Following steps need for implementation the script on your page:

Requirements:
* jQuery v1.2.x or greater
* SWFObject v2.2 or greater
* Flash Player v9.0.24 or greater
Preparation:
1. Download the jquery.uploadify-v2.1.0.zip package
2. Unzip the file and upload the contents to your website
3. Link the jQuery library, uploadify js, uploadify.css and swfobject js files
The Code:
In it's simplest form, Uploadify is very easy to implement.

  <input id="fileInput" name="fileInput" type="file" /> <script type="text/javascript">// < ![CDATA[ $(document).ready(function() { $('#fileInput').uploadify({ 'uploader'  : 'uploadify.swf', 'script'    : 'uploadify.php', 'cancelImg' : 'cancel.png', 'auto'      : true, 'folder'    : '/uploads' }); }); // ]]></script> 




Demo: http://www.uploadify.com/demo/
Download: http://www.uploadify.com/_files/jquery.uploadify-v2.1.0.zip
Source: http://www.uploadify.com/

Related Listings:

  1. Multiple File Upload – JQuery The Multiple File Upload Plugin (jQuery.MultiFile) is a non-obstrusive plugin...
  2. AJAX file upload Script Ever wanted to upload files using AJAX like in...
  3. Ajax File Upload using JQuery Script that simplifies how you traverse HTML documents, handle events, perform...

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.