-
Notifications
You must be signed in to change notification settings - Fork 26
/
range-picker.min.js
1 lines (1 loc) · 4.74 KB
/
range-picker.min.js
1
"use strict";angular.module("rgkevin.datetimeRangePicker",["vr.directives.slider"]).filter("rgTime",[function(){return function(input,type){var hours=parseInt(input/60,10),minutes=10>input-60*hours?"0"+(input-60*hours):input-60*hours,meridian=type?":00":hours>=12&&24!==hours?" pm":" am";return(!type&&hours>12?24===hours?"00":(10>hours-12?"0":"")+(hours-12):(10>hours?"0":"")+hours)+":"+minutes+meridian}}]).directive("rgRangePicker",["$compile","$timeout","$filter",function($compile,$timeout,$filter){return{restrict:"A",scope:{data:"=rgRangePicker",labels:"=",onTimeChange:"&",maxRangeDate:"=",vertical:"="},template:function(){return'<div class="rg-range-picker" ng-class="{\'rg-range-picker-vertical\':vertical}"><div class="rg-range-picker-box well" ng-class="{ \'only-calendars\': !data.hasTimeSliders, \'only-slider\': !data.hasDatePickers }"><div class="rg-range-picker-calendars" ng-show="data.hasDatePickers"><div class="rg-range-picker-calendar-box"><h5 class="rg-range-picker-calendar-label" ng-bind-template="{{datepickerTitles.from}}"></h5><datepicker ng-model="data.date.from" max-date="data.date.to" min-date="data.date.min" show-weeks="false" class="clean-calendar"></datepicker></div><div class="rg-range-picker-calendar-box right"><h5 class="rg-range-picker-calendar-label" ng-bind-template="{{datepickerTitles.to}}"></h5><datepicker ng-model="data.date.to" min-date="data.date.from" max-date="data.date.max" show-weeks="false" class="clean-calendar"></datepicker></div></div><div class="rg-range-picker-slider" id="rgRangePickerSliderContainer" ng-show="data.hasTimeSliders"><div class="rg-range-picker-slider-labels"><div class="row"><div class="rg-range-picker-divider xs-hidden"><span class="label">to</span></div><div class="col-xs-6 text-center"><span class="label label-range-picker">{{data.time.from | rgTime:data.time.hours24}}</span></div><div class="col-xs-6 text-center"><span class="label label-range-picker">{{data.time.to | rgTime:data.time.hours24}}</span></div></div></div></div></div></div>'},link:function(scope,element,attrs){function renderSlider(){!sliderAlreadyRender&&scope.data.hasTimeSliders&&(sliderContainer.append(slider),$compile(slider)(scope),sliderAlreadyRender=!0,element.width()<=sliderMinWidth&&angular.element(".rg-range-picker",element[0]).addClass("rg-range-picker-responsive"))}function timeChanges(newValue,oldValue){angular.isUndefined(timeChangePromise)||$timeout.cancel(timeChangePromise),newValue!==oldValue&&(timeChangePromise=$timeout(function(){scope.onTimeChange()({from:$filter("rgTime")(scope.data.time.from,!0),to:$filter("rgTime")(scope.data.time.to,!0),range:$filter("rgTime")(scope.data.time.to-scope.data.time.from,!0)})},500))}function updateMinAndMaxDate(){var currentRange=scope.data.date.to.getTime()-scope.data.date.from.getTime(),offset=maxRange-currentRange,_min=scope.data.date.from.getTime()-offset<superMinDate?superMinDate:scope.data.date.from.getTime()-offset,_max=scope.data.date.to.getTime()+offset>superMaxDate?superMaxDate:scope.data.date.to.getTime()+offset;scope.data.date.min=new Date(_min),scope.data.date.max=new Date(_max)}var timeChangePromise,sliderMinWidth=400,sliderContainer=angular.element("#rgRangePickerSliderContainer",element[0]),slider=angular.element('<div slider class="clean-slider" ng-model="data.time.from" ng-model-range="data.time.to" floor="{{data.time.dFrom}}" ceiling="{{data.time.dTo}}" buffer="{{data.time.minRange || 1}}" step="{{data.time.step || 1}}" step-width="{{data.time.step || 1}}" precision="0" stretch="3"></div>'),sliderAlreadyRender=!1,defaultLabels={date:{from:"START_DATE",to:"END_DATE"}},timeDefaults={from:480,to:1020,dFrom:0,dTo:1440,step:15,minRange:15,hours24:!0},dateDefaults={from:new Date,to:new Date,min:null,max:null};scope.data.hasDatePickers=angular.isObject(scope.data.date),scope.data.hasTimeSliders=angular.isObject(scope.data.time),scope.datepickerTitles=angular.extend(defaultLabels.date,scope.labels&&scope.labels.date),scope.data.hasDatePickers&&(scope.data.date=angular.extend(dateDefaults,scope.data.date)),scope.data.hasTimeSliders&&(scope.data.time=angular.extend(timeDefaults,scope.data.time)),attrs.collapse?scope.$watch(function(){return element[0].className},function(){element.hasClass("in")&&renderSlider()}):renderSlider(),!angular.isUndefined(scope.onTimeChange())&&scope.data.hasTimeSliders&&(scope.$watch("data.time.from",timeChanges),scope.$watch("data.time.to",timeChanges));var maxRange=864e5*(scope.maxRangeDate&&scope.maxRangeDate-1||0),superMaxDate=scope.data.date&&scope.data.date.max&&scope.data.date.max.getTime(),superMinDate=scope.data.date&&scope.data.date.min&&scope.data.date.min.getTime();scope.maxRangeDate&&scope.data.hasDatePickers&&(scope.$watch("data.date.from",updateMinAndMaxDate),scope.$watch("data.date.to",updateMinAndMaxDate))},controller:function(){}}}]);