spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column9
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
Logo

The DHTML Lab Jigsaw Puzzle, Part II: IE4 cont'd
the controls


Of all the controls, we have discussed the Solve button, the Grid button and the Break button in detail. In this page, we will look at the other buttons and pull-down SELECT menus.

The Hint Button

The Hint button solves one piece automatically. The piece selected is the next-in-line to be solved. Clicking the Hint button calls the giveHint() function:

If the puzzle is not broken, giveHint() does nothing. If it is, solve() is called with an argument of false. This will make solve()'s local isFullSolve variable false, as well, causing only one piece to be repositioned. See the discussion on solve() for more details.

The Drag ON/OFF Button

As a bonus feature, we've included draggability for the complete puzzle object, elPuzzle. However, a user might want to turn this feature off. If you recall, we created the isPuzzDraggable variable to track puzzle draggability. The Drag ON/OFF button calls the dragToggle() function:

When a puzzle is broken, it is not draggable whether we allow draggability or not. Therefore, dragToggle() first reverses the value of isPuzzDraggable. If the puzzle is not broken, it reverses the value of the puzzle's draggable property as well. Whenever the draggable property is set by other functions, they first check for a true value of isPuzzDraggable.

Finally, the cursor shapes and the display of the button are modified to reflect the change in draggability.

The SELECT Menus

At any time during puzzle play, the piece count can be changed. If a change is made in the Across: or Down: menus, their onChange event handler sets the value of three variables:

The three variables are set but will only make a difference if the puzzle is broken. The menu options may be changed over and over. It is only when the Break button is clicked that the variables affect the puzzle. The breakUp() function uses them to determine whether the piece elements need to be created or resized. This procedure is discussed in great detail in our previous column.

Conversely, the image drop-down menu causes an immediate update when its value is changed:

The puzzle image src is changed and a new image begins loading. The initPuzz() function is called, which as we know cleans up any unsolved pieces via the allDone() function, and then initializes the puzzle from scratch.

That about wraps up our discussion of the puzzle code. The next page has yet another instance of a working puzzle, and a short summary.


Produced by Peter Belesis and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

All Rights Reserved. Legal Notices.
Created: Nov. 13, 1997
Revised: Jan. 18, 1998

URL: http://www.webreference.com/dhtml/column9/puzzCtrl.html