Last active
December 17, 2015 04:59
-
-
Save fabiorochafg/5554263 to your computer and use it in GitHub Desktop.
A way to make resizable fonts accessible.
This file contains 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
.fontSize80 { font-size: 80% !important; } | |
.fontSize90 { font-size: 90% !important; } | |
.fontSize100 { font-size: 100% !important; } | |
.fontSize110 { font-size: 110% !important; } | |
.fontSize120 { font-size: 120% !important; } | |
.fontSize130 { font-size: 130% !important; } | |
.fontSize140 { font-size: 140% !important; } | |
.fontSize150 { font-size: 150% !important; } | |
.fontSize160 { font-size: 160% !important; } | |
.fontSize170 { font-size: 170% !important; } | |
.fontSize180 { font-size: 180% !important; } | |
.fontSize190 { font-size: 190% !important; } | |
.fontSize200 { font-size: 200% !important; } |
This file contains 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
<ul> | |
<li><a href="#" class="increaseFontSize" title="Increase font size">Increase font size</a></li> | |
<li><a href="#" class="normalFontSize" title="Normal font size">Normal font size</a></li> | |
<li><a href="#" class="decreaseFontSize" title="Decrease font size">Decrease font size</a></li> | |
</ul> |
This file contains 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
// Read cookie | |
function getCookie(strCookie){ | |
var strName = strCookie + "="; | |
var arrCookies = document.cookie.split(';'); | |
for (var i = 0; i < arrCookies.length; i++) { | |
var strValorCookie = arrCookies[i]; | |
while (strValorCookie.charAt(0) == ' ') { | |
strValorCookie = strValorCookie.substring(1, strValorCookie.length); | |
} | |
if (strValorCookie.indexOf(strName) == 0) { | |
return strValorCookie.substring(strName.length, strValorCookie.length); | |
} | |
} | |
return ''; | |
} | |
// Set cookie | |
function setCookie(name, value, expires, path, domain, secure) { | |
// set time, it's in milliseconds | |
var today = new Date(); | |
today.setTime( today.getTime() ); | |
/* | |
if the expires variable is set, make the correct | |
expires time, the current script below will set | |
it for x number of days, to make it for hours, | |
delete * 24, for minutes, delete * 60 * 24 | |
*/ | |
path = '/'; | |
if ( expires ) { | |
expires = expires * 1000 * 60 * 60 * 24; | |
} | |
var expires_date = new Date( today.getTime() + (expires) ); | |
document.cookie = name + "=" +escape( value ) + | |
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + | |
( ( path ) ? ";path=" + path : "" ) + | |
( ( domain ) ? ";domain=" + domain : "" ) + | |
( ( secure ) ? ";secure" : "" ); | |
} | |
// Resize font | |
function resizeFont(signal){ | |
var size = 100; | |
var cookieSize = getCookie ("fontSize"); | |
if (cookieSize != ""){ | |
setFontSize(cookieSize); | |
size = parseInt(cookieSize); | |
} | |
if (signal == "plus" && size < 200) { | |
size += 10; | |
} else if (signal == "minus" && size > 80) { | |
size -= 10; | |
} else if (signal == "normal") { | |
size = 100; | |
} | |
setFontSize(size); | |
} | |
// Set Font Size | |
function setFontSize(fontSize){ | |
var cookieSize = getCookie("fontSize"); | |
// Set the containers that will have their fonts resized | |
var ids_containers = ['top','menu','content','footer']; | |
for (i=0; i<ids_containers.length; i++) { | |
var container = document.getElementById(ids_containers[i]); | |
if (container) { | |
$("#" + container.id).removeClass("fontSize" + cookieSize); | |
$("#" + container.id).addClass("fontSize" + fontSize); | |
} | |
} | |
if (cookieSize != fontSize){ | |
setCookie("fontSize", fontSize); | |
} | |
} | |
$(document).ready(function() { | |
var cookieSize = getCookie("fontSize"); | |
if (cookieSize != ""){ | |
setFontSize(cookieSize); | |
} | |
$("a.increaseFontSize").click(function(){ | |
resizeFont("plus"); | |
return(false); | |
}); | |
$("a.decreaseFontSize").click(function(){ | |
resizeFont("minus"); | |
return(false); | |
}); | |
$("a.normalFontSize").click(function(){ | |
resizeFont("normal"); | |
return(false); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment