diff --git a/build/ImagePreviewGroup/ImagePreviewGroup.js b/build/ImagePreviewGroup/ImagePreviewGroup.js index 4ccda4d..da0c34c 100644 --- a/build/ImagePreviewGroup/ImagePreviewGroup.js +++ b/build/ImagePreviewGroup/ImagePreviewGroup.js @@ -7,8 +7,11 @@ angular restrict: "E", transclude: true, replace: true, + scope: { + preview: "=", + }, template: template, - controller: function ($scope, $element) { + controller: function ($scope, $element, $attrs) { this.getContext = function () { return $scope; }; @@ -25,36 +28,66 @@ angular return $scope.state.childrens.length - 1; }; + $scope.setCurrent = function (value) { + $scope.state.current = value; + + if ( + typeof $scope.preview === "object" && + typeof $scope.preview.onCurrentChange === "function" + ) { + $scope.preview.onCurrentChange(value); + } + }; + + $scope.setVisible = function (value) { + $scope.state.visible = value; + + if ( + typeof $scope.preview === "object" && + typeof $scope.preview.onVisibleChange === "function" + ) { + $scope.preview.onVisibleChange(value); + } + }; + $scope.handleOpen = function (index) { - $scope.state.current = index; + $scope.setCurrent(index); $scope.state.src = $scope.state.childrens[index].state.src; - $scope.state.visible = true; + $scope.setVisible(true); }; $scope.handleClose = function () { - $scope.state.visible = false; + $scope.setVisible(false); }; $scope.handlePrev = function () { - $scope.state.current = - $scope.state.current > 0 ? $scope.state.current - 1 : 0; + $scope.setCurrent( + $scope.state.current > 0 ? $scope.state.current - 1 : 0 + ); $scope.state.src = $scope.state.childrens[$scope.state.current].state.src; }; $scope.handleNext = function () { - $scope.state.current = + $scope.setCurrent( $scope.state.current < $scope.state.childrens.length - 1 ? $scope.state.current + 1 - : $scope.state.childrens.length - 1; + : $scope.state.childrens.length - 1 + ); $scope.state.src = $scope.state.childrens[$scope.state.current].state.src; }; $scope.handlePreview = function () { + let className; + + if ($attrs.class) { + className = ` ${$attrs.class}`; + } + esNgAntd.createLayer( ` -