archive: December 2009

09
DEC
2009

I wished I used widgets. Why havn’t it? Because the coding around them is mostly hardcoded. Lets take a common scenario that I see all the time and from other people:

User A downloads Plugin A. Plugin A has a widget which has hardcoded data output. User A has a custom theme (or a downloaded theme.) and Plugin A does not conform to the theme’s design making User A scramble for help. They check the WordPress.org forums for help in getting Widget of Plugin A changed. User A gets no help. Uninstalls the Plugin A and then is one less user that Author has their plugin installed.

Now my way of what might be coming to a WordPress enabled site soon (3.x.x would be the earliest):

User A downloads Plugin A. Plugin A has a widget. User A has a custom theme (or a downloaded theme) and that theme has a class that extends Walker_Widget called My_Walker_Widget. User A enables that Widget and it looks nice and pretty with their theme. They smile. :)

When the theme author updates their theme, all User’s A widgets will look like they belong there.

The Walker Widget is based of the original walker which controls the design of the output of either pages and categories. This time it’s for Widget design purposes.

I have started a ticket with a first version of a  patch on the WordPress trac site for people to test out. Currently I have change the formatting of all 12 default WordPress plugins to use the new system with the extended classes doing all the formatting. Things can still change between this patch and another. Also in the ticket is an example of my own ‘Walker_Widget_Rabbit’ design class that I have done for my development version of this theme with the Widget changes, but below is an updated version that I worked on including some custom functions I added to the design class.

class Walker_Widget_Rabbit extends Walker_Widget {

 /*
 *
 */
 function start_widget($args, &$output) {
 global $rabbithole;

 $output .= do_action('sidebar_before_module', $args['classname']);
 $output .= do_action('sidebar_before_module_' . $args['classname']);

 if ($this->scrollable($args) && (bool) $rabbithole->get_option('scrolling'))
 $output .= $this->scrollable($args, 'javascript');

 $output .= sprintf( "<div class='module widget %s'>", $args['classname'] );
 }

 /*
 *
 */
 function title_widget($args, &$output) {
 global $rabbithole;

 $output .= "<div class='head'>";
 $output .= "<h3>" . $args['title'] . "</h3>";

 if ($this->scrollable($args) && (bool) $rabbithole->get_option('scrolling'))
 $output .= "<div class='desc'>" . sprintf( __("navi: <a id=\"prev_%s\">prev</a>&nbsp;/&nbsp;<a id=\"next_%s\">next</a>"), $args['classname'], $args['classname']) . "</div>";

 $output .= "</div>";

 }

 /*
 *
 */
 function content_widget($args, &$output) {
 $output .= "<div class='wrap'>" . $this->scrollable($args, 'style') . "</div>";
 }

 function end_widget($args, &$output) {
 $output .= "</div>";
 $output .= do_action('sidebar_after_module', $args['classname']);
 $output .= do_action('sidebar_after_module_' . $args['classname']);
 }

 /** Customer Functions of the Widget Walker **/

 function scrollable($args, $area = 'enabled') {
 global $rabbithole;

 if ( $area == 'enabled' ) {
 switch ($args['classname']) {
 case 'widget_categories':
 case 'widget_archive': return true;
 default: return false;
 }
 }

 if ( $area == 'style' ) {
 switch ($args['style']) {
 case 'none':
 break;
 default:
 $args['output'] = "<ul class='dash-strip'>" . $args['output'] . "</ul>";
 }

 if ($this->scrollable($args) && (bool) $rabbithole->get_option('scrolling'))
 $args['output'] = $this->scrollable($args, 'style_wrap');

 return $args['output'];
 }

 if ( $area == 'style_wrap' ) {

 switch ($args['classname']) {
 case 'widget_categories': return "<div class='content-scroll'>" . $args['output'] . "</div>";
 case 'widget_archive': return "<div class='content-scroll-large'>" . $args['output'] . "</div>";
 }

 }

 if ( $area == 'javascript' ) {

 $obj = $args['classname'];
 switch ($obj) {
 case 'widget_categories': $size = 5;
 case 'widget_archive': $size = 6;
 }

 return "<script type='text/javascript'>
 /* <![CDATA[ */
 jQuery(document).ready(function() {
 jQuery(\".".$obj."\").scrollable({
 vertical: true,
 size: ".$size.",
 keyboard: false,
 items: '.dash-strip',
 easing: 'linear',
 prevPage: '#prev_".$obj."',
 nextPage: '#next_".$obj."',
 disabledClass: 'disabled_Scroll',
 clickable: false
 });
 });
 /* ]]> */
 </script>";
 }

 }

}

Comments 0

Commenting is closed

No Comments Yet