-
Notifications
You must be signed in to change notification settings - Fork 7
/
duration-picker.min.js
1 lines (1 loc) · 2.59 KB
/
duration-picker.min.js
1
!function(i){function t(i,t){for(var e in Object.keys(i))-1!=t.stages.indexOf(Object.keys(i)[e])&&t.jqitem.find("#duration-"+Object.keys(i)[e]).val(i[Object.keys(i)[e]])}function e(i){var t=[];for(var e in Object.keys(i))-1==["classname","responsive","type"].indexOf(Object.keys(i)[e])&&t.push(Object.keys(i)[e]);return t}function n(i,t){var e='<div class="durationpicker-container '+i.classname+'">',n=i.type;for(var s in t)e+='<div class="durationpicker-innercontainer"><input min="'+i[t[s]].min+'" max="'+i[t[s]].max+'" placeholder="0" type="'+n+'" id="duration-'+t[s]+'" class="durationpicker-duration" ><span class="durationpicker-label">'+i[t[s]].label+"</span></div>";return e+="</div>"}var s=function(t,s){this.settings=s,this.stages=e(this.settings),this.template=n(this.settings,this.stages),this.jqitem=i(this.template),this.jqchildren=this.jqitem.children(),this.element=i(t),this.setup(),this.resize(),this.jqchildren.find(".durationpicker-duration").trigger("change")};s.prototype={constructor:s,setup:function(){this.element.before(this.jqitem),this.element.hide(),this.jqchildren.find(".durationpicker-duration").on("change",{ths:this},function(t){var e=t.data.ths.element,n="";i(this).parent().parent().find("input").each(function(){var t=i(this),e=0;null!=t.val()&&""!=t.val()&&(e=t.val()),n+=e+" "+t.next().text()+","}),n=n.slice(0,-1),e.val(n)}),i(".durationpicker-duration").trigger("change"),window.addEventListener("resize",this.resize.bind(this))},resize:function(){if(this.settings.responsive){var t=parseInt(this.jqitem.css("padding-left").split("px")[0])+parseInt(this.jqitem.css("padding-right").split("px")[0]),e=t,n=t;this.jqchildren.each(function(){var t=i(this);e+=t.outerWidth(),n+=t.outerHeight()}),this.jqitem.parent().width()<e?(this.jqchildren.each(function(){i(this).css("display","block")}),this.jqitem.css("height",n)):this.jqchildren.each(function(){i(this).css("display","inline-block")})}},getitem:function(){return this.jqitem},setvalues:function(e){t(e,this),i(".durationpicker-duration").trigger("change")},disable:function(){this.jqchildren.children("input").each(function(i,t){t.readOnly=!0})},enable:function(){this.jqchildren.children("input").each(function(i,t){t.readOnly=!1})}},i.fn.durationPicker=function(t){if(void 0==t)e=i.extend(!0,{},i.fn.durationPicker.defaults,t);else var e=i.extend(!0,{},{classname:"form-control",responsive:!0,type:"number"},t);return new s(this,e)},i.fn.durationPicker.defaults={hours:{label:"h",min:0,max:24},minutes:{label:"m",min:0,max:59},seconds:{label:"s",min:0,max:59},classname:"form-control",type:"number",responsive:!0},i.fn.durationPicker.Constructor=s}(jQuery);