Delete button morphing into confirmation button

by dipish

HTML

<a href="#" class="btn-del" data-confirm="Really delete?" /></a>

CSS

body {
    margin: 30px;
}

.btn-del {
    display: block;
    box-sizing: border-box;
    position: relative;
    
    overflow: hidden;
    /* force text into one line */
    white-space: nowrap;
    
    /* some skinning */
    background-color: #FF8566;
    color: #fff;
    border: solid 1px #E66950;
    font-size: 12px;
    font-family: sans-serif;
    text-decoration: none;
    line-height: 1em;
    padding: 0.25em;
    
    /* make it rounded*/
     border-radius: 50%;
    
    /* fixed size for "icon mode" */
    width: 14px;
    height: 14px;
    
    /* enable transitions */
    -moz-transition: all 500ms; 
    -webkit-transition: all 500ms;  
    -ms-transition: all 500ms;  
    -o-transition: all 500ms;  
    transition: all 500ms;  
}

.btn-del:after {
    content: 'X';
    position: absolute;
    /* how to make these universal?*/
    top: 0;
    left: 2px;
}

.btn-del-expanded {
    padding: 0.25em;
    border-radius: 0; /* can't specify pixels here, have to use the same unit for transitions to work */
}

.btn-del-expanded:after {
    display: none;
}

JavaScript

var expandedCls = 'btn-del-expanded';

$('.btn-del').click(function(e) {
    var el = $(this);

    if(el.hasClass(expandedCls)) {
        el.removeClass(expandedCls)
            .empty()
            .css({
                width: 14,
                height: 14
            });
    } else {
        el.addClass(expandedCls)
            .text(el.data('confirm'))
            .css({
                width: el.prop('scrollWidth'),
                height: el.prop('scrollHeight')
            });
    }            
    
    e.preventDefault();
    return false;
});