-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathtr-boards.client.directive.js
128 lines (118 loc) · 4.77 KB
/
tr-boards.client.directive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(function(){
'use strict';
/**
* Directive that simply picks a background image given element and emits copyright info down the scope.
*
* Usage:
* <div tr-boards="imageid">
*
* Or from many:
* <div tr-boards="['imageid1', 'imageid2']">
*/
angular
.module('core')
.directive('trBoards', trBoardsDirective);
/* @ngInject */
function trBoardsDirective() {
return {
restrict: 'A',
replace: false,
scope: {
trBoards: '='
},
link: function(scope, elem, attr) {
// If requested photo is missing or request is invalid, rely on this photo
var defaultPhoto = 'bokeh';
var photos = {
'bokeh': {
'name': 'Sandra', // "pinkorchid_too"
'url': 'https://www.flickr.com/photos/artfullife/3589991695',
'license': 'CC',
'license_url': 'https://creativecommons.org/licenses/by-sa/2.0/',
'file': 'flickr-bokeh.jpg'
},
'forestpath': {
'name': 'Johnson', //Johnson Cameraface
'url': 'https://www.flickr.com/photos/54459164@N00/15506455245',
'license': 'CC',
'license_url': 'https://creativecommons.org/licenses/by-nc-sa/2.0/',
'file': 'flickr-forestpath.jpg'
},
'forestpath-toned': {
'name': 'Johnson', //Johnson Cameraface
'url': 'https://www.flickr.com/photos/54459164@N00/15506455245',
'license': 'CC',
'license_url': 'https://creativecommons.org/licenses/by-nc-sa/2.0/',
'file': 'flickr-forestpath-toned.jpg'
},
'sierranevada': {
'name': 'Simona',
'url': 'http://www.wanderlust.lt',
'license': 'CC',
'license_url': 'https://creativecommons.org/licenses/by-nc-nd/4.0/',
'file': 'ss-sierranevada.jpg'
},
'hitchroad': {
// https://www.facebook.com/photo.php?fbid=10152802854942931&set=pcb.10152802854987931&type=1&theater
// Permission asked for Trustroots & Hitchwiki by Mikael Korpela
'name': 'Andrew W Bugelli',
'url': 'http://www.containstraces.blogspot.com/',
'file': 'ab-hitchroad-toned.jpg' // ab-hitchroad.jpg
},
'guitarcamper': {
// Permission granted for Trustroots (asked by Mikael Korpela)
'name': 'Guillaume Ohz',
'file': 'go-camper.jpg'
},
'maroccomap': {
// Permission granted for Trustroots (asked by Mikael Korpela)
'name': 'Guillaume Ohz',
'file': 'go-maroccomap.jpg'
},
'rainbowpeople': {
// Permission granted for Trustroots (asked by Mikael Korpela)
'name': 'Antonio Fulghieri',
'url': 'https://aaoutthere.wordpress.com/',
'license': 'CC',
'license_url': 'https://creativecommons.org/licenses/by-nc-nd/4.0/',
'file': 'af-rainbow-people.jpg'
},
'happyhippies': {
// Permission granted for Trustroots (asked by Mikael Korpela)
'name': 'Antonio Fulghieri',
'url': 'https://aaoutthere.wordpress.com/',
'license': 'CC',
'license_url': 'https://creativecommons.org/licenses/by-nc-nd/4.0/',
'file': 'af-happyhippies.jpg'
},
'desertgirl': {
// https://www.facebook.com/agniete.melisa
// Permission granted for Trustroots (asked by Mikael Korpela)
'name': 'Agnietė Melisa',
'url': 'https://www.facebook.com/pages/My-Road-Tales/844001355694245',
'file': 'am-desertgirl.jpg'
},
'wavewatching': {
// https://www.facebook.com/gala.hyde
// Permission granted for Trustroots (asked by Mikael Korpela)
'name': 'Andrea Nieblas',
'url': 'https://www.flickr.com/photos/andreanieblas/',
'file': 'an-wavewatching.jpg'
}
};
// scope.trBoards might be an array (therefore just pick one key from it) or a string (thus just use it as is)
var key = angular.isArray(scope.trBoards) ? scope.trBoards[Math.floor(Math.random() * (scope.trBoards.length))] : scope.trBoards;
// Pick the photo
var photo = photos[key] || photos[defaultPhoto];
// Add photo as a background to the element
elem.addClass('board-' + key);
elem.css({
'background-image': 'url(/modules/core/img/board/' + photo.file + ')'
//'background-position': (photo.position ? photo.position : '50% 50%')
});
// Send copyright info down the scope... something will pick it up! (pst, core/app-controller)
scope.$emit('photoCreditsUpdated', photo);
}
};
}
})();