X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=plugins%2Ffind%2Fdialogs%2Ffind.js;h=2bd18af2e4e7fe714d87e45b042f6e95719def22;hp=efc20863f782fed1d1d6d6729f95e279d00ed464;hb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;hpb=055b6b0792ce7dc53d47af606b367c04b927c2ab diff --git a/plugins/find/dialogs/find.js b/plugins/find/dialogs/find.js index efc2086..2bd18af 100644 --- a/plugins/find/dialogs/find.js +++ b/plugins/find/dialogs/find.js @@ -3,7 +3,7 @@ Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ -(function(){function a(h){return h.type==CKEDITOR.NODE_TEXT&&h.getLength()>0;};function b(h){return!(h.type==CKEDITOR.NODE_ELEMENT&&h.isBlockBoundary(CKEDITOR.tools.extend({},CKEDITOR.dtd.$empty,CKEDITOR.dtd.$nonEditable)));};var c=function(){var h=this;return{textNode:h.textNode,offset:h.offset,character:h.textNode?h.textNode.getText().charAt(h.offset):null,hitMatchBoundary:h._.matchBoundary};},d=['find','replace'],e=[['txtFindFind','txtFindReplace'],['txtFindCaseChk','txtReplaceCaseChk'],['txtFindWordChk','txtReplaceWordChk'],['txtFindCyclic','txtReplaceCyclic']];function f(h){var i,j,k,l;i=h==='find'?1:0;j=1-i;var m,n=e.length;for(m=0;m0){y.offset--;return c.call(y);}else if(x&&y.offsety._.rangeLength)x.pop();return w;},moveNext:function(){var y=this;var w=y._.walker.next(),x=y._.cursors;if(w.hitMatchBoundary)y._.cursors=x=[];x.push(w);if(x.length>y._.rangeLength)x.shift();return w;},getEndCharacter:function(){var w=this._.cursors;if(w.length<1)return null;return w[w.length-1].character;},getNextCharacterRange:function(w){var x,y,z=this._.cursors;if((x=z[z.length-1])&&x.textNode)y=new k(m(x));else y=this._.walker;return new l(y,w);},getCursors:function(){return this._.cursors;}};function m(w,x){var y=new CKEDITOR.dom.range();y.setStart(w.textNode,x?w.offset:w.offset+1);y.setEndAt(h.document.getBody(),CKEDITOR.POSITION_BEFORE_END);return y;};function n(w){var x=new CKEDITOR.dom.range();x.setStartAt(h.document.getBody(),CKEDITOR.POSITION_AFTER_START);x.setEnd(w.textNode,w.offset);return x;};var o=0,p=1,q=2,r=function(w,x){var y=[-1];if(x)w=w.toLowerCase();for(var z=0;z0&&w.charAt(z)!=w.charAt(y[z+1]-1))y[z+1]=y[y[z+1]-1]+1;}this._={overlap:y,state:0,ignoreCase:!!x,pattern:w};};r.prototype={feedCharacter:function(w){var x=this;if(x._.ignoreCase)w=w.toLowerCase();for(;;){if(w==x._.pattern.charAt(x._.state)){x._.state++;if(x._.state==x._.pattern.length){x._.state=0;return q;}return p;}else if(!x._.state)return o;else x._.state=x._.overlap[x._.state];}return null;},reset:function(){this._.state=0;}};var s=/[.,"'?!;: \u0085\u00a0\u1680\u280e\u2028\u2029\u202f\u205f\u3000]/,t=function(w){if(!w)return true;var x=w.charCodeAt(0);return x>=9&&x<=13||x>=8192&&x<=8202||s.test(w);},u={searchRange:null,matchRange:null,find:function(w,x,y,z,A,B){var K=this;if(!K.matchRange)K.matchRange=new l(new k(K.searchRange),w.length);else{K.matchRange.removeHighlight();K.matchRange=K.matchRange.getNextCharacterRange(w.length);}var C=new r(w,!x),D=o,E='%';while(E!==null){K.matchRange.moveNext();while(E=K.matchRange.getEndCharacter()){D=C.feedCharacter(E);if(D==q)break;if(K.matchRange.moveNext().hitMatchBoundary)C.reset();}if(D==q){if(y){var F=K.matchRange.getCursors(),G=F[F.length-1],H=F[0],I=new k(n(H),true),J=new k(m(G),true);if(!(t(I.back().character)&&t(J.next().character)))continue; -}K.matchRange.setMatched();if(A!==false)K.matchRange.highlight();return true;}}K.matchRange.clearMatched();K.matchRange.removeHighlight();if(z&&!B){K.searchRange=v(true);K.matchRange=null;return arguments.callee.apply(K,Array.prototype.slice.call(arguments).concat([true]));}return false;},replaceCounter:0,replace:function(w,x,y,z,A,B,C){var H=this;var D=false;if(H.matchRange&&H.matchRange.isMatched()&&!H.matchRange._.isReplaced){H.matchRange.removeHighlight();var E=H.matchRange.toDomRange(),F=h.document.createText(y);if(!C){var G=h.getSelection();G.selectRanges([E]);h.fire('saveSnapshot');}E.deleteContents();E.insertNode(F);if(!C){G.selectRanges([E]);h.fire('saveSnapshot');}H.matchRange.updateFromDomRange(E);if(!C)H.matchRange.highlight();H.matchRange._.isReplaced=true;H.replaceCounter++;D=true;}else D=H.find(x,z,A,B,!C);return D;}};function v(w){var x,y=h.getSelection(),z=h.document.getBody();if(y&&!w){x=y.getRanges()[0].clone();x.collapse(true);}else{x=new CKEDITOR.dom.range();x.setStartAt(z,CKEDITOR.POSITION_AFTER_START);}x.setEndAt(z,CKEDITOR.POSITION_BEFORE_END);return x;};return{title:h.lang.findAndReplace.title,resizable:CKEDITOR.DIALOG_RESIZE_NONE,minWidth:350,minHeight:165,buttons:[CKEDITOR.dialog.cancelButton],contents:[{id:'find',label:h.lang.findAndReplace.find,title:h.lang.findAndReplace.find,accessKey:'',elements:[{type:'hbox',widths:['230px','90px'],children:[{type:'text',id:'txtFindFind',label:h.lang.findAndReplace.findWhat,isChanged:false,labelLayout:'horizontal',accessKey:'F'},{type:'button',align:'left',style:'width:100%',label:h.lang.findAndReplace.find,onClick:function(){var w=this.getDialog();if(!u.find(w.getValueOf('find','txtFindFind'),w.getValueOf('find','txtFindCaseChk'),w.getValueOf('find','txtFindWordChk'),w.getValueOf('find','txtFindCyclic')))alert(h.lang.findAndReplace.notFoundMsg);}}]},{type:'vbox',padding:0,children:[{type:'checkbox',id:'txtFindCaseChk',isChanged:false,style:'margin-top:28px',label:h.lang.findAndReplace.matchCase},{type:'checkbox',id:'txtFindWordChk',isChanged:false,label:h.lang.findAndReplace.matchWord},{type:'checkbox',id:'txtFindCyclic',isChanged:false,'default':true,label:h.lang.findAndReplace.matchCyclic}]}]},{id:'replace',label:h.lang.findAndReplace.replace,accessKey:'M',elements:[{type:'hbox',widths:['230px','90px'],children:[{type:'text',id:'txtFindReplace',label:h.lang.findAndReplace.findWhat,isChanged:false,labelLayout:'horizontal',accessKey:'F'},{type:'button',align:'left',style:'width:100%',label:h.lang.findAndReplace.replace,onClick:function(){var w=this.getDialog(); -if(!u.replace(w,w.getValueOf('replace','txtFindReplace'),w.getValueOf('replace','txtReplace'),w.getValueOf('replace','txtReplaceCaseChk'),w.getValueOf('replace','txtReplaceWordChk'),w.getValueOf('replace','txtReplaceCyclic')))alert(h.lang.findAndReplace.notFoundMsg);}}]},{type:'hbox',widths:['230px','90px'],children:[{type:'text',id:'txtReplace',label:h.lang.findAndReplace.replaceWith,isChanged:false,labelLayout:'horizontal',accessKey:'R'},{type:'button',align:'left',style:'width:100%',label:h.lang.findAndReplace.replaceAll,isChanged:false,onClick:function(){var w=this.getDialog(),x;u.replaceCounter=0;u.searchRange=v(true);if(u.matchRange){u.matchRange.removeHighlight();u.matchRange=null;}h.fire('saveSnapshot');while(u.replace(w,w.getValueOf('replace','txtFindReplace'),w.getValueOf('replace','txtReplace'),w.getValueOf('replace','txtReplaceCaseChk'),w.getValueOf('replace','txtReplaceWordChk'),false,true)){}if(u.replaceCounter){alert(h.lang.findAndReplace.replaceSuccessMsg.replace(/%1/,u.replaceCounter));h.fire('saveSnapshot');}else alert(h.lang.findAndReplace.notFoundMsg);}}]},{type:'vbox',padding:0,children:[{type:'checkbox',id:'txtReplaceCaseChk',isChanged:false,label:h.lang.findAndReplace.matchCase},{type:'checkbox',id:'txtReplaceWordChk',isChanged:false,label:h.lang.findAndReplace.matchWord},{type:'checkbox',id:'txtReplaceCyclic',isChanged:false,'default':true,label:h.lang.findAndReplace.matchCyclic}]}]}],onLoad:function(){var w=this,x,y,z=false;this.on('hide',function(){z=false;});this.on('show',function(){z=true;});this.selectPage=CKEDITOR.tools.override(this.selectPage,function(A){return function(B){A.call(w,B);var C=w._.tabs[B],D,E,F;E=B==='find'?'txtFindFind':'txtFindReplace';F=B==='find'?'txtFindWordChk':'txtReplaceWordChk';x=w.getContentElement(B,E);y=w.getContentElement(B,F);if(!C.initialized){D=CKEDITOR.document.getById(x._.inputId);C.initialized=true;}if(z)f.call(this,B);};});},onShow:function(){u.searchRange=v();this.selectPage(i);},onHide:function(){var w;if(u.matchRange&&u.matchRange.isMatched()){u.matchRange.removeHighlight();h.focus();w=u.matchRange.toDomRange();if(w)h.getSelection().selectRanges([w]);}delete u.matchRange;},onFocus:function(){if(i=='replace')return this.getContentElement('replace','txtFindReplace');else return this.getContentElement('find','txtFindFind');}};};CKEDITOR.dialog.add('find',function(h){return g(h,'find');});CKEDITOR.dialog.add('replace',function(h){return g(h,'replace');});})(); +(function(){var a;function b(i){return i.type==CKEDITOR.NODE_TEXT&&i.getLength()>0&&(!a||!i.isReadOnly());};function c(i){return!(i.type==CKEDITOR.NODE_ELEMENT&&i.isBlockBoundary(CKEDITOR.tools.extend({},CKEDITOR.dtd.$empty,CKEDITOR.dtd.$nonEditable)));};var d=function(){var i=this;return{textNode:i.textNode,offset:i.offset,character:i.textNode?i.textNode.getText().charAt(i.offset):null,hitMatchBoundary:i._.matchBoundary};},e=['find','replace'],f=[['txtFindFind','txtFindReplace'],['txtFindCaseChk','txtReplaceCaseChk'],['txtFindWordChk','txtReplaceWordChk'],['txtFindCyclic','txtReplaceCyclic']];function g(i){var j,k,l,m;j=i==='find'?1:0;k=1-j;var n,o=f.length;for(n=0;n0){z.offset--;return d.call(z);}else if(y&&z.offsetz._.rangeLength)y.pop();return x;},moveNext:function(){var z=this;var x=z._.walker.next(),y=z._.cursors;if(x.hitMatchBoundary)z._.cursors=y=[];y.push(x);if(y.length>z._.rangeLength)y.shift();return x;},getEndCharacter:function(){var x=this._.cursors;if(x.length<1)return null;return x[x.length-1].character;},getNextCharacterRange:function(x){var y,z,A=this._.cursors;if((y=A[A.length-1])&&y.textNode)z=new l(n(y));else z=this._.walker;return new m(z,x);},getCursors:function(){return this._.cursors;}};function n(x,y){var z=new CKEDITOR.dom.range();z.setStart(x.textNode,y?x.offset:x.offset+1);z.setEndAt(i.document.getBody(),CKEDITOR.POSITION_BEFORE_END);return z;};function o(x){var y=new CKEDITOR.dom.range();y.setStartAt(i.document.getBody(),CKEDITOR.POSITION_AFTER_START);y.setEnd(x.textNode,x.offset);return y;};var p=0,q=1,r=2,s=function(x,y){var z=[-1];if(y)x=x.toLowerCase();for(var A=0;A0&&x.charAt(A)!=x.charAt(z[A+1]-1))z[A+1]=z[z[A+1]-1]+1;}this._={overlap:z,state:0,ignoreCase:!!y,pattern:x};};s.prototype={feedCharacter:function(x){var y=this;if(y._.ignoreCase)x=x.toLowerCase();for(;;){if(x==y._.pattern.charAt(y._.state)){y._.state++;if(y._.state==y._.pattern.length){y._.state=0;return r;}return q;}else if(!y._.state)return p;else y._.state=y._.overlap[y._.state];}return null;},reset:function(){this._.state=0;}};var t=/[.,"'?!;: \u0085\u00a0\u1680\u280e\u2028\u2029\u202f\u205f\u3000]/,u=function(x){if(!x)return true;var y=x.charCodeAt(0);return y>=9&&y<=13||y>=8192&&y<=8202||t.test(x);},v={searchRange:null,matchRange:null,find:function(x,y,z,A,B,C){var L=this;if(!L.matchRange)L.matchRange=new m(new l(L.searchRange),x.length);else{L.matchRange.removeHighlight();L.matchRange=L.matchRange.getNextCharacterRange(x.length);}var D=new s(x,!y),E=p,F='%';while(F!==null){L.matchRange.moveNext(); +while(F=L.matchRange.getEndCharacter()){E=D.feedCharacter(F);if(E==r)break;if(L.matchRange.moveNext().hitMatchBoundary)D.reset();}if(E==r){if(z){var G=L.matchRange.getCursors(),H=G[G.length-1],I=G[0],J=new l(o(I),true),K=new l(n(H),true);if(!(u(J.back().character)&&u(K.next().character)))continue;}L.matchRange.setMatched();if(B!==false)L.matchRange.highlight();return true;}}L.matchRange.clearMatched();L.matchRange.removeHighlight();if(A&&!C){L.searchRange=w(true);L.matchRange=null;return arguments.callee.apply(L,Array.prototype.slice.call(arguments).concat([true]));}return false;},replaceCounter:0,replace:function(x,y,z,A,B,C,D){var I=this;a=1;var E=false;if(I.matchRange&&I.matchRange.isMatched()&&!I.matchRange._.isReplaced&&!I.matchRange.isReadOnly()){I.matchRange.removeHighlight();var F=I.matchRange.toDomRange(),G=i.document.createText(z);if(!D){var H=i.getSelection();H.selectRanges([F]);i.fire('saveSnapshot');}F.deleteContents();F.insertNode(G);if(!D){H.selectRanges([F]);i.fire('saveSnapshot');}I.matchRange.updateFromDomRange(F);if(!D)I.matchRange.highlight();I.matchRange._.isReplaced=true;I.replaceCounter++;E=true;}else E=I.find(y,A,B,C,!D);a=0;return E;}};function w(x){var y,z=i.getSelection(),A=i.document.getBody();if(z&&!x){y=z.getRanges()[0].clone();y.collapse(true);}else{y=new CKEDITOR.dom.range();y.setStartAt(A,CKEDITOR.POSITION_AFTER_START);}y.setEndAt(A,CKEDITOR.POSITION_BEFORE_END);return y;};return{title:i.lang.findAndReplace.title,resizable:CKEDITOR.DIALOG_RESIZE_NONE,minWidth:350,minHeight:165,buttons:[CKEDITOR.dialog.cancelButton],contents:[{id:'find',label:i.lang.findAndReplace.find,title:i.lang.findAndReplace.find,accessKey:'',elements:[{type:'hbox',widths:['230px','90px'],children:[{type:'text',id:'txtFindFind',label:i.lang.findAndReplace.findWhat,isChanged:false,labelLayout:'horizontal',accessKey:'F'},{type:'button',align:'left',style:'width:100%',label:i.lang.findAndReplace.find,onClick:function(){var x=this.getDialog();if(!v.find(x.getValueOf('find','txtFindFind'),x.getValueOf('find','txtFindCaseChk'),x.getValueOf('find','txtFindWordChk'),x.getValueOf('find','txtFindCyclic')))alert(i.lang.findAndReplace.notFoundMsg);}}]},{type:'vbox',padding:0,children:[{type:'checkbox',id:'txtFindCaseChk',isChanged:false,style:'margin-top:28px',label:i.lang.findAndReplace.matchCase},{type:'checkbox',id:'txtFindWordChk',isChanged:false,label:i.lang.findAndReplace.matchWord},{type:'checkbox',id:'txtFindCyclic',isChanged:false,'default':true,label:i.lang.findAndReplace.matchCyclic}]}]},{id:'replace',label:i.lang.findAndReplace.replace,accessKey:'M',elements:[{type:'hbox',widths:['230px','90px'],children:[{type:'text',id:'txtFindReplace',label:i.lang.findAndReplace.findWhat,isChanged:false,labelLayout:'horizontal',accessKey:'F'},{type:'button',align:'left',style:'width:100%',label:i.lang.findAndReplace.replace,onClick:function(){var x=this.getDialog(); +if(!v.replace(x,x.getValueOf('replace','txtFindReplace'),x.getValueOf('replace','txtReplace'),x.getValueOf('replace','txtReplaceCaseChk'),x.getValueOf('replace','txtReplaceWordChk'),x.getValueOf('replace','txtReplaceCyclic')))alert(i.lang.findAndReplace.notFoundMsg);}}]},{type:'hbox',widths:['230px','90px'],children:[{type:'text',id:'txtReplace',label:i.lang.findAndReplace.replaceWith,isChanged:false,labelLayout:'horizontal',accessKey:'R'},{type:'button',align:'left',style:'width:100%',label:i.lang.findAndReplace.replaceAll,isChanged:false,onClick:function(){var x=this.getDialog(),y;v.replaceCounter=0;v.searchRange=w(true);if(v.matchRange){v.matchRange.removeHighlight();v.matchRange=null;}i.fire('saveSnapshot');while(v.replace(x,x.getValueOf('replace','txtFindReplace'),x.getValueOf('replace','txtReplace'),x.getValueOf('replace','txtReplaceCaseChk'),x.getValueOf('replace','txtReplaceWordChk'),false,true)){}if(v.replaceCounter){alert(i.lang.findAndReplace.replaceSuccessMsg.replace(/%1/,v.replaceCounter));i.fire('saveSnapshot');}else alert(i.lang.findAndReplace.notFoundMsg);}}]},{type:'vbox',padding:0,children:[{type:'checkbox',id:'txtReplaceCaseChk',isChanged:false,label:i.lang.findAndReplace.matchCase},{type:'checkbox',id:'txtReplaceWordChk',isChanged:false,label:i.lang.findAndReplace.matchWord},{type:'checkbox',id:'txtReplaceCyclic',isChanged:false,'default':true,label:i.lang.findAndReplace.matchCyclic}]}]}],onLoad:function(){var x=this,y,z,A=false;this.on('hide',function(){A=false;});this.on('show',function(){A=true;});this.selectPage=CKEDITOR.tools.override(this.selectPage,function(B){return function(C){B.call(x,C);var D=x._.tabs[C],E,F,G;F=C==='find'?'txtFindFind':'txtFindReplace';G=C==='find'?'txtFindWordChk':'txtReplaceWordChk';y=x.getContentElement(C,F);z=x.getContentElement(C,G);if(!D.initialized){E=CKEDITOR.document.getById(y._.inputId);D.initialized=true;}if(A)g.call(this,C);};});},onShow:function(){v.searchRange=w();this.selectPage(j);},onHide:function(){var x;if(v.matchRange&&v.matchRange.isMatched()){v.matchRange.removeHighlight();i.focus();x=v.matchRange.toDomRange();if(x)i.getSelection().selectRanges([x]);}delete v.matchRange;},onFocus:function(){if(j=='replace')return this.getContentElement('replace','txtFindReplace');else return this.getContentElement('find','txtFindFind');}};};CKEDITOR.dialog.add('find',function(i){return h(i,'find');});CKEDITOR.dialog.add('replace',function(i){return h(i,'replace');});})();