index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. menu - header
  3. */
  4. import $ from '../../util/dom-core.js'
  5. import DropList from '../droplist.js'
  6. // 构造函数
  7. function Questionborder(editor) {
  8. this.editor = editor
  9. this.$elem = $('<div class="lsiten-e-menu">题框</div>')
  10. this.type = 'droplist'
  11. // 当前是否 active 状态
  12. this._active = false
  13. // 初始化 droplist
  14. this.droplist = new DropList(this, {
  15. width: 100,
  16. $title: $('<p>题框</p>'),
  17. type: 'list', // droplist 以列表形式展示
  18. list: [
  19. { $elem: $('<p>客观题框</p>'), value: 'question_1' },
  20. { $elem: $('<p>主观题框</p>'), value: 'question_2' }
  21. ],
  22. onClick: (value) => {
  23. // 注意 this 是指向当前的 Head 对象
  24. this._command(value)
  25. }
  26. })
  27. }
  28. // 原型
  29. Questionborder.prototype = {
  30. constructor: Questionborder,
  31. // 执行命令
  32. _command: function (value) {
  33. console.log(value)
  34. let funName = 'lsiten_' + value;
  35. if (this[funName]) {
  36. this[funName]();
  37. }
  38. },
  39. lsiten_question_1: function () {
  40. this.editor.cmd.do('border', {type: 1, data: {
  41. row: 2,
  42. column: 3
  43. }});
  44. },
  45. lsiten_question_2: function () {
  46. this.editor.cmd.do('border', {type: 2, data: {}});
  47. }
  48. }
  49. export default Questionborder