button.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ///import core
  2. ///import uicore
  3. ///import ui/stateful.js
  4. (function (){
  5. var utils = baidu.editor.utils,
  6. UIBase = baidu.editor.ui.UIBase,
  7. Stateful = baidu.editor.ui.Stateful,
  8. Button = baidu.editor.ui.Button = function (options){
  9. this.initOptions(options);
  10. this.initButton();
  11. };
  12. Button.prototype = {
  13. uiName: 'button',
  14. label: '',
  15. title: '',
  16. showIcon: true,
  17. showText: true,
  18. initButton: function (){
  19. this.initUIBase();
  20. this.Stateful_init();
  21. },
  22. getHtmlTpl: function (){
  23. return '<div id="##" class="edui-box %%">' +
  24. '<div id="##_state" stateful>' +
  25. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' + (this.title ? 'title="' + this.title + '"' : '') +
  26. ' class="%%-body" onmousedown="return false;" onclick="return $$._onClick();">' +
  27. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : '') +
  28. (this.showText ? '<div class="edui-box edui-label">' + this.label + '</div>' : '') +
  29. '</div>' +
  30. '</div>' +
  31. '</div></div>';
  32. },
  33. postRender: function (){
  34. this.Stateful_postRender();
  35. this.setDisabled(this.disabled)
  36. },
  37. _onClick: function (){
  38. if (!this.isDisabled()) {
  39. this.fireEvent('click');
  40. }
  41. }
  42. };
  43. utils.inherits(Button, UIBase);
  44. utils.extend(Button.prototype, Stateful);
  45. })();