bootstrap-table-bulma.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @author zhixin wen <wenzhixin2010@gmail.com>
  3. * https://github.com/wenzhixin/bootstrap-table/
  4. * theme: https://github.com/jgthms/bulma/
  5. */
  6. $.extend($.fn.bootstrapTable.defaults, {
  7. classes: 'table is-bordered is-hoverable',
  8. buttonsPrefix: '',
  9. buttonsClass: 'button'
  10. })
  11. $.fn.bootstrapTable.theme = 'bulma'
  12. $.BootstrapTable = class extends $.BootstrapTable {
  13. initConstants () {
  14. super.initConstants()
  15. this.constants.classes.buttonsGroup = 'buttons has-addons'
  16. this.constants.classes.buttonsDropdown = 'button dropdown is-right'
  17. this.constants.classes.input = 'input'
  18. this.constants.classes.paginationDropdown = 'ui dropdown'
  19. this.constants.classes.dropup = 'is-up'
  20. this.constants.classes.dropdownActive = 'is-active'
  21. this.constants.classes.paginationActive = 'is-current'
  22. this.constants.classes.buttonActive = 'is-active'
  23. this.constants.html.toobarDropdow = ['<div class="dropdown-menu"><div class="dropdown-content">', '</div></div>']
  24. this.constants.html.toobarDropdowItem = '<label class="dropdown-item">%s</label>'
  25. this.constants.html.pageDropdown = ['<div class="dropdown-menu"><div class="dropdown-content">', '</div></div>']
  26. this.constants.html.pageDropdownItem = '<a class="dropdown-item %s" href="#">%s</a>'
  27. this.constants.html.dropdownCaret = '<span class="icon is-small"><i class="fas fa-angle-down" aria-hidden="true"></i></span>'
  28. this.constants.html.pagination = ['<ul class="pagination%s">', '</ul>'],
  29. this.constants.html.paginationItem = '<li><a class="page-item pagination-link%s" href="#">%s</a></li>'
  30. }
  31. initToolbar () {
  32. super.initToolbar()
  33. this.handleToolbar()
  34. }
  35. handleToolbar () {
  36. if (this.$toolbar.find('.dropdown').length) {
  37. this._initDropdown()
  38. }
  39. }
  40. initPagination () {
  41. super.initPagination()
  42. if (this.options.pagination && !this.options.onlyInfoPagination) {
  43. this._initDropdown()
  44. }
  45. }
  46. _initDropdown () {
  47. const $dropdowns = this.$container.find('.dropdown:not(.is-hoverable)')
  48. $dropdowns.off('click').on('click', e => {
  49. const $this = $(e.currentTarget)
  50. e.stopPropagation()
  51. $dropdowns.not($this).removeClass('is-active')
  52. $this.toggleClass('is-active')
  53. })
  54. $(document).off('click.bs.dropdown.bulma').on('click.bs.dropdown.bulma', () => {
  55. $dropdowns.removeClass('is-active')
  56. })
  57. }
  58. }