msnbc.components.InlineArt = msnbc.components.Component.extend({ setup: function(){ // }, insert: function(selectr){ var self = this; jQuery.each(selectr, function() { var p = $(this).parent(); /*add width and class to parent markup*/ if (this.width == 0) { /*dumb browsers get more intensive code*/ $(p).find('span,cite').css({'width': 296 + 'px'}); } else { /*cool browsers get short code*/ $(p.children()).css({'width': this.width + 'px'}); $(p).css({'width': this.width + 'px'}); } $(p).parent().addClass('inlineart'); /*clean up content*/ self.scrubCaption(p, this); if ($(p).find('.img-credit')) { self.reverseCredit($(this).siblings('.img-credit'),$(this).siblings('.caption')); } }); }, scrubCaption: function(parent, img) { /*clean up caption*/ var caption = $(parent).find('.caption'); var ctext = caption.text(); var imgtype = (ctext.indexOf('jpg') > 0) ? imgtype = ctext.indexOf('jpg') : imgtype = ctext.indexOf('JPG'); var alttext = ctext.indexOf($(img).attr('alt')); /*if the caption includes image file information, remove it*/ if (imgtype > 0) { var trim = ctext.substr(0,imgtype); caption.html(trim); } /*if the caption includes the alt text string, remove it*/ if (alttext > 0) { var trim = ctext.substr(0,alttext); caption.html(trim); } }, reverseCredit: function(credit,caption) { var s = credit.children(); var markup = ''; if (s.length > 1) { var byl = $(credit).find('.byline'); var src = $(credit).find('.source'); markup = '
' + $(byl).text() + '/' + $(src).text() + '
'; credit.html(markup); } $(caption).before(credit); } });