button.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. if (options.name) {
  10. var btnName = options.name;
  11. var cssRules = options.cssRules;
  12. if (!options.className) {
  13. options.className = "edui-for-" + btnName;
  14. }
  15. options.cssRules =
  16. ".edui-" +
  17. (options.theme || "default") +
  18. " .edui-toolbar .edui-button.edui-for-" +
  19. btnName +
  20. " .edui-icon {" +
  21. cssRules +
  22. "}";
  23. }
  24. this.initOptions(options);
  25. this.initButton();
  26. });
  27. Button.prototype = {
  28. uiName: "button",
  29. label: "",
  30. title: "",
  31. showIcon: true,
  32. showText: true,
  33. cssRules: "",
  34. initButton: function() {
  35. this.initUIBase();
  36. this.Stateful_init();
  37. if (this.cssRules) {
  38. utils.cssRule("edui-customize-" + this.name + "-style", this.cssRules);
  39. }
  40. },
  41. getHtmlTpl: function() {
  42. return (
  43. '<div id="##" class="edui-box %%">' +
  44. '<div id="##_state" stateful>' +
  45. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' +
  46. (this.title ? 'title="' + this.title + '"' : "") +
  47. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  48. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : "") +
  49. (this.showText
  50. ? '<div class="edui-box edui-label">' + this.label + "</div>"
  51. : "") +
  52. "</div>" +
  53. "</div>" +
  54. "</div></div>"
  55. );
  56. },
  57. postRender: function() {
  58. this.Stateful_postRender();
  59. this.setDisabled(this.disabled);
  60. },
  61. _onMouseDown: function(e) {
  62. var target = e.target || e.srcElement,
  63. tagName = target && target.tagName && target.tagName.toLowerCase();
  64. if (tagName == "input" || tagName == "object" || tagName == "object") {
  65. return false;
  66. }
  67. },
  68. _onClick: function() {
  69. if (!this.isDisabled()) {
  70. this.fireEvent("click");
  71. }
  72. },
  73. setTitle: function(text) {
  74. var label = this.getDom("label");
  75. label.innerHTML = text;
  76. }
  77. };
  78. utils.inherits(Button, UIBase);
  79. utils.extend(Button.prototype, Stateful);
  80. })();