/*!***********************************************
 Copyright (c) 2019, Neusoft Inc.
 All rights reserved
 图表秀 Version 1.0.0 2019.9.3
 ************************************************/
"use strict";angular.module("common.dvAccordion",["ui.bootstrap.transition"]).constant("dvAccordionConfig",{closeOthers:!0}).run(["$templateCache",function(n){n.put("dv-accordion.html",'<div class="dv-accordion-group" ng-transclude></div>'),n.put("dv-accordion-chart.html",'<div class="dv-accordion-group-chart" ng-transclude></div>'),n.put("dv-accordion-group.html",'<div class="panel panel-default">\n  <div class="panel-heading">\n    <h4 class="panel-title">\n      <div class="accordion-toggle" ng-click="toggleOpen()" dv-accordion-transclude="heading"><span ng-class="{\'text-muted\': isDisabled}">{{heading}}</span></div>\n    </h4>\n  </div>\n  <div class="panel-collapse" dv-collapse="!isOpen">\n\t  <div class="panel-body" ng-transclude></div>\n  </div>\n</div>\n')}]).controller("dvAccordionController",["$scope","$attrs","dvAccordionConfig",function(n,o,e){this.groups=[],this.closeOthers=function(e){(angular.isDefined(o.closeOthers)?n.$eval(o.closeOthers):accordionConfig.closeOthers)&&angular.forEach(this.groups,function(n){n!==e&&(n.isOpen=!1)})},this.afterClose=function(e){(angular.isDefined(o.closeOthers)?n.$eval(o.closeOthers):accordionConfig.closeOthers)&&(angular.forEach(this.groups,function(n){n===e||n.isDisabled||(n.isOpen=!0)}),e.isOpen=!0)},this.addGroup=function(e){var o=this;this.groups.push(e),e.$on("$destroy",function(n){o.removeGroup(e)})},this.removeGroup=function(n){var e=this.groups.indexOf(n);-1!==e&&this.groups.splice(e,1)},this.getGroupCount=function(){return this.groups.length}}]).directive("dvAccordion",function(){return{restrict:"EA",controller:"dvAccordionController",controllerAs:"accordion",transclude:!0,replace:!1,templateUrl:"dv-accordion.html",link:function(n,e,o,i){function t(){var n=e.parent().height();i.panelBodyHeight=n-i.panelHeadingHeight*i.getGroupCount()}n.$on("$destroy",function(){$(window).off("resize",t)}),i.panelHeadingHeight=e.find(".panel-heading").first().outerHeight(!0),setTimeout(t,0),$(window).on("resize",t)}}}).directive("dvAccordionChart",function(){return{restrict:"EA",controller:"dvAccordionController",controllerAs:"accordion",transclude:!0,replace:!1,templateUrl:"dv-accordion-chart.html",link:function(n,e,o,i){function t(){var n=e.parent().height();i.panelBodyHeight=n-i.panelHeadingHeight*i.getGroupCount()}n.$on("$destroy",function(){$(window).off("resize",t)}),i.panelHeadingHeight=e.find(".panel-heading").first().outerHeight(!0),setTimeout(t,0),$(window).on("resize",t)}}}).directive("dvAccordionGroup",function(){return{require:"^dvAccordion",restrict:"EA",transclude:!0,replace:!0,templateUrl:"dv-accordion-group.html",scope:{heading:"@",isOpen:"=?",isDisabled:"=?"},controller:function(){this.setHeading=function(n){this.heading=n}},link:function(e,n,o,i){i.addGroup(e);n.find(".panel-heading").outerHeight(!0);e.$watch("isOpen",function(n){n&&i.closeOthers(e)}),e.toggleOpen=function(){e.isDisabled||(e.isOpen=!e.isOpen,e.isOpen||i.afterClose(e))}}}}).directive("dvAccordionHeading",function(){return{restrict:"EA",transclude:!0,template:"",replace:!0,require:"^dvAccordionGroup",link:function(n,e,o,i,t){i.setHeading(t(n,function(){}))}}}).directive("dvAccordionTransclude",function(){return{require:"^dvAccordionGroup",link:function(n,e,o,i){n.$watch(function(){return i[o.dvAccordionTransclude]},function(n){n&&(e.html(""),e.append(n))})}}}).directive("dvCollapse",["$transition",function(d){return{require:"^dvAccordion",link:function(n,i,e,o){var t,c=!0;function r(n){var e=d(i,n);return t&&t.cancel(),(t=e).then(o,o),e;function o(){t===e&&(t=void 0)}}function s(){i.children(".panel-body").css({overflowY:"hidden"}),i.removeClass("collapsing"),i.addClass("collapse in"),i.parent().css({height:"calc(100% - "+o.panelHeadingHeight*(o.getGroupCount()-1)+"px)"}),i.css({height:"calc(100% - "+o.panelHeadingHeight+"px)"}),n.$broadcast("accordion-expand-done")}function a(){i.children(".panel-body").css({overflowY:"auto"}),i.removeClass("collapsing"),i.addClass("collapse")}n.$watch(e.dvCollapse,function(n){n?c?(c=!1,a(),i.css({height:0})):(i.parent().css({height:"auto"}),i.css({height:o.panelBodyHeight+"px"}),setTimeout(function(){i[0].offsetWidth,i.children(".panel-body").css({overflowY:"hidden"}),i.removeClass("collapse in").addClass("collapsing"),r({height:0}).then(a)},0)):c?(c=!1,s()):(i.children(".panel-body").css({overflowY:"hidden"}),i.removeClass("collapse").addClass("collapsing"),r({height:o.panelBodyHeight+"px"}).then(s))})}}}]);