All I wanted to do was back up the Young Israel databases, some way more amenable to automation than phpMyAdmin. There are lots of PHP-based solutions on the web, but all seem based on mysqldump. I implemented one and found myself faced with an eyeful of אריאל מאיר יעקב בן דוד אברהם where the Hebrew names should be. Turns out this a known bug; mysqldump can't handle Unicode. There are reports of workarounds, but I spent 8 hours not getting anything to work.

So I had to write my own backup, going through each database on a server then each table in the database, writing the appropriate INSERT INTO commands (thank goodness the SHOW CREATE DATABASE and SHOW CREATE TABLE commands work correctly). It wasn't terribly miserable (not nearly as miserable it was trying to use someone else's tool that doesn't work), and now I get my  אריאל מאיר יעקב בן דוד אברהם just fine, and the backup works. I import the generated file into my local copy of mySQL and it regenerates the databases.

Continue reading ‘The Agony of Unicode (and backing up mySQL)’ »

I don't like writing function(){$(this).doStuff()} for callbacks and wanted some more elegant way of binding objects to functions. I could always use something like Prototype's bind, but I don't want to modify built-in types (because John Resig says not to) and I generally just want to bind plugins to jQuery objects, so it ought to be a plugin. Inspired by Ariel Flesler's jquery.sugar and John Resig's ultrachaining.

So we have $.later and $.fn.later. $.later() returns a chainable function that is bound at call time to this. $.later().css('color', 'red').append('<span>more</span>') is the same as function() { $(this).css('color', 'red').append('<span>more</span>') }. $(selector, context).later() is similar, but binds to $(selector, context) at call time: $('p').later().css('color', 'red').append('<span>more</span>') is the same as function() { $('p').css('color', 'red').append('<span>more</span>') }

Download the code.

Examples


	$('#example1').click($.later().toggleClass('bold'));
	

	<div id="example1">
		Example 1: 
		<span>Click Me</span>
	</div>
	

	$('#example2').click($('.example:last').later().animate({fontSize: '+=2'}, $('.example:first').later().fadeOut().fadeIn()));
	

	<div id="example2">
		Example 2: 
		<span class="example">Click Me</span> | 
		<span class="example">Watch Me</span>
	</div>
	

One thing that bugged me about my textpopup plugin was that the popup would not necessarily be visible on screen. datepicker moves the widget to a visible spot on screen, which I find very disconcerting. Ariel Flesler's scrollTo was my inspiration, but it scrolls an element so that its top left corner is at the top left of the screen. I want to scroll as little as possible to have the element in its entirety visible. Thus $('#myelement').scrollIntoView().

Download the code.

See the demo.

Continue reading ‘New plugin scrollIntoView’ »

I've updated my widgets tutorials to use jQuery UI 1.6, pulling the rc5 release off the svn site and turning them into pages rather than posts, since they seem to be so popular. See the widget tutorial and the extending widgets page.

Now all I need is for the UI team to officially release 1.6 so I can load it from googleapis rather than the jquery svn!

I keep telling myself I'll learn Haskell but my brain usually fries halfway through the tutorial. I've always thought that javascript is LISP in C's clothing, and jQuery helps undress it a bit. Now it turns out that really jQuery is really forcing it to cross-dress in Haskell. I guess I understood Haskell all along!

Updated 2011-02-28; minor bug fix. Thanks, brian!

Every time I create or use a jQuery plugin, I realize that the assigning of behaviors to elements on the page is a design decision, not a programming one, and one that should be made by the guy in charge of the CSS, not the guy in charge of the javascript. Even when I'm the same guy, I want to wear each hat separately. But these presentational enhancements are written in javascript and applied in javascript. So my "presentational" code is in two different files:

style.css

.gallery a { border: 1px solid green }
style.js

$('.gallery a').lightbox({overlayBgColor: '#ddd'});

I could put the presentational javascript in the HTML with $.metadata but while that's fine for quick-and-dirty pages, it's evil in production since it completely violates the separation of data/structure/presentation/behavior.

As I and others have noted before, the application of these plugins belongs in the stylesheet, and I finally got it to work:

style.css

.gallery a {
  border: 1px solid green;
  -jquery-lightbox: {overlayBgColor: '#ddd'};
}

and a single call to start it off: $(document).parsecss($.parsecss.jquery) .

Download the code.

See the demo.

Continue reading ‘jQuery CSS parser’ »

I was playing with Brandon Aaron's gradient plugin (based on Steven Slayer's gradient) and started adding options and playing with it, so now you can use named colors, percent sizes, and animation.

Download the code.

See the demo page.

Continue reading ‘gradient on steroids’ »

Last modified 2011-10-28; added box option

The Hebrew pop-up keyboard on the YI site search box was always hard-coded and kind of obtrusive, so I wanted to make a jQuery plugin to add a keyboard to any input type="text" or textarea. To make it more flexible, I factored it into a general-purpose popup widget and the keyboard itself.

Download the code.

Continue reading ‘New UI widgets: textpopup and hebrewKeyboard’ »
The yomim tovim are over, so I will hopefully have a chance to play with jQuery again. But on the programming side, one thing I had to do was turn a table of honors, something like this:
Rosh Hashana 1Rosh Hashana 2Yom Kippur
MaarivPerson 1Person 2Person 3
ShacharitPerson 4Person 5Person 6
MusafPerson 7Person 8Person 9
And turn it into this:
WhenWhatWho
Rosh Hashana 1MaarivPerson 1
Rosh Hashana 1ShacharitPerson 4
Rosh Hashana 1MusafPerson 7
Rosh Hashana 2MaarivPerson 2
Rosh Hashana 2ShacharitPerson 5
Rosh Hashana 2MusafPerson 8
Yom KippurMaarivPerson 3
Yom KippurShacharitPerson 6
Yom KippurMusafPerson 9
Continue reading ‘Turning a table into a list in Excel’ »
Switched themes to Barthelme; very simple and elegant. Removed the Chili code highlighting line-numbering, which only worked intermittently, tended to get lost in the margins of the <pre> elements, and didn't add much.