mui.enterfocus.js 574 B

1234567891011121314151617181920
  1. (function($) {
  2. $.enterfocus = function(selector, callback) {
  3. var boxArray = [].slice.call(document.querySelectorAll(selector));
  4. for (var index in boxArray) {
  5. var box = boxArray[index];
  6. box.addEventListener('keyup', function(event) {
  7. if (event.keyCode == 13) {
  8. var boxIndex = boxArray.indexOf(this);
  9. if (boxIndex == boxArray.length - 1) {
  10. if (callback) callback();
  11. } else {
  12. //console.log(boxIndex);
  13. var nextBox = boxArray[++boxIndex];
  14. nextBox.focus();
  15. }
  16. }
  17. }, false);
  18. }
  19. };
  20. }(window.mui = window.mui || {}));