Mini Shell
tinymce.PluginManager.add("textpattern",function(t){function e(){return l&&(i.sort(function(t,e){return t.start.length>e.start.length?-1:t.start.length<e.start.length?1:0}),l=!1),i}function n(t){for(var n=e(),a=0;a<n.length;a++)if(0===t.indexOf(n[a].start)&&(!n[a].end||t.lastIndexOf(n[a].end)==t.length-n[a].end.length))return n[a]}function a(t,n,a){var r,s,d;for(r=e(),d=0;d<r.length;d++)if(s=r[d],s.end&&t.substr(n-s.end.length-a,s.end.length)==s.end)return s}function r(e){function r(){i=i.splitText(f),i.splitText(l-f-h),i.deleteData(0,m.start.length),i.deleteData(i.data.length-m.end.length,m.end.length)}var s,d,o,i,l,f,g,c,m,h,u;return s=t.selection,d=t.dom,s.isCollapsed()&&(o=s.getRng(!0),i=o.startContainer,l=o.startOffset,g=i.data,h=e?1:0,3==i.nodeType&&(m=a(g,l,h),m&&(f=Math.max(0,l-h),f=g.lastIndexOf(m.start,f-m.end.length-1),-1!==f&&(c=d.createRng(),c.setStart(i,f),c.setEnd(i,l-h),m=n(c.toString()),m&&m.end&&!(i.data.length<=m.start.length+m.end.length)))))?(u=t.formatter.get(m.format),u&&u[0].inline?(r(),t.formatter.apply(m.format,{},i),i):void 0):void 0}function s(){var e,a,r,s,d,o,i,l,f,g,c;if(e=t.selection,a=t.dom,e.isCollapsed()&&(i=a.getParent(e.getStart(),"p"))){for(f=new tinymce.dom.TreeWalker(i,i);d=f.next();)if(3==d.nodeType){s=d;break}if(s){if(l=n(s.data),!l)return;if(g=e.getRng(!0),r=g.startContainer,c=g.startOffset,s==r&&(c=Math.max(0,c-l.start.length)),tinymce.trim(s.data).length==l.start.length)return;l.format&&(o=t.formatter.get(l.format),o&&o[0].block&&(s.deleteData(0,l.start.length),t.formatter.apply(l.format,{},s),g.setStart(r,c),g.collapse(!0),e.setRng(g))),l.cmd&&t.undoManager.transact(function(){s.deleteData(0,l.start.length),t.execCommand(l.cmd)})}}}function d(){var e,n;n=r(),n&&(e=t.dom.createRng(),e.setStart(n,n.data.length),e.setEnd(n,n.data.length),t.selection.setRng(e)),s()}function o(){var e,n,a,s,d;e=r(!0),e&&(d=t.dom,n=e.data.slice(-1),/[\u00a0 ]/.test(n)&&(e.deleteData(e.data.length-1,1),a=d.doc.createTextNode(n),e.nextSibling?d.insertAfter(a,e.nextSibling):e.parentNode.appendChild(a),s=d.createRng(),s.setStart(a,1),s.setEnd(a,1),t.selection.setRng(s)))}var i,l=!0;i=t.settings.textpattern_patterns||[{start:"*",end:"*",format:"italic"},{start:"**",end:"**",format:"bold"},{start:"#",format:"h1"},{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:"1. ",cmd:"InsertOrderedList"},{start:"* ",cmd:"InsertUnorderedList"},{start:"- ",cmd:"InsertUnorderedList"}],t.on("keydown",function(t){13!=t.keyCode||tinymce.util.VK.modifierPressed(t)||d()},!0),t.on("keyup",function(t){32!=t.keyCode||tinymce.util.VK.modifierPressed(t)||o()}),this.getPatterns=e,this.setPatterns=function(t){i=t,l=!0}});
Zerion Mini Shell 1.0