Created
February 22, 2019 16:17
-
-
Save simistern/8e328e2c76c973ef1b8e741dcf64960c to your computer and use it in GitHub Desktop.
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
Posts = new Mongo.Collection('posts'); | |
Session.setDefault('subreddit', 'all'); | |
Session.setDefault('searching', false); | |
SUPPORTED_MEDIA_TYPES = ['jpg', 'png', 'gif']; | |
Tracker.autorun(function() { | |
console.log('show session ', Session); | |
if (Session.get('subreddit')) { | |
var searchHandle = Meteor.subscribe('subredditSearch', Session.get('subreddit')); | |
Session.set('searching', ! searchHandle.ready()); | |
} | |
}); | |
Template.body.events({ | |
'submit form': function(e, t) { | |
e.preventDefault(); | |
var subreddit = t.$('input[type=text]').val(); | |
if (subreddit) { | |
Session.set('subreddit', subreddit); | |
} | |
}, | |
'click .icon': function(e) { | |
e.preventDefault(); | |
var post = Blaze.getData(e.target); | |
var post_holder = $('.post[data-id=' + post.id + ']'); | |
var image = $('.post[data-id=' + post.id + ']').find('.image-preview'); | |
if (image.is(':visible')) { | |
console.log('show'); | |
image.slideUp(); | |
} else { | |
if (Meteor.call('checkSupportedTypes', post.url.substr(post.url.length - 3))) { | |
image.prop('src', post.url).slideDown(); | |
} else { | |
window.open(post.url, '_blank'); | |
} | |
} | |
} | |
}); | |
Template.body.helpers({ | |
posts: function() { | |
return Posts.find(); | |
}, | |
searching: function() { | |
return Session.get('searching'); | |
} | |
}); | |
Meteor.methods({ | |
checkSupportedTypes: function(url) { | |
if (SUPPORTED_MEDIA_TYPES.indexOf(url) > -1) { return true; } | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment