1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/webtrees_ynh.git synced 2024-09-03 18:26:37 +02:00
webtrees_ynh/sources/packages/ckeditor-4.5.2-custom/plugins/find/dialogs/find.js

1 line
No EOL
10 KiB
JavaScript

(function(){function g(h){return h.type==CKEDITOR.NODE_TEXT&&0<h.getLength()&&(!e||!h.isReadOnly())}function c(h){return !(h.type==CKEDITOR.NODE_ELEMENT&&h.isBlockBoundary(CKEDITOR.tools.extend({},CKEDITOR.dtd.$empty,CKEDITOR.dtd.$nonEditable)))}function f(p,k){function j(q,n){var s=this,t=new CKEDITOR.dom.walker(q);t.guard=n?c:function(w){!c(w)&&(s._.matchBoundary=!0)};t.evaluator=g;t.breakOnFalse=1;q.startContainer.type==CKEDITOR.NODE_TEXT&&(this.textNode=q.startContainer,this.offset=q.startOffset-1);this._={matchWord:n,walker:t,matchBoundary:!1}}function i(q,n){var s=p.createRange();s.setStart(q.textNode,n?q.offset:q.offset+1);s.setEndAt(p.editable(),CKEDITOR.POSITION_BEFORE_END);return s}function x(q){var n=p.getSelection(),s=p.editable();n&&!q?(q=n.getRanges()[0].clone(),q.collapse(!0)):(q=p.createRange(),q.setStartAt(s,CKEDITOR.POSITION_AFTER_START));q.setEndAt(s,CKEDITOR.POSITION_BEFORE_END);return q}var u=new CKEDITOR.style(CKEDITOR.tools.extend({attributes:{"data-cke-highlight":1},fullMatch:1,ignoreReadonly:1,childRule:function(){return 0}},p.config.find_highlight,!0));j.prototype={next:function(){return this.move()},back:function(){return this.move(!0)},move:function(q){var n=this.textNode;if(null===n){return b.call(this)}this._.matchBoundary=!1;if(n&&q&&0<this.offset){this.offset--}else{if(n&&this.offset<n.getLength()-1){this.offset++}else{for(n=null;!n&&!(n=this._.walker[q?"previous":"next"].call(this._.walker),this._.matchWord&&!n||this._.walker._.end);){}this.offset=(this.textNode=n)?q?n.getLength()-1:0:0}}return b.call(this)}};var v=function(q,n){this._={walker:q,cursors:[],rangeLength:n,highlightRange:null,isMatched:0}};v.prototype={toDomRange:function(){var q=p.createRange(),n=this._.cursors;if(1>n.length){var s=this._.walker.textNode;if(s){q.setStartAfter(s)}else{return null}}else{s=n[0],n=n[n.length-1],q.setStart(s.textNode,s.offset),q.setEnd(n.textNode,n.offset+1)}return q},updateFromDomRange:function(q){var n=new j(q);this._.cursors=[];do{q=n.next(),q.character&&this._.cursors.push(q)}while(q.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 q=this.toDomRange(),n=q.createBookmark();u.applyToRange(q,p);q.moveToBookmark(n);this._.highlightRange=q;n=q.startContainer;n.type!=CKEDITOR.NODE_ELEMENT&&(n=n.getParent());n.scrollIntoView();this.updateFromDomRange(q)}},removeHighlight:function(){if(this._.highlightRange){var n=this._.highlightRange.createBookmark();u.removeFromRange(this._.highlightRange,p);this._.highlightRange.moveToBookmark(n);this.updateFromDomRange(this._.highlightRange);this._.highlightRange=null}},isReadOnly:function(){return this._.highlightRange?this._.highlightRange.startContainer.isReadOnly():0},moveBack:function(){var q=this._.walker.back(),n=this._.cursors;q.hitMatchBoundary&&(this._.cursors=n=[]);n.unshift(q);n.length>this._.rangeLength&&n.pop();return q},moveNext:function(){var q=this._.walker.next(),n=this._.cursors;q.hitMatchBoundary&&(this._.cursors=n=[]);n.push(q);n.length>this._.rangeLength&&n.shift();return q},getEndCharacter:function(){var n=this._.cursors;return 1>n.length?null:n[n.length-1].character},getNextCharacterRange:function(q){var n,s;s=this._.cursors;s=(n=s[s.length-1])&&n.textNode?new j(i(n)):this._.walker;return new v(s,q)},getCursors:function(){return this._.cursors}};var r=function(q,n){var s=[-1];n&&(q=q.toLowerCase());for(var t=0;t<q.length;t++){for(s.push(s[t]+1);0<s[t+1]&&q.charAt(t)!=q.charAt(s[t+1]-1);){s[t+1]=s[s[t+1]-1]+1}}this._={overlap:s,state:0,ignoreCase:!!n,pattern:q}};r.prototype={feedCharacter:function(n){for(this._.ignoreCase&&(n=n.toLowerCase());;){if(n==this._.pattern.charAt(this._.state)){return this._.state++,this._.state==this._.pattern.length?(this._.state=0,2):1}if(this._.state){this._.state=this._.overlap[this._.state]}else{return 0}}return null},reset:function(){this._.state=0}};var h=/[.,"'?!;: \u0085\u00a0\u1680\u280e\u2028\u2029\u202f\u205f\u3000]/,o=function(q){if(!q){return !0}var n=q.charCodeAt(0);return 9<=n&&13>=n||8192<=n&&8202>=n||h.test(q)},m={searchRange:null,matchRange:null,find:function(F,E,C,A,B,n){this.matchRange?(this.matchRange.removeHighlight(),this.matchRange=this.matchRange.getNextCharacterRange(F.length)):this.matchRange=new v(new j(this.searchRange),F.length);for(var w=new r(F,!E),t=0,s="%";null!==s;){for(this.matchRange.moveNext();s=this.matchRange.getEndCharacter();){t=w.feedCharacter(s);if(2==t){break}this.matchRange.moveNext().hitMatchBoundary&&w.reset()}if(2==t){if(C){var y=this.matchRange.getCursors(),q=y[y.length-1],y=y[0],z=p.createRange();z.setStartAt(p.editable(),CKEDITOR.POSITION_AFTER_START);z.setEnd(y.textNode,y.offset);y=z;q=i(q);y.trim();q.trim();y=new j(y,!0);q=new j(q,!0);if(!o(y.back().character)||!o(q.next().character)){continue}}this.matchRange.setMatched();!1!==B&&this.matchRange.highlight();return !0}}this.matchRange.clearMatched();this.matchRange.removeHighlight();return A&&!n?(this.searchRange=x(1),this.matchRange=null,arguments.callee.apply(this,Array.prototype.slice.call(arguments).concat([!0]))):!1},replaceCounter:0,replace:function(s,n,A,y,z,w,t){e=1;if(this.matchRange&&this.matchRange.isMatched()&&!this.matchRange._.isReplaced&&!this.matchRange.isReadOnly()){this.matchRange.removeHighlight();n=this.matchRange.toDomRange();A=p.document.createText(A);if(!t){var q=p.getSelection();q.selectRanges([n]);p.fire("saveSnapshot")}n.deleteContents();n.insertNode(A);t||(q.selectRanges([n]),p.fire("saveSnapshot"));this.matchRange.updateFromDomRange(n);t||this.matchRange.highlight();this.matchRange._.isReplaced=!0;this.replaceCounter++;s=1}else{s=this.find(n,y,z,w,!t)}e=0;return s}},l=p.lang.find;return{title:l.title,resizable:CKEDITOR.DIALOG_RESIZE_NONE,minWidth:350,minHeight:170,buttons:[CKEDITOR.dialog.cancelButton(p,{label:p.lang.common.close})],contents:[{id:"find",label:l.find,title:l.find,accessKey:"",elements:[{type:"hbox",widths:["230px","90px"],children:[{type:"text",id:"txtFindFind",label:l.findWhat,isChanged:!1,labelLayout:"horizontal",accessKey:"F"},{type:"button",id:"btnFind",align:"left",style:"width:100%",label:l.find,onClick:function(){var n=this.getDialog();m.find(n.getValueOf("find","txtFindFind"),n.getValueOf("find","txtFindCaseChk"),n.getValueOf("find","txtFindWordChk"),n.getValueOf("find","txtFindCyclic"))||alert(l.notFoundMsg)}}]},{type:"fieldset",label:CKEDITOR.tools.htmlEncode(l.findOptions),style:"margin-top:29px",children:[{type:"vbox",padding:0,children:[{type:"checkbox",id:"txtFindCaseChk",isChanged:!1,label:l.matchCase},{type:"checkbox",id:"txtFindWordChk",isChanged:!1,label:l.matchWord},{type:"checkbox",id:"txtFindCyclic",isChanged:!1,"default":!0,label:l.matchCyclic}]}]}]},{id:"replace",label:l.replace,accessKey:"M",elements:[{type:"hbox",widths:["230px","90px"],children:[{type:"text",id:"txtFindReplace",label:l.findWhat,isChanged:!1,labelLayout:"horizontal",accessKey:"F"},{type:"button",id:"btnFindReplace",align:"left",style:"width:100%",label:l.replace,onClick:function(){var n=this.getDialog();m.replace(n,n.getValueOf("replace","txtFindReplace"),n.getValueOf("replace","txtReplace"),n.getValueOf("replace","txtReplaceCaseChk"),n.getValueOf("replace","txtReplaceWordChk"),n.getValueOf("replace","txtReplaceCyclic"))||alert(l.notFoundMsg)}}]},{type:"hbox",widths:["230px","90px"],children:[{type:"text",id:"txtReplace",label:l.replaceWith,isChanged:!1,labelLayout:"horizontal",accessKey:"R"},{type:"button",id:"btnReplaceAll",align:"left",style:"width:100%",label:l.replaceAll,isChanged:!1,onClick:function(){var n=this.getDialog();m.replaceCounter=0;m.searchRange=x(1);m.matchRange&&(m.matchRange.removeHighlight(),m.matchRange=null);for(p.fire("saveSnapshot");m.replace(n,n.getValueOf("replace","txtFindReplace"),n.getValueOf("replace","txtReplace"),n.getValueOf("replace","txtReplaceCaseChk"),n.getValueOf("replace","txtReplaceWordChk"),!1,!0);){}m.replaceCounter?(alert(l.replaceSuccessMsg.replace(/%1/,m.replaceCounter)),p.fire("saveSnapshot")):alert(l.notFoundMsg)}}]},{type:"fieldset",label:CKEDITOR.tools.htmlEncode(l.findOptions),children:[{type:"vbox",padding:0,children:[{type:"checkbox",id:"txtReplaceCaseChk",isChanged:!1,label:l.matchCase},{type:"checkbox",id:"txtReplaceWordChk",isChanged:!1,label:l.matchWord},{type:"checkbox",id:"txtReplaceCyclic",isChanged:!1,"default":!0,label:l.matchCyclic}]}]}]}],onLoad:function(){var q=this,n,s=0;this.on("hide",function(){s=0});this.on("show",function(){s=1});this.selectPage=CKEDITOR.tools.override(this.selectPage,function(t){return function(C){t.call(q,C);var B=q._.tabs[C],z;z="find"===C?"txtFindWordChk":"txtReplaceWordChk";n=q.getContentElement(C,"find"===C?"txtFindFind":"txtFindReplace");q.getContentElement(C,z);B.initialized||(CKEDITOR.document.getById(n._.inputId),B.initialized=!0);if(s){var y;C="find"===C?1:0;var B=1-C,w,A=d.length;for(w=0;w<A;w++){z=this.getContentElement(a[C],d[w][C]),y=this.getContentElement(a[B],d[w][B]),y.setValue(z.getValue())}}}})},onShow:function(){m.searchRange=x();var q=this.getParentEditor().getSelection().getSelectedText(),n=this.getContentElement(k,"find"==k?"txtFindFind":"txtFindReplace");n.setValue(q);n.select();this.selectPage(k);this[("find"==k&&this._.editor.readOnly?"hide":"show")+"Page"]("replace")},onHide:function(){var n;m.matchRange&&m.matchRange.isMatched()&&(m.matchRange.removeHighlight(),p.focus(),(n=m.matchRange.toDomRange())&&p.getSelection().selectRanges([n]));delete m.matchRange},onFocus:function(){return"replace"==k?this.getContentElement("replace","txtFindReplace"):this.getContentElement("find","txtFindFind")}}}var e,b=function(){return{textNode:this.textNode,offset:this.offset,character:this.textNode?this.textNode.getText().charAt(this.offset):null,hitMatchBoundary:this._.matchBoundary}},a=["find","replace"],d=[["txtFindFind","txtFindReplace"],["txtFindCaseChk","txtReplaceCaseChk"],["txtFindWordChk","txtReplaceWordChk"],["txtFindCyclic","txtReplaceCyclic"]];CKEDITOR.dialog.add("find",function(h){return f(h,"find")});CKEDITOR.dialog.add("replace",function(h){return f(h,"replace")})})();