forked from uservidya/java-mag-angularjs-article
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngcube.js
77 lines (77 loc) · 3.01 KB
/
ngcube.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
angular.module('angularjsde.cube', []);
'use strict';
angular.module('angularjsde.cube').provider('flickr', function () {
var API_KEY;
this.apiKey = function (apiKey) {
if (apiKey) {
API_KEY = apiKey;
}
return apiKey;
};
this.$get = [
'$http',
function ($http) {
var getPhotosByTagFn = function (tag) {
return $http.get('http://api.flickr.com/services/rest/', {
params: {
method: 'flickr.photos.search',
api_key: API_KEY,
format: 'json',
nojsoncallback: 1,
per_page: '6',
tags: tag,
tag_mode: 'all'
}
}).then(function (response) {
var array = response.data.photos.photo.map(function (photo) {
return 'http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}.jpg'.replace('{farm-id}', photo.farm).replace('{server-id}', photo.server).replace('{id}', photo.id).replace('{secret}', photo.secret);
});
return array;
});
};
return {
getPhotosByTag: function (tag) {
return getPhotosByTagFn(tag);
},
getApiKey: function () {
return API_KEY;
}
};
}
];
});
angular.module('angularjsde.cube').directive('cube', [
'flickr',
function (flickr) {
return {
restrict: 'E',
templateUrl: 'views/cube.html',
scope: {
x: '@initX',
y: '@initY',
z: '@initZ',
tag: '@'
},
link: function (scope) {
if (scope.tag) {
flickr.getPhotosByTag(scope.tag).then(function (imgArray) {
scope.img = imgArray;
});
}
}
};
}
]);
(function (module) {
try {
module = angular.module('angularjsde.cube');
} catch (e) {
module = angular.module('angularjsde.cube', []);
}
module.run([
'$templateCache',
function ($templateCache) {
$templateCache.put('/srcviews/cube.html', '<div class="cube-container">\n' + ' <div class="inputs">\n' + ' X: <input type="range" min="0" max="360" step="1" ng-model="x"/>\n' + ' Y: <input type="range" min="0" max="360" step="1" ng-model="y"/>\n' + ' Z: <input type="range" min="0" max="360" step="1" ng-model="z"/>\n' + ' </div>\n' + '\n' + ' <div class="perspective">\n' + ' <div class="cube"\n' + ' style="-webkit-transform: rotateX({{x}}deg) rotateY({{y}}deg) rotate({{z}}deg)">\n' + ' <div class="front" style="background-image: url({{img[0]}})">front</div>\n' + ' <div class="back" style="background-image: url({{img[1]}})">back</div>\n' + ' <div class="top" style="background-image: url({{img[2]}})">top</div>\n' + ' <div class="bottom" style="background-image: url({{img[3]}})">bottom</div>\n' + ' <div class="left" style="background-image: url({{img[4]}})">left</div>\n' + ' <div class="right" style="background-image: url({{img[5]}})">right</div>\n' + ' </div>\n' + ' </div>\n' + '</div>');
}
]);
}());