In The Shadow of The Fuhrer: Microsoft Announces IE9
Today Microsoft's IEBlog featured "An Early Look at IE9 for Developers," and Extreme Tech had an article about the Professional Developer Conference IE9 Showcase.
There has been significant progress in IE since IE6, but I still can't help fearing the crotch shot that may come if Microsoft makes an announcement similar to this one for real. Hopefully Microsoft has learned a thing or two from polishing the turd that is IE. We'll see.
IE6 Flickering CSS Background Image Solution(s)
As we all go about our lives, hurtling toward a new decade and the future, IE6 is there to kick us in the goods, again.
The problem: In IE6, when you mouseover an element that has a background image, the image flickers on and of. Unacceptable. Ryan Carver over at fivesevensix.com fleshed out the issue way back when.
The solution(s): Microsoft createth and Microsoft solveth, proprietarily of course. Don't get your hopes up too high though, the documentation misspells or rather miscapitolizes a couple of things so their information is just about as good as their browsers.
Javascript:
// The try/catch construct allows you to forgo browser detection. Just fire off the command, and if it fails it probably wasn't IE6 anyway.
try {
document.execCommand("BackgroundImageCache",false,true);
} catch(error){}
CSS:
html {
filter: expression(document.execCommand("BackgroundImageCache", false, true));
}
Credit for originally unearthing the solutions goes to Dan Popa. I've reproduced it here so that I can easily find it up as much as anything else. I hope it helps.
How to Conditionally Set an Animation Target in jQuery
The question: "How can I get the last child of an element, or if the element has no children (is empty), the element itself?"
"Who cares?" you say. Well suppose you have a container that is populated via AJAX calls, and you want to have new items fadeIn() unless the container is empty, in which case, you want to hide() the container itself and use slideDown() to reveal the content.
The initial HTML migth look something like this:
<div id="container"></div>
After a few calls to the server you have something like:
<div id="container"> <div id="item1" class="itemClass"></div> <div id="item2" class="itemClass"></div> <div id="item3" class="itemClass"></div> </div>
One way to accomplish this task would be:
var target;
if($('#container .itemClass').length){
target = $('#container .itemClass:last');
} else {
target = $('#container');
}
target.hide();
// Code to get stuff from the server.
if($('#container') == target){
target.slideDown();
} else {
target.fadeIn();
}
But that doesn't really feel like savvy jQuery. So how do we do it without a lot of conditional statements? Here's how:
var target = $('#container, #container .itemClass').find(':last');
The variable target now contains a reference to the jQuery object that describes either the last element with a class of itemClass, or the container div if it has no children with a class of itemClass. In other words:
For an empty container the above statement is equivalent to:
var target = $('#container');
For a container that has at least one child with a class of itemClass the above statement is equivalent to:
var target = $('#container .itemClass:last');
What now? Glad you asked. The target can now be used for hiding/revealing like so:
target.hide();
// Code to get stuff from the server.
target.hasClass('itemClass') ? target.fadeIn() : target.slideDown() ;
Now, when the page loads and the container is empty, the container is hidden, loaded with content and then revealed using slideDown(). Once the container has been loaded with some content, each new item that is added will fadeIn().
By using the power of jQuery's selectors, we've reduced our code from 12 lines to 3 lines. Not too shabby, and this technique will work equally well for the above example, an unordered list or any content that consists of similar elements wrapped with a containing element.
Time Machine, The Poor Man’s SVN…
First, let me start off by stating that, despite the title of this article, Time Machine is not a replacement for SVN.
Having said that, Time Machine can be setup to backup data in a way that provides some of the same functionality as SVN, namely keeping earlier versions of a file around in case things get so banged up that it is just easier to go back and start over.
WHAT THIS IS: An interesting technique to automatically backup programming/web/design projects meant for fairly savvy users.
WHAT THIS IS NOT: A tutorial on setting up or using Time Machine. A good way to backup your data to protect it from loss.
CAUTION: Following these directions can potentially damage your operating system and/or data. These instructions are based on my own personal experience, you may find that your experience differs in some way. Backup all of your data before attempting this or any operation that modifies your hard drive's partition table. I offer no guarantees or warranties of any kind, proceed at your own risk.
So without further ado, here's what you do:
- Use Boot Camp Assistant to slice off a chunk of hard drive to be used for the Time Machine backup. Since I'm dealing primarily with text based data like HTML, CSS and JavaScript I decided to make the my new partition 10GB (a number between 20 to 30 times the size of your project folder should do nicely).
- Run Boot Camp Assistant (Applications > Utilities > Boot Camp Assistant).
- Click "Continue."
- Select the size for your new partition.
- Click "Partition"
- Once Boot Camp Assistant finishes partitioning your hard drive, QUIT BOOT CAMP ASSISTANT. Either use Cmd-Q or Boot Camp Assistant > Quit. Boot Camp Assistant is designed to help you setup Windows on your Mac, we don't want that, we just wanted to have it partition the hard drive for us.
- Format the new partition. Since Boot Camp Assistant sets up the partition with a Windows filing system, we need to format the partition with the Mac filing system.
- Run Disk Utility. (Applications > Utilities > Disk Utility).
- Select the partition you just created from the list on the left, then select "Erase" from the options at the top of the data area on the right.
- Select "Mac OS Extended (Journaled)" for format and then type in a suitably clever name for the disk.
- Click "Erase", then click it again.
- Setup Time Machine.
- Open System Preferences, then click "Time Machine."
- Click "Select Disk," then pick your disk from the list. Time Machine will gripe that the selected disk is just a partition on the primary disk and it isn' t really backing up data. Bend the machine to your will by continuing with the selected disk anyway.
- Click "Options..." and begin the exclusion fun. Exclude everything except for the folder you want to backup. The quickest way is to exclude everything at the root of your hard drive except for the "Users" directory (if your files are in your account).
- Turn the Time Machine on. It should start the initial backup immediately. I also like to check "Show Time Machine status in the menu bar" as it gives me a quick way to initialize a backup manually if I want to.
- Change the Time Machine schedule.
- Open Terminal.
- At the command prompt enter:
sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 900 - The number, in this case, 900, represents the number of seconds between backups. 900 / 60 = 15 minutes. Adjust the number to suit your needs.
- Get on with your life comfortable in the knowledge that every 15 minutes Time Machine will run and quietly backup any recent changes to the files in your project directory.
That's it. Now when you get to that place where it's better to just pretend the last 3 hours of coding never happened (and we all get to that place once in a while), you can use Time Machine to help cover up your horrible failure.
For more on Time Machine and its use, check out the official Apple support documentation at: http://support.apple.com/kb/HT1427
QUESTIONS I CANNOT ANSWER: (Please feel free to send in answers and I'll add them to the article)
- Can I use this technique with an external drive? I don't know, I've never tried, but I would assume, Yes.
- Can I use this technique if I already have a Boot Camp partition? I don't know, I've never tried, but I don't think so.
- Can I use this technique if I am already using Time Machine to backup data on my computer? I don't know, I've never tried, maybe.