Skip to content

Instantly share code, notes, and snippets.

@apipkin
Created February 19, 2010 21:40
Show Gist options
  • Save apipkin/309243 to your computer and use it in GitHub Desktop.
Save apipkin/309243 to your computer and use it in GitHub Desktop.
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