Return to Snippet

Revision: 57614
at June 3, 2012 03:31 by crypticsoft

Initial Code
// JS source
$(".btn-status .dropdown-menu a").click(function(){

    var status = $(this).attr('data-status');
    var status_html = $(this).html();
    var toggle = $(".btn-status .btn-toggle");
    var dropdown_toggle = $(".btn-status .dropdown-toggle");
    var status_input = $("input[name='att_status']");

        case "publish":
            toggle.removeAttr('class').addClass('btn btn-toggle btn-success');
            dropdown_toggle.removeAttr('class').addClass('btn dropdown-toggle btn-success');
        case "draft":
            toggle.removeAttr('class').addClass('btn btn-toggle btn-info');
            dropdown_toggle.removeAttr('class').addClass('btn dropdown-toggle btn-info');
        case "archive":
            toggle.removeAttr('class').addClass('btn btn-toggle btn-inverse');
            dropdown_toggle.removeAttr('class').addClass('btn dropdown-toggle btn-inverse');
    toggle.html( status_html ); //reset toggle with new status
    if(status!='archive') toggle.find("i").addClass('icon-white'); //set icon to white
    status_input.attr('value',status); //set the hidden input field


// add this to your HTML
<div class="btn-group alignright btn-status">
          <a href="#" class="btn btn-toggle btn-info"><i class="icon-pencil icon-white"></i> Draft</a>
          <a data-toggle="dropdown" href="#" class="btn dropdown-toggle btn-info"><span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a data-status="draft" href="#"><i class="icon-pencil"></i> Draft</a></li>
            <li><a data-status="publish" href="#"><i class="icon-ok-sign"></i> Publish</a></li>
            <li><a data-status="archive" href="#"><i class="icon-lock"></i> Archive</a></li>
          <input type="hidden" value="draft" name="att_status">

Initial URL

Initial Description
Include twitter bootstrap, as of this writing is at v2.0.4 and the following JS / html to your page and also uses Glyphicons.

Initial Title
twitter bootstrap button toggle

Initial Tags
button, twitter

Initial Language