SpiffyJr's Blogaroo

Happenings of the man known as SpiffyJr

  • Home
  • About
    • Inspiration
    • Resume
  • Projects
    • Blitzaroo
    • phpRaider
    • Zend Calendar
  • Docs
    • Blitzaroo API
    • SpiffyCalendar Docs
    • SpiffyDb Docs
  • Downloads
  • Technologies
    • Doctrine ORM
    • Dojo
    • PHP
    • Zend Framework
  • Other
    • License
Twitter RSS
Category Archives: Dojo

Creating fancy drop-down menus with HTML, CSS, and Dojo.

Posted on March 2, 2010 by SpiffyJr
15 comments

Preface

Waaaaasssuuuuupppp? Kidding. Drop-down menus are always a pain for me because you have to remember to do all kinds of CSS and it has to work in 45 different browsers. Rubbish, I say! I recently decided to add an animated drop-down menu to Blitzaroo for the user section. The HTML/CSS was pretty straight forward but I hit a snag with the JavaScript so I sent an email to the Dojo Toolkit Mailing List and got a quick response from Peter Higgins (those Dojo guys are awesome). I promised a few blogs (and more to come in the future)  to showcase some of Dojo’s quick & easy wow features. This post assumes that you already know the basics about Dojo and have included Dojo somewhere in your project. If not, please check out Dojo Campus and the Dojo Toolkit homepage to get started.

Live Demonstration

Take a peak at the live demonstration to see where we’re headed. If you’re interested in how I got there keep on reading!

The HTML

The HTML is pretty straight forward and utilizes an unordered list for the layout. Note: all of the code here is going to be a straight copy/paste from the Blitzaroo source.

<ul id="userMenu" class="tabs">
	<li>
		<div>
			<img src="/images/icons/14/add.png" alt="Add" />
			Add <span class="downArrow">&#9660;</span>
		</div>
		<ul class="dropdown">
			<li>
				<a href="/user/events/add">
					<img src="/images/icons/14/events.png" alt="Event" />
					Event
				</a>
			</li>
			<li>
				<a href="/user/profiles/add">
					<img src="/images/icons/14/profiles.png" alt="Profile" />
					Profile
				</a>
			</li>
			<li>
				<a href="/user/teams/add">
					<img src="/images/icons/14/teams.png" alt="Team" />
					Team
				</a>
			</li>
		</ul>
	</li>
	<li>
		<a href="/user">
			<img src="/images/icons/14/dashboard.png" alt="Dashboard" />
			Dashboard
		</a>
	</li>
	<li>
		<a href="/user/events">
			<img src="/images/icons/14/events.png" alt="Events" />
			Events
		</a>
	</li>
	<li>
		<a href="/user/profiles">
			<img src="/images/icons/14/profiles.png" alt="Profiles" />
			Profiles
		</a>
	</li>
	<li>
		<a href="/user/teams">
			<img src="/images/icons/14/teams.png" alt="Teams" />
			Teams
		</a>
	</li>
</ul>

The only required attributes are class=”tabs” on the root <ul> and class=”dropdown” on each <ul> that is going to be a drop-down menu. The above menu has four regular links (Dashboard, Events, Profiles, and Teams.) and one drop-down menu (Add). I’ve spruced it up a bit by adding a few images but that is completely optional. I use the id tag on the root <ul> for styling the menu. No surprise here but the HTML renders a menu that looks like:

The CSS

.downArrow {
	font-size: 85%;
	vertical-align: text-bottom;
}

#userMenu {
	-webkit-border-radius: 8px;
	background: #f5faf5;
	border: 1px solid #bbcfbb;
	display: table;
	font-size: 13px;
	font-weight: bold;
	list-style-type: none;
	margin: 8px 0;
	padding: 0 12px;
	position: relative;
}

#userMenu li {
	cursor: pointer;
	font-size: 12px;
	list-style: none;
	display: table-cell;
	float: left;
	position: relative;
	text-shadow: 0px 0px 1px #fff;
}

#userMenu li a,#userMenu li div {
	color: #154f14;
	font-size: 11px;
	padding: 5px 12px;
}

#userMenu li a:hover,#userMenu li div:hover {
	background-color: #dae8da;
	text-decoration: none;
}

#userMenu img {
	margin-right: 3px;
	vertical-align: top;
}

#userMenu a {
	position: relative;
	display: block;
}

#userMenu .dropdown {
	-webkit-border-bottom-left-radius: 8px;
	-webkit-border-bottom-right-radius: 8px;
	background: #f5faf5;
	border: 1px solid #BBCFBB;
	margin: 0;
	padding: 0;
	position: absolute;
	z-index: 999;
	top: 24px;
	left: -999em;
	height: 1px;
	display: block;
}

#userMenu .dropdown li {
	margin: 0;
	padding: 0;
	list-style: none;
	width: 145px;
}

#userMenu .dropdown li:hover {
	opacity: 1;
}

#userMenu .dropdown li a {
	display: block;
	padding: 6px 14px;
	text-shadow: 0px 0px 1px #fff;
}

#userMenu .dropdown li a:hover {
	text-decoration: none;
}

I’m a huge fan of CSS3 so I use border-radius quite liberally. Blitzaroo isn’t released yet so I haven’t added the Mozilla border-radius (-moz-border-radius) equivalent so you can either add it or remove the radius all together. The CSS itself is nothing special – I use display: block with a touch of padding on <a> tags and float <li> tags left for the parent so that we have a horizontal menu. With a slight change of the CSS you could create a vertical drop-down (slide out?) menu. I use left: -999em for accessibility (and for the Dojo animation we’ll be using).  So, with the addition of CSS the menu now looks like:

The JavaScript

I found the JavaScript on a tutorial to Create The Fanciest Dropdown Menu You Ever Saw which uses jQuery rather than Dojo. Personally, I think jQuery is over-hyped and I love Dojo (/me wipes nose). I took the JavaScript listed there, combined it with the mailing list love from Peter Higgins, and came up with:

dojo.addOnLoad(function() {
	// user menu special effects
	var userMenu = dojo.byId("userMenu");
	if (userMenu) {
		dojo.query(".dropdown").forEach(function(n) {
	    	var l = dojo.query(n);
	        l.parent().at(0)
				.onmouseenter(function(){
					dojo.style(l[0], "left", "0");
					dojo.fx.wipeIn({node: l[0], duration: 250}).play();
				})
				.onmouseleave(function(){
					dojo.style(l[0], "left", "-999em");
					dojo.style(l[0], "display", "none");
				});
	    });
    }
});

This little snippet recursively checks for .dropdown and when the mouse enters sets left: 0; followed by an animated Dojo wipeIn. On mouse out it sets left: -999em; and then sets the display to none. I tried a number of CSS/FX combinations to come up with a solution that worked and this is about all I could come up with. You could use any combination of Dojo FX to stylize your own menu. My favorites are wipeIn, wipeOut, fadeIn, and fadeOut combined with easing. Try out a few combinations and see what you like best. Enjoy!

Reblog this post [with Zemanta]
GD Star Rating
loading...
Categories: Dojo | Tags: Cascading Style Sheets, CSS, Data Formats, Dojo Toolkit, HTML, HTML element, JavaScript, Style Sheets

Creating a Twitter-esque login box with Dojo

Posted on February 27, 2010 by SpiffyJr
3 comments

Introduction

I promised a few blogs (and more to come in the future)  to showcase some of Dojo’s quick & easy wow features. First up, a Twitter-esque login box for Dojo. I assume that you already know the basics about Dojo and have included Dojo somewhere in your project. If not, please check out Dojo Campus and the Dojo Toolkit homepage for getting the basics.

The Login Box

Twitter is a very clean and easy to use website. One really cool feature they have is a pop-down login box that stays hidden until the user clicks on it. The majority of the box is done in CSS but the box does require a touch of JavaScript to bring it to life.

Twitter Login Box

The HTML

Let’s get the ball rolling by setting up the HTML.

<html>
<head><title>A Twitter login box!</title></head>
<body>
	<a id="loginLink" href="/login">
		Login <span id="loginArrow" class="arrow">&#9660;</span>
	</a>
	<div id="loginDropdown">
		<form action="/login" method="post">
			<p>
				<label for="topUsername" class="bold">Username</label>
				<input id="topUsername" name="username" title="username" type="text" style="width: 180px;" />
			</p>
			<p>
				<label for="topPassword" class="bold">Password</label>
				<input id="topPassword" name="password" title="password" type="password" style="width: 180px;" />
			</p>
			<p>
				<input id="loginSubmit" value="Login" type="submit" />
				<input id="remember" name="remember" value="1" type="checkbox" />
				<label for="remember">Remember me</label>
			</p>
		</form>
	</div>
</body>
</html>

If you load your page in a browser you should have something that looks similar to the image below.

The CSS

That brings me back to the good ole’ days. Let’s spruce it up a bit with a little CSS.  Add the CSS below to the <head></head> section of the page we created earlier.

<style type="text/css">
	#loginLink {
		color: #555;
		font-weight: bold;
		text-decoration: none;
	}

	#loginLink.menuOpen {
		background-color: #bccdbc;
		border: 2px solid #bbcfbb;
		border-bottom: 0;
		padding: 4px;
		padding-bottom: 6px;
	}

	#loginDropdown {
		background-color: #bccdbc;
		border: 2px solid #555;
		display: none;
		font-size: 12px;
		padding: 8px 5px;
		position: absolute;
		text-align: left;
		z-index: 999;
	}

	#loginDropdown input[type=text],#loginDropdown input[type=password] {
		display: block;
		border: 1px solid #888888;
		font-size: 13px;
		margin: 0 0 5px;
		padding: 3px 2px;
		width: 203px;
	}

	#loginDropdown.menuOpen {
		display:block;
	}
</style>

I’m not a designer but at least it looks a little better.

The Dojo

Now then, onto the fun stuff! Let’s make use of Dojo and use dojo.connect() to make the login box come to life.

<script type="text/javascript">
dojo.addOnLoad(function() {
        // fire whenever a click happens on our login link
	dojo.connect(dojo.byId("loginLink"), "onclick", function(e){
                // stop the default action from happening which would take us to the login page
		dojo.stopEvent(e);

                // add the menuOpen class to the loginLink and loginDropdown
                // menuOpen puts a border around loginLink and sets display:block for the loginDropdown
		dojo.toggleClass("loginLink", "menuOpen");
		dojo.toggleClass("loginDropdown", "menuOpen");

                // toggles the arrow
		var arrow = dojo.byId("loginArrow");
		if (arrow.innerHTML == String.fromCharCode(9660)) {
			arrow.innerHTML = "&#9650;";
		} else {
			arrow.innerHTML = "&#9660;";
		}
	});
});
</script>

The End

That’s all there is to it! With a little touching up of the CSS you can make a box that looks identical to Twitter’s or, better yet, customize it to suit your site. I’ll be posting more wowie Dojo snippets in the near future.

Reblog this post [with Zemanta]
GD Star Rating
loading...
Categories: Dojo | Tags: Cascading Style Sheets, CSS, Dojo, Dojo Toolkit, HTML, JavaScript, Twitter, Website

Dojo marketing and increasing the community

Posted on February 26, 2010 by SpiffyJr
4 comments

The Problem

Recently, a discussion opened up on the Dojo Toolkit Mailing List about the lack of a strong marketing and a small community compared jQuery. Torrey Rice was kind enough to elaborate and hit the nail square on the head when he said:

Showing off the hardcore stuff that’s really cool to us (like data stores and charting) is fine but we have to understand that the vast majority of people don’t care about that stuff.. they want to quickly add effects and do dom manipulation.

I see plenty of blogs posting how to do wowie things with jQuery such as 20 Cool Tricks for jQuery but when I started learning Dojo there weren’t many blogs that touched on the fancy effects of JavaScript. Dojo documentation has improved greatly in the six months I’ve been using it but it would have been a great help to have a list of blog posts I could copy & paste from. Having said that – this is my attempt to get to the ball rolling. Enjoy!

Quick & Easy Dojo Effects

  1. Creating a Twitter-esque login box
  2. Creating fancy drop-down menus with HTML, CSS, and Dojo.
  3. Creating a fadeOut loader with Dojo.
Reblog this post [with Zemanta]
GD Star Rating
loading...
Categories: Dojo | Tags: Blog, Cascading Style Sheets, Dojo Toolkit, HTML, JavaScript, JQuery, Languages, Marketing, Programming, Twitter
Page 2 of 2«12
  • Recent Posts

    • Keep your Git fork clean
    • Get started with Zend Framework 2 modules!
    • More Doctrine 2 and Zend Framework integration goodies!
    • Super sexy URLs with ZF and the joy of controller plugins!
    • Formatting your API to work with dojox.data.JsonRestStore (#dojo)
  • Categories

    • Other
      • Random
    • Projects
      • Blitzaroo
      • phpRaider
      • SpiffyDb
      • View Helpers
      • Zend Calendar
    • SpiffyJr
    • Technologies
      • Dojo
      • PHP
      • Zend Framework
  • Tag Cloud

      Ajax Algorithm api Blitzaroo Blog BSD licenses calendar Cascading Style Sheets CSS database Data Formats Dojo Dojo Toolkit event Framework game Google HTML HTML element JavaScript JQuery json Languages mapper Marketing mmorpg model php Programming Projects Scripts Source code Style sheet Style Sheets Twitter Website zend Zend Framework
  • Archives

    • December 2011
    • November 2011
    • July 2011
    • April 2011
    • March 2011
    • December 2010
    • November 2010
    • October 2010
    • March 2010
    • February 2010
    • November 2009
    • October 2009
    • September 2009
© SpiffyJr's Blogaroo. Proudly Powered by WordPress | Nest Theme by YChong