Within the following block of code:
showContent: function(){
this.box.removeClass('MultiBoxLoading');
this.removeContent();
this.contentContainer = new Element('div', {
'id': 'MultiBoxContentContainer',
'styles': {
opacity: 0,
width: this.contentObj.width,
height: (Number(this.contentObj.height)+this.contentObj.xH)
}
}).inject(this.box,'inside');
The script sets the width of the content box directly to contentObj.width, which works well if the browser has the image cached; however, it may not work as expected otherwise.
Asset.js is used to load an image in the following segment:
load: function(element){
this.box.addClass('MultiBoxLoading');
this.getContent(element);
if(this.type == 'image'){
var xH = this.contentObj.xH;
this.contentObj = new Asset.image(element.href,{onload:this.resize.bind(this)});
this.contentObj.xH = xH;
}else{
this.resize();
};
},
The issue arises because the browser only determines the actual width and height of the image after the onload event fires. Although the image object is returned early into contentObj, it might be best to delay this until after onload triggers. The onload event should handle injecting the image into the container and setting its dimensions instead of calling this.resize(image) immediately.
This insight could guide potential refactoring efforts for optimizing the class functionality.
ADDITIONALLY: var xH = this.contentObj.xH;
and this.contentObj.xH = xH;
-> storing additional elements directly within the object? This method predates mootools 1.2, which introduced closure-based UID-specific storage per element. Such practice can lead to inefficiencies in IE, memory leaks, etc. It's recommended to refactor by utilizing
this.contentObj.store("xH", something)
and
this.contentObj.retrieve("xH")
to retrieve the stored data.