16 lines
11 KiB
JavaScript
16 lines
11 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.resizable.min"],e)}(function(){return function(e,t){function n(e){return g.test(e)}function i(e){return m.test(e)||/^\d+$/.test(e)}function r(e){return!n(e)&&!i(e)}function o(e,n){return function(i,r){var o,a=this.element.find(i).data(D);return 1==arguments.length?a[e]:(a[e]=r,n&&(o=this.element.data("kendo"+this.options.name),o.resize(!0)),t)}}function a(e){var t=this,n=e.orientation;t.owner=e,t._element=e.element,t.orientation=n,p(t,n===C?l:s),t._resizable=new d.ui.Resizable(e.element,{orientation:n,handle:".k-splitbar-draggable-"+n+"[data-marker="+e._marker+"]",hint:f(t._createHint,t),start:f(t._start,t),max:f(t._max,t),min:f(t._min,t),invalidClass:"k-restricted-size-"+n,resizeend:f(t._stop,t)})}var s,l,d=window.kendo,c=d.ui,u=d.keys,p=e.extend,f=e.proxy,h=c.Widget,m=/^\d+(\.\d+)?px$/i,g=/^\d+(\.\d+)?%$/i,v=".kendoSplitter",_="expand",k="collapse",b="contentLoad",w="error",y="resize",x="layoutChange",C="horizontal",T="vertical",S="mouseenter",F="click",D="pane",E="mouseleave",A="k-state-focused",I="k-"+D,H="."+I,N=h.extend({init:function(e,t){var n,i=this;h.fn.init.call(i,e,t),i.wrapper=i.element,n=i.options.orientation.toLowerCase()!=T,i.orientation=n?C:T,i._dimension=n?"width":"height",i._keys={decrease:n?u.LEFT:u.UP,increase:n?u.RIGHT:u.DOWN},i._resizeStep=10,i._marker=d.guid().substring(0,8),i._initPanes(),i.resizing=new a(i),i.element.triggerHandler("init"+v)},events:[_,k,b,w,y,x],_attachEvents:function(){var t=this,n=t.options.orientation;t.element.children(".k-splitbar-draggable-"+n).on("keydown"+v,e.proxy(t._keydown,t)).on("mousedown"+v,function(e){e.currentTarget.focus()}).on("focus"+v,function(t){e(t.currentTarget).addClass(A)}).on("blur"+v,function(n){e(n.currentTarget).removeClass(A),t.resizing&&t.resizing.end()}).on(S+v,function(){e(this).addClass("k-splitbar-"+t.orientation+"-hover")}).on(E+v,function(){e(this).removeClass("k-splitbar-"+t.orientation+"-hover")}).on("mousedown"+v,function(){t._panes().append("<div class='k-splitter-overlay k-overlay' />")}).on("mouseup"+v,function(){t._panes().children(".k-splitter-overlay").remove()}).end().children(".k-splitbar").on("dblclick"+v,f(t._togglePane,t)).children(".k-collapse-next, .k-collapse-prev").on(F+v,t._arrowClick(k)).end().children(".k-expand-next, .k-expand-prev").on(F+v,t._arrowClick(_)).end().end(),e(window).on("resize"+v+t._marker,f(t.resize,t))},_detachEvents:function(){var t=this;t.element.children(".k-splitbar-draggable-"+t.orientation).off(v).end().children(".k-splitbar").off("dblclick"+v).children(".k-collapse-next, .k-collapse-prev, .k-expand-next, .k-expand-prev").off(v),e(window).off("resize"+v+t._marker)},options:{name:"Splitter",orientation:C,panes:[]},destroy:function(){h.fn.destroy.call(this),this._detachEvents(),this.resizing&&this.resizing.destroy(),d.destroy(this.element),this.wrapper=this.element=null},_keydown:function(t){var n,i=this,r=t.keyCode,o=i.resizing,a=e(t.currentTarget),s=i._keys,l=r===s.increase,d=r===s.decrease;l||d?(t.ctrlKey?(n=a[d?"next":"prev"](),o&&o.isResizing()&&o.end(),n[i._dimension]()?i._triggerAction(k,a[d?"prev":"next"]()):i._triggerAction(_,n)):o&&o.move((d?-1:1)*i._resizeStep,a),t.preventDefault()):r===u.ENTER&&o&&(o.end(),t.preventDefault())},_initPanes:function(){var e=this.options.panes||[],t=this;this.element.addClass("k-widget").addClass("k-splitter").children().each(function(n,i){"script"!=i.nodeName.toLowerCase()&&t._initPane(i,e[n])}),this.resize()},_initPane:function(t,n){t=e(t).attr("role","group").addClass(I),t.data(D,n?n:{}).toggleClass("k-scrollable",n?n.scrollable!==!1:!0),this.ajaxRequest(t)},ajaxRequest:function(e,t,n){var i,r=this;e=r.element.find(e),i=e.data(D),t=t||i.contentUrl,t&&(e.append("<span class='k-icon k-loading k-pane-loading' />"),d.isLocalUrl(t)?jQuery.ajax({url:t,data:n||{},type:"GET",dataType:"html",success:function(t){r.angular("cleanup",function(){return{elements:e.get()}}),e.html(t),r.angular("compile",function(){return{elements:e.get()}}),r.trigger(b,{pane:e[0]})},error:function(t,n){r.trigger(w,{pane:e[0],status:n,xhr:t})}}):e.removeClass("k-scrollable").html("<iframe src='"+t+"' frameborder='0' class='k-content-frame'>This page requires frames in order to show content</iframe>"))},_triggerAction:function(e,t){this.trigger(e,{pane:t[0]})||this[e](t[0])},_togglePane:function(t){var n,i=this,r=e(t.target);r.closest(".k-splitter")[0]==i.element[0]&&(n=r.children(".k-icon:not(.k-resize-handle)"),1===n.length&&(n.is(".k-collapse-prev")?i._triggerAction(k,r.prev()):n.is(".k-collapse-next")?i._triggerAction(k,r.next()):n.is(".k-expand-prev")?i._triggerAction(_,r.prev()):n.is(".k-expand-next")&&i._triggerAction(_,r.next())))},_arrowClick:function(t){var n=this;return function(i){var r,o=e(i.target);o.closest(".k-splitter")[0]==n.element[0]&&(r=o.is(".k-"+t+"-prev")?o.parent().prev():o.parent().next(),n._triggerAction(t,r))}},_updateSplitBar:function(e,t,n){var i=function(e,t){return t?"<div class='k-icon "+e+"' />":""},r=this.orientation,o=t.resizable!==!1&&n.resizable!==!1,a=t.collapsible,s=t.collapsed,l=n.collapsible,d=n.collapsed;e.addClass("k-splitbar k-state-default k-splitbar-"+r).attr("role","separator").attr("aria-expanded",!(s||d)).removeClass("k-splitbar-"+r+"-hover").toggleClass("k-splitbar-draggable-"+r,o&&!s&&!d).toggleClass("k-splitbar-static-"+r,!o&&!a&&!l).html(i("k-collapse-prev",a&&!s&&!d)+i("k-expand-prev",a&&s&&!d)+i("k-resize-handle",o)+i("k-collapse-next",l&&!d&&!s)+i("k-expand-next",l&&d&&!s))},_updateSplitBars:function(){var t=this;this.element.children(".k-splitbar").each(function(){var n=e(this),i=n.prevAll(H).first().data(D),r=n.nextAll(H).first().data(D);r&&t._updateSplitBar(n,i,r)})},_removeSplitBars:function(){this.element.children(".k-splitbar").remove()},_panes:function(){return this.element.children(H)},_resize:function(){var i,o,a,s,l,c,u,p,f,h,m=this,g=m.element,v=g.children(H),_=m.orientation==C,k=g.children(".k-splitbar"),b=k.length,w=_?"width":"height",y=g[w]();0===b?(b=v.length-1,v.slice(0,b).after("<div tabindex='0' class='k-splitbar' data-marker='"+m._marker+"' />"),m._updateSplitBars(),k=g.children(".k-splitbar")):m._updateSplitBars(),k.each(function(){y-=this[_?"offsetWidth":"offsetHeight"]}),i=0,o=0,a=e(),v.css({position:"absolute",top:0})[w](function(){var s,l=e(this).data(D)||{};if(l.collapsed)s=0,e(this).css("overflow","hidden");else{if(r(l.size))return a=a.add(this),t;s=parseInt(l.size,10),n(l.size)&&(s=Math.floor(s*y/100))}return o++,i+=s,s}),y-=i,s=a.length,l=Math.floor(y/s),a.slice(0,s-1).css(w,l).end().eq(s-1).css(w,y-(s-1)*l),c=0,u=_?"height":"width",p=_?"left":"top",f=_?"offsetWidth":"offsetHeight",0===s&&(h=v.filter(function(){return!(e(this).data(D)||{}).collapsed}).last(),h[w](y+h[0][f])),g.children().css(u,g[u]()).each(function(e,t){"script"!=t.tagName.toLowerCase()&&(t.style[p]=Math.floor(c)+"px",c+=t[f])}),m._detachEvents(),m._attachEvents(),d.resize(v),m.trigger(x)},toggle:function(e,n){var i,r=this;e=r.element.find(e),i=e.data(D),(n||i.collapsible)&&(1==arguments.length&&(n=i.collapsed===t?!1:i.collapsed),i.collapsed=!n,i.collapsed?e.css("overflow","hidden"):e.css("overflow",""),r.resize(!0))},collapse:function(e){this.toggle(e,!1)},expand:function(e){this.toggle(e,!0)},_addPane:function(e,t,n){var i=this;return n.length&&(i.options.panes.splice(t,0,e),i._initPane(n,e),i._removeSplitBars(),i.resize(!0)),n},append:function(t){t=t||{};var n=this,i=e("<div />").appendTo(n.element);return n._addPane(t,n.options.panes.length,i)},insertBefore:function(t,n){n=e(n),t=t||{};var i=this,r=i.wrapper.children(".k-pane").index(n),o=e("<div />").insertBefore(e(n));return i._addPane(t,r,o)},insertAfter:function(t,n){n=e(n),t=t||{};var i=this,r=i.wrapper.children(".k-pane").index(n),o=e("<div />").insertAfter(e(n));return i._addPane(t,r+1,o)},remove:function(t){t=e(t);var n=this;return t.length&&(d.destroy(t),t.each(function(t,i){n.options.panes.splice(n.wrapper.children(".k-pane").index(i),1),e(i).remove()}),n._removeSplitBars(),n.options.panes.length&&n.resize(!0)),n},size:o("size",!0),min:o("min"),max:o("max")});c.plugin(N),s={sizingProperty:"height",sizingDomProperty:"offsetHeight",alternateSizingProperty:"width",positioningProperty:"top",mousePositioningProperty:"pageY"},l={sizingProperty:"width",sizingDomProperty:"offsetWidth",alternateSizingProperty:"height",positioningProperty:"left",mousePositioningProperty:"pageX"},a.prototype={press:function(e){this._resizable.press(e)},move:function(e,t){this.pressed||(this.press(t),this.pressed=!0),this._resizable.target||this._resizable.press(t),this._resizable.move(e)},end:function(){this._resizable.end(),this.pressed=!1},destroy:function(){this._resizable.destroy(),this._resizable=this._element=this.owner=null},isResizing:function(){return this._resizable.resizing},_createHint:function(t){var n=this;return e("<div class='k-ghost-splitbar k-ghost-splitbar-"+n.orientation+" k-state-default' />").css(n.alternateSizingProperty,t[n.alternateSizingProperty]())},_start:function(t){var n=this,r=e(t.currentTarget),o=r.prev(),a=r.next(),s=o.data(D),l=a.data(D),d=parseInt(o[0].style[n.positioningProperty],10),c=parseInt(a[0].style[n.positioningProperty],10)+a[0][n.sizingDomProperty]-r[0][n.sizingDomProperty],u=parseInt(n._element.css(n.sizingProperty),10),p=function(e){var t=parseInt(e,10);return(i(e)?t:u*t/100)||0},f=p(s.min),h=p(s.max)||c-d,m=p(l.min),g=p(l.max)||c-d;n.previousPane=o,n.nextPane=a,n._maxPosition=Math.min(c-m,d+h),n._minPosition=Math.max(d+f,c-g)},_max:function(){return this._maxPosition},_min:function(){return this._minPosition},_stop:function(t){var n,i,o,a,s,l,c,u,p=this,f=e(t.currentTarget),h=p.owner;return h._panes().children(".k-splitter-overlay").remove(),t.keyCode!==d.keys.ESC&&(n=t.position,i=f.prev(),o=f.next(),a=i.data(D),s=o.data(D),l=n-parseInt(i[0].style[p.positioningProperty],10),c=parseInt(o[0].style[p.positioningProperty],10)+o[0][p.sizingDomProperty]-n-f[0][p.sizingDomProperty],u=p._element.children(H).filter(function(){return r(e(this).data(D).size)}).length,(!r(a.size)||u>1)&&(r(a.size)&&u--,a.size=l+"px"),(!r(s.size)||u>1)&&(s.size=c+"px"),h.resize(!0)),!1}}}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |