Instantly share code, notes, and snippets.

@NV /c2f.html
Created May 16, 2014

Embed
What would you like to do?
Meteor temperature converter sample app. http://temperature.meteor.com
<head>
<title>Temperature converter</title>
</head>
<body>
{{> c2f}}
</body>
<template name="c2f">
<input type="number" value="{{celsius}}" id="c">℃ ⟷
<input type="number" value="{{fahrenheit}}" id="f">℉
</template>
// client/c2f.js
function c2f(c) {
return 9 / 5 * parseFloat(c) + 32;
}
function f2c(f) {
return 5 / 9 * (f - 32);
}
Session.setDefault('c', 0);
Template.c2f.celsius = function () {
return Session.get('c');
};
Template.c2f.fahrenheit = function () {
return c2f(Session.get('c'));
};
Template.c2f.events({
'input #c': function (e) {
Session.set('c', parseFloat(e.target.value));
},
'input #f': function(e) {
Session.set('c', f2c(parseFloat(e.target.value)));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment