JQuery

Using jQuery to Simulate the <Blink> tag

March 15, 2010 · 2 min read

While this post actually has nothing to do with ASP.NET MVC directly, the only common denominator is that I came up with this technique while working on the platform.

To be a true 1:1 copy of the previous website I would be converting to ASP.NET MVC, I had to come up with a way to reintroduce the <blink> tag to XHTML. While you are perfectly able to use <blink> it doesn't actually do any blinking in IE8 or Firefox. To show that properly, jQuery comes to the rescue.

The technique is really pretty simple:

  1. Define your element with an arbitrary id or class (i.e.: <div id="#alertheader">)
  2. Style the content accordingly
  3. Use jQuery/javascript to show and hide content on an interval
setInterval(function() {
    jQuery.each(jQuery.browser, function(i) {
        if ($.browser.msie) {
            $('#alertheader').css({ opacity: '0' }).stop().animate({ opacity: '1' }, "fast", "swing");
        }
        if ($.browser.mozilla) {
            $('#alertheader').stop().animate({ opacity: '1' }, "fast", "swing");
        }
    });
}, 600);

You should hopefully notice the caveat I ran into immediately. IE and Firefox animate their opacity changes differently so it required special handling. An easy exercise for the reader would be to optimize this code to remove the IE/Mozilla check during the setInterval call.

You can achieve similar results by using a series of .fadeOut(x).fadeIn(x) calls but I had to make sure the sum of all calls didn't become less than the setInterval "loop" or it would blink wildly. The other problem it introduces is when text "fades" it can often look weird in either browser if you use a relatively fast interval. This became a headache very early on.

While I can't take whole credit for the technique, the primary Stack Overflow problem that got me started can be found here: https://stackoverflow.com/questions/1375646/jquery-animate-opacity-doesnt-work-properly-on-ie. In the post the user Eric states that jQuery should handle the opacity support for you. It does. For some reason to produce output I felt was adequate, no one definition would work across both browsers.

Upcoming ASP.NET MVC posts

January 20, 2010 · 1 min read

Most of this may or may not be relevant to your situation but after completing development, staging, and most of the production implementation of an ASP.NET MVC site I wanted to share some of what I learned.

The majority are one or two-off hacks from someone else's code or a down/upgrade where appropriate, creating a Frankenstein. These won't necessarily be in order I don't think.

  • Homepage - various jQuery plugins & content fetching
  • Content/ structure
  • Elmah

    • Code version: 1.1.11517.2009
    • Downgraded ELMAH_LogError stored procedure to SQL 2000
    • ELMAH_LogError pruning taken from 2 blog posts from a single source
  • Editing 1:1, 1:M or M:M in Entity Framework
  • Validation with xVal and DataAnnotations - straight up from the samples
  • Image/Link/CSS/JScriptHelpers - using tagbuilder to eliminate a lot of code in markup
  • jQuery uses

    • Delete links - tweak of an Http Delete implementation
    • Ajaxy Http Post/Gets
    • Image rollover
    • Google analytics
    • TinyMCE
  • Areas

    • Views/Web.config copied from main project
    • T4MVCAdmin fork to handle Links and Controller references (that is now quite old)
  • SQL 2000 from 2005

    • nvarchar(max) to nvarchar(4000) - ntext is more of a 1:1 mapping but it meant significant stored proc changes
    • using SqlPubWiz
  • MsBuild scripts - dependency chaining, SqlPubWiz integration via Community Tasks, etc.

    • Database
    • Web

I'll try to refer to this verbatim as my defacto outline and even that isn't quite structured correctly enough. It'll work itself out as the posts are made I'm sure. I'm using this to hopefully keep me motivated to completing them all.