1 | (function (global, factory) {
|
2 | if (typeof define === "function" && define.amd) {
|
3 | define([], factory);
|
4 | } else if (typeof exports !== "undefined") {
|
5 | factory();
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory();
|
11 | global.bootstrapTableKeyEvents = mod.exports;
|
12 | }
|
13 | })(this, function () {
|
14 | 'use strict';
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | !function ($) {
|
25 |
|
26 | 'use strict';
|
27 |
|
28 | $.extend($.fn.bootstrapTable.defaults, {
|
29 | keyEvents: false
|
30 | });
|
31 |
|
32 | var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
33 | _init = BootstrapTable.prototype.init;
|
34 |
|
35 | BootstrapTable.prototype.init = function () {
|
36 | _init.apply(this, Array.prototype.slice.apply(arguments));
|
37 | this.initKeyEvents();
|
38 | };
|
39 |
|
40 | BootstrapTable.prototype.initKeyEvents = function () {
|
41 | if (this.options.keyEvents) {
|
42 | var that = this;
|
43 |
|
44 | $(document).off('keydown').on('keydown', function (e) {
|
45 | var $search = that.$toolbar.find('.search input'),
|
46 | $refresh = that.$toolbar.find('button[name="refresh"]'),
|
47 | $toggle = that.$toolbar.find('button[name="toggle"]'),
|
48 | $paginationSwitch = that.$toolbar.find('button[name="paginationSwitch"]');
|
49 |
|
50 | if (document.activeElement === $search.get(0) || !$.contains(document.activeElement, that.$toolbar.get(0))) {
|
51 | return true;
|
52 | }
|
53 |
|
54 | switch (e.keyCode) {
|
55 | case 83:
|
56 |
|
57 | if (!that.options.search) {
|
58 | return;
|
59 | }
|
60 | $search.focus();
|
61 | return false;
|
62 | case 82:
|
63 |
|
64 | if (!that.options.showRefresh) {
|
65 | return;
|
66 | }
|
67 | $refresh.click();
|
68 | return false;
|
69 | case 84:
|
70 |
|
71 | if (!that.options.showToggle) {
|
72 | return;
|
73 | }
|
74 | $toggle.click();
|
75 | return false;
|
76 | case 80:
|
77 |
|
78 | if (!that.options.showPaginationSwitch) {
|
79 | return;
|
80 | }
|
81 | $paginationSwitch.click();
|
82 | return false;
|
83 | case 37:
|
84 |
|
85 | if (!that.options.pagination) {
|
86 | return;
|
87 | }
|
88 | that.prevPage();
|
89 | return false;
|
90 | case 39:
|
91 |
|
92 | if (!that.options.pagination) {
|
93 | return;
|
94 | }
|
95 | that.nextPage();
|
96 | return;
|
97 | }
|
98 | });
|
99 | }
|
100 | };
|
101 | }(jQuery);
|
102 | }); |
\ | No newline at end of file |