fontOperator.directive.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. angular.module('kityminderEditor')
  2. .directive('fontOperator', function() {
  3. return {
  4. restrict: 'E',
  5. templateUrl: 'ui/directive/fontOperator/fontOperator.html',
  6. scope: {
  7. minder: '='
  8. },
  9. replace: true,
  10. link: function(scope) {
  11. var minder = scope.minder;
  12. var currentTheme = minder.getThemeItems();
  13. scope.fontSizeList = [10, 12, 16, 18, 24, 32, 48];
  14. scope.fontFamilyList = [{
  15. name: '宋体',
  16. val: '宋体,SimSun'
  17. }, {
  18. name: '微软雅黑',
  19. val: '微软雅黑,Microsoft YaHei'
  20. }, {
  21. name: '楷体',
  22. val: '楷体,楷体_GB2312,SimKai'
  23. }, {
  24. name: '黑体',
  25. val: '黑体, SimHei'
  26. }, {
  27. name: '隶书',
  28. val: '隶书, SimLi'
  29. }, {
  30. name: 'Andale Mono',
  31. val: 'andale mono'
  32. }, {
  33. name: 'Arial',
  34. val: 'arial,helvetica,sans-serif'
  35. }, {
  36. name: 'arialBlack',
  37. val: 'arial black,avant garde'
  38. }, {
  39. name: 'Comic Sans Ms',
  40. val: 'comic sans ms'
  41. }, {
  42. name: 'Impact',
  43. val: 'impact,chicago'
  44. }, {
  45. name: 'Times New Roman',
  46. val: 'times new roman'
  47. }, {
  48. name: 'Sans-Serif',
  49. val: 'sans-serif'
  50. }];
  51. scope.$on('colorPicked', function(event, color) {
  52. event.stopPropagation();
  53. scope.foreColor = color;
  54. minder.execCommand('forecolor', color);
  55. });
  56. scope.setDefaultColor = function() {
  57. var currentNode = minder.getSelectedNode();
  58. var fontColor = minder.getNodeStyle(currentNode, 'color');
  59. // 有可能是 kity 的颜色类
  60. return typeof fontColor === 'object' ? fontColor.toHEX() : fontColor;
  61. };
  62. scope.foreColor = scope.setDefaultColor() || '#000';
  63. scope.getFontfamilyName = function(val) {
  64. var fontName = '';
  65. scope.fontFamilyList.forEach(function(ele, idx, arr) {
  66. if (ele.val === val) {
  67. fontName = ele.name;
  68. return '';
  69. }
  70. });
  71. return fontName;
  72. }
  73. }
  74. }
  75. });