Blame view

public/assets/libs/bootstrap-table/src/extensions/key-events/bootstrap-table-key-events.js 2.65 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  /**
   * @author: Dennis Hernández
   * @webSite: http://djhvscf.github.io/Blog
   * @version: v1.0.0
   *
   * @update zhixin wen <wenzhixin2010@gmail.com>
   */
  
  !function ($) {
  
      'use strict';
  
      $.extend($.fn.bootstrapTable.defaults, {
          keyEvents: false
      });
  
      var BootstrapTable = $.fn.bootstrapTable.Constructor,
          _init = BootstrapTable.prototype.init;
  
      BootstrapTable.prototype.init = function () {
          _init.apply(this, Array.prototype.slice.apply(arguments));
          this.initKeyEvents();
      };
  
      BootstrapTable.prototype.initKeyEvents = function () {
          if (this.options.keyEvents) {
              var that = this;
  
              $(document).off('keydown').on('keydown', function (e) {
                  var $search = that.$toolbar.find('.search input'),
                      $refresh = that.$toolbar.find('button[name="refresh"]'),
                      $toggle = that.$toolbar.find('button[name="toggle"]'),
                      $paginationSwitch = that.$toolbar.find('button[name="paginationSwitch"]');
  
                  if (document.activeElement === $search.get(0) || !$.contains(document.activeElement ,that.$toolbar.get(0))) {
                      return true;
                  }
  
                  switch (e.keyCode) {
                      case 83: //s
                          if (!that.options.search) {
                              return;
                          }
                          $search.focus();
                          return false;
                      case 82: //r
                          if (!that.options.showRefresh) {
                              return;
                          }
                          $refresh.click();
                          return false;
                      case 84: //t
                          if (!that.options.showToggle) {
                              return;
                          }
                          $toggle.click();
                          return false;
                      case 80: //p
                          if (!that.options.showPaginationSwitch) {
                              return;
                          }
                          $paginationSwitch.click();
                          return false;
                      case 37: // left
                          if (!that.options.pagination) {
                              return;
                          }
                          that.prevPage();
                          return false;
                      case 39: // right
                          if (!that.options.pagination) {
                              return;
                          }
                          that.nextPage();
                          return;
                  }
              });
          }
      };
  }(jQuery);