index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. menu - fontSize
  3. */
  4. import $ from '../../util/dom-core.js'
  5. import DropList from '../droplist.js'
  6. // 构造函数
  7. function FontSize(editor) {
  8. this.editor = editor
  9. this.$elem = $('<div class="lsiten-e-menu"><i class="lsiten-e-icon-text-heigh"></i></div>')
  10. this.type = 'droplist'
  11. // 当前是否 active 状态
  12. this._active = false
  13. // 初始化 droplist
  14. this.droplist = new DropList(this, {
  15. width: 160,
  16. $title: $('<p>字号</p>'),
  17. type: 'list', // droplist 以列表形式展示
  18. list: [
  19. { $elem: $('<span style="font-size: x-small;">x-small</span>'), value: '1' },
  20. { $elem: $('<span style="font-size: small;">small</span>'), value: '2' },
  21. { $elem: $('<span>normal</span>'), value: '3' },
  22. { $elem: $('<span style="font-size: large;">large</span>'), value: '4' },
  23. { $elem: $('<span style="font-size: x-large;">x-large</span>'), value: '5' },
  24. { $elem: $('<span style="font-size: xx-large;">xx-large</span>'), value: '6' }
  25. ],
  26. onClick: (value) => {
  27. // 注意 this 是指向当前的 FontSize 对象
  28. this._command(value)
  29. }
  30. })
  31. }
  32. // 原型
  33. FontSize.prototype = {
  34. constructor: FontSize,
  35. // 执行命令
  36. _command: function (value) {
  37. const editor = this.editor
  38. editor.cmd.do('fontSize', value)
  39. }
  40. }
  41. export default FontSize