rowspacing.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * 段前段后间距插件
  3. * @file
  4. * @since 1.2.6.1
  5. */
  6. /**
  7. * 设置段间距
  8. * @command rowspacing
  9. * @method execCommand
  10. * @param { String } cmd 命令字符串
  11. * @param { String } value 段间距的值,以px为单位
  12. * @param { String } dir 间距位置,top或bottom,分别表示段前和段后
  13. * @example
  14. * ```javascript
  15. * editor.execCommand( 'rowspacing', '10', 'top' );
  16. * ```
  17. */
  18. UE.plugins["rowspacing"] = function() {
  19. var me = this;
  20. me.setOpt({
  21. rowspacingtop: ["5", "10", "15", "20", "25"],
  22. rowspacingbottom: ["5", "10", "15", "20", "25"]
  23. });
  24. me.commands["rowspacing"] = {
  25. execCommand: function(cmdName, value, dir) {
  26. this.execCommand("paragraph", "p", {
  27. style: "margin-" + dir + ":" + value + "px"
  28. });
  29. return true;
  30. },
  31. queryCommandValue: function(cmdName, dir) {
  32. var pN = domUtils.filterNodeList(
  33. this.selection.getStartElementPath(),
  34. function(node) {
  35. return domUtils.isBlockElm(node);
  36. }
  37. ),
  38. value;
  39. //trace:1026
  40. if (pN) {
  41. value = domUtils
  42. .getComputedStyle(pN, "margin-" + dir)
  43. .replace(/[^\d]/g, "");
  44. return !value ? 0 : value;
  45. }
  46. return 0;
  47. }
  48. };
  49. };