lineheight.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * 设置行内间距
  3. * @file
  4. * @since 1.2.6.1
  5. */
  6. UE.plugins["lineheight"] = function() {
  7. var me = this;
  8. me.setOpt({ lineheight: ["1", "1.5", "1.75", "2", "3", "4", "5"] });
  9. /**
  10. * 行距
  11. * @command lineheight
  12. * @method execCommand
  13. * @param { String } cmdName 命令字符串
  14. * @param { String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  15. * @example
  16. * ```javascript
  17. * editor.execCommand( 'lineheight', 1.5);
  18. * ```
  19. */
  20. /**
  21. * 查询当前选区内容的行高大小
  22. * @command lineheight
  23. * @method queryCommandValue
  24. * @param { String } cmd 命令字符串
  25. * @return { String } 返回当前行高大小
  26. * @example
  27. * ```javascript
  28. * editor.queryCommandValue( 'lineheight' );
  29. * ```
  30. */
  31. me.commands["lineheight"] = {
  32. execCommand: function(cmdName, value) {
  33. this.execCommand("paragraph", "p", {
  34. style: "line-height:" + (value == "1" ? "normal" : value + "em")
  35. });
  36. return true;
  37. },
  38. queryCommandValue: function() {
  39. var pN = domUtils.filterNodeList(
  40. this.selection.getStartElementPath(),
  41. function(node) {
  42. return domUtils.isBlockElm(node);
  43. }
  44. );
  45. if (pN) {
  46. var value = domUtils.getComputedStyle(pN, "line-height");
  47. return value == "normal" ? 1 : value.replace(/[^\d.]*/gi, "");
  48. }
  49. }
  50. };
  51. };