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

Commit e5f2980

Browse files
committed
Merge pull request #24 from appirio-tech/slider-with-shadow
Updated slider code to allow shadow around preview
2 parents c0890ba + 9bedc18 commit e5f2980

File tree

6 files changed

+128
-225
lines changed

6 files changed

+128
-225
lines changed

example/styles/main.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ h1 {
6969
}
7070
}
7171
}
72+
73+
.image-viewer-container {
74+
height: 100vh;
75+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
modal.flex.column(show="true" background-click-close=true)
2-
image-viewer-header.flex(handle="batman" title="My Very Important Project Images" download-allowed="true")
1+
modal(show="true" background-click-close=true)
2+
.image-viewer-container.flex.column
3+
image-viewer-header.flex(handle="batman" title="My Very Important Project Images" download-allowed="true")
34

4-
image-slide-viewer.flex.flex-grow(files="vm.files" starting-file="vm.startingFile" show-notifications="vm.showNotifications")
5+
image-slide-viewer.flex.flex-grow(files="vm.files" starting-file="vm.startingFile" show-notifications="vm.showNotifications")
Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,41 @@
11
'use strict'
22

3-
ImageViewerController = ($scope) ->
3+
ImageViewerController = ->
44
vm = this
5-
vm.files = $scope.files
6-
vm.showNotifications = $scope.showNotifications
7-
startingFile = $scope.startingFile
8-
vm.onFileChange = $scope.onFileChange
9-
vm.imageZoomedIn = false
10-
vm.prevFile = null
11-
vm.nextFile = null
12-
vm.showSmallImage = false
13-
$scope.setAutoBg = false
14-
15-
16-
updateFiles = ->
17-
if vm.currentIndex + 1 < vm.files.length
18-
vm.nextFile = true
19-
else
20-
vm.nextFile = null
21-
22-
if vm.currentIndex - 1 >= 0
23-
vm.prevFile = true
24-
else
25-
vm.prevFile = null
5+
vm.zoom = false
6+
vm.prevFile = false
7+
vm.nextFile = false
8+
vm.largeImage = false
269

2710
activate = ->
28-
vm.file = startingFile
29-
30-
vm.currentIndex = vm.files.indexOf vm.file
11+
update(vm.files.indexOf vm.startingFile)
3112

32-
vm.nextFile = vm.currentIndex + 1 < vm.files.length
33-
34-
vm.prevFile = vm.currentIndex - 1 >= 0
13+
update = (fileIndex) ->
14+
vm.file = vm.files[fileIndex]
15+
vm.currentIndex = fileIndex
16+
vm.nextFile = vm.currentIndex + 1 < vm.files.length
17+
vm.prevFile = vm.currentIndex > 0
18+
vm.zoom = false
3519

3620
vm.onFileChange({file: vm.file}) if vm.onFileChange
3721

38-
$scope.setAutoBg = true
39-
40-
$scope.$watch 'showSmallImage', (newVal, OldVal) ->
41-
vm.showSmallImage = newVal
42-
4322
vm.viewNext = ->
44-
vm.file = vm.files[vm.currentIndex + 1]
45-
46-
vm.currentIndex = vm.files.indexOf vm.file
47-
48-
updateFiles()
49-
50-
vm.imageZoomedIn = false
51-
52-
vm.onFileChange({file: vm.file}) if vm.onFileChange
53-
54-
$scope.setAutoBg = true
55-
23+
update(vm.currentIndex + 1)
5624

5725
vm.viewPrevious = ->
58-
vm.file = vm.files[vm.currentIndex - 1]
59-
60-
vm.currentIndex = vm.files.indexOf vm.file
61-
62-
updateFiles()
63-
64-
vm.imageZoomedIn = false
65-
66-
vm.onFileChange({file: vm.file}) if vm.onFileChange
67-
68-
$scope.setAutoBg = true
69-
26+
update(vm.currentIndex - 1)
7027

7128
vm.selectFile = (file) ->
72-
vm.file = file
73-
74-
vm.currentIndex = vm.files.indexOf vm.file
75-
76-
updateFiles()
77-
78-
vm.imageZoomedIn = false
79-
80-
vm.onFileChange({file: vm.file}) if vm.onFileChange
81-
82-
$scope.setAutoBg = true
83-
29+
update(vm.files.indexOf file)
8430

8531
vm.isCurrent = (file) ->
8632
(vm.files.indexOf file) == vm.currentIndex
8733

8834
vm.toggleZoom = ->
89-
vm.imageZoomedIn = !vm.imageZoomedIn
35+
vm.zoom = !vm.zoom
9036

9137
activate()
9238

9339
vm
9440

95-
ImageViewerController.$inject = ['$scope']
96-
9741
angular.module('appirio-tech-ng-ui-components').controller 'ImageViewerController', ImageViewerController

src/scripts/directives/image-viewer.directive.coffee

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,31 @@
11
'use strict'
22

33
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()
4+
link = (scope) ->
5+
container = document.getElementsByClassName('image-container')[0]
6+
image = document.getElementsByClassName('preview-image')[0]
7+
8+
checkOverflow = ->
9+
wide = image.naturalWidth > container.clientWidth
10+
tall = image.naturalHeight > container.clientHeight
11+
12+
scope.$apply "vm.largeImage = #{ wide || tall }"
13+
14+
image.onload = ->
15+
checkOverflow()
16+
17+
$($window).bind 'resize', ->
18+
checkOverflow()
3019

3120
restrict: 'E'
3221
controller: 'ImageViewerController as vm'
3322
templateUrl: 'views/image-viewer.directive.html'
3423
link: link
35-
scope:
24+
scope: {}
25+
bindToController:
3626
files : '='
3727
startingFile : '='
38-
showNotifications : '='
28+
showNotifications : '&'
3929
onFileChange : '&'
4030

4131
directive.$inject = ['$window']

src/styles/image-viewer.scss

Lines changed: 70 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,97 @@
11
@import "work/work-includes";
22

33
image-slide-viewer {
4-
display: block;
4+
position: absolute;
5+
top: 0;
6+
height: 100vh;
7+
margin-top: 100px;
8+
padding-bottom: 100px;
9+
box-sizing: border-box;
510

611
main {
712
width : 100vw;
8-
padding: 20px;
9-
padding-top: 10px;
1013

11-
.content {
12-
overflow: hidden;
14+
.meta {
1315
text-align: center;
14-
width: 100%;
16+
margin-bottom: 20px;
17+
}
1518

16-
.slideshow {
17-
width: 100%;
18-
.icon.arrow {
19-
width: 33px;
20-
height: 74px;
21-
}
19+
.content {
20+
align-items: stretch;
21+
min-height: 1px;
2222

23-
.preview {
24-
overflow: hidden;
25-
text-align: center;
26-
padding: 20px 0;
23+
.previous, .next {
24+
flex-basis: 75px;
2725

28-
.previous, .next {
29-
min-width: 50px;
26+
.arrow-previous, .arrow-next {
27+
margin: auto;
3028

31-
.arrow-previous, .arrow-next {
32-
margin: auto
33-
}
29+
.icon.arrow {
30+
width: 33px;
31+
height: 74px
32+
}
33+
}
34+
}
3435

35-
.arrow-next {
36-
margin: auto
37-
}
36+
.image-container {
37+
position: relative;
38+
text-align: center;
39+
40+
&.small, &.fit {
41+
img {
42+
position: absolute;
43+
top: 50%;
44+
left: 50%;
45+
transform: translateY(-50%) translateX(-50%);
46+
max-width: 100%;
47+
max-height: 100%;
3848
}
49+
}
3950

40-
.image {
41-
width: 100%;
42-
max-width: 1000px;
43-
margin-right: 80px;
44-
margin-left: 80px;
45-
46-
.img-container {
47-
width: 100%;
48-
height: 100%;
49-
max-height: 800px;
50-
max-width: 1000px;
51-
52-
&.zoomed {
53-
54-
> .bg-image {
55-
overflow: auto;
56-
57-
img {
58-
59-
&:hover {
60-
cursor: zoom-out;
61-
}
62-
}
63-
}
64-
}
65-
66-
&.small {
67-
> .bg-image {
68-
overflow: auto;
69-
}
70-
}
71-
72-
.bg-image {
73-
margin-top: 40px;
74-
background-size: contain;
75-
background-repeat: no-repeat;
76-
background-position: center;
77-
width: 100%;
78-
79-
&:hover {
80-
cursor: zoom-in;
81-
}
82-
83-
&.small {
84-
&:hover {
85-
cursor: inherit;
86-
}
87-
}
88-
}
89-
}
51+
&.fit {
52+
img {
53+
cursor: zoom-in;
9054
}
9155
}
9256

93-
.thumbnails {
57+
&.full {
58+
overflow: scroll;
9459
text-align: center;
95-
max-width: 100vw;
96-
padding: 20px;
97-
min-height: 100px;
98-
overflow: auto;
99-
white-space: nowrap;
100-
101-
> * {
102-
display: inline-block;
103-
margin: 10px;
104-
position: relative;
105-
106-
&.elevated {
107-
opacity: 0.4;
108-
}
109-
}
11060

111-
button {
112-
img {
113-
width : 60px;
114-
height : 50px;
115-
display: block;
116-
}
61+
img {
62+
cursor: zoom-out;
11763
}
11864
}
11965
}
12066
}
67+
68+
.thumbnails {
69+
flex-basis: 110px;
70+
flex-shrink: 0;
71+
text-align: center;
72+
width: 100vw;
73+
padding: 25px;
74+
overflow: auto;
75+
white-space: nowrap;
76+
77+
> * {
78+
display: inline-block;
79+
margin: 0 10px;
80+
position: relative;
81+
82+
&.elevated {
83+
opacity: 0.4;
84+
}
85+
}
86+
87+
button {
88+
img {
89+
width : 60px;
90+
height : 50px;
91+
display: block;
92+
}
93+
}
94+
}
12195
}
12296
}
12397

0 commit comments

Comments
 (0)