examples.js 556 B

12345678910111213141516171819
  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. return;
  10. }
  11. if (!spaces) {
  12. spaces = text.match(/(^\s+)/)[1].length;
  13. }
  14. codes.push(text.substring(spaces));
  15. });
  16. $(this).next().find('code').html(codes.join('\n'));
  17. });
  18. });