Yahoo! UI Library

gallery-nodelist-extras  1.0.0

Yahoo! UI Library > gallery-nodelist-extras > slideshow-image-scaler.js (source view)
Search:
 
Filters
var ImageScaling = function(config) {
	this._ss = config.host;

	ImageScaling.superclass.constructor.apply(this, arguments);
};

ImageScaling.NS = 'scaling';
ImageScaling.NAME = 'slideshowImageScaler';

ImageScaling.ATTRS = {
	height: {
		validator: Y.Lang.isNumber
	},
	width: {
		validator: Y.Lang.isNumber
	},
	scaleFactor: {
		validator: Y.Lang.isNumber
	}
};

Y.extend(ImageScaling, Y.Plugin.Base, {
	initializer: function(config) {
		this.doAfter("_createImage", this._scaleImage);
	},
	_scaleImage: function(img) {
		var scaleFactor = this.get('scaleFactor'),
		    width = img.width || this.get('width'),
		    height = img.height || this.get('height'),
		    imageNode = img._node.one('img');

		if (scaleFactor) {
			imageNode.setStyles({height: scaleFactor + '%', width: scaleFactor + '%'});
		} else {
			if (width) { imageNode.setStyle('width', width); }
			if (height){ imageNode.setStyle('height', height); }
		}
	}
});

Y.SlideShow.ImageScaler = ImageScaling;

Copyright © 2011 Yahoo! Inc. All rights reserved.