Created
April 4, 2012 23:35
-
-
Save basketofsoftkittens/2306580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// homemint/assets/js/models/model.ProductImage.js | |
mint.model.register({ | |
name:"ProductImage", | |
inherits:"ProductImage", // inherits functionality from the mintjs product image model | |
Class:{ | |
defaults:{ | |
// the image name that represents which properties | |
// the contstructor the main image attribute. this | |
// can be passed into the constructor from whichever | |
// view/collection uses this model | |
mainImageName:'about' | |
} | |
initialize:function(attrs){ | |
var raw = this.get("raw") | |
, images = this.get | |
, name = attrs.mainImageName || this.get("mainImageName") | |
, image = | |
{ | |
src:"" // the main image src, | |
height: 0 // image height | |
width: 0 // image width | |
}; | |
if (name == "about") { | |
var tmp = raw.image_attributes; | |
if (tmp && tmp.hm_about_image) { | |
image.height = 20; | |
image.width = 20; | |
image.src = tmp.hm_about_image.replace("{width}",image.width).replace("{height}",image.height); | |
} | |
} | |
if (image.src.length) { | |
// change the image object to use the default image | |
} | |
} | |
}); | |
// use case in showroom : view | |
var product = new ConfigurableProductModel({mainImageName:'about'}); | |
this.render({product:product}); | |
// use case in showroom : template | |
<image src="${product.image.src}" height="${product.image.height}" src="${product.image.width}" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment