corrade-nucleus-nucleons – Blame information for rev 24
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | /** |
2 | * @author Homer Glascock <HopGlascock@gmail.com> |
||
3 | * @version: v1.0.0 |
||
4 | */ |
||
5 | |||
6 | !function ($) { |
||
7 | "use strict"; |
||
8 | |||
9 | var sprintf = $.fn.bootstrapTable.utils.sprintf; |
||
10 | |||
11 | var reInit = function (self) { |
||
12 | self.initHeader(); |
||
13 | self.initSearch(); |
||
14 | self.initPagination(); |
||
15 | self.initBody(); |
||
16 | }; |
||
17 | |||
18 | $.extend($.fn.bootstrapTable.defaults, { |
||
19 | showToggleBtn: false, |
||
20 | multiToggleDefaults: [], //column names go here |
||
21 | }); |
||
22 | |||
23 | $.fn.bootstrapTable.methods.push('hideAllColumns', 'showAllColumns'); |
||
24 | |||
25 | var BootstrapTable = $.fn.bootstrapTable.Constructor, |
||
26 | _initToolbar = BootstrapTable.prototype.initToolbar; |
||
27 | |||
28 | BootstrapTable.prototype.initToolbar = function () { |
||
29 | |||
30 | _initToolbar.apply(this, Array.prototype.slice.apply(arguments)); |
||
31 | |||
32 | var that = this, |
||
33 | $btnGroup = this.$toolbar.find('>.btn-group'); |
||
34 | |||
35 | if (typeof this.options.multiToggleDefaults === 'string') { |
||
36 | this.options.multiToggleDefaults = JSON.parse(this.options.multiToggleDefaults); |
||
37 | } |
||
38 | |||
39 | if (this.options.showToggleBtn && this.options.showColumns) { |
||
40 | var showbtn = "<button class='btn btn-default hidden' id='showAllBtn'><span class='glyphicon glyphicon-resize-full icon-zoom-in'></span></button>", |
||
41 | hidebtn = "<button class='btn btn-default' id='hideAllBtn'><span class='glyphicon glyphicon-resize-small icon-zoom-out'></span></button>"; |
||
42 | |||
43 | $btnGroup.append(showbtn + hidebtn); |
||
44 | |||
45 | $btnGroup.find('#showAllBtn').click(function () { that.showAllColumns(); |
||
46 | $btnGroup.find('#hideAllBtn').toggleClass('hidden'); |
||
47 | $btnGroup.find('#showAllBtn').toggleClass('hidden'); |
||
48 | }); |
||
49 | $btnGroup.find('#hideAllBtn').click(function () { that.hideAllColumns(); |
||
50 | $btnGroup.find('#hideAllBtn').toggleClass('hidden'); |
||
51 | $btnGroup.find('#showAllBtn').toggleClass('hidden'); |
||
52 | }); |
||
53 | } |
||
54 | }; |
||
55 | |||
56 | BootstrapTable.prototype.hideAllColumns = function () { |
||
57 | var that = this, |
||
58 | defaults = that.options.multiToggleDefaults; |
||
59 | |||
60 | $.each(this.columns, function (index, column) { |
||
61 | //if its one of the defaults dont touch it |
||
62 | if (defaults.indexOf(column.field) == -1 && column.switchable) { |
||
63 | column.visible = false; |
||
64 | var $items = that.$toolbar.find('.keep-open input').prop('disabled', false); |
||
65 | $items.filter(sprintf('[value="%s"]', index)).prop('checked', false); |
||
66 | } |
||
67 | }); |
||
68 | |||
69 | reInit(that); |
||
70 | }; |
||
71 | |||
72 | BootstrapTable.prototype.showAllColumns = function () { |
||
73 | var that = this; |
||
74 | $.each(this.columns, function (index, column) { |
||
75 | if (column.switchable) { |
||
76 | column.visible = true; |
||
77 | } |
||
78 | |||
79 | var $items = that.$toolbar.find('.keep-open input').prop('disabled', false); |
||
80 | $items.filter(sprintf('[value="%s"]', index)).prop('checked', true); |
||
81 | }); |
||
82 | |||
83 | reInit(that); |
||
84 | |||
85 | that.toggleColumn(0, that.columns[0].visible, false); |
||
86 | }; |
||
87 | |||
88 | }(jQuery); |