examples.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $('.start-example').click(function () {
  30. var $parent = $(this).hide().parent();
  31. $parent.next('.bs-example').add($parent.next().next('.bs-example'))
  32. .find('table').bootstrapTable('destroy').bootstrapTable();
  33. });
  34. $(window).resize(function () {
  35. $('table[data-toggle="table"]').add($('table[id]')).bootstrapTable('resetView');
  36. });
  37. });
  38. function buildTable($el, cells, rows) {
  39. var i, j, row,
  40. columns = [],
  41. data = [];
  42. for (i = 0; i < cells; i++) {
  43. columns.push({
  44. field: 'field' + i,
  45. title: 'Cell' + i
  46. });
  47. }
  48. for (i = 0; i < rows; i++) {
  49. row = {};
  50. for (j = 0; j < cells; j++) {
  51. row['field' + j] = 'Row-' + i + '-' + j;
  52. }
  53. data.push(row);
  54. }
  55. $el.bootstrapTable('destroy').bootstrapTable({
  56. columns: columns,
  57. data: data
  58. });
  59. }