X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=plugins%2Fselection%2Fplugin.js;h=3199f98612aedebdfca255feacbb4c22029683d4;hp=19b3aab6d6190496b350ccfe16ee005a6668eb7a;hb=8761695d9b70afe75905deaac88f78c1f8aeb32d;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91 diff --git a/plugins/selection/plugin.js b/plugins/selection/plugin.js index 19b3aab..3199f98 100644 --- a/plugins/selection/plugin.js +++ b/plugins/selection/plugin.js @@ -5,5 +5,5 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function(){function a(){var k=this;try{var h=k.getSelection();if(!h)return;var i=h.getStartElement(),j=new CKEDITOR.dom.elementPath(i);if(!j.compare(k._.selectionPreviousPath)){k._.selectionPreviousPath=j;k.fire('selectionChange',{selection:h,path:j,element:i});}}catch(l){}};var b,c;function d(){c=true;if(b)return;e.call(this);b=CKEDITOR.tools.setTimeout(e,200,this);};function e(){b=null;if(c){CKEDITOR.tools.setTimeout(a,0,this);c=false;}};var f={exec:function(h){switch(h.mode){case 'wysiwyg':h.document.$.execCommand('SelectAll',false,null);break;case 'source':}},canUndo:false};CKEDITOR.plugins.add('selection',{init:function(h){h.on('contentDom',function(){var i=h.document;if(CKEDITOR.env.ie){var j,k;i.on('focusin',function(){if(j){try{j.select();}catch(n){}j=null;}});h.window.on('focus',function(){k=true;m();});h.document.on('beforedeactivate',function(){k=false;h.document.$.execCommand('Unselect');});i.on('mousedown',l);i.on('mouseup',function(){k=true;setTimeout(function(){m(true);},0);});i.on('keydown',l);i.on('keyup',function(){k=true;m();});i.on('selectionchange',m);function l(){k=false;};function m(n){if(k){var o=h.document,p=o&&o.$.selection;if(n&&p&&p.type=='None')if(!o.$.queryCommandEnabled('InsertImage')){CKEDITOR.tools.setTimeout(m,50,this,true);return;}j=p&&p.createRange();d.call(h);}};}else{i.on('mouseup',d,h);i.on('keyup',d,h);}});h.addCommand('selectAll',f);h.ui.addButton('SelectAll',{label:h.lang.selectAll,command:'selectAll'});h.selectionChange=d;}});CKEDITOR.editor.prototype.getSelection=function(){return this.document&&this.document.getSelection();};CKEDITOR.editor.prototype.forceNextSelectionCheck=function(){delete this._.selectionPreviousPath;};CKEDITOR.dom.document.prototype.getSelection=function(){var h=new CKEDITOR.dom.selection(this);return!h||h.isInvalid?null:h;};CKEDITOR.SELECTION_NONE=1;CKEDITOR.SELECTION_TEXT=2;CKEDITOR.SELECTION_ELEMENT=3;CKEDITOR.dom.selection=function(h){var k=this;var i=h.getCustomData('cke_locked_selection');if(i)return i;k.document=h;k.isLocked=false;k._={cache:{}};if(CKEDITOR.env.ie){var j=k.getNative().createRange();if(!j||j.item&&j.item(0).ownerDocument!=k.document.$||j.parentElement&&j.parentElement().ownerDocument!=k.document.$)k.isInvalid=true;}return k;};var g={img:1,hr:1,li:1,table:1,tr:1,td:1,embed:1,object:1,ol:1,ul:1,a:1,input:1,form:1,select:1,textarea:1,button:1,fieldset:1,th:1,thead:1,tfoot:1};CKEDITOR.dom.selection.prototype={getNative:CKEDITOR.env.ie?function(){return this._.cache.nativeSel||(this._.cache.nativeSel=this.document.$.selection); }:function(){return this._.cache.nativeSel||(this._.cache.nativeSel=this.document.getWindow().$.getSelection());},getType:CKEDITOR.env.ie?function(){var h=this._.cache;if(h.type)return h.type;var i=CKEDITOR.SELECTION_NONE;try{var j=this.getNative(),k=j.type;if(k=='Text')i=CKEDITOR.SELECTION_TEXT;if(k=='Control')i=CKEDITOR.SELECTION_ELEMENT;if(j.createRange().parentElement)i=CKEDITOR.SELECTION_TEXT;}catch(l){}return h.type=i;}:function(){var h=this._.cache;if(h.type)return h.type;var i=CKEDITOR.SELECTION_TEXT,j=this.getNative();if(!j)i=CKEDITOR.SELECTION_NONE;else if(j.rangeCount==1){var k=j.getRangeAt(0),l=k.startContainer;if(l==k.endContainer&&l.nodeType==1&&k.endOffset-k.startOffset==1&&g[l.childNodes[k.startOffset].nodeName.toLowerCase()])i=CKEDITOR.SELECTION_ELEMENT;}return h.type=i;},getRanges:CKEDITOR.env.ie?(function(){var h=function(i,j){i=i.duplicate();i.collapse(j);var k=i.parentElement(),l=k.childNodes,m;for(var n=0;n0)break;else if(p===0)return{container:k,offset:n};m=null;}}if(!m){m=i.duplicate();m.moveToElementText(k);m.collapse(false);}m.setEndPoint('StartToStart',i);var q=m.text.replace(/(\r\n|\r)/g,'\n').length;while(q>0)q-=l[--n].nodeValue.length;if(q===0)return{container:k,offset:n};else return{container:l[n],offset:-q};};return function(){var t=this;var i=t._.cache;if(i.ranges)return i.ranges;var j=t.getNative(),k=j&&j.createRange(),l=t.getType(),m;if(!j)return[];if(l==CKEDITOR.SELECTION_TEXT){m=new CKEDITOR.dom.range(t.document);var n=h(k,true);m.setStart(new CKEDITOR.dom.node(n.container),n.offset);n=h(k);m.setEnd(new CKEDITOR.dom.node(n.container),n.offset);return i.ranges=[m];}else if(l==CKEDITOR.SELECTION_ELEMENT){var o=t._.cache.ranges=[];for(var p=0;p=0){d.collapse(true);b.setEnd(d.endContainer.$,d.endOffset);}else throw e;}var c=d.document.getSelection().getNative();c.removeAllRanges();c.addRange(b);};