Wednesday
Feb032010

Transitioning to Java

So my work, in the wisdom of someone that is not me has decided that we should standardize the language and environments that we program in to Java and Eclipse.  I am sure you can already sense my excitement.  I'm not particularly afraid of the Java language or even think it will particularly hard to learn the language.   Its nearly identical to C# in syntax and even a lot of the framework is the same, I think.  I think my biggest transition will be the tools around programming.  This means going from Visual Studio to Eclipse.

Click to read more ...

Monday
Nov092009

A Custom Ellipsis Plug-in for JQuery

I had a requirement to be able to show a long description for an item in a limited space.  The descriptions were coming from a 3rd party database and could be of any length.  The design called for the description area being two lines tall.  There is a CSS attribute called text-overflow: ellipsis.  It had several problems, however.  First of all it only worked on a single line basis. Mostly it had the big issue of not working at all in Firefox as it was a non-standard CSS call.

I found a jquery plugin to duplicate the functionality of the CSS call but like the CSS call it only worked on a single line.  My design spec also called for a More/Less link to be affixed to the block of text to expand it/ contract it.  The More/Less also had to support different cultures.

//ellipsis plugin http://devongovett.wordpress.com/2009/04/06/text-overflow-ellipsis-for-firefox-via-jquery/ + comments + custom mods
(function($) {
    $.fn.ellipsis = function(lines, enableUpdating, moreText, lessText) {
        return $(this).each(function() {
            var el = $(this);
            var resetDescription = function(height, originalText) {
            el.html(originalText);
            el.animate({ "height": height }, "normal", null, function() {
                el.ellipsis(true, true, moreText, lessText);
          });
            }

            if (el.css("overflow") == "hidden") {
 
                var originalText = el.html();
                var availWidth = el.width();
                var availHeight = el.height();
 
                var MoreLessTag;
                if (moreText) {
                    enableUpdating = true;
                    MoreLessTag = " <a class='MoreLessTag' href='#' >" + moreText + "</a>";
                }
                else MoreLessTag = "";
 
                var t = $(this.cloneNode(true))
                    .hide()
                    .css({
                        'position': 'absolute',
                        'overflow': 'visible',
                        'max-width': 'none',
                        'max-height': 'none'
                    });
                if (lines) t.css("height", "auto").width(availWidth);
                else t.css("width", "auto");
                el.after(t);
                t.append(" <a class='MoreLessTag' href='#' >" + lessText + "</a>");
 
                var fullHeight = t.height();
 
                var avail = (lines) ? availHeight : availWidth;
                var test = (lines) ? t.height() : t.width();
                var foundMin = false, foundMax = false;
                if (test > avail) {
                    //Binary search style trimming of the temp element to find its optimal size
                    var min = 0;
                    var max = originalText.length;
                    while (min <= max) {
                        var trimLocation = (min + max) / 2;
                        var text = originalText.substr(0, trimLocation);
                        t.html(text + "&hellip;" + MoreLessTag);
 
                        test = (lines) ? t.height() : t.width();
                        if (test > avail) {
                            if (foundMax)
                                foundMin = true;
 
                            max = trimLocation - 1;
                            if (min > max) {
                                //If we would be ending decrement the min and regenerate the text so we don't end with a
                                //slightly larger text than there is space for
                                trimLocation = (max + max - 2) / 2;
                                text = originalText.substr(0, trimLocation);
                                t.html(text + "&hellip;" + MoreLessTag);
                                break;
                            }
                        }
                        else if (test < avail) {
                            min = trimLocation + 1;
                        }
                        else {
                            if (foundMin && foundMax && ((max - min) / max < .2))
                                break;
                            foundMax = true;
                            min = trimLocation + 1;
                        }
                    }
                }
 
                el.html(t.html());
                t.remove();
 
 
                if (moreText) {
                    jQuery(".MoreLessTag", this).click(function(event) {
                        event.preventDefault();
                        el.html(originalText);
                        el.animate({ "height": fullHeight }, "normal", null, function() {
                        });
                        el.append(" <a class='MoreLessTag' href='#' >" + lessText + "</a>");
                        jQuery(".MoreLessTag", el).click(function(event) {
                            event.preventDefault();
                            resetDescription(availHeight, originalText);
 
                        });
                    });
                }
                else {
                    var replaceTags = new RegExp(/<\/?[^>]+>/gi);
                    el.attr("alt", originalText.replace(replaceTags, ''));
                    el.attr("title", originalText.replace(replaceTags, ''));
                }
 
                if (enableUpdating == true) {
                    var oldW = el.width();
                    var oldH = el.height();
                    el.one("resize", function() {
                        if (el.width() != oldW || (lines && el.height != oldH)) {
                            el.html(originalText);
                            el.ellipsis(lines, enableUpdating, moreText, lessText);
                        }
                    });
                }
            }
 
        });
    };
})(jQuery); 

The following features are added from the original:

  • More/Less link with expansion
  • multiple lines
  • title and alt text if no more/less text is provided

This hasn't been tested extensively under different conditions.

Things I would do if I had an infinite amount of time:

  • More Testing
  • Ability to override the More/Less text click event

Enjoy – I hope someone finds this useful.  This was my first foray into doing a jQuery plugin.  Even though a good chunk of the code was copied, I still learned quite a bit.

Wednesday
Sep232009

Today is my 40th Birthday.

Technically, its the 40th Anniversary of my birthday.  I figured I should write something down today so when I am reminiscing 80 years from now, I will remember how it felt to be so young.   If you aren't my future self reading this, well maybe it will give you a bit of insight into my life.  If you aren't interested in that, why are you here on my site? 

Click to read more ...

Wednesday
Sep092009

Exercise Increase

For the last couple of weeks I have been focusing on tracking my calories, in and out.  Much of it has been with the help of a great app my wife found called Calorie Counter on the Android.    Calorie counter links to fatsecret.com which has a database of foods and exercise that you can enter in to keep track of your progress.  A great feature of the app on my G1 is that I can scan a barcode and more likely than not, the food is in the database already.  This makes it very easy to keep track of during the day.   Although I have been trying to eat balanced with not too much of anything, I am not trying a low carb diet at this point.  Just trying to keep the calories I am eating less than the calories my body is comsuming.  You can see my progress at the fatsecret site.  

Yesterday after walking my three miles in the morning (at about 3 mph). I was feeling pretty good and decided that today I would try to move up to jogging.  Although I was able to run/jog down the street, I felt a lot impact on my legs and on my body in general.  I decided that I would just try to increase the speed I was walking until I could lose more wieght and try to run again.   So I completed 2 miles this morning in just over 30 minutes and could definately feel some muscle pain/soreness in my calves shins.  So I will try to work on that speed for the next while until I feel pretty comfortable doing that for one hour or more.  

Friday
Sep042009

Squarespace featured on High Scalability Blog

The High Scalability Blog featured Squarespace recently and it was interesting overview of some of the technology that my site runs on.  I have to admit that I feel a bit guilty not running on Dotnetnuke or another Microsoft platform but I do like the ease of use of Squarespace.    I encountered Squarespace much the same way that Todd @ High Scalability did, through advertising on Twit.TV.  

My main wish is that Squarespace was a bit more extensible.  I'd like to add my own modules.  I'd probably even plug through Java to do it if I had to.  I'd really like to overhaul the Kingdom of Atenveldt Order of Precedence and put it on a platform that runs fast and is consistantly reliable.  This weekend I plan on spending some time on the site, upgrading to the latest version of DNN and maybe working on the skin a bit.  I have had a couple of designers show interest in helping me make a skin but nothing has ever come through with it. Maybe I can bring some more life back to the DNN based Atenveldt site with a bit of TLC. (tender loving care, not the learning channel... )