history-menu.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. (function () {
  2. // 获取 wangEditor 构造函数和 jquery
  3. var E = window.wangEditor;
  4. var $ = window.jQuery;
  5. // 用 createMenu 方法创建菜单
  6. E.createMenu(function (check) {
  7. // 定义菜单id,不要和其他菜单id重复。编辑器自带的所有菜单id,可通过『参数配置-自定义菜单』一节查看
  8. var menuId = 'history';
  9. // check将检查菜单配置(『参数配置-自定义菜单』一节描述)中是否该菜单id,如果没有,则忽略下面的代码。
  10. if (!check(menuId)) {
  11. return;
  12. }
  13. // this 指向 editor 对象自身
  14. var editor = this;
  15. // 创建 menu 对象
  16. var menu = new E.Menu({
  17. editor: editor, // 编辑器对象
  18. id: menuId, // 菜单id
  19. title: '历史', // 菜单标题
  20. // 正常状态和选中状态下的dom对象,样式需要自定义
  21. $domNormal: $('<a href="#" tabindex="-1"><i class="fa fa-history" aria-hidden="true" name="history"></i></a>'),
  22. $domSelected: $('<a href="#" tabindex="-1" class="selected"><i class="fa fa-history" aria-hidden="true" name="history"></i></a>')
  23. });
  24. // 菜单正常状态下,点击将触发该事件
  25. menu.clickEvent = function (e) {
  26. window.documentHistory();
  27. };
  28. // 菜单选中状态下,点击将触发该事件
  29. menu.clickEventSelected = function (e) {
  30. };
  31. // 增加到editor对象中
  32. editor.menus[menuId] = menu;
  33. });
  34. })();