Skip to content

Commit a3a0cc1

Browse files
v
1 parent 6e6f070 commit a3a0cc1

File tree

17 files changed

+297
-1116
lines changed

17 files changed

+297
-1116
lines changed

release/wangEditor.js

Lines changed: 125 additions & 526 deletions
Large diffs are not rendered by default.

release/wangEditor.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/wangEditor.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/editor/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import _config from '../config.js'
77
import Menus from '../menus/index.js'
88
import Text from '../text/index.js'
99
import Command from '../command/index.js'
10-
import API from '../select-range/index.js'
10+
import selectionAPI from '../selection/index.js'
1111

1212
// id,累加
1313
let editorId = 1
@@ -88,12 +88,12 @@ Editor.prototype = {
8888

8989
// 封装 command
9090
_initCommand: function () {
91-
this.command = new Command(this)
91+
this.cmd = new Command(this)
9292
},
9393

9494
// 封装 selection range API
95-
_initSelectionRangeAPI: function () {
96-
this.api = new API(this)
95+
_initSelectionAPI: function () {
96+
this.sAPI = new selectionAPI(this)
9797
},
9898

9999
// 创建编辑器
@@ -114,7 +114,7 @@ Editor.prototype = {
114114
this._initCommand()
115115

116116
// 封装 selection range API
117-
this._initSelectionRangeAPI()
117+
this._initSelectionAPI()
118118
}
119119
}
120120

src/js/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import polyfill from './util/poly-fill.js'
2-
import ierange from './util/ierange.js'
32
import Editor from './editor/index.js'
43

54
// polyfill
65
polyfill()
76

8-
// 兼容 IE 的 Range 和 Selection 的 API
9-
ierange()
10-
117
// 将 css 代码添加到 <style> 中
128
function createStyle(cssContent) {
139
var style

src/js/menus/bold.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Bold.prototype = {
1919

2020
// 点击事件
2121
onClick: function (e) {
22-
22+
// 点击菜单将触发这里
2323
},
2424

2525
// 试图改变 active 状态

src/js/menus/droplist/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
droplist
3+
*/
4+
5+
// 构造函数
6+
function DropList() {
7+
8+
}
9+
10+
// 原型
11+
DropList.prototype = {
12+
constructor: DropList,
13+
14+
// 显示(插入DOM)
15+
show: function () {
16+
17+
},
18+
19+
// 隐藏(移除DOM)
20+
hide: function () {
21+
22+
}
23+
}
24+
25+
export default DropList

src/js/menus/head.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
menu - header
33
*/
44
import $ from '../util/dom-core.js'
5+
import DropList from './droplist/index.js'
56

67
// 构造函数
78
function Head(editor) {
@@ -11,6 +12,9 @@ function Head(editor) {
1112

1213
// 当前是否 active 状态
1314
this.active = false
15+
16+
// 初始化 droplist
17+
this.droplist = new DropList()
1418
}
1519

1620
// 原型

src/js/menus/index.js

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@
22
菜单集合
33
*/
44
import { objForEach } from '../util/util.js'
5-
6-
// 存储菜单的构造函数
7-
const MenuConstructors = {}
8-
9-
// 引入所有的菜单,并记录
10-
import Bold from './bold.js'
11-
MenuConstructors.bold = Bold
12-
13-
import Head from './head.js'
14-
MenuConstructors.head = Head
15-
16-
import Link from './link.js'
17-
MenuConstructors.link = Link
18-
5+
import MenuConstructors from './menu-list.js'
196

207
// 构造函数
218
function Menus(editor) {
@@ -64,12 +51,57 @@ Menus.prototype = {
6451

6552
// 绑定菜单 click mouseenter 事件
6653
_bindEvent: function () {
54+
const menus = this.menus
55+
objForEach(menus, (key, menu) => {
56+
const type = menu.type
57+
if (!type) {
58+
return
59+
}
60+
const $elem = menu.$elem
61+
const droplist = menu.droplist
62+
const panel = menu.panel
63+
64+
// 点击类型,例如 bold
65+
if (type === 'click' && menu.onClick) {
66+
$elem.on('click', e => {
67+
menu.onClick(e)
68+
})
69+
}
6770

71+
// 下拉框,例如 head
72+
if (type === 'droplist' && droplist) {
73+
$elem.on('mouseenter', e => {
74+
// 显示
75+
if (droplist.hideTimeoutId) {
76+
// 清除之前的定时隐藏
77+
clearTimeout(droplist.hideTimeoutId)
78+
}
79+
droplist.show()
80+
}).on('mouseleave', e => {
81+
// 定时隐藏
82+
droplist.hideTimeoutId = setTimeout(() => {
83+
droplist.hide()
84+
}, 500)
85+
})
86+
}
87+
88+
// 弹框类型,例如 link
89+
if (type === 'panel' && panel) {
90+
$elem.on('click', e => {
91+
panel.show()
92+
})
93+
}
94+
})
6895
},
6996

7097
// 尝试修改菜单状态
7198
changeActive: function () {
72-
99+
const menus = this.menus
100+
objForEach(menus, (key, menu) => {
101+
if (menu.tryChangeActive) {
102+
menu.tryChangeActive()
103+
}
104+
})
73105
}
74106
}
75107

src/js/menus/link.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
menu - link
33
*/
44
import $ from '../util/dom-core.js'
5+
import Panel from './panel/index.js'
56

67
// 构造函数
78
function Link(editor) {
@@ -11,6 +12,9 @@ function Link(editor) {
1112

1213
// 当前是否 active 状态
1314
this.active = false
15+
16+
// 初始化 Panel
17+
this.panel = new Panel()
1418
}
1519

1620
// 原型

0 commit comments

Comments
 (0)