Showing posts with label geek. Show all posts
Showing posts with label geek. Show all posts

Wednesday, June 3, 2009

How to Localize a Browse Button

Yes, I have seen more complaints about this than you can image but the good news is not only can you 'localize' it but make it pretty. Wanna see what I'm talking about?


In case you're not familiar with the problem, a form input type of "file" connects to the client's operating system via an Application Programming Interface (API). That familiar window that allows us to select our file is displayed depending on your operating system (*nix, Windows, Mac). Because of this, it was deemed as a security risk to allow a developer to interfere in any way with this functionality.

What browser will this work on?

First and foremost, this will work in IE 6 and 7, FF 2 and 3, and Safari on MAC.

What you need


1) 2 Images: One to display English one to display French. (Or whatever languages you choose.)


Admittedly, these aren't pretty but they'll do. The file name you give your images plays a roll (well at least for this example). The English one I've called browseen_US and browsefr_FR. Why? Because when we swap (by pressing the French or English link) the buttons will swap based on locale. In addition, the image dimensions should stay the same. In this case they're not quite the same so you can see the difference.

2) The Code (Read the comments throughout)


<html>
<head>
<script type="text/javascript">
//Set your default language
var myLang="fr_FR";

//The 'switchTo...' functions will be triggered when we select the
//English or French link.
//The call to initFileUploads updates the UI.
function switchToEnglish() {
myLang="en_US";
initFileUploads();
}

function switchToFrench() {
myLang="fr_FR";
initFileUploads();
}

//This function will update the UI. Note this is where the magic happens.
//We will be using a regular file input type but we use a combination
//of CSS and JavaScript to overlay the English and French buttons.
function initFileUploads() {

var fakeFileUpload = document.createElement('div');

fakeFileUpload.className = 'fakefile';
fakeFileUpload.appendChild(document.createElement('input'));
var image = document.createElement('img');

image.src='browse'+myLang+'.jpg';
image.id="uploadImgId";

fakeFileUpload.appendChild(image);
var x = document.getElementsByTagName('input');

for (var i=0;i<x.length;i++) {
if (x[i].type != 'file') continue;
if (x[i].parentNode.className != 'fileinputs') continue;
x[i].className = 'file hidden';
var clone = fakeFileUpload.cloneNode(true);
x[i].parentNode.appendChild(clone);
x[i].relatedElement = clone.getElementsByTagName('input')[0];
x[i].onchange = x[i].onmouseout = function () {
this.relatedElement.value = this.value;
}
}
}

//This function is called just as a test to see what will be submitted.
//The output will be different depending on the browser you're using.
function viewSubmit() {
for(i=0; i<document.browseTest.elements.length; i++) {
if(document.browseTest.elements[i].name == "") {
document.write("This is the dynamically generated input. ---- ");
}
document.write("The field name is: " + document.browseTest.elements[i].name + " and it’s value is: " + document.browseTest.elements[i].value + ".<br />");
}
}
</script>

<!--These styles are needed for the magic to work. You may have to adapt these depending on what browser you need this to work in. -- >
<style type="text/css">
div.fileinputs {
position: relative;
/*ie7 and ff2 are colliding*/
width: auto;
}

div.fileinputs .file {
/*For ie7 only*/
width: 235px;
}

div.fakefile {
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}

input.file {
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
/*Required for ff2 ONLY*/
width: 145px;
z-index: 2;
}

#uploadImgId {
position: absolute;
/*ie 7 needs this*/
width: 90px;
}

</style>
</head>

<!--The initFileUploads is called to update the UI upon entering the page. -->
<body onload="initFileUploads();">

<fieldset><legend>Browse Button Localization</legend>
Select Language: <a href="#" onclick="switchToEnglish()">English</a>
<a href="javascript:switchToFrench()">French</a><p>

<form name="browseTest" class="example">
<div class="fileinputs">
<input type="file" class="file" name="originalFileInput"/>
</div>

<br />
<input type="button" name="submit" value="View the Submission Value" onclick="viewSubmit()">
</form>
</fieldset>

</body>
</html>

Feel free to swipe!

Saturday, May 16, 2009

Cool Online Web Tools

The nice thing about the majority of these free tools is that no account creation is required.

Button Factory - http://dabuttonfactory.com/
Create buttons online. It's free and has nice 2.0 buttons!

Drawter - http://drawter.com/
Whoever made this deserves an award. Quite intuitive free tool that allows you to draw your website and generates the code for it.

WhosAmungUs - http://whos.amung.us/
Web site tracking widget including displaying visitor info on a map.

Sosius - http://sosius.com/Haven't tried this personally (yet) but it looks cool. It's an online workspace.

Bubbl.us - http://www.bubbl.us/
Cool mind mapping online.

Buttonator - http://www.buttonator.com/
Modern styles for making buttons.

Charts - http://charts.hohli.com/
Great for making quick charts.

Online Code Converter - http://code.cside.com/3rdpage/us/javaUnicode/converter.html
Convert character codes.

MorgueFile - http://www.morguefile.com/
Stock photos even for commercial use (read the 'license').

Wufoo - http://wufoo.com/
Create online forms for every occassion you can imagine. Versatile and good for inspiration.

280 Slides - http://280slides.com/Editor/
It's basically Powerpoint online. Free and easy.

Color Scheme Designer 3 - http://colorschemedesigner.com/
Design colour schemes online. (Nice interface)

COLOURlovers - http://www.colourlovers.com/palettes
This is an interesting site that not only provides colour schemes but also schemes based on patterns.

Pattern Tap - http://patterntap.com/
Awesome place for inspiration. You can view the different looks of 404 Pages, Audio, Breadcrumbs, Borders, Comments, Contact etc...

Kuler - http://kuler.adobe.com/#themes/rating?time=30
Colour schemes you can contribute and create.

IzzyMenu (Builder) - http://www.izzymenu.com/
Comprehensive online menu builder that doesn't require an account.

Wirenode - http://www.wirenode.com/
This is an "ok" site. It provides a fast way, visual way of creating a site for mobile devices.

doTemplate - http://www.dotemplate.com/
This is the ultimate for lazy visual people. Customize the templates they have online and the templates are actually good!

Web Graphics Maker - http://en.web-graphics-maker.com/
Make backgrounds, lines, and bullets online. Includes transparency on png's.

Bradicon! - http://ico.bradleygill.com/advanced.php
Turn images in to icons.

Text to PNG - http://www.text2png.com/
Interesting concept. Converts plain text into a png. You can either use hosted (free) or grab the source for yourself (requires php).

Iconspedia - http://www.iconspedia.com/
Ok, not a tool but wicked Web 2.0 style icons/buttons/images.

Fresh Badge - http://www.freshbadge.com/
An ok site that generates badges.

Loading GIF Generator - http://www.webscriptlab.com/index.php
Good idea! Create animations to use as a 'loading' message.

Dynamic Drive Button Maker Online - http://tools.dynamicdrive.com/button/
Creates small buttons (eg, rss, xhtml etc...)

Timelines - http://www.mytimelines.net/
Create cut and paste timelines from any feed.

Wordle - http://www.wordle.net
Create tag clouds.

Iaza - http://iaza.com/
Vast assortment of image manipulation capabilities online.

LogoMaker - http://logomaker.com/
Cool creative customizable icons. Create the logo and link to it for free or download it for a price.

FotoFlexer - http://fotoflexer.com/
Basic image manipulation online.

Maya - http://www.stockfreephoto.com/
Online image manipulation. You can also download this and place it on your own site for free. (PHP)

Pixenate - http://pixenate.com/
Another free online image manipulation site.

Online Button Maker - http://www.advancewebsoft.com/free-oscommerce-cre-loaded-zen-cart-oscmax-button-generator-p.html
Pretty good button generator.

Big Huge Labs - http://bighugelabs.com/
Show off your pics from Flickr or Facebook. Create calendars, motivation posters, badges and more.

Cool Text - http://cooltext.com/
Cool Text

Logo Generator - http://www.logogenerator.com/
Excellent online logo generator and it's free!


Tuesday, May 12, 2009

Geeky Stuff

In case you're wondering what I do, I'm a Lead Content Developer for a company on the East Coast. The company's focus is on the gathering, managing, and presentation of geospatial data. My focus however, is on all things 'portal' (Liferay Portal to be exact). This includes troubleshooting, maintaining, recommending/evaluating, and developing applications that sit inside the portal called portlets. I also create training materials and if required, deliver it (yes, as in standing up in front of a bunch of people for a couple of days and walking them through various tasks).

I've decided that aside from personal notes on this blog, I will be sharing geeky tidbits. Not sure if anyone will bother reading it but at least it gives me something to do...