UNPKG

3.41 kBJavaScriptView Raw
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
7$.extend($.fn.bootstrapTable.defaults, {
8 classes: 'table hover',
9 buttonsPrefix: '',
10 buttonsClass: 'button'
11})
12
13$.fn.bootstrapTable.theme = 'foundation'
14
15$.BootstrapTable = class extends $.BootstrapTable {
16 initConstants () {
17 super.initConstants()
18
19 this.constants.classes.buttonsGroup = 'button-group'
20 this.constants.classes.buttonsDropdown = 'dropdown-container'
21 this.constants.classes.paginationDropdown = ''
22 this.constants.classes.dropdownActive = 'is-active'
23 this.constants.classes.paginationActive = 'current'
24 this.constants.classes.buttonActive = 'success'
25
26 this.constants.html.toolbarDropdown = ['<div class="dropdown-pane" data-dropdown><ul class="vertical menu">', '</ul></div>']
27 this.constants.html.toolbarDropdownItem = '<li class="dropdown-item-marker"><label class="dropdown-item">%s</label></li>'
28 this.constants.html.toolbarDropdownSeparator = '<li><hr></li>'
29 this.constants.html.pageDropdown = ['<div class="dropdown-pane" id="pagination-list-id" data-dropdown><ul class="vertical menu">', '</ul></div>']
30 this.constants.html.pageDropdownItem = '<li class="dropdown-item %s"><a href="#">%s</a></li>'
31 this.constants.html.dropdownCaret = '<i class="fa fa-angle-down"></i>'
32 this.constants.html.pagination = ['<ul class="pagination%s">', '</ul>']
33 this.constants.html.paginationItem = '<li><a class="page-item%s" aria-label="%s" href="#">%s</a></li>'
34 this.constants.html.inputGroup = '<div class="input-group">%s <div class="input-group-button">%s</div></div>'
35 this.constants.html.searchInput = '<input class="%s input-%s input-group-field" type="search" placeholder="%s">'
36 }
37
38 initToolbar () {
39 super.initToolbar()
40 this.handleToolbar()
41 }
42
43 handleToolbar () {
44 if (this.$toolbar.find('.dropdown-toggle').length) {
45 this.$toolbar.find('.dropdown-toggle').each((i, el) => {
46 if (!$(el).next().length) {
47 return
48 }
49
50 const id = `toolbar-columns-id${i}`
51
52 $(el).next().attr('id', id)
53 $(el).attr('data-toggle', id)
54 const $pane = $(el).next()
55 .attr('data-position', 'bottom')
56 .attr('data-alignment', 'right')
57
58 new window.Foundation.Dropdown($pane)
59 })
60
61 this._initDropdown()
62 }
63 }
64
65 initPagination () {
66 super.initPagination()
67
68 if (this.options.pagination && this.paginationParts.includes('pageSize')) {
69 const $el = this.$pagination.find('.dropdown-toggle')
70
71 $el.attr('data-toggle', $el.next().attr('id'))
72
73 const $pane = this.$pagination.find('.dropdown-pane')
74 .attr('data-position', 'top')
75 .attr('data-alignment', 'left')
76
77 new window.Foundation.Dropdown($pane)
78
79 this._initDropdown()
80 }
81 }
82
83 _initDropdown () {
84 const $dropdowns = this.$container.find('.dropdown-toggle')
85
86 $dropdowns.off('click').on('click', e => {
87 const $this = $(e.currentTarget)
88
89 e.stopPropagation()
90
91 $this.next().foundation('toggle')
92
93 if ($dropdowns.not($this).length) {
94 $dropdowns.not($this).next().foundation('close')
95 }
96 })
97
98 $(document).off('click.bs.dropdown.foundation').on('click.bs.dropdown.foundation', () => {
99 $dropdowns.next().foundation('close')
100 })
101 }
102}