Total Complexity | 4 |
Complexity/F | 1 |
Lines of Code | 32 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /*global jQuery */ |
||
12 | (function( $ ){ |
||
13 | |||
14 | $.fn.fitText = function( kompressor, options ) { |
||
15 | |||
16 | // Setup options |
||
17 | var compressor = kompressor || 1, |
||
18 | settings = $.extend({ |
||
19 | 'minFontSize' : Number.NEGATIVE_INFINITY, |
||
20 | 'maxFontSize' : Number.POSITIVE_INFINITY |
||
21 | }, options); |
||
22 | |||
23 | return this.each(function(){ |
||
24 | |||
25 | // Store the object |
||
26 | var $this = $(this); |
||
27 | |||
28 | // Resizer() resizes items based on the object width divided by the compressor * 10 |
||
29 | var resizer = function () { |
||
30 | $this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize))); |
||
31 | }; |
||
32 | |||
33 | // Call once to set. |
||
34 | resizer(); |
||
35 | |||
36 | // Call on resize. Opera debounces their resize by default. |
||
37 | $(window).on('resize.fittext orientationchange.fittext', resizer); |
||
38 | |||
39 | }); |
||
40 | |||
41 | }; |
||
42 | |||
43 | })( jQuery ); |
||
44 |