Updated Plugins (markdown)

jeena 2013-03-31 13:09:34 -07:00
parent e3877a5e61
commit 1132049da4

@ -108,51 +108,4 @@ ol li .message a.name {
ol li:hover .message a.name { ol li:hover .message a.name {
background: #efefef; background: #efefef;
} }
```
<h2 id="tmp-conv"><a href="#tmp-conv">Add converted temperature</a></h2>
``` javascript
// A Bungloo plugin to automatically convert Fahrenheit to Celsius
// and vice versa. Change the unit in the line: var unit = "F";
$(document).ready(function() {
if(bungloo_instance && bungloo_instance.body) {
bungloo_instance.body.addEventListener(
'DOMNodeInserted',
tmpConv,
false
);
}
});
function tmpConv(e) {
var unit = "F"; // either F or C, the one you want to convert
var element = e.target;
if(element.parentNode != bungloo_instance.body) return;
var message = $(element).find(".message");
var callback = f2cCallback;
if (unit == "C") callback = c2fCallback;
var regex = new RegExp("(-?[0-9]+) ?°? ?" + unit + "+", "ig");
text = message.html().replace(regex, callback);
message.html(text);
}
function f2cCallback(f, fahrenheit) {
fahrenheit = parseInt(fahrenheit, 10);
var celsius = (fahrenheit - 32) * 5 / 9;
return f + " (" + parseInt(celsius) + "°C)";
}
function c2fCallback(c, celsius) {
celsius = parseInt(celsius, 10);
var fahrenheit = celsius * 1.8 + 32;
return c + " (" + parseInt(fahrenheit) + "°F)";
}
``` ```