Simple Time Select for Ruby On Rails Just Got Simpler

I added a start_hour and end_hour feature to my simple time select. Here are the details from the README:

Simple time select also takes a start_hour and end_hour option to be specified in military format (between 0-23).

<%= time_select "event", "time", { :default => Time.now.change(:hour => 21), :simple_time_select => true, 
:minute_interval => 20, :time_separator => "", :start_hour => 10, :end_hour => 14 } %>

The start hour behaves as you would expect but the end_hour may not. If you specify the end_hour as 10, your time select will include 10:15, 10:30, 10:45. So the end_hour sets the last hour that the time select will include. Leave a comment if you want me to change this.

The code is hosted on github here: http://github.com/tamoyal/simple_time_select/tree/master

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Software | Tagged , , , | 8 Comments

jQuery Rounded Corners with Rounded Borders with Set Width

Dave Methvin wrote a plugin for jQuery to easily round corners. Then Mike Alsup improved on the plugin by adding more effects. Mike’s solution for adding a rounded border is great but he doesn’t give good copy and paste code. I had to dig through the source on the page to figure out some usage. He also misses (or I cannot find) an important piece – some of us want to specify the dimensions of our rounded box with rounded borders. Before using this code, you need to make sure you have downloaded jQuery and jquery.corner.js and obviously include them on your page.

Here is a simple explanation and example with code:

div.rounded_box{
    background-color: #ccdaff; 
    color: #333; 
    padding: 10px;
    border:0;
    margin: 0;
    zoom:1;
}
/* border with rounded corners */
div.rounded_border {  background: #6666ff; padding: 8px; }

That is the CSS for the rounded box and rounded border to go around the box. The only attributes you should need to change are anything color related and the padding (pretty obvious what they do but you can mess with the values after you get this example working).

Now you have 2 options for your HTML/Javascript set up (note that I have namespaced my jQuery functions to $j instead of $). The first option is probably a bit faster while the second option avoids an extra wrapper div in your code, allowing you to specify the width inline. Here is the first option:

<div style="width: your width here;">
     <div id="my_rounded_box_id1" class="rounded_box">
          <p>Content</p>
     </div>
</div>
 
<div style="width: your width here;">
     <div id="my_rounded_box_id2" class="rounded_box">
          <p>Content</p>
     </div>
</div>
     $j(function(){
         $j('div.rounded_box').wrap('<div class="rounded_border"></div>'); //apply border
	 $j('div.rounded_box').corner("round 8px").parent().css('padding', '2px').corner("round 10px"); //round box and border
     });

Here is the second option:

<div id="my_rounded_box_id1" class="rounded_box" style="width: your width here;">
     <p>Content</p>
</div>
 
<div id="my_rounded_box_id2" class="rounded_box" style="width: your width here;">
     <p>Content</p>
</div>
function roundDiv(id){
	var tmp_width = $j('#'+id+'').css("width"); //get the width of target el
	$j('#'+id+'').css("width",""); //clear width value (or else corners screws up)
	$j('#'+id+'').wrap('<div class="rounded_border" style="width: ' +tmp_width+ ';"></div>'); //apply border
	$j('#'+id+'').corner("round 8px").parent().css('padding', '2px').corner("round 10px"); //round box and border
}
 
$j(function(){
 	//round each box separately so that we can specify inline dimensions
	roundDiv('my_rounded_box_id1');
	roundDiv('my_rounded_box_id2');
});

Enjoy!

UPDATE: After some more testing, the second option seems to be more cross browser compatible. I highly recommend using that option.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Software | Tagged , , , | 25 Comments

Fix for broken drag and drop in Wordpress Sociable plugin

Drag and drop is broken in the Wordpress Sociable plugin which means you cannot easily reorder your bookmarking options. I have seen posts 2 weeks old asking for a fix for this and I am too impatient…so here it is.

Navigate to your sociable plugin directory and create a file called “sociable-admin.js”. Add the following code to the file:

jQuery(document).ready(function(){
  jQuery("#sociable_site_list").sortable({});
});
/* make checkbox action prettier */
function toggle_checkbox(id) {
	var checkbox = document.getElementById(id);
 
	checkbox.checked = !checkbox.checked;
	if (checkbox.checked)
		checkbox.parentNode.className = 'active';
	else
		checkbox.parentNode.className = 'inactive';
}

Save the file and reload your sociable admin panel. Drag and drop should work now.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Software | Tagged , , , , | 3 Comments

Truncate your Flex ComboBox text

Today I ran into a situation where I wanted my ComboBox drop down text to have a 9px font size and a 10px font size on the text input portion. This is a problem because your labels can easily get cut off.

Ugly:
ComboBox text cut off
I think this is prettier:
ComboBox text with ellipsis



Here is how to do it:

<mx:Script>
	<![CDATA[
            [Bindable] private var carriers:ArrayCollection = new ArrayCollection();
            private static const CARRIER_TEXT_MAX_WIDTH:int = 18;
 
            private function some_type_of_init_function():void{
                  carriers = ConfigurationData.getInstance().mobile_carriers;
            }
 
            private function truncatePrompt():void{
		if(carrier_select.text.length > CARRIER_TEXT_MAX_WIDTH){
		   carrier_select.text = carrier_select.text.slice(0,CARRIER_TEXT_MAX_WIDTH-3) + "...";
		}
	     }
	]]>
</mx:Script>
<mx:ComboBox id="carrier_select" rowCount="5" height="26" width="154" 
		dataProvider="{carriers}"
		change="truncatePrompt()" />

You will obviously have to change the CARRIER_TEXT_MAX_WIDTH to fit your needs. Note that calling this on the “change” event is not as pretty because there is a delay.
UPDATE:
Turns out for this to work properly you will have to call the function from the change event. Sorry for not testing this more before I posted.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Software | 13 Comments

The Art And Science Of Seductive Interactions

I will generally stay away from posting other people’s content on my blog because this is not a news site. But I really liked this presentation… (sorry if it is a bit slow loading, slideshare isn’t perfect)

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in marketing | Leave a comment

Flex widget with rounded corners (code included)

It should be really easy to create the template for a widget with rounded corners in Flex. It is certainly not a difficult task, but it is not obvious. Rather than explain the things you need to pay attention to, I will just post the code below. After setting up a flex project with the following code, add and remove some lines to see what they do. Feel free to post any questions you have here.

Here is the application code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute" width="450" height="220" backgroundAlpha="0">
 
	<mx:Style>
		Panel {
		   borderStyle: solid;
		   borderThickness: 0;
		   cornerRadius: 10;
		   borderColor: #cccccc;
		   backgroundColor: #eeeeee;
		   roundedBottomCorners: true;
		}
	</mx:Style>
 
	<mx:Panel id="application_container" width="100%" height="100%" 
		dropShadowEnabled="false">
 
	</mx:Panel>
 
</mx:Application>

In your wrapper file, make sure to set wmode to transparent. Here is how you do it with SWFObject (assuming your object is “so”):

so.addParam("wmode","transparent");
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Software | Tagged , , , , | 1 Comment

Small tool tips for Adobe Flex validation errors

If you are using Adobe Flex forms, chances are you have come across validators. I do not like the way validators work out of the box, and it is a real pain to work against them. I will post a better way to validate your forms later. For now, I want to show you how to save real estate in your Flex forms when using validators.

The error tool tips associated with validators are big. I will show you how to make them smaller.

Add this CSS to your Flex project (mx:style tag or external css file):

.errorTip { 
			borderColor: #0000FF;
			paddingTop: 0;
			paddingBottom: 0;
			paddingLeft: 4;
			paddingRight: 4;
			fontWeight: bold;
			fontSize: 9px;
			backgroundColor: #0000ff;
			cornerRadius: 8;
		}
ToolTip{
     borderSkin: ClassReference("com.your_project_name.skins.SmallToolTip");
}

Then put a file called SmallToolTip.as in your com.__________.skins (fill in the blank) directory with these contents:

package com.your_project_name.skins
{
	import mx.skins.halo.HaloBorder;
	import mx.core.mx_internal;
	import flash.display.Graphics;
 
	use namespace mx_internal;
 
	public class SmallToolTip extends HaloBorder
	{
		public function SmallToolTip()
		{
			super();
		}
 
		override mx_internal function drawBorder(w:Number, h:Number):void{
			super.drawBorder(w,h);
			// Draw a small tail at the bottom left side of the tooltip
			var gr:Graphics = graphics;
			gr.beginFill(getStyle('borderColor'), 1);
			gr.moveTo(x + 7, y + h);
			gr.lineTo(x + 10, y + h + 4);
			gr.lineTo(x + 13, y + h)
			gr.moveTo(x + 7, y + h);
			gr.endFill();
		}	
	}
}

This only works for drawing a tool tip with the tail at the bottom left. But you can draw a tail wherever you want by altering the Graphics code which is super easy. Removing the padding and drawing a smaller tail are the two big ways to make the tool tip take up less real estate, with the least amount of work.

Before:

bigtt_1f

After:

smalltt_2f

smalltt_1f

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Software | Tagged , , , , , | 5 Comments

The best time_select plugin for Ruby On Rails!

In some cases, the Ruby on Rails time_select helper is much uglier than it needs to be. It spits out 3 select boxes for the hour, minutes, and seconds. Your users do not always need accuracy to the minute. For example, you do not schedule doctor’s appointments for 3:13PM. You would at least round to the nearest 15 minutes. Another shortcoming of the rails time_select helper is that you cannot configure it for 12 hour AM/PM times by default. You must write your own plugin to make this happen.

Simple Time Select

Yesterday I decided that I wanted a really simple time_select component for my Ruby on Rails application. Specifically, a time_select with only ONE select field. I developed the Simple Time Select plugin to do this, as well as handle minute intervals. For example, if you set your minute interval to 15, you get options such as: “6:00 PM”, “6:15 PM”, “6:30 PM”, etc. As you can see from the screen shot (where the interval is set to 20 minutes), this control also implements an AM/PM time format.

Also note that this component is great if you ONLY care about the time input from a user. As is, the helper does not generate the hidden date fields associated with the usual time_select helper.

Visit the github page to read more and install the plugin:
http://github.com/tamoyal/simple_time_select/tree/master
Also be sure to check out the latest update.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Software | Tagged , , , , , | 13 Comments

My work at Total Music

As of January 15th, I no longer work at Total Music. I spent a lot of time developing this music player widget with another great engineer. When Alpha mode is over, you will be able to post these media players to any social network or website. You will also be able to log into any music player widget on the web, and add people’s songs to your playlist if you are a registered user….and of course, you can purchase the music if you choose.

Let me know what you think! (Sorry if it does not work for you, I am no longer maintaining the app)

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Music, Software | 2 Comments

Congratulations Facebook

\"Facebook\" is searched in Google more than \"Porn\"

\"Facebook\" is searched in Google more than \"Porn\"

Data From Google Insights

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

Posted in Random | Tagged , , , | Leave a comment