KISSY.Editor.add("clipboard",function(r){var l=KISSY,h=l.Editor,m=l.Node,i=l.UA,s=h.Range,o=h.RANGE,p=l.Event;h.Paste||function(){function q(a){this.editor=a;this._init()}function t(a){if(!(!i.ie||a.document.compatMode=="BackCompat")){var c=a.getSelection(),d;if(c.getType()==u.SELECTION_ELEMENT&&(d=c.getSelectedElement())){var f=c.getRanges()[0],e=new m(a.document.createTextNode(""));e.insertBefore(d);f.setStartBefore(e);f.setEndAfter(d);c.selectRanges([f]);setTimeout(function(){if(d.parent()){e.remove();
c.selectElement(d)}},0)}}}l.augment(q,{_init:function(){var a=this.editor;i.ie?p.on(a.document,"keydown",this._paste,this):p.on(a.document,"paste",this._paste,this);a.addCommand("copy",new n("copy"));a.addCommand("cut",new n("cut"));a.addCommand("paste",new n("paste"))},_paste:function(a){if(!(a.type==="keydown"&&!(a.keyCode===86&&(a.ctrlKey||a.metaKey)))){var c=this,d=c.editor,f=d.document;if(c._running)a.halt();else{var e=d.getSelection();a=new s(f);var b=new m(i.webkit?"<body></body>":"<div></div>",
null,f);i.webkit&&b[0].appendChild(f.createTextNode("\u00a0"));f.body.appendChild(b[0]);b.css({position:"absolute",top:e.getStartElement().offset().top+"px",width:"1px",height:"1px",overflow:"hidden"});b.css("left","-1000px");var j=e.createBookmarks();a.setStartAt(b,o.POSITION_AFTER_START);a.setEndAt(b,o.POSITION_BEFORE_END);a.select(true);c._running=true;setTimeout(function(){b._4e_remove();var g;b=i.webkit&&(g=b._4e_first())&&g.hasClass("Apple-style-span")?g:b;e.selectBookmarks(j);g=b.html();var k=d.fire("paste",
{html:g,holder:b});if(k!==undefined)g=k;k=null;if(/(class="?Mso|style="[^"]*\bmso\-|w:WordDocument)/.test(g))k=d.htmlDataProcessor.wordFilter;d.insertHtml(g,k);c._running=false},0)}}}});h.Paste=q;var v=function(a,c){var d=a.document,f=new m(d.body),e=false,b=function(){e=true};f.on(c,b);(i.ie>7?d:d.selection.createRange()).execCommand(c);f.detach(c,b);return e},w=i.ie?function(a,c){return v(a,c)}:function(a,c){try{return a.document.execCommand(c)}catch(d){return false}},x={cut:"\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u7f16\u8f91\u5668\u81ea\u52a8\u6267\u884c\u526a\u5207\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl/Cmd+X)\u6765\u5b8c\u6210",
copy:"\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u7f16\u8f91\u5668\u81ea\u52a8\u6267\u884c\u590d\u5236\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl/Cmd+C)\u6765\u5b8c\u6210",paste:"\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u7f16\u8f91\u5668\u81ea\u52a8\u6267\u884c\u7c98\u8d34\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl/Cmd+V)\u6765\u5b8c\u6210"},n=function(a){this.type=a;this.canUndo=this.type=="cut"};n.prototype={exec:function(a){this.type=="cut"&&t(a);(a=w(a,this.type))||alert(x[this.type]);return a}};var u=h.Selection,y={copy:"\u590d\u5236",paste:"\u7c98\u8d34",cut:"\u526a\u5207"};h.on("contextmenu",function(a){var c=a.contextmenu,d=c.cfg.editor,f=c.elDom,e={copy:0,cut:0,paste:0},b;for(b in e){if(!e.hasOwnProperty(b))break;e[b]=f.one(".ke-paste-"+b);(function(j){var g=
e[j];if(!g){g=(new m("<a href='#'class='ke-paste-"+j+"'>"+y[j]+"</a>")).appendTo(f);g.on("click",function(k){k.halt();if(!g.hasClass("ke-menuitem-disable")){c.hide();setTimeout(function(){d.execCommand(j)},30)}})}e[j]=g})(b);a=e[b];(d.document.queryCommandEnabled(b)?true:false)?a.removeClass("ke-menuitem-disable"):a.addClass("ke-menuitem-disable")}})}();new h.Paste(r)},{attach:false});
