Created
February 19, 2010 21:40
-
-
Save apipkin/309243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI.add('text-resize',function(Y){ | |
var _current = 0; | |
var Resize = { | |
MIN : 10, | |
MAX : 18, | |
DEFAULT : 14, | |
UNIT : 'px', | |
COOKIE : 'GP_FONT_SIZE', | |
domready : function() { | |
_current = this._load() || this.DEFAULT; | |
Y.all('.text-resize-up').on('click',function(e){e.preventDefault(); this.up();},this); | |
Y.all('.text-resize-down').on('click',function(e){e.preventDefault(); this.down();},this); | |
this._save(_current); | |
this._update(); | |
}, | |
up : function() { | |
if(_current + 1 <= this.MAX) { | |
this._save(++_current); | |
this._update(); | |
} | |
}, | |
down : function() { | |
if(_current - 1 >= this.MIN) { | |
this._save(--_current); | |
this._update(); | |
} | |
}, | |
_update : function() { | |
Y.one('body').setStyle('fontSize', _current + this.UNIT); | |
}, | |
_save : function(size) { | |
Y.Cookie.set(this.COOKIE, size + this.UNIT, { | |
'expires' : new Date("January 12, 2025"), | |
'path' : '/' | |
}); | |
}, | |
_load : function() { | |
return parseFloat(Y.Cookie.get(this.COOKIE),10); | |
} | |
}; | |
Y.namespace('Text').Resize = Resize; | |
},'1.1',{'requires':['node','event','cookie']}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment