template.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ///import core
  2. ///import plugins\inserthtml.js
  3. ///import plugins\cleardoc.js
  4. ///commands 模板
  5. ///commandsName template
  6. ///commandsTitle 模板
  7. ///commandsDialog dialogs\template
  8. UE.plugins['template'] = function () {
  9. UE.commands['template'] = {
  10. execCommand:function (cmd, obj) {
  11. obj.html && this.execCommand("inserthtml", obj.html);
  12. }
  13. };
  14. this.addListener("click", function (type, evt) {
  15. var el = evt.target || evt.srcElement,
  16. range = this.selection.getRange();
  17. var tnode = domUtils.findParent(el, function (node) {
  18. if (node.className && domUtils.hasClass(node, "ue_t")) {
  19. return node;
  20. }
  21. }, true);
  22. tnode && range.selectNode(tnode).shrinkBoundary().select();
  23. });
  24. this.addListener("keydown", function (type, evt) {
  25. var range = this.selection.getRange();
  26. if (!range.collapsed) {
  27. if (!evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  28. var tnode = domUtils.findParent(range.startContainer, function (node) {
  29. if (node.className && domUtils.hasClass(node, "ue_t")) {
  30. return node;
  31. }
  32. }, true);
  33. if (tnode) {
  34. domUtils.removeClasses(tnode, ["ue_t"]);
  35. }
  36. }
  37. }
  38. });
  39. };