How do I… Create a customized JavaScript jump menu in Dreamweaver CS3?

4 12 2007

If you are in charge of maintaining a Web site, one of your recurring tasks is likely accommodating a committee of supervisors or clients that want to add links to the site on a continuing basis. This can often lead to a cluttered navigation interface, if it doesn’t destroy your layout altogether.

Fortunately, Adobe Dreamweaver CS3 has many tools that can provide quick and easy solutions to problems like these. One of the more practical solutions to an ever-expanding list of navigation links is a JavaScript “jump” menu, which is a pull-down form menu that automatically directs the user’s browser to another Web page as soon as they select an option from the menu. And the best part is that no knowledge of advanced scripting techniques is required to implement it. You can even use some simple CSS code to give your Jump menu a distinct look.

If you don’t own a copy of Dreamweaver CS3, you can download a fully functioning 30-day trial.

This blog post is also available as a TechRepublic gallery and TechRepublic download. The download includes an example of the JavaScript described in this How do I… blog post.

Let’s begin by opening Dreamweaver and creating a new HTML document (Figure A) by selecting the New option from the File menu. In the Dialog box that appears, Select HTML in the Page type column. Ignore the other options in the box, and click the “Create” button.

Figure A

Creating a new HTML document in Dreamweaver CS3

Before you do anything else, save your document. It is always a good idea to save a new HTML document in Dreamweaver in the directory that houses your parent Web site before you begin coding. This will help avoid broken and misdirected links later on if you decide to link to internal site pages.

Dreamweaver lets your author a page via its WYSIWYG tools as well as by hand-coding. Its best to have both options visible at all times so that you can switch back and forth and see how modifying the code affects the browser preview and vice-versa. If both the Code and Design view are not visible, click on the button that is labeled “Split”. You will find it in-between the Code and Design buttons near the top of the screen, under the document tab (Figure B).

Figure B

Clicking the Split button lets you see both the Code and Design windows

Now it is time to build our Jump menu. Go to the top of the screen and in the horizontal Insert menu (it runs across the screen just under the Application menus) click on the Forms tab to bring up the Form objects. (Figure C)

Figure C

Select the Forms tab to bring up the Form objects palette

Next, click on the Jump Menu button. This will make a dialog box appear, as in Figure D.

Figure D

Click the Jump Menu button to bring up the Jump Menu authoring box

Let’s have the first item in our Jump Menu take us to Google.com. The field labeled “Text:” is the text that will appear in the menu when the user views it in his browser. It can be whatever you wish, including most special characters. For now, let’s keep this simple. In the “Text;” field, enter the word Google (Figure E). The field below it, labeled “When selected, go to URL:” is the Web address that will be the destination tied to the copy in the “Text:” field. Enter the URL http://www.google.com.

Figure E

Creating the first item in the Jump Menu

Next, let’s add two more items to the Jump menu. Click the Add Item button two times and you’ll see the Jump menu add two more blank entries. (Figure F)

Figure F

Adding two blank items to the Jump Menu

Click on item1 in the Menu Items list and fill out the Text and Selected URL fields just as you did before, linking the new item to an absolute URL. Repeat the process again with item2. (Figure G)

Figure G

Linking the two new menu items

Now let’s say that you want to rearrange the order of the items in the menu list. This is easily done with the two arrow buttons in the upper right area of the dialog box. Click on the last entry in the Menu items box to select it. Then click on the up arrow until the last item is now at the top of the list, as in Figure H.

Figure H

Re-ordering the Menu items

When you are satisfied with the content of your Jump Menu, click the OK button to return to Dreamweaver’s main authoring area to see your menu. (Figure I)

Figure I

The newly-created Jump Menu

Before we test it, let’s use some simple CSS code to make the Jump Menu a little more distinguished. Go to the top of the screen and from the Window menu, select the CSS option. The CSS palette will open, as shown in Figure J.

Figure J

The CSS palette

Click on the Add CSS Rule button to bring up the CSS Rule dialog box (Figure K). In the Selector Type options, choose the Tag option. In the Tag pull-down menu, choose the “Select” tag. Finally, click the Radio button at the bottom that is labeled “This document only.”

What these options do is define the appearance of your Jump Menu automatically, so that you do not have to assign a CSS class to the menu later or worry about an external Style sheet. Click OK to continue to the CSS Rule Definition dialog box.

Figure K

The New CSS Rule dialog box

The CSS Rule Definition dialog box will open at the Type Category, From the Font pull-down menu, select the font set “Arial, Helvetica, sans-serif”, then give it a size of 10, as shown in Figure L.

Figure L

Defining Type options for the New CSS Rule

Now select the Background Category and select a light value color, as shown in Figure M.

Figure M

Defining Background options for the New CSS Rule

Click OK to return to Dreamweaver’s authoring area. The styles you defined should be readily viewable in the Jump Menu. (Figure N) Save your document, and then open it up in a Web browser to test it.

Figure N

The completed Jump Menu

There is no limit to the number of items the Jump menu can list, and of course, you can even link it to Web pages within your own Web site. Use the CSS customization to make it fit right in with your site’s unique look and feel.

courtesy @Techrepublic


AddThis Feed Button





Support rich text with the Yahoo User Interface Library

6 11 2007

During a recent project, my team’s task was to redesign a Web page that utilized an ActiveX control as a rich text editor. One goal of the project was to replace the ActiveX control with a more standardized approach. We chose to use the rich text editor available with the Yahoo! User Interface (YUI) Library. This week I examine using the YUI Library’s Rich Text Editor.

YUI! Library

The YUI Library is a set of utilities and controls in JavaScript, as well as CSS templates for building richly interactive Web applications using standard technologies such as DHTML, DOM scripting, and AJAX.

You can download the YUI Library 2.3.1 for free from SourceForge.net. The download allows you to install the libraries on a Web server. Another option is to use the library files directly from Yahoo! servers. Yahoo! provides an excellent overview of how to use its servers for applications implementing functionality via the YUI Library.

Rich Text Editor

A recent addition to the YUI Library is the Rich Text Editor. It is a user interface control that replaces the standard HTML textarea element. It allows for the rich formatting of text content, including common structural treatments like lists, formatting treatments like bold and italic text, and drag-and-drop inclusion and sizing of images.

A critical feature of the Rich Text Editor is its toolbar, which provides access to various features like text formatting, color choices, and so forth. You may choose which toolbar features to include in an implementation via scripting. In addition, the toolbar is extensible via a plug-in architecture so that advanced implementations can achieve a high degree of customization.

Putting the Rich Text Editor to work

If you want to use the Rich Text Editor, it requires a YUI Library CSS skin to properly render the control. The following YUI Library files (CSS and JavaScript source files) are necessary to use the Rich Text Editor. The following lines reference the files on the previously mentioned Yahoo! servers, but you may use a local installation as well.

The following base HTML is used to deliver the Rich Text Box, but you’ll still need to add scripting to fully implement the control.

This text will be displayed in the text area.

Now the cols and rows attributes of the HTML texarea element will be overridden by settings specified in the Rich Text Editor’s script. The name assigned to the HTML textarea element is important, since it will be used in the JavaScript code when establishing the relationship between a textarea element and a Rich Text Editor.

Also, the class assigned to the HTML body element (yui-skin-sam) is used to visually format the Rich Text Editor control. This CSS skin is defined in the CSS file imported into the application (see previous list). The skin should be applied to the parent HTML element of the textarea element. In this case, the HTML body element is used, but it could be any element that contains the textarea.

Once the textarea has been defined along with the proper YUI Library files included in the page, the Rich Text Editor control must be rendered. The rendering is accomplished via JavaScript placed within the page. The script can be used to define various Rich Text Editor options such as the toolbar. As an example, I may use the following JavaScript to format our Rich Text Editor:

var rtf = new YAHOO.widget.Editor(‘texteditor’, {

height: ‘300px’,

width: ‘522px’});

rtf.render();

This snippet establishes the height and width of the editor while declaring an instance of the Rich Text Editor. Also, it assigns the textarea called textedtior to the Rich Text Editor. The final line in the script actually causes the Rich Text Editor to display when it calls its render method.

When you use the Rich Text Editor control without any specifics about the toolbar, it results in the default behavior of including all toolbar features like text alignment, font face, font size, color, and so forth. You may choose to limit the toolbar options available to users.

The final example uss a Rich Text Editor, but the toolbar options are defined in the JavaScript code to render it. The following options are used:

  • The toolbar options are defined in its own variable. This is later used to instantiate the editor.
  • A title is assigned to the editor via the toolbar’s titlebar property.
  • The collapse property signals whether the user may collapse/hide the toolbar.
  • The buttons property allows you to define the buttons displayed in the toolbar. In this example, buttons are displayed for text formatting as well as selecting colors.

Once the toolbar options are defined, a Rich Text Editor object is instantiated with the toolbar variable passed to it along with the HTML textarea element. The final step is to render the control. A complete list of options is available in the YUI Library API documentation.

Working with YUI Library Rich Text Editor

body { margin:0; padding:0; font-face: arial; font-size: 10pt;}

.yui-editor-container {z-index: 999;}

.editable {

border: 5px solid black;

argin-top: 100px;

margin: .25em;

float: left;

width: 350px;

height: 100px;

overflow: auto;

}

.textbox {

margin-left: 10px;

width: 100px;

height: 25px;

}

.label {

margin-left: 10px;

width: 50px;

height: 25px;

font-weight: bold;

}

First Name:

Last Name:

Test within TextArea.

var toolbar = {

height: ‘200px’,

width: ‘420px’,

toolbar: {

titlebar: ‘TechRepublic.com Editor’,

collapse: true,

buttons: [

{ group: 'textstyle', label: 'Font Style',

buttons: [

{ type: 'push', label: 'Bold', value: 'bold' },

{ type: 'push', label: 'Italic', value: 'italic' },

{ type: 'push', label: 'Underline', value: 'underline' },

{ type: 'separator' },

{ type: 'select', label: 'Arial', value: 'fontname', disabled: true,

menu: [

{ text: 'Arial', checked: true },

{ text: 'Arial Black' },

{ text: 'Comic Sans MS' },

{ text: 'Courier New' },

{ text: 'Lucida Console' },

{ text: 'Tahoma' },

{ text: 'Times New Roman' },

{ text: 'Trebuchet MS' },

{ text: 'Verdana' }

] },

{ type: ’spin’, label: ‘13′, value: ‘fontsize’, range: [ 9, 75 ], disabled: true },

{ type: ’separator’ },

{ type: ‘color’, label: ‘Font Color’, value: ‘forecolor’, disabled: true },

{ type: ‘color’, label: ‘Background Color’, value: ‘backcolor’, disabled: true }

] } ] } };

myEditor = new YAHOO.widget.Editor(‘texteditor’, toolbar);

myEditor.render();

It is worth noting that the text is formatted using standard HTML to format the text within the Rich Text Editor, so bold text uses the HTML strong element; the font element is used for font styling, and so forth.

An improved interface

I have been a big fan of the YUI Library since I first discovered it more than a year ago. It allows developers to build powerful Web interfaces using code that has been fully tested for proper functionality. The Rich Text Editor is just one example of the power controls available in the YUI Library.

courtesy @TechRepublic





Use Ruby on Rails to create a social networking Web site with full community searching and browsing functionality

29 10 2007

Ruby on Rails is fast displacing PHP, ASP, and J2EE as programmers’ development framework of choice, thanks to its elegant design and emphasis on practical results. Learn how to build large-scale projects with Rails by developing a real-world application: a social networking Web site like MySpace, Facebook, or Friendster. In this chapter download from RailsSpace: Building a Social Networking Website with Ruby on Rails, focus on adding searching and browsing functionality to your site. First, add full-text search to your site using the open-source tool Ferret. Then, stalker-enable your site by adding the ability to browse by age, sex, and location.


Title: RailsSpace: Building a Social Networking Website with Ruby on Rails
Author: Michael Hartl, Aurelius Prochazka
Publisher: Addison Wesley Professional
Chapter 11: Searching and Browsing
ISBN: 0-321-48079-1; Copyright 2008 Addison Wesley Professional. All rights reserved.
Used with permission from the publisher. Available from booksellers or direct from Addison Wesley Professional

here is a sample version of Chapter 11 of this book.

source @TechRepublic





Why developers should check out ColdFusion 8

29 10 2007

Adobe ColdFusion 8 (CF 8) is a force to be reckoned with in the application server space. I’ve been using ColdFusion for 10 years, and I haven’t seen the community this excited about a new release in a long time. The recent release is by far the most compelling version since they moved to the Java platform — and possibly even the most compelling version ever.

There is a long list of new features and enhancements in CF 8, but in this article, I’m just going to focus on five of my favorites.

Server Monitor

The Developer and Enterprise Editions of CF 8 offer the highly anticipated Server Monitor feature. This might be the single biggest addition to ColdFusion, since it blows away anything I’ve seen on any other server platform.

Using the beautiful Flex-based Server Monitor interface, you can now watch requests move through a live server. You can see exactly how much memory a session or an application is using, what the template cache is doing, and which threads are taking too long to run.

You can also drill down into live requests and see which individual tags or method calls are slowing things down. It’s immensely powerful to watch the monitor and immediately tune your code in response. Is a query getting executed a lot? Cache it! Is a tag or function causing a bottleneck? Now you know exactly what line of code to optimize. Want to write your own code that runs in response to a hung thread, low JVM memory, or anything else? The monitor API will let you.

Exchange integration

It’s incredibly easy to integrate CF 8 with Microsoft Exchange. With a few lines of code, you can add events to Exchange calendars; add and remove attendees; manipulate tasks, contacts, lists, and more.

Love it or hate it, Exchange is such a staple for many IT departments that the ability to interact with it — or even build your own full-blown interface to your Exchange data — is a big boon to a lot of businesses that use ColdFusion.

AJAX capabilities

Another hugely popular addition in CF 8 is a large set of built-in AJAX functionality. By using simple tags or JavaScript functions, ColdFusion will handle all the chores for creating great AJAX-based applications. CF 8 makes these things a snap: autosuggest, related select boxes, dynamic content updates, and EXT-based datagrids.

One of the coolest features is the ability to create JavaScript proxies for server-side ColdFusion Components (CFCs). You can call a method on the proxy, and under the hood it will make a call to the corresponding method on the CFC. All the work of translating data to and from JavaScript Object Notation, converting ColdFusion datatypes into JavaScript types, and protecting against hack attempts is all handled for you by the ColdFusion server.

There’s even an excellent AJAX debugging window that shows everything that is going on. This probably has the biggest “wow” factor for the new release, since developers of any skill level can whip up a jaw-dropping AJAX application in minutes.

Image manipulation

CF 8 takes image manipulation to a new level. Adobe added more than 50 new tags and functions for dealing with images. The capabilities include simple things like resizing, getting image sizes, and converting images, as well as virtually any image-based task you can imagine. This includes drawing, adding text, and adding effects such as blurring, antialiasing, and rotating.

Performance

The best improvement in CF 8 is that it’s really fast. The development team really outdid themselves in this area. Depending on the application, it can be up to 10 times faster than CF 6 or CF 7. Some processes, like CFC instantiation, are an eye-popping 23 times faster than CF 7. So even if you upgrade to CF 8 and don’t use any new features, your application could easily triple or quadruple its performance on the same hardware. This is quite a compelling reason to upgrade.

Great extras

I’m only scratching the surface of all the amazing new capabilities in CF 8. The list goes on and on to include: generating ATOM and RSS feeds with one line of code; zip file manipulation; built-in Flex Data Services; ColdFusion administrator enhancements; and PDF and PDF form generation. There are three additional benefits to using CF 8 that I will briefly cover.

CF 8 lets you integrate with .NET objects as easily as you can currently integrate with Java objects. The .NET assets can be remote, which means you can use them even if your ColdFusion server is running a UNIX-based OS.

Adobe supplies a series of nice plug-ins for the Eclipse IDE that work with CF 8. This includes simple things like built-in ColdFusion docs, automatic generation of CFCs (including ActiveRecord, Data Access Objects, Beans, etc.), and wizards that will generate a full-blown AJAX application. It also includes a full debugging perspective. In conjunction with the free CFEclipse plug-in, this makes Eclipse the standard IDE for most advanced ColdFusion developers.

CF 8 gives you the ability to do your own thread-based programming. If you have a long running task, you can fire off another processing thread and forget about it; or you can trigger multiple threads to speed up a process and then join them back together and continue.

Download a free edition of CF 8

CF 8 Developer Edition is free, so I urge you to give it an honest look. I believe existing ColdFusion users will find a lot to like in version 8, and new users should try out this application server.

What do you think of CF 8?

Now that I’ve shared my thoughts about my favorite features and enhancements in CF 8, I want to hear what you think of this release. What features do you like the most in CF 8? If you aren’t using CF 8, what features pique your interest enough to give it a look?