-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.fontResizer.js
77 lines (58 loc) · 2.06 KB
/
jquery.fontResizer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Change Font size base in a DOM element
* Using jQuery
*/
(function($) {
$.fn.fontResizer = function( options ) {
var opts = $.extend( {}, $.fn.fontResizer.defaults, options);
return this.each(function() {
var $this = $(this);
var o = $.metadata ? $.extend({}, opts, $this.metadata()) : opts;
// if jQuery Cookie is available, store user's preferences
if ( typeof( $.cookie ) != 'undefined' ) {
//console.log( typeof( $.cookie ));
var $cookie_name = "fontResizer_cookie";
var originalFontSize = $this.css("font-size");
// if exists load saved value, otherwise store it
if( $.cookie( $cookie_name ) ) {
var $getSize = $.cookie( $cookie_name );
$this.css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
} else {
$.cookie($cookie_name, originalFontSize);
}
}
// LAUNCH ACTIONS
var increaseLink = $( o.increaseLinkSelector.toString() );
var decreaseLink = $( o.decreaseLinkSelector.toString() );
increaseLink.live( 'click', function( e ) {
e.preventDefault();
e.stopPropagation();
var currentFontSize = $this.css("font-size");
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum + 2;
if (newFontSize < 17) {
$this.css({fontSize : newFontSize});
if ( typeof( $.cookie ) != 'undefined' ) { $.cookie($cookie_name, newFontSize); }
}
return false;
});
decreaseLink.live( 'click', function( e ) {
e.preventDefault();
e.stopPropagation();
var currentFontSize = $this.css("font-size");
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum - 2;
if (newFontSize > 9) {
$this.css({fontSize : newFontSize});
if ( typeof( $.cookie ) != 'undefined' ) { $.cookie($cookie_name, newFontSize); }
}
return false;
});
});
}
})(jQuery);
// Default Values
$.fn.fontResizer.defaults = {
increaseLinkSelector: '.fontPlus',
decreaseLinkSelector: '.fontMinus'
};