@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1 lines • 17.1 kB
JavaScript
module.exports=function(o){var i={};function n(e){if(i[e])return i[e].exports;var t=i[e]={exports:{},id:e,loaded:!1};return o[e].call(t.exports,t,t.exports,n),t.loaded=!0,t.exports}return n.m=o,n.c=i,n.p="",n(0)}({0:function(e,t,o){e.exports=o(1028)},3:function(e,t){e.exports=function(){throw Error("define cannot be used indirect")}},973:function(e,t){e.exports=require("./range")},1028:function(e,t,o){var i;o(3),o=[o(973)],void 0===(t="function"==typeof(i=function(){var w=window.kendo.jQuery,c=void 0,g=window.kendo,e=g.ui,p=e.editor,i=e.Widget,a=w.extend,f=g.keys,s=".kendoEditor",t=p.EditorUtils,o=p.ToolTemplate,n=p.Tool,r=g._outerWidth,d=g._outerHeight,_="overflowAnchor",u=".k-tool-group:visible .k-tool:not(.k-disabled):not([disabled]),"+".k-tool.k-overflow-anchor:visible,"+".k-tool-group:visible .k-colorpicker:not(input),"+".k-tool-group:visible .k-selectbox,"+".k-tool-group:visible .k-dropdownlist,"+".k-tool-group:visible .k-combobox .k-input-inner",l={"k-i-sup-script":"superscript","k-i-sub-script":"subscript","k-i-align-left":"justifyLeft","k-i-align-center":"justifyCenter","k-i-align-right":"justifyRight","k-i-align-justify":"justifyFull","k-i-list-unordered":"insertUnorderedList","k-i-list-ordered":"insertOrderedList","k-i-list-roman-upper":"insertUpperRomanList","k-i-list-roman-lower":"insertLowerRomanList","k-i-import":"import","k-i-indent-increase":"indent","k-i-indent-decrease":"outdent","k-i-link-horizontal":"createLink","k-i-unlink-horizontal":"unlink","k-i-image":"insertImage","k-i-file-add":"insertFile","k-i-html":"viewHtml","k-i-foreground-color":"foreColor","k-i-paint":"backColor","k-i-table-insert":"createTable","k-i-table-column-insert-left":"addColumnLeft","k-i-table-column-insert-right":"addColumnRight","k-i-table-row-insert-above":"addRowAbove","k-i-table-row-insert-below":"addRowBelow","k-i-table-row-delete":"deleteRow","k-i-table-column-delete":"deleteColumn","k-i-table-properties":"tableWizard","k-i-table-wizard":"tableWizardInsert","k-i-table-position-left":"tableAlignLeft","k-i-table-position-center":"tableAlignCenter","k-i-table-position-right":"tableAlignRight","k-i-clear-css":"cleanFormatting","k-i-cells-merge-horizontally":"mergeCellsHorizontally","k-i-cells-merge-vertically":"mergeCellsVertically","k-i-cell-split-horizontally":"splitCellHorizontally","k-i-cell-split-vertically":"splitCellVertically","k-i-copy-format":"copyFormat","k-i-apply-format":"applyFormat",".k-i-undo":"undo","k-i-redo":"redo"},h=n.extend({initialize:function(e,t){var o=t.editor.toolbar;e.attr("aria-controls",t.editor.element.attr("id")).on("click",function(){this.overflowPopup.toggle()}.bind(o))},options:{name:_},command:w.noop,update:w.noop,destroy:w.noop}),m=(t.registerTool(_,new h({key:"",ctrl:true,template:new o({template:t.overflowAnchorTemplate})})),i.extend({init:function(e,t){var o=this;t=a({},t,{name:"EditorToolbar"});i.fn.init.call(o,e,t);if(t.popup)o._initPopup();if(t.resizable&&t.resizable.toolbar){o._resizeHandler=g.onResize(function(){o.resize(true)});o.element.addClass("k-toolbar-resizable")}},events:["execute"],groups:{basic:["bold","italic","underline","strikethrough"],undo:["undo","redo"],scripts:["subscript","superscript"],alignment:["justifyLeft","justifyCenter","justifyRight","justifyFull"],links:["insertImage","insertFile","createLink","unlink"],lists:["insertUnorderedList","insertOrderedList","insertUpperRomanList","insertLowerRomanList","indent","outdent"],tablesInsert:["createTable"],tablesAddDelete:["addColumnLeft","addColumnRight","addRowAbove","addRowBelow","deleteRow","deleteColumn"],tablesMerge:["mergeCellsHorizontally","mergeCellsVertically","splitCellHorizontally","splitCellVertically"],tablesPosition:["tableAlignLeft","tableAlignCenter","tableAlignRight"],advanced:["viewHtml","cleanFormatting","print","pdf","exportAs","import"],fonts:["fontName","fontSize"],colors:["foreColor","backColor"],formatPainter:["copyFormat","applyFormat"]},overflowFlaseTools:["formatting","fontName","fontSize","foreColor","backColor","insertHtml"],_initPopup:function(){var t=this;this.window=w(this.element).wrap("<div class='editorToolbarWindow' />").parent().prepend("<span class='k-editortoolbar-dragHandle'><span class='k-icon k-i-handler-drag'></span></span>").kendoWindow({title:false,resizable:false,draggable:{dragHandle:".k-editortoolbar-dragHandle"},animation:{open:{effects:"fade:in"},close:{effects:"fade:out"}},minHeight:42,visible:false,autoFocus:false,actions:[],dragend:function(){this._moved=true}}).on("mousedown",function(e){if(!w(e.target).is(".k-icon"))t.preventPopupHide=true}).on("focusout",function(){t.options.editor.element.focusout()}).data("kendoWindow")},_toggleOverflowStyles:function(e,t){e.find("> li").toggleClass("k-item",t).find(".k-tool:not(.k-disabled), .k-overflow-button").toggleClass("k-overflow-button",t)},_initOverflowPopup:function(t){var o=this;var e="<ul class='k-editor-overflow-popup k-overflow-container k-list-container'></ul>";o.overflowPopup=w(e).appendTo("body").kendoPopup({anchor:t,origin:g.support.isRtl(o.element)?"bottom left":"bottom right",position:g.support.isRtl(o.element)?"top left":"top right",copyAnchorStyles:false,open:function(e){if(this.element.is(":empty"))e.preventDefault();o._toggleOverflowStyles(this.element,true);t.attr("aria-expanded",true)},close:function(){t.attr("aria-expanded",false)},activate:o.focusOverflowPopup.bind(o)}).data("kendoPopup")},items:function(){var e=this.options.resizable&&this.options.resizable.toolbar,t,o;o=this.element.children().find("> *, select");if(e){t=this.overflowPopup;o=o.add(t.element.children().find("> *"))}return o},focused:function(){var e=g._activeElement(),t=this.window,o=this.overflowPopup;return t&&w(e).closest(t.wrapper).length||o&&o.visible()},toolById:function(e){var t,o=this.tools;for(t in o)if(t.toLowerCase()==e)return o[t]},toolGroupFor:function(e){var t,o=this.groups;if(this.isCustomTool(e))return"custom";for(t in o)if(w.inArray(e,o[t])>=0)return t},bindTo:function(a){var d=this,e=d.window;if(d._editor)d._editor.unbind("select",d.resize.bind(d));d._editor=a;if(d.options.resizable&&d.options.resizable.toolbar)a.options.tools.push(_);d.tools=d.expandTools(a.options.tools);d.render();d.element.find(".k-combobox .k-input-inner").on("keydown",function(e){var t=w(this).closest(".k-combobox").data("kendoComboBox"),o=e.keyCode;if(o==f.RIGHT||o==f.LEFT)t.close();else if(o==f.DOWN)if(!t.dropDown.isOpened()){e.stopImmediatePropagation();t.open()}});d._attachEvents();d.items().each(function e(){var t=d._toolName(this),o=t!=="moreVertical"?d.tools[t]:d.tools.overflowAnchor,i=o&&o.options,n=a.options.messages,r=i&&i.tooltip||n[t],l=w(this);if(!o||!o.initialize)return;if(t=="fontSize"||t=="fontName"){var s=n[t+"Inherit"];l.find("input").val(s).end().find("span.k-input-inner").text(s).end()}o.initialize(l,{title:d._appendShortcutSequence(r,o),editor:d._editor});l.closest(".k-dropdownlist",d.element).addClass("k-editor-widget");l.closest(".k-combobox",d.element).addClass("k-editor-widget");l.closest(".k-colorpicker",d.element).next(".k-colorpicker").addClass("k-editor-widget")});a.bind("select",d.resize.bind(d));d.update();if(e)e.wrapper.css({top:"",left:"",width:""})},show:function(){var e=this,t=e.window,o=e.options.editor,i,n,r,l=g.support.browser;if(t){i=t.wrapper;n=o.element;if(!i.is(":visible")||!e.window.options.visible){if(!i[0].style.width)i.width(this._getWindowWidth());if(!t._moved){r=n.offset();i.css({top:Math.max(0,parseInt(r.top,10)-d(i)-parseInt(e.window.element.css("padding-bottom"),10)),left:Math.max(0,parseInt(r.left,10))})}if((l.msie||l.edge)&&e._overlaps(n))setTimeout(function(){t.open()},0);else t.open()}}},_getWindowWidth:function(){var e=this,t=e.window.wrapper,o=e.options.editor.element;return r(o)-parseInt(t.css("border-left-width"),10)-parseInt(t.css("border-right-width"),10)},_overlaps:function(e){var t=this.window.wrapper,o=t.offset(),i=o.left,n=o.top,r=e.offset(),l=r.left,s=r.top;return!(l+e.width()<i||l>i+t.width()||s+e.height()<n||s>n+t.height())},hide:function(){if(this.window)this.window.close()},focus:function(){var e="tabIndex";var t=this.element;var o=this._editor.element.attr(e);t.attr(e,o||0).trigger("focus").find(u).first().trigger("focus");if(!o&&o!==0)t.removeAttr(e)},focusOverflowPopup:function(){var e="tabIndex";var t=this.overflowPopup.element;var o=this._editor.element.attr(e);t.closest(".k-animation-container").addClass("k-overflow-wrapper");t.attr(e,o||0).find(u).first().trigger("focus");if(!o&&o!==0)t.removeAttr(e)},_appendShortcutSequence:function(e,t){if(!t.key)return e;var o=e+" (";if(t.ctrl)o+="Ctrl + ";if(t.shift)o+="Shift + ";if(t.alt)o+="Alt + ";o+=t.key+")";return o},_nativeTools:["insertLineBreak","insertParagraph","redo","undo","autoLink"],tools:{},isCustomTool:function(e){return!(e in g.ui.Editor.defaultTools)},expandTools:function(e){var t,o,i=this._nativeTools,n,r=g.deepExtend({},g.ui.Editor.defaultTools),l={},s;for(o=0;o<e.length;o++){t=e[o];s=t.name;if(w.isPlainObject(t))if(s&&r[s]){l[s]=a({},r[s]);a(l[s].options,t)}else{n=a({cssClass:"k-i-gear",type:"button",title:""},t);if(!n.name)n.name="custom";n.cssClass="k-"+n.name;if(!n.template&&n.type=="button"){n.template=p.EditorUtils.buttonTemplate;n.title=n.title||n.tooltip}l[s]={options:n}}else if(r[t])l[t]=r[t]}for(o=0;o<i.length;o++)if(!l[i[o]])l[i[o]]=r[i[o]];return l},render:function(){var e=this,f=e.tools,o,t,p,i,u=e._editor.element,c=e.element.empty(),h,n,r=e._editor.options.tools,l,s,m=0,v=e.options.resizable&&e.options.resizable.toolbar,a=this.overflowFlaseTools;function k(e){var t="";if(e.getHtml)t=e.getHtml();else{if(!g.isFunction(e))e=g.template(e);t=e(o)}return g.trim(t)}function d(){if(l.children().length){if(v){l.data("position",m);m++}l.appendTo(c)}}function b(e){if(e!==_){l=w("<li class='k-tool-group' role='presentation' />");l.data("overflow",w.inArray(e,a)===-1?true:false)}else l=w("<li class='k-overflow-tools' />")}c.empty();if(r.length)i=r[0].name||r[0];b(i,a);for(s=0;s<r.length;s++){i=r[s].name||r[s];o=f[i]&&f[i].options;if(!o&&w.isPlainObject(i))o=i;t=o&&o.template;if(i=="break"){d();w("<li class='k-row-break' role='presentation' />").appendTo(e.element);b(i,a)}if(!t)continue;n=e.toolGroupFor(i);if(h!=n||i==_){d();b(i,a);h=n}if(i==_)t.options.title=e.options.messages.overflowAnchor;t=k(t);p=w(t).appendTo(l);if(n=="custom"){d();b(i,a)}if(o.exec&&p.hasClass("k-tool"))p.on("click",o.exec.bind(u[0]))}d();w(e.element).children(":has(> .k-tool)").not(".k-overflow-tools").addClass("k-button-group");e.updateGroups();if(v)e._initOverflowPopup(e.element.find(".k-overflow-anchor"));e.angular("compile",function(){return{elements:e.element}})},updateGroups:function(){w(this.element).children().not(".k-overflow-tools").each(function(){w(this).children().removeClass("k-group-start k-group-end").first().addClass("k-group-start").end().last().addClass("k-group-end").end()})},decorateFrom:function(t){this.items().filter(".k-decorated").each(function(){var e=w(this).data("kendoSelectBox");if(e)e.decorate(t)})},destroy:function(){i.fn.destroy.call(this);var e,t=this.tools;for(e in t)if(t[e].destroy)t[e].destroy();if(this.window)this.window.destroy();if(this._resizeHandler)g.unbindResize(this._resizeHandler);if(this.overflowPopup)this.overflowPopup.destroy()},_attachEvents:function(){var e=this,t=e.overflowPopup?e.overflowPopup.element:w([]);e.attachToolsEvents(e.element.add(t))},attachToolsEvents:function(e){var d=this,t="[role=button].k-tool",o=t+":not(.k-disabled)"+", [role=button].k-i-import:not(.k-disabled)",i=t+".k-disabled",n=".k-dropdownlist",r=".k-colorpicker",l=[t,n,r].join(",");e.off(s).on("mouseenter"+s,o,function(){w(this).addClass("k-hover")}).on("mouseleave"+s,o,function(){w(this).removeClass("k-hover")}).on("mousedown"+s,l,function(e){e.preventDefault()}).on("keydown"+s,u,function(e){var r=this;var t=d.options.resizable&&d.options.resizable.toolbar;var o=g.support.isRtl(d.element)?-1:1;var i;var n,l,s=e.keyCode;function a(e,t,o){var i=t.find(u);var n=i.index(r)+e;if(o)n=Math.max(0,Math.min(i.length-1,n));return i[n]}if(s==f.RIGHT||s==f.LEFT)if(!w(r).is(".k-dropdownlist"))n=a(s==f.RIGHT?1*o:-1*o,d.element,true);else n=w(r);else if(t&&(s==f.UP||s==f.DOWN))n=a(s==f.DOWN?1:-1,d.overflowPopup.element,true);else if(s==f.HOME){n=d.element.find(u)[0];e.preventDefault()}else if(s==f.END){i=d.element.find(u).filter(function(){return w(this).css("visibility")!=="hidden"});n=i[i.length-1];e.preventDefault()}else if(s==f.ESC){if(d.overflowPopup&&d.overflowPopup.visible())d.overflowPopup.close();n=d._editor}else if(s==f.TAB&&!(e.ctrlKey||e.altKey)){if(t)l=w(r.parentElement).hasClass("k-overflow-tool-group")?d.overflowPopup.element:d.element;else l=d.element;if(e.shiftKey)n=a(-1,l);else{n=a(1,l);if(!n||w(n).closest(".k-overflow-tools").css("visibility")==="hidden")n=d._editor}}if(n){e.preventDefault();n.focus()}if((s===f.ENTER||s===f.SPACEBAR)&&(w(r).is("button")||w(r).is("a"))&&!w(r).attr("href"))d._executeToolCommand(r,e)}).on("click"+s,o,function(e){d._executeToolCommand(this,e)}).on("click"+s,i,function(e){e.preventDefault()})},_executeToolCommand:function(e,t){var o=this;var i=w(e);t.preventDefault();t.stopPropagation();i.removeClass("k-hover");if(!i.is("[data-popup]"))o._editor.exec(o._toolName(e))},_toolName:function(e){if(!e)return;var t=e.className;if(/k-tool\b/i.test(t))t=e.firstChild.className;var o=w.grep(t.split(" "),function(e){return!/^k-(widget|tool|tool-icon|icon|state-hover|header|combobox|dropdown|selectbox|colorpicker)$/i.test(e)});if(o[0]){var i=o[0];if(l[i])i=l[i];if(i.indexOf("k-i-")>=0)return g.toCamelCase(i.substring(i.indexOf("k-i-")+4));else return i.substring(i.lastIndexOf("-")+1)}return"custom"},refreshTools:function(){var o=this,i=o._editor,e=i.getRange(),n=p.RangeUtils.textNodes(e),r=i.options.immutables,l=o._immutablesContext(e);n=p.Dom.filterBy(n,p.Dom.htmlIndentSpace,true);if(!n.length)n=[e.startContainer];o.items().each(function(){var e=o.tools[o._toolName(this)];if(e){var t=w(this);if(e.update)e.update(t,n,i.undoRedoStack);if(r)o._updateImmutablesState(e,t,l)}});this.update()},_immutablesContext:function(e){if(this._editor.options.immutables)if(e.collapsed)return p.Immutables.immutablesContext(e);else return p.RangeUtils.editableTextNodes(e).length===0},_updateImmutablesState:function(e,t,o){var i=e.name;var n=t;var r=e.options.trackImmutables;if(r===c)r=w.inArray(i,p.Immutables.toolsToBeUpdated)>-1;if(r){var l=o?"none":"";if(!t.is(".k-tool")){var s=t.data();for(var a in s)if(a.match(/^kendo[A-Z][a-zA-Z]*/)){var f=s[a];n=f.wrapper;break}}n.css("display",l);var d=n.closest("li");if(d.children(":visible").length===0)d.css("display",l)}},update:function(){this.updateGroups()},_resize:function(e){var t=e.width;var o=this.options.resizable&&this.options.resizable.toolbar;var i=this.overflowPopup;var n=this.options.editor.element;var r=this.window;this.refreshTools();if(!o)return;if(r){r.wrapper.width(this._getWindowWidth());if(!r._moved)r.wrapper.css({left:Math.max(0,parseInt(n.offset().left,10))})}if(i.visible())i.close(true);this._refreshWidths();this._shrink(t);this._stretch(t);this._toggleOverflowStyles(this.element,false);this._toggleOverflowStyles(this.overflowPopup.element,true);this.element.children("li.k-overflow-tools").css("visibility",i.element.is(":empty")?"hidden":"visible")},_refreshWidths:function(){this.element.children("li").each(function(e,t){var o=w(t);o.data("outerWidth",r(o,true))})},_shrink:function(e){var t,o;if(e<this._groupsWidth()){o=this._visibleGroups().filter(":not(.k-overflow-tools)");for(var i=o.length-1;i>=0;i--){t=o.eq(i);if(e>this._groupsWidth())break;else this._hideGroup(t)}}},_stretch:function(e){var t,o;if(e>this._groupsWidth()){o=this._hiddenGroups();for(var i=0;i<o.length;i++){t=o.eq(i);if(e<this._groupsWidth()||!this._showGroup(t,e))break}}},_hiddenGroups:function(){var e=this.overflowPopup;var t=this.element.children("li.k-tool-group").filter(":hidden");t=t.add(e.element.children("li"));t.sort(function(e,t){return w(e).data("position")>w(t).data("position")?1:-1});return t},_visibleGroups:function(){return this.element.children("li.k-tool-group, li.k-overflow-tools").filter(":visible")},_groupsWidth:function(){var e=0;this._visibleGroups().each(function(){e+=w(this).data("outerWidth")});return Math.ceil(e)},_hideGroup:function(e){if(e.data("overflow")){var t=this.overflowPopup;e.detach().prependTo(t.element).addClass("k-overflow-tool-group")}else e.addClass("k-hidden")},_showGroup:function(e,t){var o,i,n;if(e.hasClass("k-disabled"))return true;if(e.hasClass("k-overflow-tool-group"))n=e.data("outerWidth");else{e.removeClass("k-hidden");n=r(e,true);e.addClass("k-hidden")}if(e.length&&t>this._groupsWidth()+n){if(e.hasClass("k-overflow-tool-group")){o=e.data("position");if(o===0)e.detach().prependTo(this.element);else{i=this.element.children().filter(function(e,t){return w(t).data("position")===o-1});e.detach().insertAfter(i)}e.removeClass("k-overflow-tool-group")}else e.removeClass("k-hidden");return true}return false}}));w.extend(p,{Toolbar:m})})?i.apply(t,o):i)||(e.exports=t)}});