@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines • 9.56 kB
JavaScript
/* @license */
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`kendo.popup.min.js`),require(`kendo.html.button.min.js`),require(`kendo.actionsheet.min.js`)):typeof define==`function`&&define.amd?define([`exports`,`kendo.popup.min`,`kendo.html.button.min`,`kendo.actionsheet.min`],t):(e=typeof globalThis<`u`?globalThis:e||self,t((e.kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Timeselector={}),e.kendo._globals.Popup,e.kendo._globals.HtmlButton,e.kendo._globals.Actionsheet))})(this,function(e,t,n,r){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let i={id:`timeselector`,name:`TimeSelector`,category:`web`,description:`The TimeSelector widget allows the end user to select a time range from a popup`,depends:[`popup`,`html.button`,`actionsheet`]};(function(e,t){var n=window.kendo,r=n.ui,i=n.htmlEncode,a=r.Widget,o=n.html,s=e.extend,c=n.mediaQuery,l=`change`,u=`click`,d=`scroll`,f=`k-focus`,p=n.keys,m=`.kendoTimeSelector`,o=n.html,h=({value:e})=>`<li class='k-item' data-value='${i(e)}'><span>${i(e)}</span></li>`,g=({title:e,name:t})=>`<div class="k-time-list-wrapper"><span class="k-title">${i(e)}</span><div class="k-time-list"><div class="k-content k-scrollable k-time-container" data-name="${i(t)}"><ul class="k-reset"></ul><div class="k-scrollable-placeholder"></div></div></div></div>`,_=a.extend({init:function(e,t){var r=this;a.fn.init.call(r,e,t),r.bigScreenMQL=c(`large`),r.smallScreenMQL=c(`small`),r.options.adaptiveMode==`auto`&&r.smallScreenMQL.onChange(function(){r.popup&&n.isFunction(r.popup.fullscreen)&&r.popup.fullscreen(r.smallScreenMQL.mediaQueryList.matches)}),r._wrappers(),r.options.adaptiveMode!==`auto`&&r._buttons(!0),r._attchHandlers(),r._shortCuts(),r._columns(),r._popup()},options:{name:`TimeSelector`,columns:[],shortcuts:[],adaptiveMode:`none`,adaptiveTitle:null,adaptiveSubtitle:null,size:t,fillMode:t,rounded:t,messages:{set:`Set`,cancel:`Cancel`,days:`Days`,hours:`Hours`,minutes:`Minutes`,milliseconds:`Milliseconds`,seconds:`Seconds`}},events:[l],addTranslate:function(){for(var e=this._listsContainer.find(`.k-time-container.k-content.k-scrollable`),t=e.length,n,r,i,a,o,s,c=0;c<t;c++)n=e.eq(c),r=x(n.find(`.k-item:visible`).eq(0)),i=n.outerHeight(),a=(i-r)/2,o=`translateY(`+a+`px)`,s=i-r,n.find(`ul`).css({transform:o,"-ms-transform":o}),n.find(`.k-scrollable-placeholder`).css({height:n.find(`ul`).height()+s}),n.off(m).on(u+m,`.k-item`,this._itemClickHandler.bind(this)).on(d+m,this._listScrollHandler.bind(this))},applyValue:function(t){if(t){var r=this,i=this._listsContainer.find(`.k-time-container.k-content.k-scrollable`),a=y(t);i.each(function(t,i){var o=r.options.columns[t],s=a[o.name];s>=o.min&&s<=o.max&&r._scrollListToPosition(e(i),n.format(o.selectorFormat,s))})}},toggle:function(){this.popup.toggle()},destroy:function(){this._listContainer.off(m),this._timeSelectorWrapper.off(m),this.popup&&=(this.popup.destroy(),null),this.bigScreenMQL&&this.bigScreenMQL.destroy(),this.smallScreenMQL&&this.smallScreenMQL.destroy()},_attchHandlers:function(){var e=this;e._listContainer.on(`keydown`+m,this._scrollerKeyDownHandler.bind(this)),e._timeSelectorWrapper.on(`click`+m,`.k-time-fast-selection button`,this._applyShortCut.bind(this)),e._timeSelectorWrapper.on(`click`+m,`.k-timeduration-footer button.k-time-cancel`,this._cancelClickHandler.bind(this)),e._timeSelectorWrapper.on(`click`+m,`.k-timeduration-footer button.k-time-accept`,this._setClickHandler.bind(this)),e._listContainer.on(`mouseover`+m,`.k-time-list-wrapper`,this._mouseOverHandler.bind(this))},_applyShortCut:function(t){t.preventDefault(),this._value=parseInt(e(t.currentTarget).attr(n.attr(`value`))),this.options.change(this._value),this.popup.close(),this.options.focus()},_scrollerKeyDownHandler:function(t){var r=this,i=t.keyCode,a=e(t.currentTarget).find(`.k-time-list-wrapper.k-focus`),o=r._listContainer.find(`.k-time-list-wrapper`),s=o.length,c=o.index(a),l=n.support.isRtl(r.wrapper),u=x(a.find(`.k-item:visible`).eq(0)),d=a.find(`.k-time-container.k-content.k-scrollable`);if(a.length){if((i==p.UP||i==p.DOWN)&&t.altKey){t.preventDefault(),r.toggle(),setTimeout(function(){r.popup.visible()||r.options.focus()},100);return}i==p.RIGHT&&!l||i==p.LEFT&&l?c+1<s&&r._focusList(o.eq(c+1)):i==p.LEFT&&!l||i==p.RIGHT&&l?c-1>=0&&r._focusList(o.eq(c-1)):i==p.UP?(d.scrollTop(d.scrollTop()-u),t.preventDefault()):i==p.DOWN?(d.scrollTop(d.scrollTop()+u),t.preventDefault()):i===p.ENTER?r._setClickHandler(t):i===p.ESC&&r._cancelClickHandler(t)}},_mouseOverHandler:function(t){this._focusList(e(t.currentTarget))},_focusList:function(e){this._listContainer.find(`.k-time-list-wrapper`).removeClass(f),e.addClass(f),this._listContainer.trigger(`focus`),this._scrollTop=e.find(`.k-scrollable`).scrollTop()},_setClickHandler:function(t){e(n._activeElement()).attr(n.attr(`value`))||(t.preventDefault(),this._value=v(this._currentValues),this.options.change(this._value),this.popup.close(),this.options.focus())},_cancelClickHandler:function(t){e(n._activeElement()).attr(n.attr(`value`))||(t.preventDefault(),this.popup.close(),this.options.focus())},_itemClickHandler:function(t){var n=e(t.originalEvent.currentTarget),r=n.find(`.k-item:visible`).index(e(t.currentTarget)),i=x(n.find(`.k-item:visible`).eq(0));n.scrollTop(r*i)},_listScrollHandler:function(t){var n=this,r=x(e(t.currentTarget).find(`.k-item:visible`).eq(0));n._internalScroll||(n._scrollingTimeout&&clearTimeout(n._scrollingTimeout),n._scrollingTimeout=setTimeout(function(){t.currentTarget.scrollTop%r>1&&(t.currentTarget.scrollTop+=r-t.currentTarget.scrollTop%r),n._scrollTop=t.currentTarget.scrollTop,n._updateCurrentlySelected()},100))},_findSelectedValue:function(e){var t=b(e.scrollTop(),x(e.find(`.k-item:visible`).eq(0)));return e.find(`.k-item:visible`).eq(t).attr(`data-value`)},_updateCurrentlySelected:function(){var t=this,n=this._listsContainer.find(`.k-content.k-scrollable`);this._listsContainer.is(`:visible`)&&(t._currentValues={},n.each(function(){var n=e(this);t._currentValues[n.attr(`data-name`)]=parseInt(t._findSelectedValue(n))}))},_scrollListToPosition:function(e,t){var n=e.find(`.k-item[data-value="`+t+`"]`),r=x(n);e.scrollTop(e.find(`.k-item:visible`).index(n)*r)},_renderList:function(t,r){if(r){for(var i=this,a=e(g({name:r.name,title:i.options.messages[r.name]})),o=``,s=r.min;s<=r.max;s+=r.step)o+=h({value:n.format(r.selectorFormat,s)});a.find(`ul`).html(o),a.appendTo(t)}},_columns:function(){var e=this,t,n=e.options;if(e._listsContainer)for(var r=0;r<n.columns.length;r++)t=n.columns[r],e._renderList(e._listsContainer,t)},_shortCuts:function(){var t=this,r=t.options,i;if(t._shortcuts)for(var a=0;a<r.shortcuts.length;a++)i=r.shortcuts[a],e(o.renderButton(`<button class="k-button ${n.getValidCssClass(`k-button-`,`size`,t.options.size)}">`+i.text+`</button>`,{rounded:r.rounded})).attr(n.attr(`value`),i.value).appendTo(t._shortcuts)},_buttons:function(t){let n=this,r=n.options,a=e(`<div class='k-actions k-actions-stretched k-actions-horizontal k-timeduration-footer'>`+o.renderButton(`<button class="k-time-cancel k-button">`+i(r.messages.cancel)+`</button>`,{rounded:r.rounded,size:r.size})+o.renderButton(`<button class="k-time-accept">`+i(r.messages.set)+`</button>`,{rounded:r.rounded,size:r.size,themeColor:`primary`})+`</div>`);return t&&a.appendTo(n._timeSelectorWrapper),a},_wrappers:function(){var t=this,r=t.options;t._timeSelectorWrapper=e(`<div></div>`),t._listContainer=e(`<div tabindex='0' class='k-timeselector ${n.getValidCssClass(`k-timeselector-`,`size`,t.options.size)}'></div>`),t._listContainer.appendTo(t._timeSelectorWrapper),r.shortcuts&&(t._shortcuts=e(`<div class='k-actions k-actions-start k-actions-horizontal k-time-fast-selection'></div>`).appendTo(t._listContainer)),r.columns.length&&(t._listsContainer=e(`<div class='k-time-list-container'><span class='k-time-highlight'></span></div>`).appendTo(t._listContainer),t._listsContainer.attr(`id`,r.id))},_popup:function(){var e=this,t=e.options;t.adaptiveMode==`auto`&&!e.bigScreenMQL.mediaQueryList.matches?(e._timeSelectorWrapper.appendTo(document.body),e.popup=new r.ActionSheet(e._timeSelectorWrapper,{adaptive:!0,title:t.adaptiveTitle||`Set time`,subtitle:t.adaptiveSubtitle,closeButton:{icon:`check`,themeColor:`primary`},footerTemplate:e._buttons.bind(e),fullscreen:e.smallScreenMQL.mediaQueryList.matches,popup:s(!0,{},t.popup,{anchor:t.anchor,open:t.open,close:t.close,isRtl:n.support.isRtl(t.anchor)}),activate:function(){e.addTranslate(),e._value?e.applyValue(e._value):e._updateCurrentlySelected(),e._focusList(e._listContainer.find(`.k-time-list-wrapper`).eq(0))}})):e.popup=new r.Popup(e._timeSelectorWrapper,s(!0,{},t.popup,{anchor:t.anchor,open:t.open,close:t.close,isRtl:n.support.isRtl(t.anchor),activate:function(){e.addTranslate(),e._value?e.applyValue(e._value):e._updateCurrentlySelected(),e._focusList(e._listContainer.find(`.k-time-list-wrapper`).eq(0))}}))}});function v(e){return(e.days||0)*864e5+(e.hours||0)*36e5+(e.minutes||0)*6e4+(e.seconds||0)*1e3+(e.milliseconds||0)}function y(e){var t,n=Math.floor(e/864e5);t=e%864e5;var r=Math.floor(t/36e5);t=e%36e5;var i=Math.floor(t/6e4);t=e%6e4;var a=Math.floor(t/1e3);return t=e%1e3,{days:n,hours:r,minutes:i,seconds:a,milliseconds:t}}function b(e,t){return Math.max(Math.round(e/t),0)}function x(e){return e.length&&e[0].getBoundingClientRect().height}r.plugin(_)})(window.kendo.jQuery);var a=kendo;e.__meta__=i,e.default=a});
//# sourceMappingURL=kendo.timeselector.min.js.map