Toolbar.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. define([
  2. 'summernote/core/list',
  3. 'summernote/core/dom',
  4. 'summernote/module/Button'
  5. ], function (list, dom, Button) {
  6. /**
  7. * @class module.Toolbar
  8. *
  9. * Toolbar
  10. */
  11. var Toolbar = function () {
  12. var button = new Button();
  13. this.update = function ($toolbar, styleInfo) {
  14. button.update($toolbar, styleInfo);
  15. };
  16. /**
  17. * @param {Node} button
  18. * @param {String} eventName
  19. * @param {String} value
  20. */
  21. this.updateRecentColor = function (buttonNode, eventName, value) {
  22. button.updateRecentColor(buttonNode, eventName, value);
  23. };
  24. /**
  25. * activate buttons exclude codeview
  26. * @param {jQuery} $toolbar
  27. */
  28. this.activate = function ($toolbar) {
  29. $toolbar.find('button')
  30. .not('button[data-event="codeview"]')
  31. .removeClass('disabled');
  32. };
  33. /**
  34. * deactivate buttons exclude codeview
  35. * @param {jQuery} $toolbar
  36. */
  37. this.deactivate = function ($toolbar) {
  38. $toolbar.find('button')
  39. .not('button[data-event="codeview"]')
  40. .addClass('disabled');
  41. };
  42. /**
  43. * @param {jQuery} $container
  44. * @param {Boolean} [bFullscreen=false]
  45. */
  46. this.updateFullscreen = function ($container, bFullscreen) {
  47. var $btn = $container.find('button[data-event="fullscreen"]');
  48. $btn.toggleClass('active', bFullscreen);
  49. };
  50. /**
  51. * @param {jQuery} $container
  52. * @param {Boolean} [isCodeview=false]
  53. */
  54. this.updateCodeview = function ($container, isCodeview) {
  55. var $btn = $container.find('button[data-event="codeview"]');
  56. $btn.toggleClass('active', isCodeview);
  57. if (isCodeview) {
  58. this.deactivate($container);
  59. } else {
  60. this.activate($container);
  61. }
  62. };
  63. /**
  64. * get button in toolbar
  65. *
  66. * @param {jQuery} $editable
  67. * @param {String} name
  68. * @return {jQuery}
  69. */
  70. this.get = function ($editable, name) {
  71. var $toolbar = dom.makeLayoutInfo($editable).toolbar();
  72. return $toolbar.find('[data-name=' + name + ']');
  73. };
  74. /**
  75. * set button state
  76. * @param {jQuery} $editable
  77. * @param {String} name
  78. * @param {Boolean} [isActive=true]
  79. */
  80. this.setButtonState = function ($editable, name, isActive) {
  81. isActive = (isActive === false) ? false : true;
  82. var $button = this.get($editable, name);
  83. $button.toggleClass('active', isActive);
  84. };
  85. };
  86. return Toolbar;
  87. });