Skip to content

Commit

Permalink
add aspect-ratio to rias for calculating height (fixes #557)
Browse files Browse the repository at this point in the history
  • Loading branch information
aFarkas committed Dec 7, 2018
1 parent 2d08b1a commit 046f0b6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions plugins/rias/ls.rias.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
absUrl: false,
modifyOptions: noop,
widthmap: {},
ratio: false
ratio: false,
traditionalRatio: false,
'aspect-ratio': false,
};

config = (lazySizes && lazySizes.cfg) || window.lazySizesConfig;
Expand Down Expand Up @@ -159,12 +161,14 @@

options.widths.forEach(function(width){
var widthAlias = options.widthmap[width] || width;
var ratio = options['aspect-ratio'] || options.ratio;
var traditionalRatio = !options['aspect-ratio'] && riasCfg.traditionalRatio;
var candidate = {
u: url.replace(regWidth, widthAlias)
.replace(regHeight, options.ratio ?
riasCfg.traditionalRatio ?
Math.round(width * options.ratio) :
Math.round(width / options.ratio)
.replace(regHeight, ratio ?
traditionalRatio ?
Math.round(width * ratio) :
Math.round(width / ratio)
: ''),
w: width
};
Expand Down

0 comments on commit 046f0b6

Please sign in to comment.