bootstrap-table-foundation.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @author zhixin wen <wenzhixin2010@gmail.com>
  3. * https://github.com/wenzhixin/bootstrap-table/
  4. * theme: https://github.com/zurb/foundation-sites
  5. */
  6. $.extend($.fn.bootstrapTable.defaults, {
  7. classes: 'table hover',
  8. buttonsPrefix: '',
  9. buttonsClass: 'button'
  10. })
  11. $.fn.bootstrapTable.theme = 'foundation'
  12. $.BootstrapTable = class extends $.BootstrapTable {
  13. initConstants () {
  14. super.initConstants()
  15. this.constants.classes.buttonsGroup = 'button-group'
  16. this.constants.classes.buttonsDropdown = 'dropdown-container'
  17. this.constants.classes.paginationDropdown = ''
  18. this.constants.classes.dropdownActive = 'is-active'
  19. this.constants.classes.paginationActive = 'current'
  20. this.constants.classes.buttonActive = 'success'
  21. this.constants.html.toobarDropdow = ['<ul class="dropdown-pane" id="toolbar-columns-id" data-dropdown><ul class="vertical menu">', '</ul></div>']
  22. this.constants.html.toobarDropdowItem = '<li><label class="dropdown-item">%s</label></li>'
  23. this.constants.html.pageDropdown = ['<div class="dropdown-pane" id="pagination-list-id" data-dropdown><ul class="vertical menu">', '</ul></div>']
  24. this.constants.html.pageDropdownItem = '<li class="dropdown-item %s"><a href="#">%s</a></li>'
  25. this.constants.html.dropdownCaret = '<i class="fa fa-angle-down"></i>'
  26. this.constants.html.pagination = ['<ul class="pagination%s">', '</ul>']
  27. this.constants.html.paginationItem = '<li><a class="page-item%s" aria-label="%s" href="#">%s</a></li>'
  28. this.constants.html.inputGroup = '<div class="input-group">%s <div class="input-group-button">%s</div></div>'
  29. this.constants.html.searchInput = '<input class="%s input-%s input-group-field" type="text" placeholder="%s">'
  30. this.constants.html.searchButton = '<button class="button" type="button" name="search" title="%s"><i class="%s %s"></i></button>'
  31. this.constants.html.searchClearButton = '<button class="button" type="button" name="clearSearch" title="%s"><i class="%s %s"></i></button>'
  32. }
  33. initToolbar () {
  34. super.initToolbar()
  35. this.handleToolbar()
  36. }
  37. handleToolbar () {
  38. if (this.$toolbar.find('.dropdown-toggle').length) {
  39. this.$toolbar.find('.dropdown-toggle').each((i, el) => {
  40. $(el).attr('data-toggle', $(el).next().attr('id'))
  41. const $pane = $(el).next()
  42. .attr('data-position', 'bottom')
  43. .attr('data-alignment', 'right')
  44. new window.Foundation.Dropdown($pane)
  45. })
  46. this._initDropdown()
  47. }
  48. }
  49. initPagination () {
  50. super.initPagination()
  51. if (this.options.pagination && !this.options.onlyInfoPagination) {
  52. const $el = this.$pagination.find('.dropdown-toggle')
  53. $el.attr('data-toggle', $el.next().attr('id'))
  54. const $pane = this.$pagination.find('.dropdown-pane')
  55. .attr('data-position', 'top')
  56. .attr('data-alignment', 'left')
  57. new window.Foundation.Dropdown($pane)
  58. this._initDropdown()
  59. }
  60. }
  61. _initDropdown () {
  62. const $dropdowns = this.$container.find('.dropdown-toggle')
  63. $dropdowns.off('click').on('click', e => {
  64. const $this = $(e.currentTarget)
  65. e.stopPropagation()
  66. $dropdowns.not($this).next().foundation('close')
  67. $this.next().foundation('toggle')
  68. })
  69. $(document).off('click.bs.dropdown.foundation').on('click.bs.dropdown.foundation', () => {
  70. $dropdowns.next().foundation('close')
  71. })
  72. }
  73. }