-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui-bootstrap-ratings.min.js
1 lines (1 loc) · 8.11 KB
/
ui-bootstrap-ratings.min.js
1
angular.module("ui.bootstrap.ratings",["ui.bootstrap.transition","ui.bootstrap.collapse","ui.bootstrap.progressbar","ui.bootstrap.rating","template/progressbar/progressbar.html","template/rating/rating.html"]);angular.module("ui.bootstrap.transition",[]).factory("$transition",["$q","$timeout","$rootScope",function($q,$timeout,$rootScope){var $transition=function(element,trigger,options){options=options||{};var deferred=$q.defer();var endEventName=$transition[options.animation?"animationEndEventName":"transitionEndEventName"];var transitionEndHandler=function(event){$rootScope.$apply(function(){element.unbind(endEventName,transitionEndHandler);deferred.resolve(element)})};if(endEventName){element.bind(endEventName,transitionEndHandler)}$timeout(function(){if(angular.isString(trigger)){element.addClass(trigger)}else if(angular.isFunction(trigger)){trigger(element)}else if(angular.isObject(trigger)){element.css(trigger)}if(!endEventName){deferred.resolve(element)}});deferred.promise.cancel=function(){if(endEventName){element.unbind(endEventName,transitionEndHandler)}deferred.reject("Transition cancelled")};return deferred.promise};var transElement=document.createElement("trans");var transitionEndEventNames={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",transition:"transitionend"};var animationEndEventNames={WebkitTransition:"webkitAnimationEnd",MozTransition:"animationend",OTransition:"oAnimationEnd",transition:"animationend"};function findEndEventName(endEventNames){for(var name in endEventNames){if(transElement.style[name]!==undefined){return endEventNames[name]}}}$transition.transitionEndEventName=findEndEventName(transitionEndEventNames);$transition.animationEndEventName=findEndEventName(animationEndEventNames);return $transition}]);angular.module("ui.bootstrap.collapse",["ui.bootstrap.transition"]).directive("collapse",["$transition",function($transition){return{link:function(scope,element,attrs){var initialAnimSkip=true;var currentTransition;function doTransition(change){var newTransition=$transition(element,change);if(currentTransition){currentTransition.cancel()}currentTransition=newTransition;newTransition.then(newTransitionDone,newTransitionDone);return newTransition;function newTransitionDone(){if(currentTransition===newTransition){currentTransition=undefined}}}function expand(){if(initialAnimSkip){initialAnimSkip=false;expandDone()}else{element.removeClass("collapse").addClass("collapsing");doTransition({height:element[0].scrollHeight+"px"}).then(expandDone)}}function expandDone(){element.removeClass("collapsing");element.addClass("collapse in");element.css({height:"auto"})}function collapse(){if(initialAnimSkip){initialAnimSkip=false;collapseDone();element.css({height:0})}else{element.css({height:element[0].scrollHeight+"px"});var x=element[0].offsetWidth;element.removeClass("collapse in").addClass("collapsing");doTransition({height:0}).then(collapseDone)}}function collapseDone(){element.removeClass("collapsing");element.addClass("collapse")}scope.$watch(attrs.collapse,function(shouldCollapse){if(shouldCollapse){collapse()}else{expand()}})}}}]);angular.module("ui.bootstrap.progressbar",[]).constant("progressConfig",{animate:true,max:100}).controller("ProgressController",["$scope","$attrs","progressConfig",function($scope,$attrs,progressConfig){var self=this,animate=angular.isDefined($attrs.animate)?$scope.$parent.$eval($attrs.animate):progressConfig.animate;this.bars=[];$scope.max=angular.isDefined($attrs.max)?$scope.$parent.$eval($attrs.max):progressConfig.max;this.addBar=function(bar,element){if(!animate){element.css({transition:"none"})}this.bars.push(bar);bar.$watch("value",function(value){bar.percent=+(100*value/$scope.max).toFixed(2)});bar.$on("$destroy",function(){element=null;self.removeBar(bar)})};this.removeBar=function(bar){this.bars.splice(this.bars.indexOf(bar),1)}}]).directive("progress",function(){return{restrict:"EA",replace:true,transclude:true,controller:"ProgressController",require:"progress",scope:{},templateUrl:"template/progressbar/progress.html"}}).directive("bar",function(){return{restrict:"EA",replace:true,transclude:true,require:"^progress",scope:{value:"=",type:"@"},templateUrl:"template/progressbar/bar.html",link:function(scope,element,attrs,progressCtrl){progressCtrl.addBar(scope,element)}}}).directive("progressbar",function(){return{restrict:"EA",replace:true,transclude:true,controller:"ProgressController",scope:{value:"=",type:"@"},templateUrl:"template/progressbar/progressbar.html",link:function(scope,element,attrs,progressCtrl){progressCtrl.addBar(scope,angular.element(element.children()[0]))}}});angular.module("ui.bootstrap.rating",[]).constant("ratingConfig",{max:5,stateOn:null,stateOff:null}).controller("RatingController",["$scope","$attrs","ratingConfig",function($scope,$attrs,ratingConfig){var ngModelCtrl={$setViewValue:angular.noop};this.init=function(ngModelCtrl_){ngModelCtrl=ngModelCtrl_;ngModelCtrl.$render=this.render;this.stateOn=angular.isDefined($attrs.stateOn)?$scope.$parent.$eval($attrs.stateOn):ratingConfig.stateOn;this.stateOff=angular.isDefined($attrs.stateOff)?$scope.$parent.$eval($attrs.stateOff):ratingConfig.stateOff;var ratingStates=angular.isDefined($attrs.ratingStates)?$scope.$parent.$eval($attrs.ratingStates):new Array(angular.isDefined($attrs.max)?$scope.$parent.$eval($attrs.max):ratingConfig.max);$scope.range=this.buildTemplateObjects(ratingStates)};this.buildTemplateObjects=function(states){for(var i=0,n=states.length;i<n;i++){states[i]=angular.extend({index:i},{stateOn:this.stateOn,stateOff:this.stateOff},states[i])}return states};$scope.rate=function(value){if(!$scope.readonly&&value>=0&&value<=$scope.range.length){ngModelCtrl.$setViewValue(value);ngModelCtrl.$render()}};$scope.enter=function(value){if(!$scope.readonly){$scope.value=value}$scope.onHover({value:value})};$scope.reset=function(){$scope.value=ngModelCtrl.$viewValue;$scope.onLeave()};$scope.onKeydown=function(evt){if(/(37|38|39|40)/.test(evt.which)){evt.preventDefault();evt.stopPropagation();$scope.rate($scope.value+(evt.which===38||evt.which===39?1:-1))}};this.render=function(){$scope.value=ngModelCtrl.$viewValue}}]).directive("rating",function(){return{restrict:"EA",require:["rating","ngModel"],scope:{readonly:"=?",onHover:"&",onLeave:"&"},controller:"RatingController",templateUrl:"template/rating/rating.html",replace:true,link:function(scope,element,attrs,ctrls){var ratingCtrl=ctrls[0],ngModelCtrl=ctrls[1];if(ngModelCtrl){ratingCtrl.init(ngModelCtrl)}}}});angular.module("template/progressbar/bar.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/progressbar/bar.html",'<div class="progress-bar" ng-class="type && \'progress-bar-\' + type" role="progressbar" aria-valuenow="{{value}}" aria-valuemin="0" aria-valuemax="{{max}}" ng-style="{width: percent + \'%\'}" aria-valuetext="{{percent | number:0}}%" ng-transclude></div>')}]);angular.module("template/progressbar/progress.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/progressbar/progress.html",'<div class="progress" ng-transclude></div>')}]);angular.module("template/progressbar/progressbar.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/progressbar/progressbar.html",'<div class="progress">\n'+' <div class="progress-bar" ng-class="type && \'progress-bar-\' + type" role="progressbar" aria-valuenow="{{value}}" aria-valuemin="0" aria-valuemax="{{max}}" ng-style="{width: percent + \'%\'}" aria-valuetext="{{percent | number:0}}%" ng-transclude></div>\n'+"</div>")}]);angular.module("template/rating/rating.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/rating/rating.html",'<span ng-mouseleave="reset()" ng-keydown="onKeydown($event)" tabindex="0" role="slider" aria-valuemin="0" aria-valuemax="{{range.length}}" aria-valuenow="{{value}}">\n'+' <i ng-repeat="r in range track by $index" ng-mouseenter="enter($index + 1)" ng-click="rate($index + 1)" class="glyphicon" ng-class="$index < value && (r.stateOn || \'glyphicon-star\') || (r.stateOff || \'glyphicon-star-empty\')">\n'+" <span class=\"sr-only\">({{ $index < value ? '*' : ' ' }})</span>\n"+" </i>\n"+"</span>")}]);