Ok, I got something to work. Here are the notes that I created as I went. They might be a little messy.
I'm basing my technique on Pete Boere's method, at http://the-echoplex.net/log/how-to-style-a-html-file-upload-control-using-css-and-javascript
Notes follow:
Step one:
* Wrap target input in an element that we can give these styles to:
display: inline-block
overflow: hidden
Peter uses 'label'. Can we do that?
Maybe....
We get our input wrapped inside an oddball <span>, which is nested
inside a div. This span seems weirdly resistant to styling.
Let's try and treat the div that way that he treats the label
The innermost wrapping element, .ginput_full seems to be utterly
resistant to resizing.
So, I'm targeting '#field_1_12", which is the list item.
Ok... we can do that. Kewl. So far, so good.
Next, we hide the actual input.
Yup, we can do that. That was easy. But now we want to add our visual
"browse" button.
In order to do this, I target this element.
#field_1_12 .gfield_label
I give it these rules:
#field_1_12 .gfield_label
position: absolute
background-color: #7a7a7a
right: -290px
top: 2px
width: 70px
height: 30px
-webkit-border-radius: 8px
-moz-border-radius: 8px
border-radius: 8px
background-image: url("/img/browse.png")
Ok, the user can still click on it, and get the file selection
dialogue. Cool.
So, now we need to give the user feedback. User wants to have their
expectation of feedback met - we have to let them know that we know
which file they have selected.
At this point, we need to throw away our sense of integrity when it
comes to such aloof concerns as "seperation of content". *sigh
We use jquery to keep a div within the form to display the name of the
file. I inject with js:
// insert a div and exploit it's presence
var displayDiv = "<div id=\"file-display\"><p></p></div> " ;
$("#field_1_12").append(displayDiv) ;
Now we need to make sure that the display div show shows the selected file.
var target = $("#field_1_12 input") ;
target.change(function(){
var fileDisplay = $("#file-display p") ;
fileDisplay.empty() ;
fileDisplay.append( $("#field_1_12 input").val()) ;
}) ;
And, we are done.
This works for me.
I have, however, not thoroughly tested it yet across browsers. I
expect that the behaviours will work just fine.
Posted 12 years ago on Wednesday January 4, 2012 |
Permalink