X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=plugins%2Ffind%2Fdialogs%2Ffind.js;h=0d64b3c1dbd02e531ef178e93d86cacc8d97eff8;hb=26ea9b471a69b563dfa9fb7c9c8d97db8e56de0e;hp=2bd18af2e4e7fe714d87e45b042f6e95719def22;hpb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;p=ckeditor.git diff --git a/plugins/find/dialogs/find.js b/plugins/find/dialogs/find.js index 2bd18af..0d64b3c 100644 --- a/plugins/find/dialogs/find.js +++ b/plugins/find/dialogs/find.js @@ -1,9 +1,24 @@ -/* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. -For licensing, see LICENSE.html or http://ckeditor.com/license -*/ - -(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');});})(); +/* + Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. + For licensing, see LICENSE.md or http://ckeditor.com/license +*/ +(function(){function y(c){return c.type==CKEDITOR.NODE_TEXT&&0b.length){var d=this._.walker.textNode;if(d)a.setStartAfter(d);else return null}else d=b[0],b=b[b.length-1],a.setStart(d.textNode,d.offset),a.setEnd(b.textNode,b.offset+1);return a},updateFromDomRange:function(a){var b=new l(a);this._.cursors=[];do a=b.next(),a.character&&this._.cursors.push(a);while(a.character);this._.rangeLength=this._.cursors.length},setMatched:function(){this._.isMatched=!0},clearMatched:function(){this._.isMatched=!1},isMatched:function(){return this._.isMatched},highlight:function(){if(!(1> +this._.cursors.length)){this._.highlightRange&&this.removeHighlight();var a=this.toDomRange(),b=a.createBookmark();v.applyToRange(a);a.moveToBookmark(b);this._.highlightRange=a;b=a.startContainer;b.type!=CKEDITOR.NODE_ELEMENT&&(b=b.getParent());b.scrollIntoView();this.updateFromDomRange(a)}},removeHighlight:function(){if(this._.highlightRange){var a=this._.highlightRange.createBookmark();v.removeFromRange(this._.highlightRange);this._.highlightRange.moveToBookmark(a);this.updateFromDomRange(this._.highlightRange); +this._.highlightRange=null}},isReadOnly:function(){return!this._.highlightRange?0:this._.highlightRange.startContainer.isReadOnly()},moveBack:function(){var a=this._.walker.back(),b=this._.cursors;a.hitMatchBoundary&&(this._.cursors=b=[]);b.unshift(a);b.length>this._.rangeLength&&b.pop();return a},moveNext:function(){var a=this._.walker.next(),b=this._.cursors;a.hitMatchBoundary&&(this._.cursors=b=[]);b.push(a);b.length>this._.rangeLength&&b.shift();return a},getEndCharacter:function(){var a=this._.cursors; +return 1>a.length?null:a[a.length-1].character},getNextCharacterRange:function(a){var b,d;d=this._.cursors;d=(b=d[d.length-1])&&b.textNode?new l(n(b)):this._.walker;return new r(d,a)},getCursors:function(){return this._.cursors}};var w=function(a,b){var d=[-1];b&&(a=a.toLowerCase());for(var c=0;c=b||8192<=b&&8202>=b||z.test(a)},e={searchRange:null,matchRange:null,find:function(a,b,d,f,e,A){this.matchRange? +(this.matchRange.removeHighlight(),this.matchRange=this.matchRange.getNextCharacterRange(a.length)):this.matchRange=new r(new l(this.searchRange),a.length);for(var i=new w(a,!b),j=0,k="%";null!==k;){for(this.matchRange.moveNext();k=this.matchRange.getEndCharacter();){j=i.feedCharacter(k);if(2==j)break;this.matchRange.moveNext().hitMatchBoundary&&i.reset()}if(2==j){if(d){var h=this.matchRange.getCursors(),m=h[h.length-1],h=h[0],g=c.createRange();g.setStartAt(c.editable(),CKEDITOR.POSITION_AFTER_START); +g.setEnd(h.textNode,h.offset);h=g;m=n(m);h.trim();m.trim();h=new l(h,!0);m=new l(m,!0);if(!x(h.back().character)||!x(m.next().character))continue}this.matchRange.setMatched();!1!==e&&this.matchRange.highlight();return!0}}this.matchRange.clearMatched();this.matchRange.removeHighlight();return f&&!A?(this.searchRange=q(1),this.matchRange=null,arguments.callee.apply(this,Array.prototype.slice.call(arguments).concat([!0]))):!1},replaceCounter:0,replace:function(a,b,d,f,e,g,i){o=1;a=0;if(this.matchRange&& +this.matchRange.isMatched()&&!this.matchRange._.isReplaced&&!this.matchRange.isReadOnly()){this.matchRange.removeHighlight();b=this.matchRange.toDomRange();d=c.document.createText(d);if(!i){var j=c.getSelection();j.selectRanges([b]);c.fire("saveSnapshot")}b.deleteContents();b.insertNode(d);i||(j.selectRanges([b]),c.fire("saveSnapshot"));this.matchRange.updateFromDomRange(b);i||this.matchRange.highlight();this.matchRange._.isReplaced=!0;this.replaceCounter++;a=1}else a=this.find(b,f,e,g,!i);o=0;return a}}, +f=c.lang.find;return{title:f.title,resizable:CKEDITOR.DIALOG_RESIZE_NONE,minWidth:350,minHeight:170,buttons:[CKEDITOR.dialog.cancelButton(c,{label:c.lang.common.close})],contents:[{id:"find",label:f.find,title:f.find,accessKey:"",elements:[{type:"hbox",widths:["230px","90px"],children:[{type:"text",id:"txtFindFind",label:f.findWhat,isChanged:!1,labelLayout:"horizontal",accessKey:"F"},{type:"button",id:"btnFind",align:"left",style:"width:100%",label:f.find,onClick:function(){var a=this.getDialog(); +e.find(a.getValueOf("find","txtFindFind"),a.getValueOf("find","txtFindCaseChk"),a.getValueOf("find","txtFindWordChk"),a.getValueOf("find","txtFindCyclic"))||alert(f.notFoundMsg)}}]},{type:"fieldset",label:CKEDITOR.tools.htmlEncode(f.findOptions),style:"margin-top:29px",children:[{type:"vbox",padding:0,children:[{type:"checkbox",id:"txtFindCaseChk",isChanged:!1,label:f.matchCase},{type:"checkbox",id:"txtFindWordChk",isChanged:!1,label:f.matchWord},{type:"checkbox",id:"txtFindCyclic",isChanged:!1,"default":!0, +label:f.matchCyclic}]}]}]},{id:"replace",label:f.replace,accessKey:"M",elements:[{type:"hbox",widths:["230px","90px"],children:[{type:"text",id:"txtFindReplace",label:f.findWhat,isChanged:!1,labelLayout:"horizontal",accessKey:"F"},{type:"button",id:"btnFindReplace",align:"left",style:"width:100%",label:f.replace,onClick:function(){var a=this.getDialog();e.replace(a,a.getValueOf("replace","txtFindReplace"),a.getValueOf("replace","txtReplace"),a.getValueOf("replace","txtReplaceCaseChk"),a.getValueOf("replace", +"txtReplaceWordChk"),a.getValueOf("replace","txtReplaceCyclic"))||alert(f.notFoundMsg)}}]},{type:"hbox",widths:["230px","90px"],children:[{type:"text",id:"txtReplace",label:f.replaceWith,isChanged:!1,labelLayout:"horizontal",accessKey:"R"},{type:"button",id:"btnReplaceAll",align:"left",style:"width:100%",label:f.replaceAll,isChanged:!1,onClick:function(){var a=this.getDialog();e.replaceCounter=0;e.searchRange=q(1);e.matchRange&&(e.matchRange.removeHighlight(),e.matchRange=null);for(c.fire("saveSnapshot");e.replace(a, +a.getValueOf("replace","txtFindReplace"),a.getValueOf("replace","txtReplace"),a.getValueOf("replace","txtReplaceCaseChk"),a.getValueOf("replace","txtReplaceWordChk"),!1,!0););e.replaceCounter?(alert(f.replaceSuccessMsg.replace(/%1/,e.replaceCounter)),c.fire("saveSnapshot")):alert(f.notFoundMsg)}}]},{type:"fieldset",label:CKEDITOR.tools.htmlEncode(f.findOptions),children:[{type:"vbox",padding:0,children:[{type:"checkbox",id:"txtReplaceCaseChk",isChanged:!1,label:f.matchCase},{type:"checkbox",id:"txtReplaceWordChk", +isChanged:!1,label:f.matchWord},{type:"checkbox",id:"txtReplaceCyclic",isChanged:!1,"default":!0,label:f.matchCyclic}]}]}]}],onLoad:function(){var a=this,b,c=0;this.on("hide",function(){c=0});this.on("show",function(){c=1});this.selectPage=CKEDITOR.tools.override(this.selectPage,function(f){return function(e){f.call(a,e);var g=a._.tabs[e],i;i="find"===e?"txtFindWordChk":"txtReplaceWordChk";b=a.getContentElement(e,"find"===e?"txtFindFind":"txtFindReplace");a.getContentElement(e,i);g.initialized||(CKEDITOR.document.getById(b._.inputId), +g.initialized=!0);if(c){var j,e="find"===e?1:0,g=1-e,k,h=p.length;for(k=0;k