OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
commands
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
FontCommands.ts
2.71 KB
02/20/2020 05:42:35 AM
rw-r--r--
📄
IndentOutdent.ts
3.67 KB
02/20/2020 05:42:35 AM
rw-r--r--
Editing: FontCommands.ts
Close
/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ */ import { Range, Node } from '@ephox/dom-globals'; import { Option } from '@ephox/katamari'; import Editor from '../api/Editor'; import Settings from '../api/Settings'; import FontInfo from '../fmt/FontInfo'; import CaretFinder from '../caret/CaretFinder'; import NodeType from '../dom/NodeType'; const findFirstCaretElement = (editor: Editor) => { return CaretFinder.firstPositionIn(editor.getBody()).map((caret) => { const container = caret.container(); return NodeType.isText(container) ? container.parentNode : container; }); }; const isRangeAtStartOfNode = (rng: Range, root: Node) => { return rng.startContainer === root && rng.startOffset === 0; }; const getCaretElement = (editor: Editor): Option<Node> => { return Option.from(editor.selection.getRng()).bind((rng) => { const root = editor.getBody(); return isRangeAtStartOfNode(rng, root) ? Option.none() : Option.from(editor.selection.getStart(true)); }); }; const fromFontSizeNumber = (editor: Editor, value: string): string => { if (/^[0-9\.]+$/.test(value)) { const fontSizeNumber = parseInt(value, 10); // Convert font size 1-7 to styles if (fontSizeNumber >= 1 && fontSizeNumber <= 7) { const fontSizes = Settings.getFontStyleValues(editor); const fontClasses = Settings.getFontSizeClasses(editor); if (fontClasses) { return fontClasses[fontSizeNumber - 1] || value; } else { return fontSizes[fontSizeNumber - 1] || value; } } else { return value; } } else { return value; } }; export const fontNameAction = (editor: Editor, value: string) => { editor.formatter.toggle('fontname', { value: fromFontSizeNumber(editor, value) }); editor.nodeChanged(); }; export const fontNameQuery = (editor: Editor) => { return getCaretElement(editor).fold( () => findFirstCaretElement(editor).map((caretElement) => FontInfo.getFontFamily(editor.getBody(), caretElement)).getOr(''), (caretElement) => FontInfo.getFontFamily(editor.getBody(), caretElement) ); }; export const fontSizeAction = (editor: Editor, value: string) => { editor.formatter.toggle('fontsize', { value: fromFontSizeNumber(editor, value) }); editor.nodeChanged(); }; export const fontSizeQuery = (editor: Editor) => { return getCaretElement(editor).fold( () => findFirstCaretElement(editor).map((caretElement) => FontInfo.getFontSize(editor.getBody(), caretElement)).getOr(''), (caretElement) => FontInfo.getFontSize(editor.getBody(), caretElement) ); };