Demo of loading images using the Flickr API with Ionic.
Created
September 4, 2015 07:01
-
-
Save benweiser/36ed456b0bd65b7fd691 to your computer and use it in GitHub Desktop.
Flickr Search Example: Nightly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html ng-app="ionicApp"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> | |
<title>Flickr</title> | |
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet"> | |
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script> | |
<script src="//code.ionicframework.com/nightly/js/angular/angular-resource.js"></script> | |
</head> | |
<body ng-controller="FlickrCtrl"> | |
<ion-header-bar class="bar-dark"> | |
<h1 class="title">Flickr Search</h1> | |
</ion-header-bar> | |
<div id="search-bar"> | |
<div class="item item-input-inset"> | |
<label class="item-input-wrapper" id="search-input"> | |
<i class="icon ion-search placeholder-icon"></i> | |
<input type="text" placeholder="Search" ng-model="query" ng-change="search()"> | |
</label> | |
</div> | |
</div> | |
<ion-content id="content" push-search> | |
<div id="photos" class="clearfix"> | |
<div class="photo" ng-repeat="photo in photos.items"> | |
<img ng-src="{{ photo.media.m }}"> | |
</div> | |
</div> | |
</ion-content> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('ionicApp', ['ionic', 'ngResource']) | |
.factory('Flickr', function($resource, $q) { | |
var photosPublic = $resource('http://api.flickr.com/services/feeds/photos_public.gne', | |
{ format: 'json', jsoncallback: 'JSON_CALLBACK' }, | |
{ 'load': { 'method': 'JSONP' } }); | |
return { | |
search: function(query) { | |
var q = $q.defer(); | |
photosPublic.load({ | |
tags: query | |
}, function(resp) { | |
q.resolve(resp); | |
}, function(err) { | |
q.reject(err); | |
}) | |
return q.promise; | |
} | |
} | |
}) | |
.controller('FlickrCtrl', function($scope, Flickr) { | |
var doSearch = ionic.debounce(function(query) { | |
Flickr.search(query).then(function(resp) { | |
$scope.photos = resp; | |
}); | |
}, 500); | |
$scope.search = function() { | |
doSearch($scope.query); | |
} | |
}) | |
.directive('pushSearch', function() { | |
return { | |
restrict: 'A', | |
link: function($scope, $element, $attr) { | |
var amt, st, header; | |
$element.bind('scroll', function(e) { | |
if(!header) { | |
header = document.getElementById('search-bar'); | |
} | |
st = e.detail.scrollTop; | |
if(st < 0) { | |
header.style.webkitTransform = 'translate3d(0, 0px, 0)'; | |
} else { | |
header.style.webkitTransform = 'translate3d(0, ' + -st + 'px, 0)'; | |
} | |
}); | |
} | |
} | |
}) | |
.directive('photo', function($window) { | |
return { | |
restrict: 'C', | |
link: function($scope, $element, $attr) { | |
var size = ($window.outerWidth / 3) - 2; | |
$element.css('width', size + 'px'); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#search-input { | |
text-align: center; | |
} | |
#photos { | |
margin: auto; | |
} | |
.photo { | |
width: 100px; | |
height: 100px; | |
margin: 1px; | |
float: left; | |
overflow: hidden; | |
} | |
.photo img { | |
min-width: 100%; | |
min-height: 100%; | |
max-width: 150%; | |
max-height: 150%; | |
} | |
#search-bar { | |
background: none; | |
position: absolute; | |
width: 100%; | |
top: 44px; | |
height: 40px; | |
z-index: 3; | |
} | |
#search-bar .item { | |
background: none; | |
border: none; | |
} | |
#content { | |
top: 44px; | |
padding-top: 45px; | |
padding-bottom: 20px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment