Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 2cb962e

Browse files
committed
Merge pull request #23 from appirio-tech/auto-bg
Show small images in actual size & prevent zoom
2 parents b9fdf35 + 57810d9 commit 2cb962e

File tree

6 files changed

+73
-5
lines changed

6 files changed

+73
-5
lines changed

example/images/shortimage.png

24.2 KB
Loading

example/scripts/controllers/image-viewer-example.controller.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ ImageViewerExampleController = ($scope, $stateParams) ->
2929
path: "work/1447877190406-e9c02ed7-00bf-4e52-8c57-4d73fec009ac/fe819b7d-2534-4878-994b-35f7b2fec185/Screen Shot 2015-12-01 at 12.35.18 PM.png",
3030
caption: "this is another one of the images",
3131
url: require "../../images/turtles-breaking.jpg"
32+
},
33+
{
34+
fileId: "nop",
35+
path: "work/1447877190406-e9c02ed7-00bf-4e52-8c57-4d73fec009ac/fe819b7d-2534-4878-994b-35f7b2fec185/Screen Shot 2015-12-01 at 12.35.18 PM.png",
36+
caption: "this is another one too",
37+
url: require "../../images/shortimage.png"
3238
}
3339
]
3440

src/scripts/controllers/image-viewer.controller.coffee

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ ImageViewerController = ($scope) ->
66
vm.showNotifications = $scope.showNotifications
77
startingFile = $scope.startingFile
88
vm.onFileChange = $scope.onFileChange
9+
vm.imageZoomedIn = false
910
vm.prevFile = null
1011
vm.nextFile = null
11-
vm.imageZoomedIn = false
12+
vm.showSmallImage = false
13+
$scope.setAutoBg = false
14+
1215

1316
updateFiles = ->
1417
if vm.currentIndex + 1 < vm.files.length
@@ -32,6 +35,11 @@ ImageViewerController = ($scope) ->
3235

3336
vm.onFileChange({file: vm.file}) if vm.onFileChange
3437

38+
$scope.setAutoBg = true
39+
40+
$scope.$watch 'showSmallImage', (newVal, OldVal) ->
41+
vm.showSmallImage = newVal
42+
3543
vm.viewNext = ->
3644
vm.file = vm.files[vm.currentIndex + 1]
3745

@@ -43,6 +51,8 @@ ImageViewerController = ($scope) ->
4351

4452
vm.onFileChange({file: vm.file}) if vm.onFileChange
4553

54+
$scope.setAutoBg = true
55+
4656

4757
vm.viewPrevious = ->
4858
vm.file = vm.files[vm.currentIndex - 1]
@@ -55,6 +65,9 @@ ImageViewerController = ($scope) ->
5565

5666
vm.onFileChange({file: vm.file}) if vm.onFileChange
5767

68+
$scope.setAutoBg = true
69+
70+
5871
vm.selectFile = (file) ->
5972
vm.file = file
6073

@@ -66,6 +79,9 @@ ImageViewerController = ($scope) ->
6679

6780
vm.onFileChange({file: vm.file}) if vm.onFileChange
6881

82+
$scope.setAutoBg = true
83+
84+
6985
vm.isCurrent = (file) ->
7086
(vm.files.indexOf file) == vm.currentIndex
7187

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
11
'use strict'
22

3-
directive = ->
3+
directive = ($window)->
4+
link = (scope, element, attrs) ->
5+
checkHeights = ->
6+
container = $('.img-container')
7+
backgroundContainer = $('.bg-image')[0]
8+
containerHeight = container.height()
9+
containerWidth = container.width()
10+
11+
image = container.find('img')
12+
imageHeight = image.attr('height')
13+
imageWidth = image.attr('width')
14+
15+
if imageHeight > 0 && imageWidth > 0
16+
if imageHeight < containerHeight && imageWidth < containerWidth
17+
scope.showSmallImage = true
18+
scope.vm.imageZoomedIn = false
19+
else
20+
scope.showSmallImage = false
21+
22+
scope.$watch 'setAutoBg', (newVal, oldVal) ->
23+
if newVal
24+
scope.setAutoBg = false
25+
checkHeights()
26+
27+
$($window).bind 'resize', ->
28+
checkHeights()
29+
scope.$digest()
30+
431
restrict: 'E'
532
controller: 'ImageViewerController as vm'
633
templateUrl: 'views/image-viewer.directive.html'
34+
link: link
735
scope:
836
files : '='
937
startingFile : '='
1038
showNotifications : '='
1139
onFileChange : '&'
1240

41+
directive.$inject = ['$window']
42+
1343
angular.module('appirio-tech-ng-ui-components').directive 'imageSlideViewer', directive

src/styles/image-viewer.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ image-slide-viewer {
6363
}
6464
}
6565

66+
&.small {
67+
> .bg-image {
68+
overflow: auto;
69+
}
70+
}
71+
6672
.bg-image {
6773
margin-top: 40px;
6874
background-size: contain;
@@ -73,6 +79,12 @@ image-slide-viewer {
7379
&:hover {
7480
cursor: zoom-in;
7581
}
82+
83+
&.small {
84+
&:hover {
85+
cursor: inherit;
86+
}
87+
}
7688
}
7789
}
7890
}

src/views/image-viewer.directive.jade

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ main.flex.column.middle.light-bg
1111
button.clean.icon.arrow
1212

1313
.image.flex.column.center
14-
.img-container.flex.flex-grow(ng-class="{zoomed: vm.imageZoomedIn}")
14+
.img-container.flex.flex-grow(ng-class="{zoomed: vm.imageZoomedIn, small: showSmallImage}")
1515

16-
.bg-image(ng-if="!vm.imageZoomedIn" ng-click="vm.toggleZoom()" style="background-image: url({{vm.file.url}})")
16+
.bg-image(ng-show="!vm.imageZoomedIn && !vm.showSmallImage" ng-click="vm.toggleZoom()" style="background-image: url({{vm.file.url}})")
1717

18-
.bg-image.zoomed.elevated(ng-if="vm.imageZoomedIn" ng-click="vm.toggleZoom()")
18+
.bg-image.zoomed.elevated(ng-show="vm.imageZoomedIn && !vm.showSmallImage" ng-click="vm.toggleZoom()")
1919
img(ng-src="{{vm.file.url}}")
2020

21+
.bg-image.zoomed.small.flex.center.middle(ng-show="!vm.imageZoomedIn && vm.showSmallImage")
22+
img(ng-src="{{vm.file.url}}")
23+
24+
2125
.next.flex.flex-grow
2226
a.arrow-next(ng-class="{invisible: !vm.nextFile}" ng-click="vm.viewNext()")
2327
button.clean.icon.arrow.right

0 commit comments

Comments
 (0)