Created
July 19, 2012 11:54
-
-
Save adtaylor/3143294 to your computer and use it in GitHub Desktop.
http://wevther.com is about the coolest idea I have seen for a while but being from the other side of the pond I couldn't understand the temps in fahrenheit.
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
# Usage: | |
# temp_converter.convertTo('f') | |
# temp_converter.convertTo('c') | |
temp_converter = | |
temps: ['.temphigh', '.templow'] | |
currentUnit: 'f' | |
toCelsius: (f)-> | |
@currentUnit = 'c' | |
Math.round((parseInt(f)-32) * (5/9)) + '°' | |
toFahrenheit: (c)-> | |
@currentUnit = 'f' | |
Math.round(parseInt(c) * (9/5) + 32) + '°' | |
convertTo: (unit)-> | |
if unit is @currentUnit then return false | |
for temp in @temps | |
$temp = $(temp) | |
$temp.text switch unit | |
when 'c' then @toCelsius $temp.text() | |
when 'f' then @toFahrenheit $temp.text() |
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
// Usage: | |
// temp_converter.convertTo('f') | |
// temp_converter.convertTo('c') | |
var temp_converter = { | |
temps: ['.temphigh', '.templow'], | |
currentUnit: 'f', | |
toCelsius: function(f) { | |
this.currentUnit = 'c'; | |
return Math.round((parseInt(f) - 32) * (5 / 9)) + '°'; | |
}, | |
toFahrenheit: function(c) { | |
this.currentUnit = 'f'; | |
return Math.round(parseInt(c) * (9 / 5) + 32) + '°'; | |
}, | |
convertTo: function(unit) { | |
var $temp, temp, _i, _len, _ref; | |
if (unit === this.currentUnit) { | |
return false; | |
} | |
_ref = this.temps; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
temp = _ref[_i]; | |
$temp = $(temp); | |
$temp.text((function() { | |
switch (unit) { | |
case 'c': | |
return this.toCelsius($temp.text()); | |
case 'f': | |
return this.toFahrenheit($temp.text()); | |
} | |
}).call(this)); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment