button.js 2.6 KB

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