commandinputmenu.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @fileOverview
  3. *
  4. * 绑定到某个命令的下拉选框
  5. *
  6. */
  7. KityMinder.registerUI('widget/commandinputmenu', function(minder) {
  8. function generate(command, menuList) {
  9. var $menu = new FUI.InputMenu({
  10. menu: {
  11. items: menuList
  12. },
  13. input: {
  14. placeholder: minder.getLang('ui.' + command),
  15. },
  16. className: ['command-widget', 'command-inputmenu', command]
  17. });
  18. $menu.bindCommandState(minder, command, function(value) {
  19. if (!$menu.selectByValue(value)) {
  20. $menu.clearSelect();
  21. }
  22. });
  23. var lastIndex = -1;
  24. $menu.bindExecution('select', function(e, info) {
  25. if (~info.index) {
  26. minder.execCommand(command, info.value);
  27. } else {
  28. $menu.select(lastIndex);
  29. }
  30. lastIndex = info.index;
  31. });
  32. return $menu;
  33. }
  34. return {
  35. generate: generate
  36. };
  37. });