Archive for August 3rd, 2008

This page is obsolete (it uses jQuery UI 1.5). Please see the updated page.

This was written largely to help me make sense of using UI to create my own widgets, but I hope it may help others. "Widget" to me means a user-interface element, like a button or something more complicated like a popup date picker, but in jQuery UI terms it means a class, members of which are associated with HTML elements; things like Draggable and Sortable. In fact, not everything that I would have called a widget uses $.widget; the UI datepicker does not.

Continue reading ‘jQuery UI Widgets’ »

Unfortunately, only the administrator seems to be able to use unfiltered HTML.

I also needed to use the Text Control plugin and set formatting to "No Formatting" to prevent escaping the single quotes. But it seems to work.

I just looked at the blog in IE, and it looks like my <pre> elements mess everything up. They have the CSS set as scroll: auto, but IE doesn't care. Honestly, at this point, I don't care either. This blog is for me to document my thoughts on creating the Young Israel website and anyone is welcome to listen in, but you're far better off in Firefox or Safari anyway.

The Using Javascript page in the Codex says to include common javascript files in your header.php file, but that means re-writing it whenever you change themes. I created a simple plugin that includes jQuery and ui.jquery on each page; it's

<?php
/*
Plugin Name: jQuery
Plugin URI: http://bililite.nfshost.com/blog/
Description: Includes the jQuery javascript framework (and the ui.jquery plugins) in your page, with some styling for <pre> elements
Author: Daniel Wachsstock
Version: 1.0
Author URI: http://bililite.nfshost.com/blog/
*/ 

function jQuery(){
echo '
   <script type="text/javascript" src="http://www.google.com/jsapi?key=apikey"></script>
   <script type="text/javascript">google.load("jquery","1");</script>
   <script type="text/javascript" src="http://ui.jquery.com/js/ui.js" ></script>
   <style>
      pre {
        background: #F4F4F4;
        border: 1px solid #B2B2B2;
        overflow: scroll;
      }
    </style>';
}

add_action('wp_head', 'jQuery');

?>

Replace apikey with your own Google API key.

I was trying to figure out how to organize the shiurim in a way that allowed for "AND" filters; something like author=shulman&tag=audio&tanach. Regular expressions won't work; but PHP allows you to use [] after a name and it automatically creates an array, so author=shulman&tag[]=audio&tag[]=tanach works (tag=audio&tag=tanach just overwrites the first tag).
The archive filter is now basically:
function shiurquery($get){
  $ret = '1';
  foreach($get as $query=>$item) $ret .= shiurquerystring($item, $query." REGEXP");
  return $ret;
}

function shiurquerystring ($item, $query){
  if (is_array($item))
    return join (' AND ', array_map ('shiurquerystring', $item, array_fill(0, count($item), $query)));
  return "$query\"$item\"";
}
Where shiurquerystring uses array_map to recursively analyze each element of the array. It's a bit obscure but works, and tighter than a for-each loop.
So shiurquerystring("shulman", "author REGEXP",) returns 'author REGEXP "shulman"' and
shiurquerystring(array("Tanach", "Audio"), "tag REGEXP")
returns 'tag REGEXP "Tanach" AND tag REGEXP "Audio"',
just as we wanted,
and shuirquery(parse_str("author=shulman&tag[]=Audio&tag[]=Tanach") returns
'1 AND author REGEXP "shulman" AND tag REGEXP "Audio" AND tag REGEXP "Tanach'.
Perfect!
The "1 AND" at the beginning makes the coding easier. The actual code is a bit more involved, to prevent cross-site scripting and to limit the filters to specific items.