emjayess
8/28/2011 - 2:21 PM

scripted layout techniques

scripted layout techniques

/**
 * @file: unlayout.js
 */
jQuery(function(){
  (function($,w) {
    var unlayout = {}
    , $w = $(w)
    , $pagehdr = $('#page-header')
    , $sidebar = $('#sidebar')
    , shrinkage = 12; // very arbitrary amount of default shrinkage

    unlayout.respond = function() {
      unlayout.contentHxW();
    };

    unlayout.contentHxW = function() {
      $main
        .height(
          $w.height() - $pagehdr.height() - shrinkage
          //Math.max($w.height(), unlayout.calcHeight()) - $pagehdr.height() - shrinkage
        )
        .width(
          $w.width() - $sidebar.width() - shrinkage
        );
    };

    $w
      // draw on load:
      .bind('load', unlayout.respond)
      // re-draw on resize: todo: debounce on $w.resize!
      .bind('resize', unlayout.respond);

    unlayout.calcHeight = function() { // ~= $.innerHeight()
      return Math.max(
        Math.max(
          d.body.scrollHeight,
          d.documentElement.scrollHeight
        ),
        Math.max(
          d.body.offsetHeight,
          d.documentElement.offsetHeight
        ),
        Math.max(
          d.body.clientHeight,
          d.documentElement.clientHeight
        )
      );
    };

    unlayout.calcWidth = function() { // ~= $.innerWidth()
      return Math.max(
        Math.max(
          d.body.scrollWidth,
          d.documentElement.scrollWidth
        ),
        Math.max(
          d.body.offsetWidth,
          d.documentElement.offsetWidth
        ),
        Math.max(
          d.body.clientWidth,
          d.documentElement.clientWidth
        )
      );
    };

  }(jQuery,window));
});