Updated Plugins (markdown)
parent
e3877a5e61
commit
1132049da4
1 changed files with 0 additions and 47 deletions
47
Plugins.md
47
Plugins.md
|
@ -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)";
|
|
||||||
}
|
|
||||||
```
|
```
|
Reference in a new issue