-
Notifications
You must be signed in to change notification settings - Fork 37
/
jquery.businessHours.min.js
7 lines (6 loc) · 2.75 KB
/
jquery.businessHours.min.js
1
2
3
4
5
6
7
/*!
* jquery.businessHours v1.0.1 - jQuery plugin allows you to easy show & manage business hours
* Copyright (c) 2015 Alex Padalka - http://gendelf.github.io/jquery.businessHours/
* License: APACHE
*/
!function(a){a.fn.businessHours=function(b){function c(a,b,c){a.val(b),c&&a.prop("readonly",!0)}var d={preInit:function(){},postInit:function(){},inputDisabled:!1,checkedColorClass:"WorkingDayState",uncheckedColorClass:"RestDayState",colorBoxValContainerClass:"colorBoxContainer",weekdays:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],operationTime:[{},{},{},{},{},{isActive:!1},{isActive:!1}],defaultOperationTimeFrom:"9:00",defaultOperationTimeTill:"18:00",defaultActive:!0,containerTmpl:'<div class="clean"/>',dayTmpl:'<div class="dayContainer"><div data-original-title="" class="colorBox"><input type="checkbox" class="invisible operationState"/></div><div class="weekday"></div><div class="operationDayTimeContainer"><div class="operationTime"><input type="text" name="startTime" class="mini-time operationTimeFrom" value=""/></div><div class="operationTime"><input type="text" name="endTime" class="mini-time operationTimeTill" value=""/></div></div></div>'},e=a(this),f={getValueOrDefault:function(a,b){return"undefined"===jQuery.type(a)||null==a?b:a},init:function(b){return this.options=a.extend(d,b),e.html(""),"function"==typeof this.options.preInit&&this.options.preInit(),this.initView(this.options),"function"==typeof this.options.postInit&&this.options.postInit(),{serialize:function(){var b=[];return e.find(".operationState").each(function(c,d){var e=a(d).prop("checked"),f=a(d).parents(".dayContainer");b.push({isActive:e,timeFrom:e?f.find("[name='startTime']").val():null,timeTill:e?f.find("[name='endTime']").val():null})}),b}}},initView:function(b){for(var d=[b.checkedColorClass,b.uncheckedColorClass],f=e.append(a(b.containerTmpl)),g=this,h=0;h<b.weekdays.length;h++)f.append(b.dayTmpl);a.each(b.weekdays,function(a,d){var f=b.operationTime[a],h=e.find(".dayContainer").eq(a);h.find(".weekday").html(d);var i=g.getValueOrDefault(f.isActive,b.defaultActive);h.find(".operationState").prop("checked",i);var j=g.getValueOrDefault(f.timeFrom,b.defaultOperationTimeFrom);c(h.find('[name="startTime"]'),j,b.inputDisabled);var k=g.getValueOrDefault(f.timeTill,b.defaultOperationTimeTill);c(h.find('[name="endTime"]'),k,b.inputDisabled)}),e.find(".operationState").change(function(){var c=a(this),e=b.checkedColorClass,f=!1;c.prop("checked")||(e=b.uncheckedColorClass,f=!0),c.parents(".colorBox").removeClass(d.join(" ")).addClass(e),c.parents(".dayContainer").find(".operationTime").toggle(!f)}).trigger("change"),b.inputDisabled||e.find(".colorBox").on("click",function(){var b=a(this).find(".operationState");b.prop("checked",!b.prop("checked")).trigger("change")})}};return f.init(b)}}(jQuery);