| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Accessibility Widget |
| 4 |
Plugin URI: http://webgrrrl.net/archives/accessibility-widget-revived.htm |
| 5 |
Description: Adds a sidebar widget to enlarge text size in your WP site. Originally created by Tane of Digital Spaghetti (http://www.tripcastradio.com/) and revived by Lorna of WebGrrrl.net. |
| 6 |
Author: Lorna Timbah (webgrrrl) |
| 7 |
Version: 2 |
| 8 |
Author URI: http://webgrrrl.net |
| 9 |
Text Domain: accessibility-widget |
| 10 |
*/ |
| 11 |
class widget_accesstxt extends WP_Widget { |
| 12 |
/** constructor */ |
| 13 |
function widget_accesstxt() { |
| 14 |
parent::WP_Widget(false, $name = 'Accessibility Widget'); |
| 15 |
} |
| 16 |
/** @see WP_Widget::widget */ |
| 17 |
function widget($args, $instance) { |
| 18 |
extract( $args ); |
| 19 |
$title = apply_filters('widget_title', $instance['title']); |
| 20 |
$tags = str_replace(" ", "", $instance['tags']); // remove whitespaces |
| 21 |
$fontsize = str_replace(" ", "", $instance['fontsize']); // remove whitespaces |
| 22 |
$afontsize = explode(",", $fontsize); // transform into arrays |
| 23 |
$controls = explode(",", str_replace(" ", "", $instance['controls'])); // remove whitespaces then transform into arrays |
| 24 |
$tips = explode(",", $instance['tips']); // transform into arrays |
| 25 |
|
| 26 |
echo $before_widget; |
| 27 |
if ( $title ) echo $before_title . $title . $after_title; |
| 28 |
?> |
| 29 |
<script type="text/javascript"> |
| 30 |
//Specify affected tags. Add or remove from list |
| 31 |
var tgs = new Array(<?php echo "'" . str_replace(",", "','", $tags) . "'"; ?>); |
| 32 |
//Specify spectrum of different font sizes |
| 33 |
var szs = new Array(<?php echo "'" . str_replace(",", "','", $fontsize) . "'"; ?>); |
| 34 |
var startSz = 2; |
| 35 |
function ts( trgt,inc ) { |
| 36 |
if (!document.getElementById) return |
| 37 |
var d = document,cEl = null,sz = startSz,i,j,cTags; |
| 38 |
sz = inc; |
| 39 |
if ( sz < 0 ) sz = 0; |
| 40 |
if ( sz > 6 ) sz = 6; |
| 41 |
startSz = sz; |
| 42 |
if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ]; |
| 43 |
cEl.style.fontSize = szs[ sz ]; |
| 44 |
for ( i = 0 ; i < tgs.length ; i++ ) { |
| 45 |
cTags = cEl.getElementsByTagName( tgs[ i ] ); |
| 46 |
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ]; |
| 47 |
} |
| 48 |
} |
| 49 |
</script> |
| 50 |
<ul> |
| 51 |
<li><?php |
| 52 |
$controlscount = count($controls); |
| 53 |
foreach ($afontsize as $key => $value) { |
| 54 |
$icontrols = ($controlscount > 1 ? $key : 0); |
| 55 |
echo "<a href=\"javascript:ts('body'," . $key . ")\" style=\"font-size:" . $value . "\" title=\"" . $tips[$icontrols] . "\">" . $controls[$icontrols] . "</a> "; |
| 56 |
} |
| 57 |
?></li> |
| 58 |
</ul> |
| 59 |
<?php echo $after_widget; ?> |
| 60 |
<?php |
| 61 |
} |
| 62 |
/** @see WP_Widget::update -- do not rename this */ |
| 63 |
function update($new_instance, $old_instance) { |
| 64 |
$instance = $old_instance; |
| 65 |
$instance['title'] = strip_tags($new_instance['title']); |
| 66 |
$instance['tags'] = strip_tags($new_instance['tags']); |
| 67 |
$instance['fontsize'] = strip_tags($new_instance['fontsize']); |
| 68 |
$instance['controls'] = strip_tags($new_instance['controls']); |
| 69 |
$instance['tips'] = strip_tags($new_instance['tips']); |
| 70 |
return $instance; |
| 71 |
} |
| 72 |
/** @see WP_Widget::form -- do not rename this */ |
| 73 |
function form($instance) { |
| 74 |
$str_default = "90%, 100%, 110%, 120%"; |
| 75 |
$title = esc_attr($instance['title']); |
| 76 |
$tags = ($instance['tags'] == "" ? "body,p,li,td" : esc_attr($instance['tags'])); |
| 77 |
$fontsize = ($instance['fontsize'] == "" ? $str_default : esc_attr($instance['fontsize'])); |
| 78 |
$controls = ($instance['controls'] == "" ? $str_default : esc_attr($instance['controls'])); |
| 79 |
$tips = ($instance['tips'] == "" ? $str_default : esc_attr($instance['tips'])); |
| 80 |
?> |
| 81 |
<p> |
| 82 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
| 83 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> |
| 84 |
</p> |
| 85 |
<p> |
| 86 |
<label for="<?php echo $this->get_field_id('tags'); ?>"><?php _e('Resize the following HTML/CSS tags:'); ?></label> |
| 87 |
<input class="widefat" id="<?php echo $this->get_field_id('tags'); ?>" name="<?php echo $this->get_field_name('tags'); ?>" type="text" value="<?php echo $tags; ?>" /><br /> |
| 88 |
Separate each tag with a comma (,) |
| 89 |
</p> |
| 90 |
<p> |
| 91 |
<label for="<?php echo $this->get_field_id('fontsize'); ?>"><?php _e('Set to these sizes:'); ?></label> |
| 92 |
<input class="widefat" id="<?php echo $this->get_field_id('fontsize'); ?>" name="<?php echo $this->get_field_name('fontsize'); ?>" type="text" value="<?php echo $fontsize; ?>" /><br /> |
| 93 |
Separate each size with a comma (,) |
| 94 |
</p> |
| 95 |
<p> |
| 96 |
<label for="<?php echo $this->get_field_id('controls'); ?>"><?php _e('Set controller text:'); ?></label> |
| 97 |
<input class="widefat" id="<?php echo $this->get_field_id('controls'); ?>" name="<?php echo $this->get_field_name('controls'); ?>" type="text" value="<?php echo $controls; ?>" /><br /> |
| 98 |
Separate each controller text with a comma (,) |
| 99 |
</p> |
| 100 |
<p> |
| 101 |
<label for="<?php echo $this->get_field_id('tips'); ?>"><?php _e('Set tooltip text on mouse hover:'); ?></label> |
| 102 |
<input class="widefat" id="<?php echo $this->get_field_id('tips'); ?>" name="<?php echo $this->get_field_name('tips'); ?>" type="text" value="<?php echo $tips; ?>" /><br /> |
| 103 |
Separate each tooltip with a comma (,) |
| 104 |
</p> |
| 105 |
<?php |
| 106 |
} |
| 107 |
} // end class widget_accesstxt |
| 108 |
add_action('widgets_init', create_function('', 'return register_widget("widget_accesstxt");')); |
| 109 |
|