[jQuery] Re: Aaron Gustafson has a great ALA-Article on (Content-)Image Alignment and Consistency
Hey Remy, thanks for putting this together. But it's not quite working right for me - in Safari it only works when the page is cached. Do you have any ideas what I can do to fix it? Thanks, Ben On Sep 27, 4:29 am, Remy Sharp [EMAIL PROTECTED] wrote: If you're talking about the If I Told You You Had a Beautiful Figure... article, here you go: functionFigureHandler(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 (){ newFigureHandler( 'main', { '0-27': 'small', '27-100': 'large' } ); newFigureHandler( '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
[jQuery] Re: Aaron Gustafson has a great ALA-Article on (Content-)Image Alignment and Consistency
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
[jQuery] Re: Aaron Gustafson has a great ALA-Article on (Content-)Image Alignment and Consistency
Is there a reason you didn't replace this.getElementsByTagName? --Erik On 9/27/07, Remy Sharp [EMAIL PROTECTED] wrote: 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
[jQuery] Re: Aaron Gustafson has a great ALA-Article on (Content-)Image Alignment and Consistency
Is there a reason you didn't replace this.getElementsByTagName? On the first .getElementsByTagName - there's no particular reason to justify using jQuery. However, the second one should really read: $('p', this).each(... There really only there because I did a two minute conversion from Prototype to jQuery.