@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1 lines • 8.12 kB
JavaScript
module.exports=function(e){function t(n){if(o[n])return o[n].exports;var l=o[n]={exports:{},id:n,loaded:!1};return e[n].call(l.exports,l,l.exports,t),l.loaded=!0,l.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}({0:function(e,t,o){e.exports=o(970)},3:function(e,t){e.exports=function(){throw Error("define cannot be used indirect")}},962:function(e,t){e.exports=require("./formatblock")},970:function(e,t,o){var n,l,i;!function(s,define){l=[o(962),o(971)],n=s,i="function"==typeof n?n.apply(t,l):n,!(void 0!==i&&(e.exports=i))}(function(){!function(e,t){var o=window.kendo,n=e.extend,l=e.proxy,i=o.ui.editor,s=i.Dom,a=i.EditorUtils,r=i.RangeUtils,c=i.Command,p="kendoEditor",d="k-state-active",m="k-state-selected",u=i.Tool,f=i.ToolTemplate,h=i.InsertHtmlCommand,b=i.BlockFormatFinder,w=i.EditorUtils.registerTool,v=o.getTouches,g=o.template,x="<td style='width:#=width#%;'>#=content#</td>",T=new b([{tags:["table"]}]),k=h.extend({init:function(t){var o=e.extend({postProcess:this.postProcess,skipCleaners:!0},t||{});h.fn.init.call(this,o)},_tableHtml:function(e,t){var o,n;return e=e||1,t=t||1,o=g(x)({width:100/t,content:i.emptyTableCellContent}),n=100/e,"<table class='k-table' data-last>"+Array(e+1).join("<tr style='height:"+n+"%;'>"+Array(t+1).join(o)+"</tr>")+"</table>"},postProcess:function(t,o){var n=e("table[data-last]",t.document).removeAttr("data-last");o.setStart(n.find("td")[0],0),o.collapse(!0),t.selectRange(o)},exec:function(){var e=this.options;e.html=this._tableHtml(e.rows,e.columns),h.fn.exec.call(this)}}),_=u.extend({initialize:function(t,o){var n,s,r,c;u.fn.initialize.call(this,t,o),n=e(this.options.popupTemplate).appendTo("body").kendoPopup({anchor:t,copyAnchorStyles:!1,open:l(this._open,this),activate:l(this._activate,this),close:l(this._close,this)}).data("kendoPopup"),t.click(l(this._toggle,this)).keydown(l(this._keydown,this)),s=this._editor=o.editor,this._popup=n,r=new i.TableWizardTool({template:new f({template:a.buttonTemplate,title:s.options.messages.tableWizard}),command:i.TableWizardCommand,insertNewTable:!0}),w("tableWizardInsert",r),c=e("<div class='k-editor-toolbar'>"+r.options.template.getHtml()+"</div>"),c.appendTo(n.element),s.toolbar&&s.toolbar.attachToolsEvents(c)},popup:function(){return this._popup},_activate:e.noop,_open:function(){this._popup.options.anchor.addClass(d)},_close:function(){this._popup.options.anchor.removeClass(d)},_keydown:function(e){var t=o.keys,n=e.keyCode;n==t.DOWN&&e.altKey?this._popup.open():n==t.ESC&&this._popup.close()},_toggle:function(t){var o=e(t.target).closest(".k-tool");o.hasClass("k-state-disabled")||this.popup().toggle()},update:function(e){var t=this.popup();t.wrapper&&"block"==t.wrapper.css("display")&&t.close(),e.removeClass("k-state-hover")},destroy:function(){this._popup.destroy()}}),y=_.extend({init:function(t){this.cols=8,this.rows=6,_.fn.init.call(this,e.extend(t,{command:k,popupTemplate:"<div class='k-ct-popup'>"+Array(this.cols*this.rows+1).join("<span class='k-ct-cell k-state-disabled' />")+"<div class='k-status'></div></div>"}))},_activate:function(){function t(t){var o=e(window);return{row:Math.floor((t.clientY+o.scrollTop()-d.top)/l)+1,col:Math.floor((t.clientX+o.scrollLeft()-d.left)/n)+1}}var n,l,i=this,s=i._popup.element,a=s.find(".k-ct-cell"),r=a.eq(0),c=a.eq(a.length-1),d=o.getOffset(r),m=o.getOffset(c),u=i.cols,f=i.rows;s.find("*").addBack().attr("unselectable","on"),m.left+=c[0].offsetWidth,m.top+=c[0].offsetHeight,n=(m.left-d.left)/u,l=(m.top-d.top)/f,s.autoApplyNS(p).on("mousemove",".k-ct-cell",function(e){i._setTableSize(t(e))}).on("mouseleave",".k-ct-cell",function(){i._setTableSize()}).on("down",".k-ct-cell",function(e){e.preventDefault();var o=v(e)[0];i._exec(t(o.location))})},_valid:function(e){return e&&e.row>0&&e.col>0&&e.row<=this.rows&&e.col<=this.cols},_exec:function(e){this._valid(e)&&(this._editor.exec("createTable",{rows:e.row,columns:e.col}),this._popup.close())},_setTableSize:function(t){var n=this._popup.element,l=n.find(".k-status"),i=n.find(".k-ct-cell"),s=this.cols,a=this._editor.options.messages;this._valid(t)?(l.text(o.format(a.createTableHint,t.row,t.col)),i.each(function(o){e(this).toggleClass(m,o%s<t.col&&o/s<t.row)})):(l.text(a.createTable),i.removeClass(m))},_keydown:function(e){var t,n,l,i,s,a,r,c;_.fn._keydown.call(this,e),this._popup.visible()&&(t=o.keys,n=e.keyCode,l=this._popup.element.find(".k-ct-cell"),i=Math.max(l.filter(".k-state-selected").last().index(),0),s=Math.floor(i/this.cols),a=i%this.cols,r=!1,n!=t.DOWN||e.altKey?n==t.UP?(r=!0,s--):n==t.RIGHT?(r=!0,a++):n==t.LEFT&&(r=!0,a--):(r=!0,s++),c={row:Math.max(1,Math.min(this.rows,s+1)),col:Math.max(1,Math.min(this.cols,a+1))},n==t.ENTER?this._exec(c):this._setTableSize(c),r&&(e.preventDefault(),e.stopImmediatePropagation()))},_open:function(){var e=this._editor.options.messages;_.fn._open.call(this),this.popup().element.find(".k-status").text(e.createTable).end().find(".k-ct-cell").removeClass(m)},_close:function(){_.fn._close.call(this),this.popup().element.off("."+p)}}),C=c.extend({exec:function(){for(var e,t,o,n,l=this.lockRange(!0),a=l.endContainer;"td"!=s.name(a);)a=a.parentNode;if(!this.immutables()||!i.Immutables.immutableParent(a)){for(t=a.parentNode,e=t.children.length,o=t.cloneNode(!0),n=0;n<t.cells.length;n++)o.cells[n].innerHTML=i.emptyTableCellContent;"before"==this.options.position?s.insertBefore(o,t):s.insertAfter(o,t),this.releaseRange(l)}}}),R=c.extend({exec:function(){var e,t,o,n,l=this.lockRange(!0),a=s.closest(l.endContainer,"td"),r=s.closest(a,"table"),c=r.rows,p=this.options.position;if(!this.immutables()||!i.Immutables.immutableParent(a)){for(e=s.findNodeIndex(a,!0),t=0;t<c.length;t++)o=c[t].cells[e],n=o.cloneNode(),n.innerHTML=i.emptyTableCellContent,"before"==p?s.insertBefore(n,o):s.insertAfter(n,o);this.releaseRange(l)}}}),A=c.extend({exec:function(){var t,o,n,l=this.lockRange(),a=r.mapAll(l,function(t){return e(t).closest("tr")[0]}),c=a[0];if(!this.immutables()||!i.Immutables.immutableParent(c)){if(t=s.closest(c,"table"),t.rows.length<=a.length)o=s.next(t),o&&!s.insignificant(o)||(o=s.prev(t)),s.remove(t);else for(n=0;n<a.length;n++)c=a[n],s.removeTextSiblings(c),o=s.next(c)||s.prev(c),o=o.cells[0],s.remove(c);o&&(l.setStart(o,0),l.collapse(!0),this.editor.selectRange(l))}}}),I=c.extend({exec:function(){var e,t,o=this.lockRange(),n=s.closest(o.endContainer,"td"),l=s.closest(n,"table"),a=l.rows,r=s.findNodeIndex(n,!0),c=a[0].cells.length;if(!this.immutables()||!i.Immutables.immutableParent(n)){if(1==c)e=s.next(l),e&&!s.insignificant(e)||(e=s.prev(l)),s.remove(l);else for(s.removeTextSiblings(n),e=s.next(n)||s.prev(n),t=0;t<a.length;t++)s.remove(a[t].cells[r]);e&&(o.setStart(e,0),o.collapse(!0),this.editor.selectRange(o))}}}),z=u.extend({command:function(e){return e=n(e,this.options),"delete"==e.action?"row"==e.type?new A(e):new I(e):"row"==e.type?new C(e):new R(e)},initialize:function(e,t){u.fn.initialize.call(this,e,t),e.addClass("k-state-disabled")},update:function(e,t){var o=!T.isFormatted(t);e.toggleClass("k-state-disabled",o)}});n(o.ui.editor,{PopupTool:_,TableCommand:k,InsertTableTool:y,TableModificationTool:z,InsertRowCommand:C,InsertColumnCommand:R,DeleteRowCommand:A,DeleteColumnCommand:I}),w("createTable",new y({template:new f({template:a.buttonTemplate,popup:!0,title:"Create table"})})),w("addColumnLeft",new z({type:"column",position:"before",template:new f({template:a.buttonTemplate,title:"Add column on the left"})})),w("addColumnRight",new z({type:"column",template:new f({template:a.buttonTemplate,title:"Add column on the right"})})),w("addRowAbove",new z({type:"row",position:"before",template:new f({template:a.buttonTemplate,title:"Add row above"})})),w("addRowBelow",new z({type:"row",template:new f({template:a.buttonTemplate,title:"Add row below"})})),w("deleteRow",new z({type:"row",action:"delete",template:new f({template:a.buttonTemplate,title:"Delete row"})})),w("deleteColumn",new z({type:"column",action:"delete",template:new f({template:a.buttonTemplate,title:"Delete column"})}))}(window.kendo.jQuery)},o(3))},971:function(e,t){e.exports=require("./insert")}});