egroupware_official/api/js/tinymce/plugins/searchreplace/plugin.min.js

1 line
8.3 KiB
JavaScript

!function(){"use strict";var r=function(e){var t=e,n=function(){return t};return{get:n,set:function(e){t=e},clone:function(){return r(n())}}},e=tinymce.util.Tools.resolve("tinymce.PluginManager"),p=tinymce.util.Tools.resolve("tinymce.util.Tools");function m(e){return e&&1===e.nodeType&&"false"===e.contentEditable}var t,n,a,o,i,s={findAndReplaceDOMText:function D(e,t,n,r,a){var o,i,x,f,p,h,d=[],c=0;function l(e,t){if(t=t||0,!e[0])throw new Error("findAndReplaceDOMText cannot handle zero-length matches");var n=e.index;if(0<t){var r=e[t];if(!r)throw new Error("Invalid capture group");n+=e[0].indexOf(r),e[0]=r}return[n,n+e[0].length,[e[0]]]}if(x=t.ownerDocument,f=a.getBlockElements(),p=a.getWhiteSpaceElements(),h=a.getShortEndedElements(),i=function u(e){var t;if(3===e.nodeType)return e.data;if(p[e.nodeName]&&!f[e.nodeName])return"";if(t="",m(e))return"\n";if((f[e.nodeName]||h[e.nodeName])&&(t+="\n"),e=e.firstChild)for(;t+=u(e),e=e.nextSibling;);return t}(t)){if(e.global)for(;o=e.exec(i);)d.push(l(o,r));else o=i.match(e),d.push(l(o,r));return d.length&&(c=d.length,function g(e,t,n){var r,a,o,i,d=[],c=0,l=e,u=t.shift(),s=0;e:for(;;){if((f[l.nodeName]||h[l.nodeName]||m(l))&&c++,3===l.nodeType&&(!a&&l.length+c>=u[1]?(a=l,i=u[1]-c):r&&d.push(l),!r&&l.length+c>u[0]&&(r=l,o=u[0]-c),c+=l.length),r&&a){if(l=n({startNode:r,startNodeIndex:o,endNode:a,endNodeIndex:i,innerNodes:d,match:u[2],matchIndex:s}),c-=a.length-i,a=r=null,d=[],s++,!(u=t.shift()))break}else if(p[l.nodeName]&&!f[l.nodeName]||!l.firstChild){if(l.nextSibling){l=l.nextSibling;continue}}else if(!m(l)){l=l.firstChild;continue}for(;;){if(l.nextSibling){l=l.nextSibling;break}if(l.parentNode===e)break e;l=l.parentNode}}}(t,d,function s(e){var m;if("function"!=typeof e){var r=e.nodeType?e:x.createElement(e);m=function(e,t){var n=r.cloneNode(!1);return n.setAttribute("data-mce-index",t),e&&n.appendChild(x.createTextNode(e)),n}}else m=e;return function(e){var t,n,r,a=e.startNode,o=e.endNode,i=e.matchIndex;if(a===o){var d=a;r=d.parentNode,0<e.startNodeIndex&&(t=x.createTextNode(d.data.substring(0,e.startNodeIndex)),r.insertBefore(t,d));var c=m(e.match[0],i);return r.insertBefore(c,d),e.endNodeIndex<d.length&&(n=x.createTextNode(d.data.substring(e.endNodeIndex)),r.insertBefore(n,d)),d.parentNode.removeChild(d),c}t=x.createTextNode(a.data.substring(0,e.startNodeIndex)),n=x.createTextNode(o.data.substring(e.endNodeIndex));for(var l=m(a.data.substring(e.startNodeIndex),i),u=[],s=0,f=e.innerNodes.length;s<f;++s){var p=e.innerNodes[s],h=m(p.data,i);p.parentNode.replaceChild(h,p),u.push(h)}var g=m(o.data.substring(0,e.endNodeIndex),i);return(r=a.parentNode).insertBefore(t,a),r.insertBefore(l,a),r.removeChild(a),(r=o.parentNode).insertBefore(g,o),r.insertBefore(n,o),r.removeChild(o),g}}(n))),c}}},h=function(e){var t=e.getAttribute("data-mce-index");return"number"==typeof t?""+t:t},g=function(e){var t=e.parentNode;e.firstChild&&t.insertBefore(e.firstChild,e),e.parentNode.removeChild(e)},d=function(e,t){var n,r=[];if((n=p.toArray(e.getBody().getElementsByTagName("span"))).length)for(var a=0;a<n.length;a++){var o=h(n[a]);null!==o&&o.length&&o===t.toString()&&r.push(n[a])}return r},f=function(e,t,n){var r=t.get(),a=e.dom;(n=!1!==n)?r++:r--,a.removeClass(d(e,t.get()),"mce-match-marker-selected");var o=d(e,r);return o.length?(a.addClass(d(e,r),"mce-match-marker-selected"),e.selection.scrollIntoView(o[0]),r):-1},x=function(e,t){var n=t.parentNode;e.remove(t),e.isEmpty(n)&&e.remove(n)},v=function(e,t){var n=f(e,t,!0);-1!==n&&t.set(n)},b=function(e,t){var n=f(e,t,!1);-1!==n&&t.set(n)},N=function(e){var t=h(e);return null!==t&&0<t.length},y=function(e,t,n){var r,a,o,i;for(a=p.toArray(e.getBody().getElementsByTagName("span")),r=0;r<a.length;r++){var d=h(a[r]);null!==d&&d.length&&(d===t.get().toString()&&(o||(o=a[r].firstChild),i=a[r].firstChild),g(a[r]))}if(o&&i){var c=e.dom.createRng();return c.setStart(o,0),c.setEnd(i,i.data.length),!1!==n&&e.selection.setRng(c),c}},w=function(e,t){return 0<d(e,t.get()+1).length},C=function(e,t){return 0<d(e,t.get()-1).length},u={done:y,find:function(e,t,n,r,a){n=(n=n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")).replace(/\s/g,"\\s"),n=a?"\\b"+n+"\\b":n;var o,i,d,c,l,u=(o=e,i=t,d=new RegExp(n,r?"g":"gi"),(l=o.dom.create("span",{"data-mce-bogus":1})).className="mce-match-marker",c=o.getBody(),y(o,i,!1),s.findAndReplaceDOMText(d,c,l,!1,o.schema));return u&&(t.set(-1),t.set(f(e,t,!0))),u},next:v,prev:b,replace:function(e,t,n,r,a){var o,i,d,c,l,u,s=t.get();for(r=!1!==r,d=e.getBody(),i=p.grep(p.toArray(d.getElementsByTagName("span")),N),o=0;o<i.length;o++){var f=h(i[o]);if(c=l=parseInt(f,10),a||c===t.get()){for(n.length?(i[o].firstChild.nodeValue=n,g(i[o])):x(e.dom,i[o]);i[++o];){if((c=parseInt(h(i[o]),10))!==l){o--;break}x(e.dom,i[o])}r&&s--}else l>t.get()&&i[o].setAttribute("data-mce-index",l-1)}return t.set(s),r?(u=w(e,t),v(e,t)):(u=C(e,t),b(e,t)),!a&&u},hasNext:w,hasPrev:C},c=function(r,a){return{done:function(e){return u.done(r,a,e)},find:function(e,t,n){return u.find(r,a,e,t,n)},next:function(){return u.next(r,a)},prev:function(){return u.prev(r,a)},replace:function(e,t,n){return u.replace(r,a,e,t,n)}}},l=function(e){return function(){return e}},T=l(!1),k=l(!0),A=function(){return S},S=(o={fold:function(e,t){return e()},is:T,isSome:T,isNone:k,getOr:a=function(e){return e},getOrThunk:n=function(e){return e()},getOrDie:function(e){throw new Error(e||"error: getOrDie called on none.")},getOrNull:function(){return null},getOrUndefined:function(){return undefined},or:a,orThunk:n,map:A,ap:A,each:function(){},bind:A,flatten:A,exists:T,forall:k,filter:A,equals:t=function(e){return e.isNone()},equals_:t,toArray:function(){return[]},toString:l("none()")},Object.freeze&&Object.freeze(o),o),B=(i="function",function(e){return function(e){if(null===e)return"null";var t=typeof e;return"object"===t&&Array.prototype.isPrototypeOf(e)?"array":"object"===t&&String.prototype.isPrototypeOf(e)?"string":t}(e)===i}),I=(Array.prototype.slice,B(Array.from)&&Array.from,function(e){return"checked"===e}),E=function(r,a){var e,o={};function i(e){(u.hasNext(r,a)?e.enable:e.disable)("next"),(u.hasPrev(r,a)?e.enable:e.disable)("prev")}r.undoManager.add(),e=p.trim(r.selection.getContent({format:"text"}));var d=function(e,t){!function(e,t){for(var n=0,r=e.length;n<r;n++)t(e[n],n,e)}(["replace","replaceall","prev","next"],t?e.disable:e.enable)};function c(e){r.windowManager.alert("Could not find the specified string.",function(){e.focus("findtext")})}var l=function(e){var t=e.getData();if(!t.findtext.length)return u.done(r,a,!1),d(e,!0),void i(e);if(o.text===t.findtext&&o.caseState===t.matchcase&&o.wholeWord===t.wholewords)return u.hasNext(r,a)?(u.next(r,a),void i(e)):void c(e);var n=u.find(r,a,t.findtext,I(t.matchcase),I(t.wholewords));n||c(e),d(e,0===n),i(e),o={text:t.findtext,caseState:t.matchcase,wholeWord:t.wholewords}};r.windowManager.open({title:"Search and Replace",size:"normal",body:{type:"panel",items:[{type:"input",name:"findtext",label:"Find"},{type:"input",name:"replacetext",label:"Replace with"},{type:"grid",columns:2,items:[{type:"checkbox",name:"matchcase",label:"Match case"},{type:"checkbox",name:"wholewords",label:"Find whole words only"}]}]},buttons:[{type:"custom",name:"find",text:"Find",align:"start",primary:!0},{type:"custom",name:"replace",text:"Replace",align:"start",disabled:!0},{type:"custom",name:"replaceall",text:"Replace All",align:"start",disabled:!0},{type:"custom",name:"prev",text:"Prev",align:"end",disabled:!0},{type:"custom",name:"next",text:"Next",align:"end",disabled:!0}],initialData:{findtext:e,replacetext:"",matchcase:"unchecked",wholewords:"unchecked"},onAction:function(e,t){var n=e.getData();switch(t.name){case"find":l(e);break;case"replace":u.replace(r,a,n.replacetext)||(d(e,!0),a.set(-1),o={});break;case"replaceall":u.replace(r,a,n.replacetext,!0,!0),d(e,!0),o={};break;case"prev":u.prev(r,a),i(e);break;case"next":u.next(r,a),i(e)}},onSubmit:l,onClose:function(){r.focus(),u.done(r,a),r.undoManager.add()}})},O=function(e,t){e.addCommand("SearchReplace",function(){E(e,t)})},M=function(e,t){return function(){E(e,t)}},R=function(e,t){e.ui.registry.addMenuItem("searchreplace",{text:"Find and replace",shortcut:"Meta+F",onAction:M(e,t),separator:"before",icon:"search"}),e.ui.registry.addButton("searchreplace",{tooltip:"Find and replace",onAction:M(e,t),icon:"search"}),e.shortcuts.add("Meta+F","",M(e,t))};e.add("searchreplace",function(e){var t=r(-1);return O(e,t),R(e,t),c(e,t)}),function F(){}}();