examples.js 598 B

1234567891011121314151617181920
  1. $(function() {
  2. $('.bs-example').each(function() {
  3. var source = $('<div></div>').text($(this).html()).html(),
  4. sources = source.split('\n'),
  5. codes = [],
  6. spaces = 0;
  7. $.each(sources, function(i, text) {
  8. if (!$.trim(text)) {
  9. i > 0 && codes.push('');
  10. return;
  11. }
  12. if (!spaces) {
  13. spaces = text.match(/(^\s+)/)[1].length;
  14. }
  15. codes.push(text.substring(spaces));
  16. });
  17. $(this).next().find('code').html(codes.join('\n'));
  18. });
  19. });