UNPKG

1.8 kBJavaScriptView Raw
1import xhtml from '../xhtml';
2
3// 初始化结点
4
5export function initDom() {
6
7 xhtml.css(this._el, {
8 "font-size": "12px",
9 position: "relative",
10 cursor: "text",
11 "font-family": this._fontFamily,
12 "background": this._colorBackground,
13 overflow: "auto"
14 });
15
16 xhtml.bind(this._el, 'click', () => {
17 this.__focusDOM.focus();
18 })
19
20 // 辅助标签
21 this.__helpDOM = xhtml.appendTo(this._el, "<span></span>");
22
23 xhtml.css(this.__helpDOM, {
24 position: "absolute",
25 "z-index": "-1",
26 "white-space": "pre",
27 "top": 0,
28 "left": 0,
29 "font-weight": this._fontWeight
30 });
31
32 // 光标
33 this.__focusDOM = xhtml.appendTo(this._el, "<textarea></textarea>");
34
35 xhtml.css(this.__focusDOM, {
36 position: "absolute",
37 width: "6px",
38 "margin-top": "3px",
39 height: "15px",
40 "line-height": "15px",
41 resize: "none",
42 overflow: "hidden",
43 padding: "0",
44 outline: "none",
45 border: "none",
46 background: "rgba(0,0,0,0)",
47 color: this._colorCursor
48 });
49
50 xhtml.attr(this.__focusDOM, {
51 wrap: "off",
52 autocorrect: "off",
53 autocapitalize: "off",
54 spellcheck: "false"
55 });
56
57 // 显示区域
58 this.__showDOM = xhtml.appendTo(this._el, "<div></div>");
59
60 xhtml.css(this.__showDOM, {
61 padding: "10px 0"
62 });
63};
64
65// 初始化视图
66
67export function initView() {
68
69 // 初始化定位光标位置
70 xhtml.css(this.__focusDOM, {
71 left: (40 + this.$$textWidth(this._contentArray[this.__lineNum])) + "px",
72 top: (10 + this.__lineNum * 21) + "px"
73 });
74 this.__focusDOM.focus();
75
76};
\No newline at end of file