forked from outbrain-inc/Leonardo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
98 lines (85 loc) · 2.74 KB
/
index.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
"use strict";
function getRandomIntInclusive(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var Flicker = angular.module('flicker-example', ['leonardo','akoenig.deckgrid'])
.config(function ($locationProvider) {
$locationProvider.html5Mode(false);
})
.controller('flickerCtrl', function ($scope, flickerGetter) {
$scope.loadClicked = function () {
$scope.loading = true;
flickerGetter.getData().then(function(data){
$scope.photos = data;
}).finally(function () {
$scope.loading = false;
});
tour.next();
};
var tour = new Shepherd.Tour({
defaults: {
classes: 'shepherd-theme-arrows'
}
});
tour.addStep('load', {
text: "Click here to load data with this<br/> example's http request to flicker.",
attachTo: '.load bottom',
buttons: []
});
tour.addStep('leonardo', {
text: 'Use leonardo to start mocking http or anything you like!',
attachTo: '.leonardo-activator',
advanceOn: '.leonardo-activator click',
buttons: []
});
tour.addStep('load-again', {
text: 'now load again!',
attachTo: '.load left',
buttons: []
});
setTimeout(function(){
tour.start();
}, 800);
});
Flicker.factory('flickerGetter', ['$q', '$http', function ($q, $http) {
var tags = ['cartoons', 'smurfs', 'nature', 'space'];
return {
getData: function(){
return $http.jsonp('http://api.flickr.com/services/feeds/photos_public.gne', {
method: 'jsonp',
params: {
tags: tags[getRandomIntInclusive(0, tags.length - 1)],
tagmode: "any",
format: 'json',
jsoncallback: 'JSON_CALLBACK'
}
}).then(function (response) {
return response.data.items.map(function (item) {
var imageUrl = item.media.m;
return {
imageUrl: imageUrl
};
});
});
},
getNinjaData: function () {
return $http.jsonp('https://api.flickr.com/services/rest', {
method: 'jsonp',
params: {
method: "flickr.photosets.getPhotos",
api_key: "70da7d9dfe17a2df01c7dfe04004af17",
"photoset_id": "72157654126439284", //72157656472911925
"user_id": "134998090@N03",
"format": "json",
jsoncallback: 'JSON_CALLBACK'
}
}).then(function (response) {
return response.data.photoset.photo.map(function (photo) {
return {
imageUrl: 'https://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_b.jpg'.replace('{farm-id}', photo.farm).replace('{server-id}', photo.server).replace('{id}', photo.id).replace('{secret}', photo.secret)
};
});
});
}
};
}]);