Files
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

1 line
6.0 KiB
JavaScript

!function(){function b(C,H,v,y,F){function j(f,d){if(d=d||0,!f[0]){throw"findAndReplaceDOMText cannot handle zero-length matches"}var g=f.index;if(d>0){var c=f[d];if(!c){throw"Invalid capture group"}g+=f[0].indexOf(c),f[0]=c}return[g,g+f[0].length,[f[0]]]}function q(d){var c;if(3===d.nodeType){return d.data}if(B[d.nodeName]){return""}if(c="",(w[d.nodeName]||A[d.nodeName])&&(c+="\n"),d=d.firstChild){do{c+=q(d)}while(d=d.nextSibling)}return c}function x(J,O,h){var p,M,f,g,m=[],L=0,P=J,K=O.shift(),N=0;J:for(;;){if((w[P.nodeName]||A[P.nodeName])&&L++,3===P.nodeType&&(!M&&P.length+L>=K[1]?(M=P,g=K[1]-L):p&&m.push(P),!p&&P.length+L>K[0]&&(p=P,f=K[0]-L),L+=P.length),p&&M){if(P=h({startNode:p,startNodeIndex:f,endNode:M,endNodeIndex:g,innerNodes:m,match:K[2],matchIndex:N}),L-=M.length-g,p=null,M=null,m=[],K=O.shift(),N++,!K){break}}else{if(!B[P.nodeName]&&P.firstChild){P=P.firstChild;continue}if(P.nextSibling){P=P.nextSibling;continue}}for(;;){if(P.nextSibling){P=P.nextSibling;break}if(P.parentNode===J){break J}P=P.parentNode}}}function E(d){var c;if("function"!=typeof d){var f=d.nodeType?d:G.createElement(d);c=function(l,h){var g=f.cloneNode(!1);return g.setAttribute("data-mce-index",h),l&&g.appendChild(G.createTextNode(l)),g}}else{c=d}return function(R){var K,N,U,t=R.startNode,J=R.endNode,M=R.matchIndex;if(t===J){var T=t;U=T.parentNode,R.startNodeIndex>0&&(K=G.createTextNode(T.data.substring(0,R.startNodeIndex)),U.insertBefore(K,T));var W=c(R.match[0],M);return U.insertBefore(W,T),R.endNodeIndex<T.length&&(N=G.createTextNode(T.data.substring(R.endNodeIndex)),U.insertBefore(N,T)),T.parentNode.removeChild(T),W}K=G.createTextNode(t.data.substring(0,R.startNodeIndex)),N=G.createTextNode(J.data.substring(R.endNodeIndex));for(var S=c(t.data.substring(R.startNodeIndex),M),L=[],Q=0,P=R.innerNodes.length;P>Q;++Q){var O=R.innerNodes[Q],u=c(O.data,M);O.parentNode.replaceChild(u,O),L.push(u)}var V=c(J.data.substring(0,R.endNodeIndex),M);return U=t.parentNode,U.insertBefore(K,t),U.insertBefore(S,t),U.removeChild(t),U=J.parentNode,U.insertBefore(V,J),U.insertBefore(N,J),U.removeChild(J),V}}var I,D,G,w,B,A,z=[],k=0;if(G=H.ownerDocument,w=F.getBlockElements(),B=F.getWhiteSpaceElements(),A=F.getShortEndedElements(),D=q(H)){if(C.global){for(;I=C.exec(D);){z.push(j(I,y))}}else{I=D.match(C),z.push(j(I,y))}return z.length&&(k=z.length,x(H,z,E(v))),k}}function a(g){function m(){var c=tinymce.ui.Factory.create({type:"window",layout:"flex",pack:"center",align:"center",onClose:function(){g.focus(),j=!1,d.unmarkAllMatches()},buttons:[{text:"Find",onclick:function(){c.find("form")[0].submit()}},{text:"Replace",disabled:!0,onclick:function(){d.replace(c.find("#replace").value())||c.statusbar.items().slice(1).disabled(!0)}},{text:"Replace all",disabled:!0,onclick:function(){d.replaceAll(c.find("#replace").value()),c.statusbar.items().slice(1).disabled(!0)}},{type:"spacer",flex:1},{text:"Prev",disabled:!0,onclick:function(){d.prev()}},{text:"Next",disabled:!0,onclick:function(){d.next()}}],title:"Find and replace",items:{type:"form",padding:20,labelGap:30,spacing:10,onsubmit:function(q){var v,p,l,s,u;return q.preventDefault(),l=c.find("#case").checked(),u=c.find("#words").checked(),s=c.find("#find").value(),s.length?(s=s.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),s=u?"\\b"+s+"\\b":s,p=new RegExp(s,l?"g":"gi"),v=d.markAllMatches(p),v?d.first():tinymce.ui.MessageBox.alert("Could not find the specified string."),c.statusbar.items().slice(1).disabled(0===v),void 0):(d.unmarkAllMatches(),c.statusbar.items().slice(1).disabled(!0),void 0)},items:[{type:"textbox",name:"find",size:40,label:"Find",value:g.selection.getNode().src},{type:"textbox",name:"replace",size:40,label:"Replace with"},{type:"checkbox",name:"case",text:"Match case",label:" "},{type:"checkbox",name:"words",text:"Whole words",label:" "}]}}).renderTo().reflow();j=!0}function f(i){var c=i.parentNode;c.insertBefore(i.firstChild,i),i.parentNode.removeChild(i)}function e(u,x){function s(){var c,l;for(c=x?g.getBody()[u?"firstChild":"lastChild"]:p[u?"endContainer":"startContainer"],l=new tinymce.dom.TreeWalker(c,g.getBody());c=l.current();){if(1==c.nodeType&&"SPAN"==c.nodeName&&null!==c.getAttribute("data-mce-index")){for(w=c.getAttribute("data-mce-index"),q=c.firstChild;c=l.current();){if(1==c.nodeType&&"SPAN"==c.nodeName&&null!==c.getAttribute("data-mce-index")){if(c.getAttribute("data-mce-index")!==w){return}t=c.firstChild}l[u?"next":"prev"]()}}l[u?"next":"prev"]()}}var q,t,v=g.selection,p=v.getRng(!0),w=-1;return u=u!==!1,s(),q&&t&&(g.focus(),u?(p.setStart(q,0),p.setEnd(t,t.length)):(p.setStart(t,0),p.setEnd(q,q.length)),v.scrollIntoView(q.parentNode),v.setRng(p)),w}function h(c){c.parentNode.removeChild(c)}var j,d=this,k=-1;d.init=function(c){c.addMenuItem("searchreplace",{text:"Find and replace",shortcut:"Ctrl+F",onclick:m,separator:"before",context:"edit"}),c.addButton("searchreplace",{tooltip:"Find and replace",shortcut:"Ctrl+F",onclick:m}),c.shortcuts.add("Ctrl+F","",m)},d.markAllMatches=function(o){var l,c;return c=g.dom.create("span",{class:"mce-match-marker","data-mce-bogus":1}),l=g.getBody(),d.unmarkAllMatches(l),b(o,l,c,!1,g.schema)},d.first=function(){return k=e(!0,!0),-1!==k},d.next=function(){return k=e(!0),-1!==k},d.prev=function(){return k=e(!1),-1!==k},d.replace=function(v,i,c){var q,y,w,x,p,t;if(-1===k&&(k=e(i)),t=e(i),w=g.getBody(),y=tinymce.toArray(w.getElementsByTagName("span")),y.length){for(q=0;q<y.length;q++){var r=y[q].getAttribute("data-mce-index");if(null!==r&&r.length&&(x=p=y[q].getAttribute("data-mce-index"),c||x===k)){for(v.length?(y[q].firstChild.nodeValue=v,f(y[q])):h(y[q]);y[++q];){if(x=y[q].getAttribute("data-mce-index"),null!==r&&r.length){if(x!==p){q--;break}h(y[q])}}}}}return-1==t&&(t=e(i,!0)),k=t,c&&g.selection.setCursorLocation(g.getBody(),0),g.undoManager.add(),-1!==k},d.replaceAll=function(c){d.replace(c,!0,!0)},d.unmarkAllMatches=function(){var i,l,c;for(c=g.getBody(),l=c.getElementsByTagName("span"),i=l.length;i--;){c=l[i],c.getAttribute("data-mce-index")&&f(c)}},g.on("beforeaddundo keydown",function(c){return j?(c.preventDefault(),!1):void 0})}tinymce.PluginManager.add("searchreplace",a)}();