fixing one typo and making string formatting consistent.
[oweals/karmaworld.git] / karmaworld / assets / js / pxem.jQuery.js
1 /*-------------------------------------------------------------------- 
2  * jQuery pixel/em conversion plugins: toEm() and toPx()
3  * by Scott Jehl (scott@filamentgroup.com), http://www.filamentgroup.com
4  * Copyright (c) Filament Group
5  * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) or GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
6  * Article: http://www.filamentgroup.com/lab/update_jquery_plugin_for_retaining_scalable_interfaces_with_pixel_to_em_con/
7  * Options:                                                                     
8                 scope: string or jQuery selector for font-size scoping            
9  * Usage Example: $(myPixelValue).toEm(); or $(myEmValue).toPx();
10 --------------------------------------------------------------------*/
11
12 $.fn.toEm = function(settings){
13         settings = jQuery.extend({
14                 scope: 'body'
15         }, settings);
16         var that = parseInt(this[0],10),
17                 scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;">&nbsp;</div>').appendTo(settings.scope),
18                 scopeVal = scopeTest.height();
19         scopeTest.remove();
20         return (that / scopeVal).toFixed(8) + 'em';
21 };
22
23
24 $.fn.toPx = function(settings){
25         settings = jQuery.extend({
26                 scope: 'body'
27         }, settings);
28         var that = parseFloat(this[0]),
29                 scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;">&nbsp;</div>').appendTo(settings.scope),
30                 scopeVal = scopeTest.height();
31         scopeTest.remove();
32         return Math.round(that * scopeVal) + 'px';
33 };