Browse Source

More key events

Dennis Hernández 10 years ago
parent
commit
ad78bc5205
1 changed files with 44 additions and 5 deletions
  1. 44 5
      src/bootstrap-table.js

+ 44 - 5
src/bootstrap-table.js

@@ -1682,19 +1682,58 @@
       if (this.options.keyEvents) {
       if (this.options.keyEvents) {
           var that = this;
           var that = this;
           $(document).off('keypress').on('keypress', function (e) {
           $(document).off('keypress').on('keypress', function (e) {
-              if (!that.options.search) {
-                  return;
-              }
-
+              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"]');
               switch (e.keyCode) {
               switch (e.keyCode) {
                   case 115://s
                   case 115://s
                   case 83://S
                   case 83://S
-                      var $search = that.$toolbar.find('.search input');
+                      if (!that.options.search) {
+                          return;
+                      }
+
                       if(document.activeElement === $search.get(0)){
                       if(document.activeElement === $search.get(0)){
                           return true;
                           return true;
                       }
                       }
                       $search.focus();
                       $search.focus();
                       return false;
                       return false;
+                  case 114: //r
+                  case 82: //R
+                      if (!that.options.showRefresh) {
+                          return;
+                      }
+
+                      if(document.activeElement === $search.get(0)){
+                          return true;
+                      }
+                      $refresh.click();
+                      return false;
+                  case 116: //t
+                  case 84: //T
+                      if (!that.options.showToggle) {
+                          return;
+                      }
+
+                      if(document.activeElement === $search.get(0)){
+                          return true;
+                      }
+
+                      $toggle.click();
+                      return false;
+                  case 112: //p
+                  case 80: //p
+                      if (!that.options.showPaginationSwitch) {
+                          return;
+                      }
+
+                      if(document.activeElement === $search.get(0)){
+                          return true;
+                      }
+
+                      $paginationSwitch.click();
+                      return false;
+
               }
               }
           });
           });
       }
       }