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)’ »
Posted by Danny on February 10, 2009 at 1:19 am under PHP, Web Design.
1 Comment.
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>
Posted by Danny on February 6, 2009 at 2:07 am under jQuery.
5 Comments.
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
’ »
Posted by Danny on February 4, 2009 at 5:27 am under jQuery.
6 Comments.
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!
Posted by Danny on January 29, 2009 at 1:24 pm under jQuery, Web Design.
Comment on this post.
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!
Posted by Danny on January 22, 2009 at 10:21 pm under jQuery.
1 Comment.
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’ »
Posted by Danny on January 16, 2009 at 12:21 am under jQuery, Web Design.
50 Comments.
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’ »
Posted by Danny on January 15, 2009 at 4:48 pm under jQuery.
Comment on this post.
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
’ »
Posted by Danny on January 2, 2009 at 1:08 am under jQuery, Judaism.
7 Comments.
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 1 | Rosh Hashana 2 | Yom Kippur |
Maariv | Person 1 | Person 2 | Person 3 |
Shacharit | Person 4 | Person 5 | Person 6 |
Musaf | Person 7 | Person 8 | Person 9 |
And turn it into this:
When | What | Who |
Rosh Hashana 1 | Maariv | Person 1 |
Rosh Hashana 1 | Shacharit | Person 4 |
Rosh Hashana 1 | Musaf | Person 7 |
Rosh Hashana 2 | Maariv | Person 2 |
Rosh Hashana 2 | Shacharit | Person 5 |
Rosh Hashana 2 | Musaf | Person 8 |
Yom Kippur | Maariv | Person 3 |
Yom Kippur | Shacharit | Person 6 |
Yom Kippur | Musaf | Person 9 |
Continue reading ‘Turning a table into a list in Excel’ »
Posted by Danny on October 23, 2008 at 11:29 pm under Microsoft Office.
Comment on this post.
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.
Posted by Danny on October 23, 2008 at 10:25 pm under Web Design.
Comment on this post.