﻿/**
* jQuery fontscale - A plugin to alter the font size of DOM elements 
* For documentation, visit http://byrnecreative.com/blog/fontscale
* Copyright (c) 2010 Ben Byrne - ben(at)fireflypartners(dot)com | http://www.fireflypartners.com
* Dual licensed under MIT and GPL.
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Date: 07/21/2010
* @author Ben Byrne
* @version 0.2
*/

(function(a) { a.fn.fontscale = function(c, b, e) { var d = a.extend(a.fn.fontscale.defaults, e); if (!a.isFunction(a.cookie)) { d.useCookie = false } if (!d.cookieLoaded && a.cookie(d.cookieName) && d.useCookie) { cookieSettings = a.fn.fontscale.readcookie(d.cookieName); if (cookieSettings.unit == d.unit && !d.cookieLoaded) { a.fn.fontscale.scale(c, cookieSettings.delta, d, true) } } this.each(function() { a(this).bind(d.event, function() { a.fn.fontscale.scale(c, b, d, false); if (a.isFunction(d.onAfter)) { d.onAfter(c, b, d) } }) }); return this }; a.fn.fontscale.reset = function(b, c) { a(b).each(function(d) { a(this).css("font-size", ""); if (c.adjustLeading) { a(this).css("line-height", "") } }); if (c.useCookie) { a.fn.fontscale.savecookie("delete", c) } }; a.fn.fontscale.scale = function(d, c, e, b) { var f = 0; if (c == "+" || c == "up") { f = e.increment } else { if (c == "-" || c == "down") { f = e.increment * -1 } else { if (c == "reset") { return a.fn.fontscale.reset(d, e) } else { if (b) { f = parseFloat(c); e.cookieLoaded = true } } } } if (e.unit == "percent" && !b) { f = 1 + (f / 100) } a(d).each(function(h) { var g = parseInt(a(this).css("font-size")); var j = parseInt(a(this).css("line-height")); if (e.unit == "percent") { a(this).css("font-size", Math.round(g * f)); if (e.adjustLeading) { a(this).css("line-height", Math.round(j * f)) } } else { a(this).css("font-size", g + f); if (e.adjustLeading) { a(this).css("line-height", j + f) } } }); if (e.useCookie && !b) { a.fn.fontscale.savecookie(f, e) } return }; a.fn.fontscale.savecookie = function(c, b) { if (c == "delete") { a.cookie(b.cookieName, null, b.cookieParams); return true } if (a.cookie(b.cookieName)) { properties = a.fn.fontscale.readcookie(b.cookieName) } else { properties = { delta: 0} } if (b.unit == properties.unit) { if (b.unit == "percent") { properties.delta = (c) ? properties.delta * c : 1 } else { properties.delta = parseInt(properties.delta) + c } return a.cookie(b.cookieName, "delta=" + properties.delta + "&unit=" + properties.unit, b.cookieParams) } else { a.cookie(b.cookieName, "delta=" + c + "&unit=" + b.unit, b.cookieParams); return true } }; a.fn.fontscale.readcookie = function(b) { val_string = a.cookie(b); var c = {}; a.each(val_string.split("&"), function() { var d = this.split("="); c[d[0]] = d[1] }); return c } })(jQuery); $.fn.fontscale.defaults = { useCookie: true, cookieName: "fontscale", cookieParams: { expires: 30, path: "/" }, increment: 2, unit: "px", adjustLeading: false, event: "click", cookieLoaded: false };
