├── .repo-rt ├── README.md ├── css ├── basic.css └── enhanced.css ├── images ├── bg-btn.png ├── bg-submit.gif ├── icon-generic.gif ├── icon-image.gif ├── icon-media.gif └── icon-zip.gif ├── index.html ├── js ├── example.js └── jQuery.fileinput.js └── license.txt /.repo-rt: -------------------------------------------------------------------------------- 1 | RETIRED 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :warning: This project is archived and the repository is no longer maintained. 2 | 3 | # Code Examples from the book [Designing with Progressive Enhancement](http://filamentgroup.com/dwpe) 4 | 5 | [![Filament Group](http://filamentgroup.com/images/fg-logo-positive-sm-crop.png) ](http://www.filamentgroup.com/) 6 | 7 | This repository includes open-sourced code developed and maintained by Filament Group, Inc. as part of the book "Designing With Progressive Enhancement" (Peachpit). 8 | 9 | All examples use the [jQuery JavaScript library](http://jquery.com). 10 | 11 | These code examples use the [EnhanceJS framework](https://github.com/filamentgroup/EnhanceJS) for applying progressive enhancement based on browser capabilities testing. 12 | -------------------------------------------------------------------------------- /css/basic.css: -------------------------------------------------------------------------------- 1 | body { font-family: "Segoe UI", Arial, sans-serif; } 2 | label{ display:block; } -------------------------------------------------------------------------------- /css/enhanced.css: -------------------------------------------------------------------------------- 1 | body { font-size: 62.5%; margin: 50px; } 2 | fieldset { padding: .6em 0;border:0;border-top: 1px dotted #ddd; } 3 | legend { font-size: 1.5em; font-weight: bold; color: #555; padding: .5em 1em .5em 0; background: #fff; } 4 | label { font-size: 1.4em; display: block; margin: .5em 10px .5em 0; } 5 | input#upload { background: #aaa url(../images/bg-btn.png) bottom repeat-x; padding: .4em 1.2em;border: 1px solid #aaa; color: #222; font-size: 1.2em; font-weight: bold; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; cursor: pointer; margin: 2em 0; } 6 | input#upload:hover { background: #eee; color: #111; border-color:#777; } 7 | 8 | 9 | /*custom upload elements*/ 10 | .customfile-input { position: absolute; height: 100px; cursor: pointer; background: transparent; border: 0; opacity: 0; -moz-opacity: 0; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); z-index: 999; } 11 | 12 | .customfile { width: 400px; background: #666; cursor: pointer; overflow: hidden; padding: 2px; border: 1px solid #444; -moz-border-radius:7px; -webkit-border-radius:7px; border-radius:7px; position: relative; } 13 | .customfile-disabled { opacity: .5; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); cursor: default; } 14 | .customfile-feedback { display: block; margin: 1px 1px 1px 5px; font-size: 1.2em; color: #fff; font-style: italic; padding: .3em .6em; } 15 | .customfile-feedback-populated { color: #fff; font-style: normal; font-weight: bold; padding-left: 20px; background: url(../images/icon-generic.gif) left 4px no-repeat; } 16 | .customfile-button { border: 1px solid #999; background: #333 url(../images/bg-submit.gif) bottom repeat-x; color: #fff; font-weight: bold; float: right; width: 50px; padding: .3em .6em; text-align: center; text-decoration: none; font-size: 1.2em; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; } 17 | .customfile-hover .customfile-button, .customfile-focus .customfile-button { color:#111; background: #aaa url(../images/bg-btn.png) bottom repeat-x; border-color:#aaa; padding: .3em .6em; } 18 | .customfile-focus .customfile-button { outline: 1px dotted #ccc; } 19 | 20 | /*file type icons*/ 21 | .customfile-ext-jpg, .customfile-ext-gif, .customfile-ext-png, .customfile-ext-jpeg, .customfile-ext-bmp { background-image: url(../images/icon-image.gif);} 22 | .customfile-ext-mp3, .customfile-ext-mp4, .customfile-ext-mov, .customfile-ext-swf, .customfile-ext-wav, .customfile-ext-m4v { background-image: url(../images/icon-media.gif);} 23 | .customfile-ext-zip, .customfile-ext-tar, .customfile-ext-sit { background-image: url(../images/icon-zip.gif);} 24 | 25 | 26 | -------------------------------------------------------------------------------- /images/bg-btn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/filamentgroup/jQuery-Custom-File-Input/db6fbd6e1d6fee247974c152b47f04d99b1e0b26/images/bg-btn.png -------------------------------------------------------------------------------- /images/bg-submit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/filamentgroup/jQuery-Custom-File-Input/db6fbd6e1d6fee247974c152b47f04d99b1e0b26/images/bg-submit.gif -------------------------------------------------------------------------------- /images/icon-generic.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/filamentgroup/jQuery-Custom-File-Input/db6fbd6e1d6fee247974c152b47f04d99b1e0b26/images/icon-generic.gif -------------------------------------------------------------------------------- /images/icon-image.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/filamentgroup/jQuery-Custom-File-Input/db6fbd6e1d6fee247974c152b47f04d99b1e0b26/images/icon-image.gif -------------------------------------------------------------------------------- /images/icon-media.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/filamentgroup/jQuery-Custom-File-Input/db6fbd6e1d6fee247974c152b47f04d99b1e0b26/images/icon-media.gif -------------------------------------------------------------------------------- /images/icon-zip.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/filamentgroup/jQuery-Custom-File-Input/db6fbd6e1d6fee247974c152b47f04d99b1e0b26/images/icon-zip.gif -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | File Uploader 6 | 7 | 26 | 27 | 38 | 39 | 40 |
41 |

Filament Group

42 |
43 | 44 | 45 |
46 |
47 | Profile image 48 | 49 | 50 | 51 |
52 |
53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /js/example.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | $('#file').customFileInput(); 3 | }); -------------------------------------------------------------------------------- /js/jQuery.fileinput.js: -------------------------------------------------------------------------------- 1 | /** 2 | * -------------------------------------------------------------------- 3 | * jQuery customfileinput plugin 4 | * Author: Scott Jehl, scott@filamentgroup.com 5 | * Copyright (c) 2009 Filament Group 6 | * licensed under MIT (filamentgroup.com/examples/mit-license.txt) 7 | * -------------------------------------------------------------------- 8 | */ 9 | (function( $ ){ 10 | $.fn.customFileInput = function(){ 11 | //apply events and styles for file input element 12 | var fileInput = $(this) 13 | .addClass('customfile-input') //add class for CSS 14 | .mouseover(function(){ upload.addClass('customfile-hover'); }) 15 | .mouseout(function(){ upload.removeClass('customfile-hover'); }) 16 | .focus(function(){ 17 | upload.addClass('customfile-focus'); 18 | fileInput.data('val', fileInput.val()); 19 | }) 20 | .blur(function(){ 21 | upload.removeClass('customfile-focus'); 22 | $(this).trigger('checkChange'); 23 | }) 24 | .bind('disable',function(){ 25 | fileInput.attr('disabled',true); 26 | upload.addClass('customfile-disabled'); 27 | }) 28 | .bind('enable',function(){ 29 | fileInput.removeAttr('disabled'); 30 | upload.removeClass('customfile-disabled'); 31 | }) 32 | .bind('checkChange', function(){ 33 | if(fileInput.val() && fileInput.val() != fileInput.data('val')){ 34 | fileInput.trigger('change'); 35 | } 36 | }) 37 | .bind('change',function(){ 38 | //get file name 39 | var fileName = $(this).val().split(/\\/).pop(); 40 | //get file extension 41 | var fileExt = 'customfile-ext-' + fileName.split('.').pop().toLowerCase(); 42 | //update the feedback 43 | uploadFeedback 44 | .text(fileName) //set feedback text to filename 45 | .removeClass(uploadFeedback.data('fileExt') || '') //remove any existing file extension class 46 | .addClass(fileExt) //add file extension class 47 | .data('fileExt', fileExt) //store file extension for class removal on next change 48 | .addClass('customfile-feedback-populated'); //add class to show populated state 49 | //change text of button 50 | uploadButton.text('Change'); 51 | }) 52 | .click(function(){ //for IE and Opera, make sure change fires after choosing a file, using an async callback 53 | fileInput.data('val', fileInput.val()); 54 | setTimeout(function(){ 55 | fileInput.trigger('checkChange'); 56 | },100); 57 | }); 58 | 59 | //create custom control container 60 | var upload = $('
'); 61 | //create custom control button 62 | var uploadButton = $('').appendTo(upload); 63 | //create custom control feedback 64 | var uploadFeedback = $('').appendTo(upload); 65 | 66 | //match disabled state 67 | if(fileInput.is('[disabled]')){ 68 | fileInput.trigger('disable'); 69 | } 70 | 71 | 72 | //on mousemove, keep file input under the cursor to steal click 73 | upload 74 | .mousemove(function(e){ 75 | fileInput.css({ 76 | 'left': e.pageX - upload.offset().left - fileInput.outerWidth() + 20, //position right side 20px right of cursor X) 77 | 'top': e.pageY - upload.offset().top - $(window).scrollTop() - 3 78 | }); 79 | }) 80 | .insertAfter(fileInput); //insert after the input 81 | 82 | fileInput.appendTo(upload); 83 | 84 | //return jQuery 85 | return $(this); 86 | }; 87 | })( jQuery ); 88 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010 Filament Group, Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. --------------------------------------------------------------------------------