Q:

Page transitions, depending on URL

This code fades each page out, before going to the URL's destination. However, there are some instances where the user doesn't go to a new page, but goes to a PDF in the browser, or it opens the default mail application. On Safari it seems, if you go to an external site (www.twitter.com) and press the back button, the .wrapper is still faded out. (Perhaps a cache thing?)
function fadeAndGo(x) {

        $(x).click(function (e) {
        e.preventDefault();
        var href = this.href;
        $('.wrapper').fadeOut(function(){
            window.location = href;

        });
        // $('.wrapper').delay()fadeIn();
    });
}

fadeAndGo('a');

Is it possible to either:

Fade out, only if the URL does not contain 'PDF, mailto', or is an external link?
Fade in after a certain amount of time (it faded out, but faded back in after a couple of seconds, in case it was a PDF/mailto).

A:

Try this:
function fadeAndGo(x) {
    $(x).click(function (e) {
        e.preventDefault();
        var href = $(this).attr("href");
        if (!/PDF|mailto/gi.test(href)) {
            $('.wrapper').fadeOut(function () {
                window.location = href;
            }).delay(2000).fadeIn();
        } else {
             window.location = href;
        }
    });
}

fadeAndGo('a');

