bootstrap-table-bulma.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.toolbarDropdown = ['<div class="dropdown-menu"><div class="dropdown-content">', '</div></div>']
  24. this.constants.html.toolbarDropdownItem = '<label class="dropdown-item dropdown-item-marker">%s</label>'
  25. this.constants.html.toolbarDropdownSeparator = '<li class="dropdown-divider"></li>'
  26. this.constants.html.pageDropdown = ['<div class="dropdown-menu"><div class="dropdown-content">', '</div></div>']
  27. this.constants.html.pageDropdownItem = '<a class="dropdown-item %s" href="#">%s</a>'
  28. this.constants.html.dropdownCaret = '<span class="icon is-small"><i class="fas fa-angle-down" aria-hidden="true"></i></span>'
  29. this.constants.html.pagination = ['<ul class="pagination%s">', '</ul>']
  30. this.constants.html.paginationItem = '<li><a class="page-item pagination-link%s" aria-label="%s" href="#">%s</a></li>'
  31. this.constants.html.searchInput = '<p class="control"><input class="%s input-%s" type="search" placeholder="%s"></p>'
  32. this.constants.html.inputGroup = '<div class="field has-addons has-addons-right">%s%s</div>'
  33. this.constants.html.searchButton = '<p class="control"><button class="%s" type="button" name="search" title="%s">%s %s</button></p>'
  34. this.constants.html.searchClearButton = '<p class="control"><button class="%s" type="button" name="clearSearch" title="%s">%s %s</button></p>'
  35. }
  36. initToolbar () {
  37. super.initToolbar()
  38. this.handleToolbar()
  39. }
  40. handleToolbar () {
  41. if (this.$toolbar.find('.dropdown').length) {
  42. this._initDropdown()
  43. }
  44. }
  45. initPagination () {
  46. super.initPagination()
  47. if (this.options.pagination && this.paginationParts.includes('pageSize')) {
  48. this._initDropdown()
  49. }
  50. }
  51. _initDropdown () {
  52. const $dropdowns = this.$container.find('.dropdown:not(.is-hoverable)')
  53. $dropdowns.off('click').on('click', e => {
  54. const $this = $(e.currentTarget)
  55. e.stopPropagation()
  56. $dropdowns.not($this).removeClass('is-active')
  57. $this.toggleClass('is-active')
  58. })
  59. $(document).off('click.bs.dropdown.bulma').on('click.bs.dropdown.bulma', () => {
  60. $dropdowns.removeClass('is-active')
  61. })
  62. }
  63. }