fuix.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @fileOverview
  3. *
  4. * 拓展 FUI 组件的功能
  5. *
  6. * @author: techird
  7. * @copyright: Baidu FEX, 2014
  8. */
  9. kity.extendClass(FUI.Widget, {
  10. setEnable: function(value) {
  11. if (value === false) this.disable();
  12. else this.enable();
  13. },
  14. setActive: function(value) {
  15. if (value === false) this.removeClass('active');
  16. else this.addClass('active');
  17. },
  18. bindExecution: function(event, fn) {
  19. var widget = this;
  20. widget.on(event, function() {
  21. if (widget.interactFlag) return;
  22. fn.apply(widget, arguments);
  23. });
  24. },
  25. bindCommandState: function(minder, command, valueHandle) {
  26. var widget = this;
  27. minder.on('interactchange', function() {
  28. widget.interactFlag = true;
  29. if (valueHandle) {
  30. var value = this.queryCommandValue(command);
  31. if (value != widget.lastHandleCommandValue) {
  32. valueHandle.call(widget, value);
  33. widget.lastHandleCommandValue = value;
  34. }
  35. }
  36. widget.setEnable(this.queryCommandState(command) !== -1);
  37. widget.setActive(this.queryCommandState(command) === 1);
  38. widget.interactFlag = false;
  39. });
  40. }
  41. });