Giter Club home page Giter Club logo

jquery-custom-input's Introduction

โš ๏ธ This project is archived and the repository is no longer maintained.

Code Examples from the book Designing with Progressive Enhancement

This repository includes open-sourced code developed and maintained by Filament Group, Inc. as part of the book "Designing With Progressive Enhancement" (Peachpit).

All examples use the jQuery JavaScript library.

These code examples use the EnhanceJS framework for applying progressive enhancement based on browser capabilities testing.

jquery-custom-input's People

Contributors

benconstable avatar jefflembeck avatar johnbender avatar scottjehl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-custom-input's Issues

Firefox problem + label

Hi,

I change the plugin to manage some weird cases with Firefox, and to manage the associated label:

$.fn.customFileInput = function(){
//apply events and styles for file input element
var fileInput = $(this)
.addClass('customfile-input') //add class for CSS
.css("top", "0px") // In Firefox, if we click on the associated label without having a hover on the input file, the display can be broken in some cases
.css("left", "0px")
.mouseover(function(){ upload.addClass('customfile-hover'); })
.mouseout(function(){ upload.removeClass('customfile-hover'); })
.focus(function(){
upload.addClass('customfile-focus');
fileInput.data('val', fileInput.val());
fileInput.trigger('click');
})
.blur(function(){
upload.removeClass('customfile-focus');
$(this).trigger('checkChange');
})
.bind('disable',function(){
fileInput.attr('disabled',true);
upload.addClass('customfile-disabled');
})
.bind('enable',function(){
fileInput.removeAttr('disabled');
upload.removeClass('customfile-disabled');
})
.bind('checkChange', function(){
if(fileInput.val() && fileInput.val() != fileInput.data('val')){
fileInput.trigger('change');
}
})
.bind('change',function(){
if($(this).val()){
//get file name
var fileName = $(this).val().split(//).pop();
//get file extension
var fileExt = 'customfile-ext-' + fileName.split('.').pop().toLowerCase();
//update the feedback
uploadFeedback
.text(fileName) //set feedback text to filename
.removeClass(uploadFeedback.data('fileExt') || '') //remove any existing file extension class
.addClass(fileExt) //add file extension class
.data('fileExt', fileExt) //store file extension for class removal on next change
.addClass('customfile-feedback-populated'); //add class to show populated state
//change text of button
uploadButton.text('Change');

        } else {
            // For the reset form case
            uploadFeedback
                .text("No file selected...")
                .attr("class", "customfile-feedback");
            uploadButton.text('Browse');
        }

    })
    .click(function(event){ //for IE and Opera, make sure change fires after choosing a file, using an async callback
        fileInput.data('val', fileInput.val());
        setTimeout(function(){
            fileInput.trigger('checkChange');
        },100);
    });

if(fileInput.attr("id")){
    // Manage properly the click on the associated label (in Firefox, we can have some problems)
    $("label[for='" + fileInput.attr("id") + "']").live("click", function(event){
        event.preventDefault();
        event.stopImmediatePropagation();
        event.stopPropagation();
        fileInput.trigger('click');
    });
}

//create custom control container
var upload = $('<div class="customfile"></div>');

//create custom control button
var uploadButton = $('<span class="customfile-button" aria-hidden="true">Browse</span>').appendTo(upload);

//create custom control feedback
var uploadFeedback = $('<span class="customfile-feedback" aria-hidden="true">No file selected...</span>').appendTo(upload);

//match disabled state
if(fileInput.is('[disabled]')){
    fileInput.trigger('disable');
}


//on mousemove, keep file input under the cursor to steal click
upload
    .mousemove(function(e){

// fileInput.css({
// 'left': e.pageX - upload.offset().left - fileInput.outerWidth() + 20, //position right side 20px right of cursor X)
// 'top': e.pageY - upload.offset().top - $(window).scrollTop() - 3
// });

        fileInput.css({
            'left': e.pageX - upload.offset().left - fileInput.outerWidth() + 20, //position right side 20px right of cursor X)
            'top': e.pageY - upload.offset().top - 20
        }); 
    })
    .insertAfter(fileInput); //insert after the input

fileInput.appendTo(upload);

//return jQuery
return $(this);

};

Table (grid) design

Nice plugin, and it works perfectly but how about table or grid design like the one bellow.

The script will fail on this case. Any ideas on how we can design this?

<table style="display: inline-block;" class="mrQuestionTable" summary="Question text goes here lorem ipsum dolorem">
    <tbody>
        <tr>
            <td id="Cell.0.0"></td>
            <td style="text-Align: Center;vertical-align: Middle;" class="mrGridQuestionText" id="Cell.1.0"> <span style="" class="mrQuestionText">column 1</span>

            </td>
            <td style="text-Align: Center;vertical-align: Middle;" class="mrGridQuestionText" id="Cell.2.0"> <span style="" class="mrQuestionText">column 2</span>

            </td>
        </tr>
        <tr>
            <td style="text-Align: Left;vertical-align: Middle;" class="mrGridCategoryText" id="Cell.0.1"> <span style="" class="mrQuestionText">Category1_Text</span>

            </td>
            <td style="text-Align: Center;vertical-align: Middle;" id="Cell.1.1">
                <div></div>
                <input type="radio" value="__1" style="" class="mrSingle" id="_Q0_Q0_Q0_C0" name="_QQ3_Q__1_Qq3a_C">
            </td>
            <td style="text-Align: Center;vertical-align: Middle;" id="Cell.2.1">
                <div></div>
                <input type="radio" value="__2" style="" class="mrSingle" id="_Q0_Q0_Q0_C1" name="_QQ3_Q__1_Qq3a_C">
            </td>
        </tr>
        <tr>
            <td style="text-Align: Left;vertical-align: Middle;" class="mrGridCategoryText" id="Cell.0.2"> <span style="" class="mrQuestionText">Category2_Text</span>

            </td>
            <td style="text-Align: Center;vertical-align: Middle;" id="Cell.1.2">
                <div></div>
                <input type="radio" value="__1" style="" class="mrSingle" id="_Q0_Q1_Q0_C0" name="_QQ3_Q__2_Qq3a_C">
            </td>
            <td style="text-Align: Center;vertical-align: Middle;" id="Cell.2.2">
                <div></div>
                <input type="radio" value="__2" style="" class="mrSingle" id="_Q0_Q1_Q0_C1" name="_QQ3_Q__2_Qq3a_C">
            </td>
        </tr>
    </tbody>
</table>

Source PSD

Could you provide the PSD files for the check boxes? I need to make them transparent.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.