neves
3/17/2014 - 1:05 PM

rails-scaffold-bootstrap.css

// rawgithub.com/neves/9598842/raw/rails-scaffold-bootstrap.js
(function() {
  var classify, cssLink, jsScript;

  classify = function(selector, klass) {
    return $(selector).addClass(klass);
  };

  cssLink = function(href) {
     $('head').append('<link rel="stylesheet" type="text/css" href="'+href+'">');
  };
  jsScript = function(src) {
     $('head').append('<script src="'+src+'"></script>');
  };

  cssLink('//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css');
  cssLink('//rawgithub.com/neves/9598842/raw/rails-scaffold-bootstrap.css');
  jsScript('//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js');

$(document).on('ready page:load', function() {
  if ( $("body").children(".container").length == 0 ) {
    classify('body', 'container');
  }
  classify('#notice', 'alert alert-success');

  classify('a[href$="/new"]', 'btn btn-success btn-lg pull-right').prepend(' <i class="glyphicon glyphicon-plus"></i> ');
  classify('a[href$="/edit"]', 'btn btn-warning').prepend(' <i class="glyphicon glyphicon-edit"></i> ');
  classify('a[data-method="delete"]', 'btn btn-danger btn-xs').prepend(' <i class="glyphicon glyphicon-trash"></i> ');
  var bt = '<button type="submit" class="btn btn-primary btn-lg pull-right"> <i class="glyphicon glyphicon-ok-sign"></i> </button>';
  $('form .actions input[name="commit"]').after( function() {return $(bt).append($(this).val())} ).remove();

  classify('a:contains("Show")', 'btn btn-info').prepend(' <i class="glyphicon glyphicon-eye-open"></i> ');
  classify('a:contains("Back")', 'btn btn-default').prepend(' <i class="glyphicon glyphicon-chevron-left"></i> ');
  
  classify('table', 'table table-striped table-bordered table-hover table-condensed');
  classify('td .btn', 'btn-xs');
  
  classify('form div.field', 'form-group');
  classify('form div.field label', 'control-label');
  $('form div.field :input').not(':radio, :checkbox, :hidden, :submit, :button').addClass('form-control');
  classify('form div.actions', 'form-group');
  $(".field:has(:checkbox)").addClass("checkbox").find('br').remove();
});

})();
html {
  background-image: url(http://subtlepatterns.com/patterns/bo_play_pattern.png);
  padding-top: 10px;
}

body {
  padding-top: 15px;
  padding-bottom: 20px;
}

.table th:empty {
  border: none;
  width: 1%;
}

#notice:empty {
  display: none;
}

select[name$="i)]"] {
  width: auto;
  display: inline-block;
}