examples.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. $(function() {
  2. 'use strict';
  3. $('.bs-example').each(function() {
  4. var source = $('<div></div>').text($(this).html()).html(),
  5. sources = source.split('\n'),
  6. codes = [],
  7. spaces = 0;
  8. try {
  9. $.each(sources, function(i, text) {
  10. if (!$.trim(text)) {
  11. i > 0 && codes.push('');
  12. return;
  13. }
  14. if (!spaces) {
  15. spaces = text.match(/(^\s+)/)[1].length;
  16. }
  17. codes.push(text.substring(spaces));
  18. });
  19. $(this).next().find('code').html(codes.join('\n'));
  20. } catch (e) {
  21. $(this).next().remove();
  22. }
  23. });
  24. $('#i18n').change(function() {
  25. $.getScript('../src/locale/bootstrap-table-' + $(this).val() + '.js', function() {
  26. $('#table-pagination').bootstrapTable('destroy').bootstrapTable();
  27. });
  28. });
  29. $(window).resize(function () {
  30. $('table[data-toggle="table"]').add($('table[id]')).bootstrapTable('resetView');
  31. });
  32. });
  33. function buildTable($el, cells, rows) {
  34. var i, j, row,
  35. columns = [],
  36. data = [];
  37. for (i = 0; i < cells; i++) {
  38. columns.push({
  39. field: 'field' + i,
  40. title: 'Cell' + i
  41. });
  42. }
  43. for (i = 0; i < rows; i++) {
  44. row = {};
  45. for (j = 0; j < cells; j++) {
  46. row['field' + j] = 'Row-' + i + '-' + j;
  47. }
  48. data.push(row);
  49. }
  50. $el.bootstrapTable('destroy').bootstrapTable({
  51. columns: columns,
  52. data: data
  53. });
  54. }