mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 23:16:52 +08:00
Flickr group search
This commit is contained in:
@ -10,12 +10,28 @@ angular.module('ionic.weather', ['ionic.weather.services', 'ionic.weather.direct
|
||||
};
|
||||
})
|
||||
|
||||
.controller('WeatherCtrl', function($scope, Weather, Geo, Flickr) {
|
||||
.controller('WeatherCtrl', function($scope, $timeout, Weather, Geo, Flickr) {
|
||||
var _this = this;
|
||||
|
||||
$scope.activeBgImageIndex = 0;
|
||||
|
||||
$scope.getActiveBackgroundImage = function() {
|
||||
if($scope.activeBgImage) {
|
||||
var item = $scope.activeBgImage;
|
||||
var url = "http://farm"+ item.farm +".static.flickr.com/"+ item.server +"/"+ item.id +"_"+ item.secret +"_m.jpg";
|
||||
return {
|
||||
'background-image': 'url(' + url + ')'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
this.getBackgroundImage = function(lat, lng) {
|
||||
Flickr.search('sunset', lat, lng).then(function(resp) {
|
||||
console.log('FLICKR', resp);
|
||||
Flickr.search('Madison, Wisconsin', lat, lng).then(function(resp) {
|
||||
var photos = resp.photos;
|
||||
if(photos.photo.length) {
|
||||
$scope.bgImages = photos.photo;
|
||||
_this.cycleBgImages();
|
||||
}
|
||||
}, function(error) {
|
||||
console.error('Unable to get Flickr images', error);
|
||||
});
|
||||
@ -41,6 +57,15 @@ angular.module('ionic.weather', ['ionic.weather.services', 'ionic.weather.direct
|
||||
});
|
||||
};
|
||||
|
||||
this.cycleBgImages = function() {
|
||||
$timeout(function cycle() {
|
||||
if($scope.bgImages) {
|
||||
$scope.activeBgImage = $scope.bgImages[$scope.activeBgImageIndex++ % $scope.bgImages.length];
|
||||
}
|
||||
$timeout(cycle, 5000);
|
||||
});
|
||||
};
|
||||
|
||||
Geo.getLocation().then(function(position) {
|
||||
console.log('GOT LAT', position);
|
||||
var lat = position.coords.latitude;
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<script src="app.js"></script>
|
||||
</head>
|
||||
<body ng-controller="WeatherCtrl">
|
||||
<div id="bg-image"></div>
|
||||
<div id="bg-image" ng-style="getActiveBackgroundImage()"></div>
|
||||
|
||||
<header id="header" class="bar bar-header bar-clear">
|
||||
<h1 class="title">
|
||||
@ -57,7 +57,7 @@
|
||||
s.addEventListener('momentumScrolled', function(e) {
|
||||
setTimeout(function() {
|
||||
var bgAmount = e.detail.scrollTop;
|
||||
bgImage.style.top = -(bgAmount / 50);
|
||||
bgImage.style.webkitTransform = 'translate3d(0, ' + -(bgAmount / 40) + 'px, 0)';
|
||||
|
||||
//var blurAmount = Math.min(3, e.detail.scrollTop / 200);
|
||||
|
||||
|
||||
@ -20,7 +20,8 @@ angular.module('ionic.weather.services', ['ngResource'])
|
||||
var baseUrl = 'http://api.flickr.com/services/rest/'
|
||||
|
||||
var flickrSearch = $resource(baseUrl, {
|
||||
method: 'flickr.photos.search',
|
||||
method: 'flickr.groups.pools.getPhotos',
|
||||
group_id: '1463451@N25',
|
||||
safe_search: 1,
|
||||
jsoncallback: 'JSON_CALLBACK',
|
||||
api_key: FLICKR_API_KEY,
|
||||
|
||||
Reference in New Issue
Block a user