OK, I haven't had a chance to test it out yet, and MooTools isn't the library I'm most familiar with (the company I'm at actually uses Prototype.js), but just going off the API this should at least be close.
Code:
window.addEvent('domready', function() {
$("div.caption").each(function(e) {
var imgWidth = e.getParent().getSize().x;
e.setStyle("width", imgWidth);
});
});
Alternatively, is there a way you can retrieve the width via $this->imgSize and then plug that into the caption as an inline style?
Code:
...
[img]<?php echo $this->src; ?>[/img]imgSize; ?> alt="<?php echo $this->alt; ?>" />
<?php if ($this->caption): ?>
<div class="caption" style="width: <?php $this->howeverYouGetTheWidth ?>px"><?php echo $this->caption; ?></div>
<?php endif; ?>
...
I'm not crazy about adding inline styles, but this is one of those rare cases where there is no real good pure CSS solution, and you kind of have to choose the lesser of 2 evils -- inline CSS, or JavaScript.
Bookmarks