WordPress/wp-includes/js/tinymce/plugins/lists/plugin.min.js

1 line
26 KiB
JavaScript

!function(u){"use strict";var e,n,t,r,o,i,a,s,c,f=tinymce.util.Tools.resolve("tinymce.PluginManager"),d=tinymce.util.Tools.resolve("tinymce.dom.RangeUtils"),l=tinymce.util.Tools.resolve("tinymce.dom.TreeWalker"),m=tinymce.util.Tools.resolve("tinymce.util.VK"),p=tinymce.util.Tools.resolve("tinymce.dom.BookmarkManager"),v=tinymce.util.Tools.resolve("tinymce.util.Tools"),g=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),h=function(e){return e&&"BR"===e.nodeName},y=function(e){return e&&3===e.nodeType},N=function(e){return e&&/^(OL|UL|DL)$/.test(e.nodeName)},S=function(e){return e&&/^(OL|UL)$/.test(e.nodeName)},C=function(e){return e&&/^(DT|DD)$/.test(e.nodeName)},O=function(e){return e&&/^(LI|DT|DD)$/.test(e.nodeName)},b=function(e){return e&&/^(TH|TD)$/.test(e.nodeName)},T=h,E=function(e,n){return n&&!!e.schema.getTextBlockElements()[n.nodeName]},L=function(e,n){return e&&e.nodeName in n},D=function(e,n){return!!h(n)&&!(!e.isBlock(n.nextSibling)||h(n.previousSibling))},w=function(e,n,t){var r=e.isEmpty(n);return!(t&&0<e.select("span[data-mce-type=bookmark]",n).length)&&r},k=function(e,n){return e.isChildOf(n,e.getRoot())},A=function(e,n){if(y(e))return{container:e,offset:n};var t=d.getNode(e,n);return y(t)?{container:t,offset:n>=e.childNodes.length?t.data.length:0}:t.previousSibling&&y(t.previousSibling)?{container:t.previousSibling,offset:t.previousSibling.data.length}:t.nextSibling&&y(t.nextSibling)?{container:t.nextSibling,offset:0}:{container:e,offset:n}},x=function(e){var n=e.cloneRange(),t=A(e.startContainer,e.startOffset);n.setStart(t.container,t.offset);var r=A(e.endContainer,e.endOffset);return n.setEnd(r.container,r.offset),n},R=g.DOM,I=function(o){var i={},e=function(e){var n,t,r;t=o[e?"startContainer":"endContainer"],r=o[e?"startOffset":"endOffset"],1===t.nodeType&&(n=R.create("span",{"data-mce-type":"bookmark"}),t.hasChildNodes()?(r=Math.min(r,t.childNodes.length-1),e?t.insertBefore(n,t.childNodes[r]):R.insertAfter(n,t.childNodes[r])):t.appendChild(n),t=n,r=0),i[e?"startContainer":"endContainer"]=t,i[e?"startOffset":"endOffset"]=r};return e(!0),o.collapsed||e(),i},_=function(o){function e(e){var n,t,r;n=r=o[e?"startContainer":"endContainer"],t=o[e?"startOffset":"endOffset"],n&&(1===n.nodeType&&(t=function(e){for(var n=e.parentNode.firstChild,t=0;n;){if(n===e)return t;1===n.nodeType&&"bookmark"===n.getAttribute("data-mce-type")||t++,n=n.nextSibling}return-1}(n),n=n.parentNode,R.remove(r),!n.hasChildNodes()&&R.isBlock(n)&&n.appendChild(R.create("br"))),o[e?"startContainer":"endContainer"]=n,o[e?"startOffset":"endOffset"]=t)}e(!0),e();var n=R.createRng();return n.setStart(o.startContainer,o.startOffset),o.endContainer&&n.setEnd(o.endContainer,o.endOffset),x(n)},B=function(e){return function(){return e}},P=function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return!t.apply(null,e)}},M=B(!1),U=B(!0),F=M,j=U,H=function(){return $},$=(r={fold:function(e,n){return e()},is:F,isSome:F,isNone:j,getOr:t=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:t,orThunk:n,map:H,ap:H,each:function(){},bind:H,flatten:H,exists:F,forall:j,filter:H,equals:e=function(e){return e.isNone()},equals_:e,toArray:function(){return[]},toString:B("none()")},Object.freeze&&Object.freeze(r),r),q=function(t){var e=function(){return t},n=function(){return o},r=function(e){return e(t)},o={fold:function(e,n){return n(t)},is:function(e){return t===e},isSome:j,isNone:F,getOr:e,getOrThunk:e,getOrDie:e,getOrNull:e,getOrUndefined:e,or:n,orThunk:n,map:function(e){return q(e(t))},ap:function(e){return e.fold(H,function(e){return q(e(t))})},each:function(e){e(t)},bind:r,flatten:e,exists:r,forall:r,filter:function(e){return e(t)?o:$},equals:function(e){return e.is(t)},equals_:function(e,n){return e.fold(F,function(e){return n(t,e)})},toArray:function(){return[t]},toString:function(){return"some("+t+")"}};return o},W={some:q,none:H,from:function(e){return null===e||e===undefined?$:q(e)}},V=function(n){return function(e){return function(e){if(null===e)return"null";var n=typeof e;return"object"===n&&(Array.prototype.isPrototypeOf(e)||e.constructor&&"Array"===e.constructor.name)?"array":"object"===n&&(String.prototype.isPrototypeOf(e)||e.constructor&&"String"===e.constructor.name)?"string":n}(e)===n}},z=V("string"),K=V("array"),X=V("boolean"),Q=V("function"),Y=V("number"),G=Array.prototype.slice,J=function(e,n){for(var t=e.length,r=new Array(t),o=0;o<t;o++){var i=e[o];r[o]=n(i,o,e)}return r},Z=function(e,n){for(var t=0,r=e.length;t<r;t++)n(e[t],t,e)},ee=function(e,n){for(var t=[],r=0,o=e.length;r<o;r++){var i=e[r];n(i,r,e)&&t.push(i)}return t},ne=function(e,n,t){return Z(e,function(e){t=n(t,e)}),t},te=function(e,n){for(var t=0,r=e.length;t<r;t++){var o=e[t];if(n(o,t,e))return W.some(o)}return W.none()},re=Array.prototype.push,oe=function(e,n){return function(e){for(var n=[],t=0,r=e.length;t<r;++t){if(!K(e[t]))throw new Error("Arr.flatten item "+t+" was not an array, input: "+e);re.apply(n,e[t])}return n}(J(e,n))},ie=function(e){return 0===e.length?W.none():W.some(e[0])},ue=function(e){return 0===e.length?W.none():W.some(e[e.length-1])},ae=(Q(Array.from)&&Array.from,"undefined"!=typeof u.window?u.window:Function("return this;")()),se=function(e,n){return function(e,n){for(var t=n!==undefined&&null!==n?n:ae,r=0;r<e.length&&t!==undefined&&null!==t;++r)t=t[e[r]];return t}(e.split("."),n)},ce=function(e,n){var t=se(e,n);if(t===undefined||null===t)throw new Error(e+" not available on this browser");return t},fe=function(e){var n,t=se("ownerDocument.defaultView",e);return(n=t,ce("HTMLElement",n)).prototype.isPrototypeOf(e)},de=tinymce.util.Tools.resolve("tinymce.dom.DomQuery"),le=function(e){var n=e.selection.getStart(!0);return e.dom.getParent(n,"OL,UL,DL",ge(e,n))},me=function(e){var t,n,r,o=e.selection.getSelectedBlocks();return v.grep((t=e,n=o,r=v.map(n,function(e){var n=t.dom.getParent(e,"li,dd,dt",ge(t,e));return n||e}),de.unique(r)),function(e){return O(e)})},ge=function(e,n){var t=e.dom.getParents(n,"TD,TH");return 0<t.length?t[0]:e.getBody()},pe=function(e,n){var t=e.dom.getParents(n,"ol,ul",ge(e,n));return ue(t)},ve=function(n,e){var t=J(e,function(e){return pe(n,e).getOr(e)});return de.unique(t)},he={isList:function(e){var n=le(e);return fe(n)},getParentList:le,getSelectedSubLists:function(e){var n,t,r,o=le(e),i=e.selection.getSelectedBlocks();return r=i,(t=o)&&1===r.length&&r[0]===t?(n=o,v.grep(n.querySelectorAll("ol,ul,dl"),function(e){return N(e)})):v.grep(i,function(e){return N(e)&&o!==e})},getSelectedListItems:me,getClosestListRootElm:ge,getSelectedDlItems:function(e){return ee(me(e),C)},getSelectedListRoots:function(e){var n,t,r,o=(t=pe(n=e,n.selection.getStart()),r=ee(n.selection.getSelectedBlocks(),S),t.toArray().concat(r));return ve(e,o)}},ye=function(e){if(null===e||e===undefined)throw new Error("Node cannot be null or undefined");return{dom:B(e)}},Ne={fromHtml:function(e,n){var t=(n||u.document).createElement("div");if(t.innerHTML=e,!t.hasChildNodes()||1<t.childNodes.length)throw u.console.error("HTML does not have a single root node",e),new Error("HTML must have a single root node");return ye(t.childNodes[0])},fromTag:function(e,n){var t=(n||u.document).createElement(e);return ye(t)},fromText:function(e,n){var t=(n||u.document).createTextNode(e);return ye(t)},fromDom:ye,fromPoint:function(e,n,t){var r=e.dom();return W.from(r.elementFromPoint(n,t)).map(ye)}},Se=function(e,n){for(var t=[],r=0;r<e.length;r++){var o=e[r];if(!o.isSome())return W.none();t.push(o.getOrDie())}return W.some(n.apply(null,t))},Ce=Object.keys,Oe=function(){return ce("Node")},be=function(e,n,t){return 0!=(e.compareDocumentPosition(n)&t)},Te=function(e,n){return be(e,n,Oe().DOCUMENT_POSITION_CONTAINED_BY)},Ee=function(e,n){var t=function(e,n){for(var t=0;t<e.length;t++){var r=e[t];if(r.test(n))return r}return undefined}(e,n);if(!t)return{major:0,minor:0};var r=function(e){return Number(n.replace(t,"$"+e))};return De(r(1),r(2))},Le=function(){return De(0,0)},De=function(e,n){return{major:e,minor:n}},we={nu:De,detect:function(e,n){var t=String(n).toLowerCase();return 0===e.length?Le():Ee(e,t)},unknown:Le},ke="Firefox",Ae=function(e,n){return function(){return n===e}},xe=function(e){var n=e.current;return{current:n,version:e.version,isEdge:Ae("Edge",n),isChrome:Ae("Chrome",n),isIE:Ae("IE",n),isOpera:Ae("Opera",n),isFirefox:Ae(ke,n),isSafari:Ae("Safari",n)}},Re={unknown:function(){return xe({current:undefined,version:we.unknown()})},nu:xe,edge:B("Edge"),chrome:B("Chrome"),ie:B("IE"),opera:B("Opera"),firefox:B(ke),safari:B("Safari")},Ie="Windows",_e="Android",Be="Solaris",Pe="FreeBSD",Me=function(e,n){return function(){return n===e}},Ue=function(e){var n=e.current;return{current:n,version:e.version,isWindows:Me(Ie,n),isiOS:Me("iOS",n),isAndroid:Me(_e,n),isOSX:Me("OSX",n),isLinux:Me("Linux",n),isSolaris:Me(Be,n),isFreeBSD:Me(Pe,n)}},Fe={unknown:function(){return Ue({current:undefined,version:we.unknown()})},nu:Ue,windows:B(Ie),ios:B("iOS"),android:B(_e),linux:B("Linux"),osx:B("OSX"),solaris:B(Be),freebsd:B(Pe)},je=function(e,n){var t=String(n).toLowerCase();return te(e,function(e){return e.search(t)})},He=function(e,t){return je(e,t).map(function(e){var n=we.detect(e.versionRegexes,t);return{current:e.name,version:n}})},$e=function(e,t){return je(e,t).map(function(e){var n=we.detect(e.versionRegexes,t);return{current:e.name,version:n}})},qe=function(e,n){return-1!==e.indexOf(n)},We=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,Ve=function(n){return function(e){return qe(e,n)}},ze=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:function(e){return qe(e,"edge/")&&qe(e,"chrome")&&qe(e,"safari")&&qe(e,"applewebkit")}},{name:"Chrome",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,We],search:function(e){return qe(e,"chrome")&&!qe(e,"chromeframe")}},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:function(e){return qe(e,"msie")||qe(e,"trident")}},{name:"Opera",versionRegexes:[We,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:Ve("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:Ve("firefox")},{name:"Safari",versionRegexes:[We,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:function(e){return(qe(e,"safari")||qe(e,"mobile/"))&&qe(e,"applewebkit")}}],Ke=[{name:"Windows",search:Ve("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:function(e){return qe(e,"iphone")||qe(e,"ipad")},versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:Ve("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"OSX",search:Ve("os x"),versionRegexes:[/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:Ve("linux"),versionRegexes:[]},{name:"Solaris",search:Ve("sunos"),versionRegexes:[]},{name:"FreeBSD",search:Ve("freebsd"),versionRegexes:[]}],Xe={browsers:B(ze),oses:B(Ke)},Qe=function(e){var n,t,r,o,i,u,a,s,c,f,d,l=Xe.browsers(),m=Xe.oses(),g=He(l,e).fold(Re.unknown,Re.nu),p=$e(m,e).fold(Fe.unknown,Fe.nu);return{browser:g,os:p,deviceType:(t=g,r=e,o=(n=p).isiOS()&&!0===/ipad/i.test(r),i=n.isiOS()&&!o,u=n.isAndroid()&&3===n.version.major,a=n.isAndroid()&&4===n.version.major,s=o||u||a&&!0===/mobile/i.test(r),c=n.isiOS()||n.isAndroid(),f=c&&!s,d=t.isSafari()&&n.isiOS()&&!1===/safari/i.test(r),{isiPad:B(o),isiPhone:B(i),isTablet:B(s),isPhone:B(f),isTouch:B(c),isAndroid:n.isAndroid,isiOS:n.isiOS,isWebView:B(d)})}},Ye={detect:(o=function(){var e=u.navigator.userAgent;return Qe(e)},a=!1,function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return a||(a=!0,i=o.apply(null,e)),i})},Ge=(u.Node.ATTRIBUTE_NODE,u.Node.CDATA_SECTION_NODE,u.Node.COMMENT_NODE,u.Node.DOCUMENT_NODE,u.Node.DOCUMENT_TYPE_NODE,u.Node.DOCUMENT_FRAGMENT_NODE,u.Node.ELEMENT_NODE),Je=(u.Node.TEXT_NODE,u.Node.PROCESSING_INSTRUCTION_NODE,u.Node.ENTITY_REFERENCE_NODE,u.Node.ENTITY_NODE,u.Node.NOTATION_NODE,Ge),Ze=function(e,n){return e.dom()===n.dom()},en=Ye.detect().browser.isIE()?function(e,n){return Te(e.dom(),n.dom())}:function(e,n){var t=e.dom(),r=n.dom();return t!==r&&t.contains(r)},nn=function(e,n){var t=e.dom();if(t.nodeType!==Je)return!1;var r=t;if(r.matches!==undefined)return r.matches(n);if(r.msMatchesSelector!==undefined)return r.msMatchesSelector(n);if(r.webkitMatchesSelector!==undefined)return r.webkitMatchesSelector(n);if(r.mozMatchesSelector!==undefined)return r.mozMatchesSelector(n);throw new Error("Browser lacks native selectors")},tn=function(e){return W.from(e.dom().parentNode).map(Ne.fromDom)},rn=function(e){return J(e.dom().childNodes,Ne.fromDom)},on=function(e,n){var t=e.dom().childNodes;return W.from(t[n]).map(Ne.fromDom)},un=function(e){return on(e,0)},an=function(e){return on(e,e.dom().childNodes.length-1)},sn=(function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n]}("element","offset"),function(n,t){tn(n).each(function(e){e.dom().insertBefore(t.dom(),n.dom())})}),cn=function(e,n){e.dom().appendChild(n.dom())},fn=function(n,e){Z(e,function(e){cn(n,e)})},dn=function(e){var n=e.dom();null!==n.parentNode&&n.parentNode.removeChild(n)},ln=function(e){return e.dom().nodeName.toLowerCase()},mn=(s=Ge,function(e){return e.dom().nodeType===s}),gn=function(e,n){var t=e.dom();!function(e,n){for(var t=Ce(e),r=0,o=t.length;r<o;r++){var i=t[r];n(e[i],i,e)}}(n,function(e,n){!function(e,n,t){if(!(z(t)||X(t)||Y(t)))throw u.console.error("Invalid call to Attr.set. Key ",n,":: Value ",t,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(n,t+"")}(t,n,e)})},pn=function(e){return ne(e.dom().attributes,function(e,n){return e[n.name]=n.value,e},{})},vn=function(e,n,t){if(!z(t))throw u.console.error("Invalid call to CSS.set. Property ",n,":: Value ",t,":: Element ",e),new Error("CSS value must be a string: "+t);var r;(r=e).style!==undefined&&Q(r.style.getPropertyValue)&&e.style.setProperty(n,t)},hn=function(e){return n=e,t=!0,Ne.fromDom(n.dom().cloneNode(t));var n,t},yn=function(e,n){var t,r,o,i,u=(t=e,r=n,o=Ne.fromTag(r),i=pn(t),gn(o,i),o);sn(e,u);var a=rn(e);return fn(u,a),dn(e),u},Nn=function(e,n){cn(e.item,n.list)},Sn=function(f,e,d){var n=e.slice(0,d.depth);return ue(n).each(function(e){var n,t,r,o,i,u,a,s,c=(n=f,t=d.itemAttributes,r=d.content,o=Ne.fromTag("li",n),gn(o,t),fn(o,r),o);u=c,cn((i=e).list,u),i.item=u,s=d,ln((a=e).list)!==s.listType&&(a.list=yn(a.list,s.listType)),gn(a.list,s.listAttributes)}),n},Cn=function(e,n,t){var r,o=function(e,n,t){for(var r,o,i,u=[],a=0;a<t;a++)u.push((r=e,o=n.listType,i={list:Ne.fromTag(o,r),item:Ne.fromTag("li",r)},cn(i.list,i.item),i));return u}(e,t,t.depth-n.length);return function(e){for(var n=1;n<e.length;n++)Nn(e[n-1],e[n])}(o),function(e,n){for(var t=0;t<e.length-1;t++)r=e[t].item,o="list-style-type",i="none",u=r.dom(),vn(u,o,i);var r,o,i,u;ue(e).each(function(e){gn(e.list,n.listAttributes),gn(e.item,n.itemAttributes),fn(e.item,n.content)})}(o,t),r=o,Se([ue(n),ie(r)],Nn),n.concat(o)},On=function(e){return nn(e,"OL,UL")},bn=function(e){return un(e).map(On).getOr(!1)},Tn=function(e){return 0<e.depth},En=function(e){return e.isSelected},Ln=function(e){var n=rn(e),t=an(e).map(On).getOr(!1)?n.slice(0,-1):n;return J(t,hn)},Dn=Object.prototype.hasOwnProperty,wn=(c=function(e,n){return n},function(){for(var e=new Array(arguments.length),n=0;n<e.length;n++)e[n]=arguments[n];if(0===e.length)throw new Error("Can't merge zero objects");for(var t={},r=0;r<e.length;r++){var o=e[r];for(var i in o)Dn.call(o,i)&&(t[i]=c(t[i],o[i]))}return t}),kn=function(n){Z(n,function(r,e){(function(e,n){for(var t=e[n].depth,r=n-1;0<=r;r--){if(e[r].depth===t)return W.some(e[r]);if(e[r].depth<t)break}return W.none()})(n,e).each(function(e){var n,t;t=e,(n=r).listType=t.listType,n.listAttributes=wn({},t.listAttributes)})})},An=function(e){var n=e,t=function(){return n};return{get:t,set:function(e){n=e},clone:function(){return An(t())}}},xn=function(i,u,a,s){return un(s).filter(On).fold(function(){u.each(function(e){Ze(e.start,s)&&a.set(!0)});var n,t,r,e=(n=s,t=i,r=a.get(),tn(n).filter(mn).map(function(e){return{depth:t,isSelected:r,content:Ln(n),itemAttributes:pn(n),listAttributes:pn(e),listType:ln(e)}}));u.each(function(e){Ze(e.end,s)&&a.set(!1)});var o=an(s).filter(On).map(function(e){return Rn(i,u,a,e)}).getOr([]);return e.toArray().concat(o)},function(e){return Rn(i,u,a,e)})},Rn=function(n,t,r,e){return oe(rn(e),function(e){return(On(e)?Rn:xn)(n+1,t,r,e)})},In=tinymce.util.Tools.resolve("tinymce.Env"),_n=function(e,n){var t,r,o,i,u=e.dom,a=e.schema.getBlockElements(),s=u.createFragment();if(e.settings.forced_root_block&&(o=e.settings.forced_root_block),o&&((r=u.create(o)).tagName===e.settings.forced_root_block&&u.setAttribs(r,e.settings.forced_root_block_attrs),L(n.firstChild,a)||s.appendChild(r)),n)for(;t=n.firstChild;){var c=t.nodeName;i||"SPAN"===c&&"bookmark"===t.getAttribute("data-mce-type")||(i=!0),L(t,a)?(s.appendChild(t),r=null):o?(r||(r=u.create(o),s.appendChild(r)),r.appendChild(t)):s.appendChild(t)}return e.settings.forced_root_block?i||In.ie&&!(10<In.ie)||r.appendChild(u.create("br",{"data-mce-bogus":"1"})):s.appendChild(u.create("br")),s},Bn=function(i,e){return J(e,function(e){var n,t,r,o=(n=e.content,r=(t||u.document).createDocumentFragment(),Z(n,function(e){r.appendChild(e.dom())}),Ne.fromDom(r));return Ne.fromDom(_n(i,o.dom()))})},Pn=function(e,n){return kn(n),(t=e.contentDocument,r=n,o=ne(r,function(e,n){return n.depth>e.length?Cn(t,e,n):Sn(t,e,n)},[]),ie(o).map(function(e){return e.list})).toArray();var t,r,o},Mn=function(e){var n,t,r=J(he.getSelectedListItems(e),Ne.fromDom);return Se([te(r,P(bn)),te((n=r,t=G.call(n,0),t.reverse(),t),P(bn))],function(e,n){return{start:e,end:n}})},Un=function(a,e,s){var n,t,r,o=(n=e,t=Mn(a),r=An(!1),J(n,function(e){return{sourceList:e,entries:Rn(0,t,r,e)}}));Z(o,function(e){var n,t,r,o,i,u;n=e.entries,t=s,Z(ee(n,En),function(e){return function(e,n){switch(e){case"Indent":n.depth++;break;case"Outdent":n.depth--;break;case"Flatten":n.depth=0}}(t,e)}),r=e.sourceList,i=a,u=e.entries,o=oe(function(e,n){if(0===e.length)return[];for(var t=n(e[0]),r=[],o=[],i=0,u=e.length;i<u;i++){var a=e[i],s=n(a);s!==t&&(r.push(o),o=[]),t=s,o.push(a)}return 0!==o.length&&r.push(o),r}(u,Tn),function(e){return ie(e).map(Tn).getOr(!1)?Pn(i,e):Bn(i,e)}),Z(o,function(e){sn(r,e)}),dn(e.sourceList)})},Fn=g.DOM,jn=function(e,n,t){var r,o,i,u,a,s;for(i=Fn.select('span[data-mce-type="bookmark"]',n),a=_n(e,t),(r=Fn.createRng()).setStartAfter(t),r.setEndAfter(n),u=(o=r.extractContents()).firstChild;u;u=u.firstChild)if("LI"===u.nodeName&&e.dom.isEmpty(u)){Fn.remove(u);break}e.dom.isEmpty(o)||Fn.insertAfter(o,n),Fn.insertAfter(a,n),w(e.dom,t.parentNode)&&(s=t.parentNode,v.each(i,function(e){s.parentNode.insertBefore(e,t.parentNode)}),Fn.remove(s)),Fn.remove(t),w(e.dom,n)&&Fn.remove(n)},Hn=function(e){nn(e,"dt")&&yn(e,"dd")},$n=function(r,e,n){Z(n,"Indent"===e?Hn:function(e){return n=r,void(nn(t=e,"dd")?yn(t,"dt"):nn(t,"dt")&&tn(t).each(function(e){return jn(n,e.dom(),t.dom())}));var n,t})},qn=function(e,n){var t=J(he.getSelectedListRoots(e),Ne.fromDom),r=J(he.getSelectedDlItems(e),Ne.fromDom),o=!1;if(t.length||r.length){var i=e.selection.getBookmark();Un(e,t,n),$n(e,n,r),e.selection.moveToBookmark(i),e.selection.setRng(x(e.selection.getRng())),e.nodeChanged(),o=!0}return o},Wn=function(e){return qn(e,"Indent")},Vn=function(e){return qn(e,"Outdent")},zn=function(e){return qn(e,"Flatten")},Kn=function(t,e){v.each(e,function(e,n){t.setAttribute(n,e)})},Xn=function(e,n,t){var r,o,i,u,a,s,c;r=e,o=n,u=(i=t)["list-style-type"]?i["list-style-type"]:null,r.setStyle(o,"list-style-type",u),a=e,Kn(s=n,(c=t)["list-attributes"]),v.each(a.select("li",s),function(e){Kn(e,c["list-item-attributes"])})},Qn=function(e,n,t,r){var o,i;for(o=n[t?"startContainer":"endContainer"],i=n[t?"startOffset":"endOffset"],1===o.nodeType&&(o=o.childNodes[Math.min(i,o.childNodes.length-1)]||o),!t&&T(o.nextSibling)&&(o=o.nextSibling);o.parentNode!==r;){if(E(e,o))return o;if(/^(TD|TH)$/.test(o.parentNode.nodeName))return o;o=o.parentNode}return o},Yn=function(f,d,l){void 0===l&&(l={});var e,n=f.selection.getRng(!0),m="LI",t=he.getClosestListRootElm(f,f.selection.getStart(!0)),g=f.dom;"false"!==g.getContentEditable(f.selection.getNode())&&("DL"===(d=d.toUpperCase())&&(m="DT"),e=I(n),v.each(function(t,e,r){for(var o,i=[],u=t.dom,n=Qn(t,e,!0,r),a=Qn(t,e,!1,r),s=[],c=n;c&&(s.push(c),c!==a);c=c.nextSibling);return v.each(s,function(e){if(E(t,e))return i.push(e),void(o=null);if(u.isBlock(e)||T(e))return T(e)&&u.remove(e),void(o=null);var n=e.nextSibling;p.isBookmarkNode(e)&&(E(t,n)||!n&&e.parentNode===r)?o=null:(o||(o=u.create("p"),e.parentNode.insertBefore(o,e),i.push(o)),o.appendChild(e))}),i}(f,n,t),function(e){var n,t,r,o,i,u,a,s,c;(t=e.previousSibling)&&N(t)&&t.nodeName===d&&(r=t,o=l,i=g.getStyle(r,"list-style-type"),u=o?o["list-style-type"]:"",i===(u=null===u?"":u))?(n=t,e=g.rename(e,m),t.appendChild(e)):(n=g.create(d),e.parentNode.insertBefore(n,e),n.appendChild(e),e=g.rename(e,m)),a=g,s=e,c=["margin","margin-right","margin-bottom","margin-left","margin-top","padding","padding-right","padding-bottom","padding-left","padding-top"],v.each(c,function(e){var n;return a.setStyle(s,((n={})[e]="",n))}),Xn(g,n,l),Jn(f.dom,n)}),f.selection.setRng(_(e)))},Gn=function(e,n,t){return s=t,(a=n)&&s&&N(a)&&a.nodeName===s.nodeName&&(i=n,u=t,(o=e).getStyle(i,"list-style-type",!0)===o.getStyle(u,"list-style-type",!0))&&(r=t,n.className===r.className);var r,o,i,u,a,s},Jn=function(e,n){var t,r;if(t=n.nextSibling,Gn(e,n,t)){for(;r=t.firstChild;)n.appendChild(r);e.remove(t)}if(t=n.previousSibling,Gn(e,n,t)){for(;r=t.lastChild;)n.insertBefore(r,n.firstChild);e.remove(t)}},Zn=function(n,e,t,r,o){if(e.nodeName!==r||et(o)){var i=I(n.selection.getRng(!0));v.each([e].concat(t),function(e){!function(e,n,t,r){if(n.nodeName!==t){var o=e.rename(n,t);Xn(e,o,r)}else Xn(e,n,r)}(n.dom,e,r,o)}),n.selection.setRng(_(i))}else zn(n)},et=function(e){return"list-style-type"in e},nt={toggleList:function(e,n,t){var r=he.getParentList(e),o=he.getSelectedSubLists(e);t=t||{},r&&0<o.length?Zn(e,r,o,n,t):function(e,n,t,r){if(n!==e.getBody())if(n)if(n.nodeName!==t||et(r)){var o=I(e.selection.getRng(!0));Xn(e.dom,n,r),Jn(e.dom,e.dom.rename(n,t)),e.selection.setRng(_(o))}else zn(e);else Yn(e,t,r)}(e,r,n,t)},mergeWithAdjacentLists:Jn},tt=g.DOM,rt=function(e,n){var t,r=n.parentNode;"LI"===r.nodeName&&r.firstChild===n&&((t=r.previousSibling)&&"LI"===t.nodeName?(t.appendChild(n),w(e,r)&&tt.remove(r)):tt.setStyle(r,"listStyleType","none")),N(r)&&(t=r.previousSibling)&&"LI"===t.nodeName&&t.appendChild(n)},ot=function(n,e){v.each(v.grep(n.select("ol,ul",e)),function(e){rt(n,e)})},it=function(e,n,t,r){var o,i,u=n.startContainer,a=n.startOffset;if(3===u.nodeType&&(t?a<u.data.length:0<a))return u;for(o=e.schema.getNonEmptyElements(),1===u.nodeType&&(u=d.getNode(u,a)),i=new l(u,r),t&&D(e.dom,u)&&i.next();u=i[t?"next":"prev2"]();){if("LI"===u.nodeName&&!u.hasChildNodes())return u;if(o[u.nodeName])return u;if(3===u.nodeType&&0<u.data.length)return u}},ut=function(e,n){var t=n.childNodes;return 1===t.length&&!N(t[0])&&e.isBlock(t[0])},at=function(e,n,t){var r,o,i,u;if(o=ut(e,t)?t.firstChild:t,ut(i=e,u=n)&&i.remove(u.firstChild,!0),!w(e,n,!0))for(;r=n.firstChild;)o.appendChild(r)},st=function(n,e,t){var r,o,i=e.parentNode;if(k(n,e)&&k(n,t)){N(t.lastChild)&&(o=t.lastChild),i===t.lastChild&&T(i.previousSibling)&&n.remove(i.previousSibling),(r=t.lastChild)&&T(r)&&e.hasChildNodes()&&n.remove(r),w(n,t,!0)&&n.$(t).empty(),at(n,e,t),o&&t.appendChild(o);var u=en(Ne.fromDom(t),Ne.fromDom(e))?n.getParents(e,N,t):[];n.remove(e),Z(u,function(e){w(n,e)&&e!==n.getRoot()&&n.remove(e)})}},ct=function(e,n,t,r){var o,i,u,a=e.dom;if(a.isEmpty(r))i=t,u=r,(o=e).dom.$(u).empty(),st(o.dom,i,u),o.selection.setCursorLocation(u);else{var s=I(n);st(a,t,r),e.selection.setRng(_(s))}},ft=function(e,n){var t,r,o,i=e.dom,u=e.selection,a=u.getStart(),s=he.getClosestListRootElm(e,a),c=i.getParent(u.getStart(),"LI",s);if(c){if((t=c.parentNode)===e.getBody()&&w(i,t))return!0;if(r=x(u.getRng(!0)),(o=i.getParent(it(e,r,n,s),"LI",s))&&o!==c)return n?ct(e,r,o,c):function(e,n,t,r){var o=I(n);st(e.dom,t,r);var i=_(o);e.selection.setRng(i)}(e,r,c,o),!0;if(!o&&!n)return zn(e),!0}return!1},dt=function(e,n){return ft(e,n)||function(o,i){var u=o.dom,e=o.selection.getStart(),a=he.getClosestListRootElm(o,e),s=u.getParent(e,u.isBlock,a);if(s&&u.isEmpty(s)){var n=x(o.selection.getRng(!0)),c=u.getParent(it(o,n,i,a),"LI",a);if(c)return o.undoManager.transact(function(){var e,n,t,r;n=s,t=a,r=(e=u).getParent(n.parentNode,e.isBlock,t),e.remove(n),r&&e.isEmpty(r)&&e.remove(r),nt.mergeWithAdjacentLists(u,c.parentNode),o.selection.select(c,!0),o.selection.collapse(i)}),!0}return!1}(e,n)},lt=function(e,n){return e.selection.isCollapsed()?dt(e,n):(r=(t=e).selection.getStart(),o=he.getClosestListRootElm(t,r),!!(t.dom.getParent(r,"LI,DT,DD",o)||0<he.getSelectedListItems(t).length)&&(t.undoManager.transact(function(){t.execCommand("Delete"),ot(t.dom,t.getBody())}),!0));var t,r,o},mt=function(n){n.on("keydown",function(e){e.keyCode===m.BACKSPACE?lt(n,!1)&&e.preventDefault():e.keyCode===m.DELETE&&lt(n,!0)&&e.preventDefault()})},gt=lt,pt=function(n){return{backspaceDelete:function(e){gt(n,e)}}},vt=function(n,t){return function(){var e=n.dom.getParent(n.selection.getStart(),"UL,OL,DL");return e&&e.nodeName===t}},ht=function(t){t.on("BeforeExecCommand",function(e){var n=e.command.toLowerCase();"indent"===n?Wn(t):"outdent"===n&&Vn(t)}),t.addCommand("InsertUnorderedList",function(e,n){nt.toggleList(t,"UL",n)}),t.addCommand("InsertOrderedList",function(e,n){nt.toggleList(t,"OL",n)}),t.addCommand("InsertDefinitionList",function(e,n){nt.toggleList(t,"DL",n)}),t.addCommand("RemoveList",function(){zn(t)}),t.addQueryStateHandler("InsertUnorderedList",vt(t,"UL")),t.addQueryStateHandler("InsertOrderedList",vt(t,"OL")),t.addQueryStateHandler("InsertDefinitionList",vt(t,"DL"))},yt=function(e){return e.getParam("lists_indent_on_tab",!0)},Nt=function(e){var n;yt(e)&&(n=e).on("keydown",function(e){e.keyCode!==m.TAB||m.metaKeyPressed(e)||n.undoManager.transact(function(){(e.shiftKey?Vn(n):Wn(n))&&e.preventDefault()})}),mt(e)},St=function(n,i){return function(e){var o=e.control;n.on("NodeChange",function(e){var n=function(e,n){for(var t=0;t<e.length;t++)if(n(e[t]))return t;return-1}(e.parents,b),t=-1!==n?e.parents.slice(0,n):e.parents,r=v.grep(t,N);o.active(0<r.length&&r[0].nodeName===i)})}},Ct=function(e){var n,t,r;t="advlist",r=(n=e).settings.plugins?n.settings.plugins:"",-1===v.inArray(r.split(/[ ,]/),t)&&(e.addButton("numlist",{active:!1,title:"Numbered list",cmd:"InsertOrderedList",onPostRender:St(e,"OL")}),e.addButton("bullist",{active:!1,title:"Bullet list",cmd:"InsertUnorderedList",onPostRender:St(e,"UL")})),e.addButton("indent",{icon:"indent",title:"Increase indent",cmd:"Indent"})};f.add("lists",function(e){return Nt(e),Ct(e),ht(e),pt(e)})}(window);