Skip to content

Instantly share code, notes, and snippets.

var resetFields = function () {
var p = Meteor.user().profile;
$('#profile-name').val(p.name);
$('#profile-country-list').select2('val', p.country);
$('#profile-email').val(Meteor.user().emails[0].address);
$('#profile-paypal-email').val(p.paypal_email);
$('#profile-password').val('');
$('#profile-confirm-password').val('');
}
Template.admin.events =
"click #createPost": () ->
Meteor.render(() ->
"{{> create_news_post}}"
)
@BenjaminRH
BenjaminRH / seeds.js
Last active December 18, 2015 05:59
Demonstrating seeding your website with example data in Meteor
if (MyCollection.find().count() === 0) {
// Insert all of the MyCollection data here
}
Session.setDefault('game-list-position', 0); // The current position for the skip
Session.setDefault('viewport', 10); // The number of games to display in the list
Template.gameList.scrollableList = function () {
return Games.find({}, {
limit: Session.get('viewport'), // Limit the games to the current viewport number
skip: Session.get('game-list-position') * Session.get('viewport') // Skip the right number of games
});
}
@BenjaminRH
BenjaminRH / gist:5725081
Last active December 18, 2015 04:19
Demonstrating doing stuff with Collection data ONLY the first time you receive it, with a few different possible approaches. It will maintain state across hot-code pushes.
Session.setDefault('done-shit', false); // In the beginning, we haven't done shit
Meteor.subscribe('foobar', function () {
// We have recieved the data (either for the first time, or in an update)
if (Session.equals('done-shit', false)) {
// This is the first time we've got it
// Do data manipulation, or something
Session.set('done-shit', true);
}
});
Deps.autorun(function () {
// The current game they're playing
var game = Games.findOne(Session.get('current-game')); // or whatever your equivalent of that is
if (! Session.equals('current-game-version', game.version)) {
// The game's version has updated
Session.set('current-game-version', game.version);
// Alert the user here
}
});
client.addListener('PING', function() {
Fiber(function() {
client.send('PONG');
}).run();
});
<head>
<title>Title</title>
<meta charset="utf-8">
<meta name="robots" content="all">
</head>
<body>
{{> nav_header}}
{{> index}}
</body>
Template.movie.events({
'click .seen': function (e, t) {
// User has set status to "seen", but not exited poster
Session.set('seen-movie', true);
},
'click .not-seen': function (e, t) {
// User has set status to "not seen", but not exited poster
Session.set('seen-movie', false);
}
'mouseout .poster': function (e, t) {
if (Meteor.isClient) {
function updateHTML(elmId, value) {
document.getElementById(elmId).innerHTML = value;
}
// This function is called when an error is thrown by the player
function onPlayerError(errorCode) {
alert("An error occured of type:" + errorCode);
}