16 lines
12 KiB
JavaScript
16 lines
12 KiB
JavaScript
/**
|
|
* Copyright 2014 Telerik AD
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
!function(e,define){define(["./kendo.core.min"],e)}(function(){return function(e,t){function n(n){var i=e(n.useButtonTag?"<button></button>":"<a></a>");return i.data({type:"button"}),i.attr(j,n.uid),n.togglable&&(i.addClass(g),n.selected&&i.addClass(b)),n.enable===!1&&i.addClass(w),n.url===t||n.useButtonTag||(i.attr("href",n.url),n.mobile&&i.attr(d.attr("role"),"button")),n.group&&i.attr(d.attr("group"),n.group),!n.togglable&&n.click&&p(n.click)&&i.data("click",n.click),n.togglable&&n.toggle&&p(n.toggle)&&i.data("toggle",n.toggle),i}function i(e){var t,n=G.button.base(e);return n.addClass(h),e.primary&&n.addClass(C),e.align&&n.addClass("k-align-"+e.align),e.id&&n.attr("id",e.id),"overflow"!=e.showText&&e.text&&(e.mobile?n.html('<span class="km-text">'+e.text+"</span>"):n.text(e.text)),t="overflow"!=e.showIcon&&(e.icon||e.spriteCssClass||e.imageUrl),t&&o(e,n),n}function r(e){var t,n=G.button.base(e);return n.addClass(m+" "+h),e.primary&&n.addClass(C),e.id&&n.attr("id",e.id+"_overflow"),"toolbar"!=e.showText&&e.text&&(e.mobile?n.html('<span class="km-text">'+e.text+"</span>"):n.text(e.text)),t="toolbar"!=e.showIcon&&(e.icon||e.spriteCssClass||e.imageUrl),t&&o(e,n),n}function o(t,n){var i,r,o,a=t.icon,s=t.spriteCssClass,l=t.imageUrl;(s||l||a)&&(i=!0,n.contents().not("span.k-sprite,span."+T+",img.k-image").each(function(t,n){(1==n.nodeType||3==n.nodeType&&e.trim(n.nodeValue).length>0)&&(i=!1)}),n.addClass(i?F:D)),a?(r=n.children("span."+T).first(),r[0]||(r=e('<span class="'+T+'"></span>').prependTo(n)),r.addClass(S+a)):s?(r=n.children("span.k-sprite").first(),r[0]||(r=e('<span class="k-sprite"></span>').prependTo(n)),r.addClass(s)):l&&(o=n.children("img.k-image").first(),o[0]||(o=e('<img alt="icon" class="k-image" />').prependTo(n)),o.attr("src",l))}function a(){var e,t=this.options.anchor,n=t.outerWidth();d.wrap(this.element).addClass("k-split-wrapper"),e="border-box"!==this.element.css("box-sizing")?n-(this.element.outerWidth()-this.element.width()):n,this.element.css({fontFamily:t.css("font-family"),"min-width":e})}function s(e){e.target.is(".k-toggle-button")||e.target.toggleClass(b,"press"==e.type)}function l(t){return t=e(t),t.hasClass("km-actionsheet")?t.closest(".km-popup-wrapper"):t.addClass("km-widget km-actionsheet").wrap('<div class="km-actionsheet-wrapper km-actionsheet-tablet km-widget km-popup"></div>').parent().wrap('<div class="km-popup-wrapper k-popup"></div>').parent()}var d=window.kendo,c=d.ui.Widget,u=e.proxy,p=d.isFunction,f="k-toolbar",h="k-button",m="k-overflow-button",g="k-toggle-button",v="k-button-group",_="k-split-button",k="k-toolbar-resizable",b="k-state-active",w="k-state-disabled",y="k-group-start",x="k-group-end",C="k-primary",T="k-icon",S="k-i-",F="k-button-icon",D="k-button-icontext",E="k-list-container k-split-container",A="k-split-button-arrow",H="k-overflow-anchor",I="k-overflow-container",N="k-toolbar-first-visible",M="k-toolbar-last-visible",R="click",O="toggle",P="open",z="close",L="overflowOpen",B="overflowClose",W="never",U="auto",V="always",q="k-overflow-hidden",j=d.attr("uid"),G={button:{base:n,toolbar:i,overflow:r},buttonGroup:{base:function(t,n,i){var r,o,a=t.buttons;for(i.data({type:"buttonGroup"}),i.attr(j,t.uid),o=0;a.length>o;o++)a[o].uid||(a[o].uid=d.guid()),r=n(e.extend({mobile:t.mobile},a[o])),r.appendTo(i);i.children().first().addClass(y),i.children().last().addClass(x)},toolbar:function(t){var n=e('<div class="'+v+'"></div>');return G.buttonGroup.base(t,G.button.toolbar,n),t.align&&n.addClass("k-align-"+t.align),t.id&&n.attr("id",t.id),n},overflow:function(t){var n=e('<li class="'+(t.mobile?"":v)+' k-overflow-group"></li>');return G.buttonGroup.base(t,G.button.overflow,n),t.id&&n.attr("id",t.id+"_overflow"),n}},splitButton:{toolbar:function(t){var n,i,r,o=e('<div class="'+_+'"></div>'),s=G.button.toolbar(t),d=e('<a class="'+h+" "+A+'"><span class="'+(t.mobile?"km-icon km-arrowdown":"k-icon k-i-arrow-s")+'"></span></a>'),c=e('<ul class="'+E+'"></ul>'),u=t.menuButtons;for(s.appendTo(o),d.appendTo(o),c.appendTo(o),r=0;u.length>r;r++)i=G.button.toolbar(e.extend({mobile:t.mobile,click:t.click},u[r])),i.wrap("<li></li>").parent().appendTo(c);return t.align&&o.addClass("k-align-"+t.align),t.id||(t.id=t.uid),o.attr("id",t.id+"_wrapper"),c.attr("id",t.id+"_optionlist").attr(j,t.rootUid),t.mobile&&(c=l(c)),n=c.kendoPopup({appendTo:t.mobile?e(t.mobile).children(".km-pane"):null,anchor:o,copyAnchorStyles:!1,animation:t.animation,open:a}).data("kendoPopup"),o.data({type:"splitButton",kendoPopup:n}),o.attr(j,t.uid),o},overflow:function(t){var n,i,r=e('<li class="'+_+'"></li>'),o=G.button.overflow(t),a=t.menuButtons;for(o.appendTo(r),i=0;a.length>i;i++)n=G.button.overflow(e.extend({mobile:t.mobile},a[i])),n.appendTo(r);return t.id&&r.attr("id",t.id+"_overflow"),r.data({type:"splitButton"}),r.attr(j,t.uid),r}},separator:{base:function(t,n){var i=e(n?'<li class="k-separator"> </li>':'<div class="k-separator"> </div>');return i.data({type:"separator"}),i.attr(j,t.uid),i},toolbar:function(e){return G.separator.base(e,!1)},overflow:function(e){return G.separator.base(e,!0)}},overflowAnchor:'<div class="k-overflow-anchor"></div>',overflowContainer:'<ul class="k-overflow-container k-list-container"></ul>'},$=c.extend({init:function(t,n){var i,r=this;if(c.fn.init.call(r,t,n),n=r.options,t=r.wrapper=r.element,t.addClass(f+" k-widget"),this.uid=d.guid(),t.attr(j,this.uid),r.isMobile="boolean"==typeof n.mobile?n.mobile:r.element.closest(".km-root")[0],r.animation=r.isMobile?{open:{effects:"fade"}}:{},r.isMobile&&(t.addClass("km-widget"),T="km-icon",S="km-",h="km-button",v="km-buttongroup km-widget",b="km-state-active",w="km-state-disabled"),n.resizable?(r._renderOverflow(),t.addClass(k),r.overflowUserEvents=new d.UserEvents(r.element,{threshold:5,filter:"."+H,tap:u(r._toggleOverflow,r)}),d.onResize(function(){r.resize()})):r.popup={element:e([])},n.items&&n.items.length)for(i=0;n.items.length>i;i++)r.add(n.items[i]);r.userEvents=new d.UserEvents(document,{threshold:5,filter:"["+j+"="+this.uid+"] ."+h+", ["+j+"="+this.uid+"] ."+m,tap:u(r._buttonClick,r),press:s,release:s}),n.resizable&&this._toggleOverflowAnchor(),d.notify(r)},events:[R,O,P,z,L,B],options:{name:"ToolBar",items:[],resizable:!0,mobile:null},destroy:function(){var t=this;t.element.find("."+_).each(function(t,n){e(n).data("kendoPopup").destroy()}),t.userEvents.destroy(),t.options.resizable&&(t.overflowUserEvents.destroy(),t.popup.destroy()),c.fn.destroy.call(t)},add:function(t){var n,i,r=G[t.type],o=t.template,a=this,s=a.isMobile?"":"k-item k-state-default",l=t.overflowTemplate;e.extend(t,{uid:d.guid(),animation:a.animation,mobile:a.isMobile,rootUid:a.uid}),o&&!l&&(t.overflow=W),t.overflow!==W&&a.options.resizable&&(l?i=e(p(l)?l(t):l):r&&(i=(r.overflow||e.noop)(t)),i&&i.length&&("LI"!==i.prop("tagName")&&(i.removeAttr(j),i=i.wrap("<li></li>").parent(),i.attr(j,t.uid)),a._attributes(i,t),i.addClass(s).appendTo(a.popup.container),i.data("overflow")===U&&i.addClass(q),a.angular("compile",function(){return{elements:i.get()}}))),t.overflow!==V&&(o?(n=p(o)?o(t):o,n instanceof jQuery||(n=e(n.replace(/^\s+|\s+$/g,""))),n=n.wrap("<div></div>").parent(),n.attr(j,t.uid)):r&&(n=(r.toolbar||e.noop)(t)),n&&n.length&&(a._attributes(n,t),a.options.resizable?(n.appendTo(a.element).css("visibility","hidden"),a._shrink(a.element.innerWidth()),n.css("visibility","visible")):n.appendTo(a.element),a.angular("compile",function(){return{elements:n.get()}})))},remove:function(e){{var t=this.element.find(e),n=t.data("type");t.attr(j)}t.parent("."+_).data("type")&&(n="splitButton",t=t.parent()),"splitButton"===n&&t.data("kendoPopup").destroy(),t.add(this.popup.element.find("["+j+"='"+t.attr(j)+"']")).remove()},enable:function(n,i){var r=this.element.find(n).attr(j);t===i&&(i=!0),i?e("["+j+"='"+r+"']").removeClass(w):e("["+j+"='"+r+"']").addClass(w)},getSelectedFromGroup:function(e){return this.element.find("."+g+"[data-group='"+e+"']").filter("."+b)},toggle:function(t,n){var i,r=e(t),o=r.data("uid"),a=r.data("group");r.hasClass(g)&&(a&&this.element.add(this.popup.element).find("."+g+"[data-group='"+a+"']").filter("."+b).removeClass(b),e.contains(this.element[0],r[0])?(i=this.popup.element.find("["+j+"='"+o+"']"),"LI"===i.prop("tagName")&&(i=i.find("."+g+":first"))):(o=o?o:r.parent().data("uid"),i=this.element.find("["+j+"='"+o+"']")),r.add(i).toggleClass(b,n))},_attributes:function(e,t){e.attr(d.attr("overflow"),t.overflow||U)},_renderOverflow:function(){var t=this,n=G.overflowContainer;t.overflowAnchor=e(G.overflowAnchor).addClass(h),t.element.append(t.overflowAnchor),t.isMobile?(t.overflowAnchor.append('<span class="km-icon km-more"></span>'),n=l(n)):t.overflowAnchor.append('<span class="k-icon k-i-more"></span>'),t.popup=new d.ui.Popup(n,{origin:"bottom right",position:"top right",anchor:t.overflowAnchor,animation:t.animation,appendTo:t.isMobile?e(t.isMobile).children(".km-pane"):null,copyAnchorStyles:!1,open:function(n){var i=d.wrap(t.popup.element).addClass("k-overflow-wrapper");t.isMobile?t.popup.container.css("max-height",parseFloat(e(".km-content:visible").innerHeight())-15+"px"):i.css("margin-left",(i.outerWidth()-i.width())/2+1),t.trigger(L)&&n.preventDefault()},close:function(e){t.trigger(B)&&e.preventDefault()}}),t.popup.container=t.isMobile?t.popup.element.find("."+I):t.popup.element,t.popup.container.attr(j,this.uid)},_toggleOverflowAnchor:function(){this.overflowAnchor.css(this.popup.element.children(":not(."+q+")").length>0?{visibility:"visible",width:""}:{visibility:"hidden",width:"1px"})},_buttonClick:function(n){var i,r,o,a,s,l,d,c,u=this;if(n.preventDefault(),r=e(n.target).closest("."+h,u.element),!r.hasClass(H)&&(!r.length&&u.popup&&(r=e(n.target).closest("."+m,u.popup.container)),a=r.hasClass(w),!a)){if(n.target.closest("."+A).length)return u._toggle(n),t;r.hasClass(g)?(l=r.data("group"),d=p(r.data("toggle"))?r.data("toggle"):null,u.toggle(r),s=r.hasClass(b),c={target:r,group:l,checked:s,id:r.attr("id")},d&&d.call(u,c),u.trigger(O,c)):(d=p(r.data("click"))?r.data("click"):null,c={target:r,id:r.attr("id")},d&&d.call(u,c),u.trigger(R,c)),r.hasClass(m)&&u.popup.close(),o=r.closest(".k-split-container"),o[0]&&(i=o.data("kendoPopup"),(i?i:o.parents(".km-popup-wrapper").data("kendoPopup")).close())}},_toggle:function(t){var n,i=e(t.target).closest("."+_),r=i.data("kendoPopup");t.preventDefault(),n=r.element.is(":visible")?this.trigger(z,{target:i}):this.trigger(P,{target:i}),n||r.toggle()},_toggleOverflow:function(){this.popup.toggle()},_resize:function(e){var t=e.width;this.popup.close(),this._shrink(t),this._stretch(t),this._markVisibles(),this._toggleOverflowAnchor()},_childrenWidth:function(){var t=0;return this.element.children(":visible").each(function(){t+=e(this).outerWidth(!0)}),Math.ceil(t)},_shrink:function(e){var t,n,i;if(e<this._childrenWidth())for(n=this.element.children(":visible:not([data-overflow='never'], ."+H+")"),i=n.length-1;i>=0&&(t=n.eq(i),!(e>this._childrenWidth()));i--)this._hideItem(t)},_stretch:function(e){var t,n,i;if(e>this._childrenWidth())for(n=this.element.children(":hidden"),i=0;n.length>i&&(t=n.eq(i),!(e<this._childrenWidth())&&this._showItem(t,e));i++);},_hideItem:function(e){e.hide(),this.popup&&this.popup.container.find(">li[data-uid='"+e.data("uid")+"']").removeClass(q)},_showItem:function(e,t){return e.length&&t>this._childrenWidth()+e.outerWidth(!0)?(e.show(),this.popup&&this.popup.container.find(">li[data-uid='"+e.data("uid")+"']").addClass(q),!0):!1},_markVisibles:function(){var e=this.popup.container.children(),t=this.element.children(":not(.k-overflow-anchor)"),n=e.filter(":not(.k-overflow-hidden)"),i=t.filter(":visible");e.add(t).removeClass(N+" "+M),n.first().add(i.first()).addClass(N),n.last().add(i.last()).addClass(M)}});d.ui.plugin($)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |