!function(){"use strict";var e=tinymce.util.Tools.resolve("tinymce.PluginManager"),y=function(){for(var e=[],t=0;tn.maxRow()||sn.maxCol()||($t.getAt(t,l,s).filter(r).isNone()?(o=f,i=e[l].element(),u=le.fromTag("td"),fn(u,le.fromTag("br")),(o?fn:ln)(i,u)):f=!0)}(m,g,h,d),o=e,f=h,s=P(ct.firstLayer(o,"tr"),function(e){return 0===e.dom().childElementCount}),A(s,hn),f.minCol()!==f.maxCol()&&f.minRow()!==f.maxRow()||A(ct.firstLayer(o,"th,td"),function(e){xt(e,"rowspan"),xt(e,"colspan")}),xt(o,"width"),xt(o,"height"),un(o,"width"),un(o,"height"),e},wn=function(e,t){return le.fromDom(e.dom().cloneNode(t))},yn=function(e){return wn(e,!1)},xn=function(e){return wn(e,!0)},Cn=function(e,t){var n,r,o,i,u=(n=e,r=t,o=le.fromTag(r),i=Ct(n),bt(o,i),o),a=it(xn(e));return mn(u,a),u},Rn=(At=gt,Pt="text",It=function(e){return At(e)?R.from(e.dom().nodeValue):R.none()},Bt=Je.detect().browser,{get:function(e){if(!At(e))throw new Error("Can only get "+Pt+" value of a "+Pt+" node");return Wt(e).getOr("")},getOption:Wt=Bt.isIE()&&10===Bt.version.major?function(e){try{return It(e)}catch(t){return R.none()}}:It,set:function(e,t){if(!At(e))throw new Error("Can only set raw "+Pt+" value of a "+Pt+" node");e.dom().nodeValue=t}}),Sn=function(e){return Rn.get(e)},Tn=function(e){return Rn.getOption(e)},Dn=function(e,t){Rn.set(e,t)},On=function(e){return"img"===lt(e)?1:Tn(e).fold(function(){return it(e).length},function(e){return e.length})},kn=["img","br"],Nn=function(e){return Tn(e).filter(function(e){return 0!==e.trim().length||-1=e.startCol()&&t.column()+t.colspan()-1<=e.finishCol()&&t.row()>=e.startRow()&&t.row()+t.rowspan()-1<=e.finishRow()},cr=function(e,t){var n=t.column(),r=t.column()+t.colspan()-1,o=t.row(),i=t.row()+t.rowspan()-1;return n<=e.finishCol()&&r>=e.startCol()&&o<=e.finishRow()&&i>=e.startRow()},lr=function(e,t){for(var n=!0,r=b(ar,t),o=t.startRow();o<=t.finishRow();o++)for(var i=t.startCol();i<=t.finishCol();i++)n=n&&$t.getAt(e,o,i).exists(r);return n?R.some(t):R.none()},fr=function(e,t,n){var r=$t.findItem(e,t,$e),o=$t.findItem(e,n,$e);return r.bind(function(r){return o.map(function(e){return t=r,n=e,ae.bounds(Math.min(t.row(),n.row()),Math.min(t.column(),n.column()),Math.max(t.row()+t.rowspan()-1,n.row()+n.rowspan()-1),Math.max(t.column()+t.colspan()-1,n.column()+n.colspan()-1));var t,n})})},sr=fr,dr=function(t,e,n){return fr(t,e,n).bind(function(e){return lr(t,e)})},mr=function(r,e,o,i){return $t.findItem(r,e,$e).bind(function(e){var t=0=t.length-1)return R.none();var e=t[n].fold(function(){var e=U(t.slice(0,n));return ni(e,function(e,t){return e.map(function(e){return{value:e,delta:t+1}})})},function(e){return R.some({value:e,delta:0})}),r=t[n+1].fold(function(){var e=t.slice(n+1);return ni(e,function(e,t){return e.map(function(e){return{value:e,delta:t+1}})})},function(e){return R.some({value:e,delta:1})});return e.bind(function(n){return r.map(function(e){var t=e.delta+n.delta;return Math.abs(e.value-n.value)/t})})},pi=function(e,t,n){var r=e();return W(r,t).orThunk(function(){return R.from(r[0]).orThunk(n)}).map(function(e){return e.element()})},vi=function(n){var e=n.grid(),t=gi(0,e.columns()),r=gi(0,e.rows());return E(t,function(t){return pi(function(){return F(r,function(e){return $t.getAt(n,e,t).filter(function(e){return e.column()===t}).fold(C([]),function(e){return[e]})})},function(e){return 1===e.colspan()},function(){return $t.getAt(n,0,t)})})},bi=function(n){var e=n.grid(),t=gi(0,e.rows()),r=gi(0,e.columns());return E(t,function(t){return pi(function(){return F(r,function(e){return $t.getAt(n,t,e).filter(function(e){return e.row()===t}).fold(C([]),function(e){return[e]})})},function(e){return 1===e.rowspan()},function(){return $t.getAt(n,t,0)})})},wi=function(e,t,n,r,o){var i=le.fromTag("div");return tn(i,{position:"absolute",left:t-r/2+"px",top:n+"px",height:o+"px",width:r+"px"}),bt(i,{"data-column":e,role:"presentation"}),i},yi=function(e,t,n,r,o){var i=le.fromTag("div");return tn(i,{position:"absolute",left:t+"px",top:n-o/2+"px",height:o+"px",width:r+"px"}),bt(i,{"data-row":e,role:"presentation"}),i},xi=function(e){var t=e.replace(/\./g,"-");return{resolve:function(e){return t+"-"+e}}},Ci={resolve:xi("ephox-snooker").resolve},Ri=function(e,t){var n=wt(e,t);return n===undefined||""===n?[]:n.split(" ")},Si=function(e){return e.dom().classList!==undefined},Ti=function(e,t){return o=t,i=Ri(n=e,r="class").concat([o]),vt(n,r,i.join(" ")),!0;var n,r,o,i},Di=function(e,t){return o=t,0<(i=P(Ri(n=e,r="class"),function(e){return e!==o})).length?vt(n,r,i.join(" ")):xt(n,r),!1;var n,r,o,i},Oi=function(e,t){Si(e)?e.dom().classList.add(t):Ti(e,t)},ki=function(e){0===(Si(e)?e.dom().classList:Ri(e,"class")).length&&xt(e,"class")},Ni=function(e,t){return Si(e)&&e.dom().classList.contains(t)},Ei=Ci.resolve("resizer-bar"),Ai=Ci.resolve("resizer-rows"),Pi=Ci.resolve("resizer-cols"),Ii=function(e){var t=Nt(e.parent(),"."+Ei);A(t,hn)},Bi=function(n,e,r){var o=n.origin();A(e,function(e,t){e.each(function(e){var t=r(o,e);Oi(t,Ei),fn(n.parent(),t)})})},Wi=function(e,t,n,r,o,i){var u,a,c,l,f=po(t),s=0=t.length||e.column()>ii.cellLength(t[0]))return $i.error("invalid start address out of table bounds, row: "+e.row()+", column: "+e.column());var r=t.slice(e.row()),o=r[0].cells().slice(e.column()),i=ii.cellLength(n[0]),u=n.length;return $i.value({rowDelta:C(r.length-u),colDelta:C(o.length-i)})},nu=function(e,t){var n=ii.cellLength(e[0]),r=ii.cellLength(t[0]);return{rowDelta:C(0),colDelta:C(n-r)}},ru=function(e,t,n){var r=t.colDelta()<0?eu:o;return(t.rowDelta()<0?Zi:o)(r(e,Math.abs(t.colDelta()),n),Math.abs(t.rowDelta()),n)},ou=function(e,t,n,r){if(0===e.length)return e;for(var o=t.startRow();o<=t.finishRow();o++)for(var i=t.startCol();i<=t.finishCol();i++)ii.mutateCell(e[o],i,ae.elementnew(r(),!1));return e},iu=function(e,t,n,r){for(var o=!0,i=0;i',t.insertBefore(r,t.firstChild)),Ia(e,t),o.align&&Aa(e,t,o.align),e.focus(),e.addVisual()})},Ja=function(t,e){var n,r,o,i,u,a,c,l,f,s,d=t.dom,m={};!0===e?(n=d.getParent(t.selection.getStart(),"table"))&&(c=n,l=(a=t).dom,f={width:l.getStyle(c,"width")||l.getAttrib(c,"width"),height:l.getStyle(c,"height")||l.getAttrib(c,"height"),cellspacing:l.getStyle(c,"border-spacing")||l.getAttrib(c,"cellspacing"),cellpadding:l.getAttrib(c,"data-mce-cell-padding")||l.getAttrib(c,"cellpadding")||Wa(a.dom,c,"padding"),border:l.getAttrib(c,"data-mce-border")||l.getAttrib(c,"border")||Wa(a.dom,c,"border"),borderColor:l.getAttrib(c,"data-mce-border-color"),caption:!!l.select("caption",c)[0],"class":l.getAttrib(c,"class")},Ea.each("left center right".split(" "),function(e){a.formatter.matchNode(c,"align"+e)&&(f.align=e)}),ba(a)&&Ea.extend(f,La.extractAdvancedStyles(l,c)),m=f):(r={label:"Cols",name:"cols"},o={label:"Rows",name:"rows"}),0=e.left&&t<=e.right&&n>=e.top&&n<=e.bottom},Yc=function(n,r,e,t,o){var i=function(e){var t=n.dom().createRange();return t.setStart(r.dom(),e),t.collapse(!0),t},u=Sn(r).length,a=function(e,t,n,r,o){if(0===o)return 0;if(t===r)return o-1;for(var i=r,u=1;u ("+e.right()+", "+e.bottom()+")"}},Wl=function(e){return Bl.nu({left:e.left,top:e.top,right:e.right,bottom:e.bottom})},Ml=function(e,t){return R.some(e.getRect(t))},_l=function(e,t,n){return mt(t)?Ml(e,t).map(Wl):gt(t)?(r=e,o=t,i=n,0<=i&&in.right();var t,n})});var n,o,i},of={point:Bl.getTop,adjuster:function(e,t,n,r,o){var i=Bl.moveUp(o,5);return Math.abs(n.top()-r.top())<1?nf.retry(i):n.bottom()o.bottom()?nf.retry(i):n.top()===o.bottom()?nf.retry(Bl.moveDown(o,1)):rf(e,t,o)?nf.retry(Bl.translate(i,5,0)):nf.none()},move:Bl.moveDown,gather:tf.after},af=function(n,r,o,i,u){return 0===u?R.some(i):(c=n,l=i.left(),f=r.point(i),c.elementFromPoint(l,f).filter(function(e){return"table"===lt(e)}).isSome()?(t=i,a=u-1,af(n,e=r,o,e.move(t,5),a)):n.situsFromPoint(i.left(),r.point(i)).bind(function(e){return e.start().fold(R.none,function(t,e){return Ll(n,t,e).bind(function(e){return r.adjuster(n,t,e,o,i).fold(R.none,function(e){return af(n,r,o,e,u-1)})}).orThunk(function(){return R.some(i)})},R.none)}));var e,t,a,c,l,f},cf=function(t,n,e){var r,o,i,u=t.move(e,5),a=af(n,t,e,u,100).getOr(u);return(r=t,o=a,i=n,r.point(o)>i.getInnerHeight()?R.some(r.point(o)-i.getInnerHeight()):r.point(o)<0?R.some(-r.point(o)):R.none()).fold(function(){return n.situsFromPoint(a.left(),t.point(a))},function(e){return n.scrollBy(0,e),n.situsFromPoint(a.left(),t.point(a)-e)})},lf={tryUp:b(cf,of),tryDown:b(cf,uf),ieTryUp:function(e,t){return e.situsFromPoint(t.left(),t.top()-5)},ieTryDown:function(e,t){return e.situsFromPoint(t.left(),t.bottom()+5)},getJumpSize:C(5)},ff=Br([{none:["message"]},{success:[]},{failedUp:["cell"]},{failedDown:["cell"]}]),sf=function(e){return Ft(e,"tr")},df={verify:function(a,e,t,n,r,c,o){return Ft(n,"td,th",o).bind(function(u){return Ft(e,"td,th",o).map(function(i){return $e(u,i)?$e(n,u)&&On(u)===r?c(i):ff.none("in same cell"):ur.sharedOne(sf,[u,i]).fold(function(){return t=i,n=u,r=(e=a).getRect(t),(o=e.getRect(n)).right>r.left&&o.left";for(var n=0;n<10;n++)e+='';e+=""}return e+="",e+=''}(),onPostRender:function(){this.lastX=this.lastY=0},onmousemove:function(e){var t,n,r=e.target;"A"===r.tagName.toUpperCase()&&(t=parseInt(r.getAttribute("data-mce-x"),10),n=parseInt(r.getAttribute("data-mce-y"),10),(this.isRtl()||"tl-tr"===this.parent().rel)&&(t=9-t),t===this.lastX&&n===this.lastY||(s(o,t,n,e.control),this.lastX=t,this.lastY=n))},onclick:function(e){var t=this;"A"===e.target.tagName.toUpperCase()&&(e.preventDefault(),e.stopPropagation(),t.parent().cancel(),o.undoManager.transact(function(){Ya(o,t.lastX+1,t.lastY+1)}),o.addVisual())}}]};function m(e){return function(){o.execCommand(e)}}var g={text:"Table properties",context:"table",onPostRender:e,onclick:m("mceTableProps")},h={text:"Delete table",context:"table",onPostRender:e,cmd:"mceTableDelete"},p={text:"Row",context:"table",menu:[{text:"Insert row before",onclick:m("mceTableInsertRowBefore"),onPostRender:t},{text:"Insert row after",onclick:m("mceTableInsertRowAfter"),onPostRender:t},{text:"Delete row",onclick:m("mceTableDeleteRow"),onPostRender:t},{text:"Row properties",onclick:m("mceTableRowProps"),onPostRender:t},{text:"-"},{text:"Cut row",onclick:m("mceTableCutRow"),onPostRender:t},{text:"Copy row",onclick:m("mceTableCopyRow"),onPostRender:t},{text:"Paste row before",onclick:m("mceTablePasteRowBefore"),onPostRender:t},{text:"Paste row after",onclick:m("mceTablePasteRowAfter"),onPostRender:t}]},v={text:"Column",context:"table",menu:[{text:"Insert column before",onclick:m("mceTableInsertColBefore"),onPostRender:t},{text:"Insert column after",onclick:m("mceTableInsertColAfter"),onPostRender:t},{text:"Delete column",onclick:m("mceTableDeleteCol"),onPostRender:t}]},b={separator:"before",text:"Cell",context:"table",menu:[{text:"Cell properties",onclick:m("mceTableCellProps"),onPostRender:t},{text:"Merge cells",onclick:m("mceTableMergeCells"),onPostRender:function(){var t=this;a.push(t),r.fold(function(){l(t)},function(e){t.disabled(e.mergable().isNone())})}},{text:"Split cell",onclick:m("mceTableSplitCells"),onPostRender:function(){var t=this;c.push(t),r.fold(function(){l(t)},function(e){t.disabled(e.unmergable().isNone())})}}]};o.addMenuItem("inserttable",d),o.addMenuItem("tableprops",g),o.addMenuItem("deletetable",h),o.addMenuItem("row",p),o.addMenuItem("column",v),o.addMenuItem("cell",b)},Gf=function(n,r){return{insertTable:function(e,t){return Ya(n,e,t)},setClipboardRows:function(e){return t=r,n=E(e,le.fromDom),void t.set(R.from(n));var t,n},getClipboardRows:function(){return r.get().fold(function(){},function(e){return E(e,function(e){return e.dom()})})}}};e.add("table",function(t){var n,r=xc(t),e=zf(t,r.lazyResize),o=ka(t,r.lazyWire),i=(n=t,{get:function(){var e=oa(n);return kr(e,Ir.selectedSelector()).fold(function(){return n.selection.getStart()===undefined?Mr.none():Mr.single(n.selection)},function(e){return Mr.multiple(e)})}}),u=Io(R.none());return Qa(t,o,e,i,u),qr(t,i,o,e),Vf(t,i),Uf(t),qf(t),t.on("PreInit",function(){t.serializer.addTempAttr(Ir.firstSelected()),t.serializer.addTempAttr(Ir.lastSelected())}),t.getParam("table_tab_navigation",!0,"boolean")&&t.on("keydown",function(e){Cl(e,t,o,r.lazyWire)}),t.on("remove",function(){r.destroy(),e.destroy()}),Gf(t,u)})}();