Put your message here! Contact me for more information
 
 







 

Archive for the ‘Ajax & Web 2.0’ Category


 

I just recently completed a demo for a client of mine. The demo was a news portal with lots of links to external news contents. I wanted to spice things up a little, so I implemented a inline link-tip (or inline popup, however, this name may confuse you with the light-box type popup) using the [[http://developer.yahoo.com/yui/|Yahoo! User Interface Library]] (YUI). Thanks to YUI, the effect is now quite easy to be implemented.

Here’s a screencast of what the inline link-top looks like

{{ http://alexle.net/wp-content/uploads/2006/10/inline.gif }}

(If you want to see the actualy demo page or get the sample code, please scroll down to the end of the post)

===== The setup =====
Here is the XHTML-compliant markup code for the content and the hover.

www.AlexLe.net has a few home-writen tutorials.

Link 1 to test if the hover is hidden properly.

www.VentureBeat.com
the blog of Matt Marshall
tracking Sillicon Valley,VC, and Startup


Basically we have a few DIVs, positioned either inline or absolutely to show how the inline link-tip works in both cases. Inside each container div, we have a link with a className of **articleTitle** and an extra attribute called **hoverId**. This extra **hoverId** attribute specifies the ID of the popup that we’d like to associate with this link.

Next, we setup the hover container div. The popup div has the className of ‘inlinePopup’ so that we can style it with CSS later on. Let’s take the div with Id ‘hover1′ as our example.

...




For this technique to work, we have to explicitly add the **style=”display:none;”** for the popup div. Setting display:none in the inlinePopup CSS class definition will not work.

For the CSS styling, we can just add these rules to the page to make things a little nicer.

===== The Javascript =====
Here is the javascript to handle the inline popup/ tooltip. The idea is after the page has been rendered properly (window onLoad is fired), we scan through the DOM, look for any link with the className of **articleTitle**, then attach custom events for onMouseOver and onMouseOut to handle the display of the popup. And thanks to YUI, adding custom events and web2.0 animations is easier than ever.

First of all, we include the YUI’s library to our page









Then we insert some javascript codes. Let’s start with the pageInit() function first.
pageInit = function() {
/* Popup summary */
/* We find all items with the articleTitle class */
var els = YAHOO.util.Dom.getElementsByClassName('articleTitle', 'a');
for( var i=0; i < els.length; i++ )
{
/* Get the hover div */
sDivId = els[i].getAttribute('hoverId');
sDiv = document.getElementById( sDivId );
YAHOO.util.Dom.setStyle( sDiv , 'opacity', '0');

/* Unhide the Summary layer when mouse over/ out*/
YAHOO.util.Event.addListener( els[i], "mouseover", hoverOver );
YAHOO.util.Event.addListener( els[i], "mouseout", hoverOut );
}
}
YAHOO.util.Event.addListener( window, "load", pageInit );

We basically find all **a** (anchor) elements in the page with the className of **articleTitle**. Then we loop through the result **els** array and look for which popup div is associated with this link. As we stored the popup div’s ID in the hoverId attribute of the link, we can just grab the value by using the getAttribute(’hoverId’). And next, we set the opacity of the popup div to 0. With YUI, we don’t have to worry about the different syntax of different browsers. Only one single line of code to set the opacity! Next, we add our custom functions to the **a** element to handle the **onMouserOver** and **onMouserOut** events with the **YAHOO.util.Event.addListener( element, “eventType”, customHandler )**

==== Custom Event Handlers ====
We can now implement our **hoverOver()** and **hoverOut()** handlers. Let’s start with **hoverOut()**

/* This function is to unhide the div, then do a smooth very web2.0 fade-in effect */
function hoverOver()
{
var sDivId = this.getAttribute('hoverId');
var sDiv = document.getElementById( sDivId );

sDiv.style.left = YAHOO.util.Dom.getX( this ) +'px';
sDiv.style.top = (YAHOO.util.Dom.getY( this ) + this.offsetHeight + 2 ) +'px';
sDiv.style.display = '';
var animIn = new YAHOO.util.Anim( sDiv, { opacity: { to: 1 } }, 0.25, YAHOO.util.Easing.easeOut);
animIn.animate();
}

When the mouse hovers over the link, this hoverOver() function is triggered. However, at this very moment, we find out that we don’t have any reference to targetted popup div, so we go grab the popup div’s id from the hoverId attribute of the a element. Luckily, we can just reference to the a element as **this**.

=== Positioning the Popup & Adding Dramatic fading effect ===
As our links can be rendered anywhere in the screen, we have to know where to put our popup div. The solution is to set the position of the popup div to the coordinates of the link. With YUI, it’s quite easy: **YAHOO.util.Dom.getX( this )** and **YAHOO.util.Dom.getY( this )** for the x and y values of the a element. But this will give us the top left corner of the boundary box of the link element, which means our popup would be placed **on top** of the link. So we add the offsetHeight of the a element to the top (Y) value of the popup, plus a few extra pixels as the ‘margin-top’. Now our div is positioned correctly. With this approach, we can place our link anywhere: whether it’s in a absolutely positioned container, or inline within a paragraph, the popup div is still positioned nicely below it.

That isn’t t too bad, is it? Now let’s add the fade-in effect. As we already set the opacity of the popup div to 0 when the page is loaded, we can just use the animation feature of YUI for the dramatically fade-in.

...
var animIn = new YAHOO.util.Anim( sDiv, { opacity: { to: 1 } }, 0.25, YAHOO.util.Easing.easeOut);
animIn.animate();
...

I use 0.25 second for the popup div to appear as I think anything longer will be quite annoying to the end-users (”whoever designed this dang page is wasting my time here”). Let’s keep our visitors happy. The YAHOO.util.Easing.easeOut is added so that the animation is eased out for a smoother appearance of our popup div.

Next, we added the **hoverOut()** handler to hide the popup div with an equally nice fade-out effect. But for **hoverOut()** to work correctly, we have to do some extra work towards the end. Here’s the code:


/* This function is to hide the div with a dramatic web2.0 fade effect */
function hoverOut()
{
var sDivId = this.getAttribute('hoverId');
var sDiv = document.getElementById( sDivId );
var animOut = new YAHOO.util.Anim( sDiv, { opacity: { to: 0 } }, 0.25, YAHOO.util.Easing.easeOut);
animOut.animate();
animOut.onComplete.subscribe( hoverHide );
}

Again, we get the reference to the popup div, then we fade it out by changing its opacity to 0. At this point, eventhough the user won’t see the popup div anymore, it’s not actually hidden. This means that the popup div is still covering up the space underneath it, thus link or clickable elements underneath won’t work (not clickable). We have to explicitly set the display of the popup div to none when the fade-out animation is finished to remove it from the page. We do this by using the **animOut.onComplete.subscribe()** to hand a callback method to the animation object. Our callback method will be called when the animation is completed and hide the popup div.

Here’s the one-line code for the hoverHide() callback function

/* Call back function used in hoverOut() */
function hoverHide()
{
this.getEl().style.display = 'none';
}

The **this** keyword now is interpreted as the animation object, not the link item. We use this.getEl() to get the reference to the targetted hover div, and set its style.display to ‘none’. Now everything’s working the way it’s supposed to. Yay!

===== Final Remarks =====
Thanks to YUI, the code is truely multi-platform compatible. All the event handlings are done through the YAHOO.util.Event so we don’t have to deal with messy browser sniffing and special cases. The YAHOO animation is simple and flexible enough for us to customize the way we want. The inline popup is also robust enough as we can style it with CSS like adding some neat drop-shadow and round-corner effects. As you can see from the screencast above, the inline popup is working correctly in the extreme case of rapidly hovering in and out. Nobody would do anything that crazy in real life but it’s nice to see how the effect behaves in extreme cases. And I think one important feature of this technique is that we can implement it to any existing page with minimal code editing.

I hope you enjoy this small tutorial!

Cheers!

===== Code & Sample Page =====
You can download the sample code of this tutorial here.
* [[http://alexle.net/wp-content/uploads/2006/10/inlinePopup.zip|Inline Popup Source File]]

The same code can be accessed here
* [[http://alexle.net/wp-content/uploads/2006/10/inlinePopup/|Demo Page]]

view comments
 

After reading my buddy’s blog (http://blog.tvlgiao.com/) about the PHPEclipse, I decided to give it a shot. I’ve been using the Zend IDE because I love the intellisense feature (a.k.a. auto-complete) of this nice IDE. The only thing is that it’s very slow to start and I had a hard time installing the debugger. Well, now the PHPEclipse package also provides the same functionalities with a complete debugger for FREE.

This is the first time I try Eclipse. My impression: impressive! The IDE loads faster than the Zend 5.1.0 IDE, eventhough both run on Java VM. The GUI of Eclipse is also slicker and it gives me the feeling of working in Visual Studio again. Installing the PHPEclipse was a breeze via the Find & Install featured under the Software Update menu. However, installing the php_dbg with Xampp wasn’t that straightforward.

At the time of writing, the php_dbg.dll is only available upto PHP engine version 5.1.2. The newest Xampp is 1.5.4, which bundles the PHP version 5.1.4. I would recommend you to install the older version of Xampp instead. Xampp 1.5.2 is the one with the correct PHP engine to work with php_dbg.

First of all, copy the php_dbg.dll-5.1.2 to the [installed xampp’s dir]/php/ext/. Then add the following lines to the php.ini file. the php.ini file that Xampp’s Apache is using is in the [installed xampp’s dir]/apache/bin/php.ini. You can see the actual path if you do a quick phpinfo().

[debugger]
extension=php_dbg.dll
debugger.enabled = true
debugger.profiler_enabled = true
debugger.JIT_host = clienthost
debugger.JIT_port = 7869

However, the default configuration of the php.ini will crash your Apache because of the loaded ZendExtensionManager.dll. What I did to solve the problem was to comment out the zend_extension_ts lines towards the end of the php.ini file like this…

;zend_extension_ts = "I:\Program Files\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll"
;zend_extension_manager.optimizer_ts = "I:\Program Files\xampp\php\zendOptimizer\lib\Optimizer"
;zend_optimizer.enable_loader = 0
;zend_optimizer.optimization_level=15
;zend_optimizer.license_path =
; Local Variables:
; tab-width: 4
; End:

After all the zend_ lines have been commented out, Apache started just fine and the phpinfo() dump confirmed that the php_dbg has been loaded.

Hope this help. Now it’s time to do some serious php apps with PHPEclipse. Ah by the way, CakePHP with PHPEclips is beautiful! We now have full code auto-complete for the CakePHP’s library! How amazing! And my friend Giao has just told me that Jseclipse for Javascript now support autocomplete for OOP-JS (prototypes and all that good stuff). Ha, it looks like that I’m hooked with Eclipse already.

view comments
 

if($p) {adsense_deluxe_ads(”);}Opening files with different custom extensions in DreamWeaver is pretty annoying: it’ll ask you for the external edit after shouting out the complain. And yes, after you configure Dreamweaver to open the file (through **Edit > Preference > File Type/ Editors**), you only get a plain Code view of the file. **Where the @#$@#$ is the Design View?** And you are working on the next killer template for a site but the template just happens to be of extension ***.thml**. In this case, I’m talking about **CakePHP**. Its default template extension is ***.THTML**. But don’t worry, be happy. Here is the solution to enable DreamWeaver Design View for any custom filetypes, and ***.THML** in particular.

**Now take a deep breath, I know you’ve been waiting for this answer. I know I have.**

- Go to **[Your_Drive_Here]:\Program Files\Macromedia\Dreamweaver MX 2004\Configuration\**
- Open the file **Extensions.txt** and add your custom extensions to the list. Remeber, in **Extensions.txt**, it’s got to be all CAPS. For **CakePhp**, add **THML** to the first line (the one ends with :All Documents) and the **16th** line of the PHP group. Here is the code for the Extensions.txt fileHTM,HTML,SHTM,SHTML,HTA,HTC,XHTML,STM,SSI,JS,AS,ASC,ASR,XML,XSL,XSD,DTD,XSLT,RSS,RDF,LBI,DWT,ASP,ASA,ASPX,ASCX,ASMX,CONFIG,CS,CSS,CFM,CFML,CFC,TLD,TXT,PHP,PHP3,PHP4,PHP5,TPL,LASSO,JSP,JSF,VB,VBS,VTM,VTML,INC,JAVA,EDML,WML,THTML,INC:All Documents
HTM,HTML,HTA,HTC,XHTML:HTML Documents
SHTM,SHTML,STM,SSI,INC:Server-Side Includes
JS:JavaScript Documents
XML,DTD,XSD,XSL,XSLT,RSS,RDF:XML Files
LBI:Library Files
DWT:Template Files
CSS:Style Sheets
ASP,ASA:Active Server Pages
ASPX,ASCX,ASMX,CS,VB,CONFIG:Active Server Plus Pages
CFM,CFML,CFC:ColdFusion Templates
AS:ActionScript Files
ASC:ActionScript Communication Files
ASR:ActionScript Remote Files
TXT:Text Files
PHP,PHP3,PHP4,PHP5,TPL,INC,THTML:PHP Files
LASSO:Lasso Files
JSP,JST:Java Server Pages
JSF:Fireworks Script
TLD:Tag Library Descriptor Files
JAVA:Java Files
WML:WML Files
EDML:EDML Files
VBS:VBScript Files
VTM,VTML:VTML Files
As this first step is just for Dreamweaver to recognize the new file extensions, we have to further edit another config file.
- Go to the **DocumentTypes** folder (still in the same path), edit the file **MMDocumentTypes.xml**\\ (fullpath: [Your_Drive_Here]:\Program Files\Macromedia\Dreamweaver MX 2004\Configuration\**DocumentTypes\MMDocumentTypes.xml**) with a Text Editor (i.e. Notepad or Notepad++). It’s not advisible to edit this particular xml file with Dreamweaver as the software may go crazy as it’s being used to edit itself.
- Go to l**ine 67**, add the THTML extesion to the **winfileextension** and **macfileextensionlist** attributes. Here is the code exerpt

<br /> <MMString:loadString id="mmdocumenttypes_14" /><br />





- Restart DreamWeaver, then open the .thml of CakePHP. Voila! It’s working! Yay! No more blind-coding.

=== Final Remarks ===

I hope you enjoy the tip. To consult the original documentations, please visit [[http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16410|Dreamweaver Technote: Changing and adding file extensions recognized by Dreamweaver MX]]. if($p)adsense_deluxe_ads(’MediumRectangleLeft’);My final take on this: Dreamweaver is an excellent tool, but the engineers did short of this very important features. Why is it not easier to assign a file extension to be opened with the Design View? Frontpage’s been doing it for years! I don’t know what is the problem with the Dreamweaver team but this is just plain dumb. Sorry, it’s pretty dumb - and it actually managed to be looked over during the user testing. Amazing. But how hard is it to include the new assignment in the GUI? Not that hard at all. -1 for you Dreamweaver!

Anyway, now with the THTML file is through, good luck with CakePHP. Please design the next killer websites to take back the glory for PHP from the RoR crowd.

view comments
 

view comments
 

Instructables.comCheck out this artilce at instructables.com about making a solar fan.
Incidentally, I just bought 2 solar fans for 2 of my friends for $14.99 a pop plus a hefty $7 something for shipping. The package is still in the mail but this raise the interest of the relevance of the instructables’ usefullness and its articles and community’s growth.

I have known about instructables a while ago as it’s another web2.0 company, and you have to read about some web2.0 companies at some points in time (I regularly follow UnderTheRadar.com and SiliconeBeat.com blogs.) The idea of instructables.com is such a good one that everyone knows that someone’s gonna do it. There are lots of people out that with interesting ideas and pet projects that they are willing to share, and there are even more people who’ll be curious to keep on reading what’s on.

Even though Wikipedia provides a way of free knowledge contributions, one thing for sure is instructables.com handles users’ input much better than wikipedia.com as there is a higher level of community-driven factor. Moreover, instructables.com has better support for graphics and images to make the artible more visually attractive and clear (the on-photo-comments is a great feature to have) as a picture worths a thousand words. Comments are generally welcome, making the community interaction even better.

I’d say instructables.com’s success in terms of scaling up and a stronger community driven by the noble purpose of knowledge sharing is guaranteed, it’s just a matter of time and words of mouth.

view comments