Skip to content

Instantly share code, notes, and snippets.

@abidibo
Created December 5, 2012 09:07
Show Gist options
  • Save abidibo/4214078 to your computer and use it in GitHub Desktop.
Save abidibo/4214078 to your computer and use it in GitHub Desktop.
Accessibilità Gino solo testo/altocontrasto/grafica
**in topBar phpModuleView**
=================================
$encode = true;
if($_SERVER['REQUEST_URI'] == '/index.php') {
$ubase = $_SERVER['REQUEST_URI']."?textview=";
$encode = false;
}
elseif(substr($_SERVER['SCRIPT_URL'], -1) == '/') {
$ubase = $_SERVER['REQUEST_URI']."?";
}
else {
$ubase = $_SERVER['REQUEST_URI']."/?";
}
$buffer .= "<a class=\"no_border aTopBar\" href=\"".$ubase.($encode ? base64_encode('textview=1') : '1')."\">"._("Solo testo")."</a>";
$buffer .= "<a class=\"aTopBar\" href=\"".$ubase.($encode ? base64_encode('textview=2') : '2')."\">"._("Alto contrasto")."</a>";
$buffer .= "<a class=\"aTopBar\" href=\"".$ubase.($encode ? base64_encode('textview=0') : '0')."\">"._("Grafica")."</a>";
if(isset($_GET['textview']) && $_GET['textview'] == 1) {
$_SESSION['textview'] = 1;
$_SESSION['textview_contrast'] = 0;
header("location: ".preg_replace("#(textview=1)|(textview/1)#", "", $_SERVER['SCRIPT_URL']));
}
elseif(isset($_GET['textview']) && $_GET['textview'] == 2) {
$_SESSION['textview'] = 1;
$_SESSION['textview_contrast'] = 1;
header("location: ".preg_replace("#(textview=2)|(textview/2)#", "", $_SERVER['SCRIPT_URL']));
}
elseif(isset($_GET['textview']) && !$_GET['textview']) {
unset($_SESSION['textview']);
unset($_SESSION['textview_contrast']);
header("location: ".preg_replace("#(textview=0)|(textview/0)#", "", $_SERVER['SCRIPT_URL']));
}
if($_SESSION['textview'] == 1) {
$buffer .= "<script type=\"text/javascript\">(function() { tv.toText({contrast: '".($_SESSION['textview_contrast'] ? 'high' : 'normal')."'}); })()</script>";
}
**javascript**
=========================
var tv;
if (!tv) {
tv = {};
}
else if( typeof tv != 'object') {
throw new Error('tv already exists and is not an object');
}
tv.removeCss = function() {
// remove all css
var csss = $$('link[type=text/css]').each(function(css) {
css.dispose();
})
}
tv.addCustomCss = function(opt) {
// remove all css
var fname = opt.contrast == 'high' ? 'textview_contrast.css' : 'textview.css';
var css = Asset.css('css/' + fname);
}
tv.removeIframes = function() {
// remove iframes
var iframes = $$('iframe').each(function(iframe) {
iframe.dispose();
})
}
tv.adjustPositions = function() {
// remove all floats
document.body.getElements('*').each(function(el) {
if(el.getStyle('float') == 'left' || el.getStyle('float') == 'right') {
el.setStyles({
'float': 'none',
'display': 'block'
});
}
if(el.getStyle('position') == 'absolute') {
el.setStyle('position', 'static');
}
})
}
tv.convertImages = function() {
// convert images in alt text
var imgs = $$('img').each(function(img) {
var alt = img.getProperty('alt') || img.getProperty('title');
console.log(alt);
if(!alt) {
//alt = 'Attributo alt mancante';
}
if(alt) {
var alt_sub = new Element('span').set('text', alt);
alt_sub.inject(img, 'after');
}
img.dispose();
})
}
tv.toText = function(opt) {
document.body.setStyle('visibility', 'hidden');
window.addEvent('load', function() {
this.removeCss();
this.addCustomCss(opt);
this.removeIframes();
this.adjustPositions();
this.convertImages();
document.body.setStyle('visibility', 'visible');
}.bind(this))
}
**css**
=========================
a {
margin: 0 2px;
}
body {
color: 333;
}
h1 {
font-size: 1.3em;
}
h2 {
font-size: 1.2em;
}
h3 {
font-size: 1.1em;
}
h4 {
font-size: 1em;
}
section, nav, article {
border: 1px solid #eee;
padding: 10px;
margin: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment