Skip to content

Instantly share code, notes, and snippets.

@walidvb
Created June 15, 2014 13:04
Show Gist options
  • Select an option

  • Save walidvb/c90eff72f2ac7d30bc03 to your computer and use it in GitHub Desktop.

Select an option

Save walidvb/c90eff72f2ac7d30bc03 to your computer and use it in GitHub Desktop.
A tumblr service to embed tumblr in a second
<my-tumblr></my-tumblr>
angular.module('Tumblr', []).factory('Tumblr', [
'$http', function($http) {
var key, url;
key = '';
url = "http://api.tumblr.com/v2/blog/walidvb.tumblr.com/posts?";
url += 'api_key=' + key;
this.getPosts = function(settings, cb) {
var value;
for (key in settings) {
value = settings[key];
console.log(key, settings[key]);
url += "&" + key + "=" + value;
}
$http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
return $http.jsonp(url, {
params: {
jsonp: 'JSON_CALLBACK'
}
}).success(cb);
};
return this;
}
]).directive('myTumblr', [
'$sce', 'Tumblr', function($sce, tumblr) {
return {
restrict: 'E',
controller: function($scope, $element, $attrs) {
tumblr.getPosts($attrs.myTumblr, function(data) {
return $scope.blog = data.response;
});
},
templateUrl: '/templates/tumblrPosts.tpl.html'
}
}
]).filter('summary', function() {
return function(input) {
var break_point, ret;
break_point = '<!-- more -->';
ret = input.indexOf(break_point) !== -1 ? input.split(break_point)[0] : input;
return ret;
};
}).filter('trust', ['$sce', function($sce){
return function(input){
return $sce.trustAsHtml(input);
}
}
]);
<div class="tumblr block">
<div class="post-list">
<article ng-repeat="post in blog.posts">
<div class="post-title">
<h3>{{post.title}}</h3>
<time class="post-date timeago" datetime="{{post.date}}" data-time="{DayOfMonthWithZero} {Month} {Year}">{{post.timestamp*1000 | date: 'd MMMM'}}</time>
</div>
<div class="post-meta">
<div class="tags" ng-if="posts.tag.length">
<span href="{TagURL}" class="tag" ng-repeat="tag in post.tags">
#{{post.tag}}
</span>
</div>
</div>
<div ng-switch="post.type">
<div class="post-body" ng-switch-when="text" ng-bind-html="post.body | trust"></div>
<div class="post-body" ng-switch-when="video" ng-bind-html="post.player[post.player.length-1].embed_code | trust"></div>
</div>
</article>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment