lineheight.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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',{style:'line-height:'+ (value == "1" ? "normal" : value + 'em') });
  34. return true;
  35. },
  36. queryCommandValue : function() {
  37. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node)});
  38. if(pN){
  39. var value = domUtils.getComputedStyle(pN,'line-height');
  40. return value == 'normal' ? 1 : value.replace(/[^\d.]*/ig,"");
  41. }
  42. }
  43. };
  44. };