If you're talking about the "If I Told You You Had a Beautiful
Figure..." article, here you go:

function FigureHandler(g, h) {
  if (typeof(h) !== 'object') {
      var h = { '75-100' : 'full-col',
              '67-75' : 'three-quarters-col',
              '50-67' : 'two-thirds-col', '34-50' : 'half-col',
              '25-34' : 'third-col',
              '0-25' : 'quarter-col' };
  }

  var i = 'div.figure';

  if (typeof(g) == 'string')
      i = '#' + g + ' ' + i;

  function init() {
      $(i).each(function () {
          var b = this.getElementsByTagName('img')[0].width;
          var c = parseInt($(this.parentNode).css('width'));
          var d = Math.ceil(b/c*100);
          var e, col_class;

          for (var f in h) {
              e = f.split('-');
              if(d > e[0] && d <= e[1]) {
                  col_class = h[f];
                  break;
              }
          }
          $(this).addClass(col_class);
          $(this.getElementsByTagName('p')).each(function () {
              this.style.width = b+'px';
          });
      });
  }

  init();
}

$(function (){
  new FigureHandler( 'main', { '0-27': 'small', '27-100': 'large' } );
  new FigureHandler( 'extras', { '0-50': 'potato', '50-100':
'tomato' } );
});

On Sep 25, 9:10 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Anyone already has a similar approach based on jQuery? If so, is there
> a chance to share it?
>
> Regards, Erik

Reply via email to