Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow upscaling svg files #698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions jquery.colorbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
innerHeight: false,
maxHeight: false,
scalePhotos: true,
scaleVectorUp: true,
scrolling: true,
opacity: 0.9,
preloading: true,
Expand All @@ -51,6 +52,7 @@
slideshowStart: "start slideshow",
slideshowStop: "stop slideshow",
photoRegex: /\.(gif|png|jp(e|g|eg)|bmp|ico|webp|jxr|svg)((#|\?).*)?$/i,
vectorRegex: /\.(svg)((#|\?).*)?$/i,

// alternate image paths for high-res displays
retinaImage: false,
Expand Down Expand Up @@ -219,6 +221,10 @@
return settings.get('photo') || settings.get('photoRegex').test(url);
}

function isVector(settings, url) {
return settings.get('vectorRegex').test(url);
}

function retinaUrl(settings, url) {
return settings.get('retinaUrl') && window.devicePixelRatio > 1 ? url.replace(settings.get('photoRegex'), settings.get('retinaSuffix')) : url;
}
Expand Down Expand Up @@ -975,19 +981,35 @@
photo.width = photo.width / window.devicePixelRatio;
}

var allowUp = isVector(settings, href) && settings.get('scaleVectorUp');

if (settings.get('scalePhotos')) {
setResize = function () {
photo.height -= photo.height * percent;
photo.width -= photo.width * percent;
// Only allow scaling up (percent < 0) when scaleVectorUp was
// specified and this is vector image.
if (percent > 0 || allowUp){
photo.height -= photo.height * percent;
photo.width -= photo.width * percent;
}
};
if (settings.mw && photo.width > settings.mw) {
if (settings.mw) {
percent = (photo.width - settings.mw) / photo.width;
setResize();
}
if (settings.mh && photo.height > settings.mh) {
if (settings.mh) {
percent = (photo.height - settings.mh) / photo.height;
setResize();
}
if (allowUp) {
// If upscaling is allowed, there's a chance that the height scaling
// will have pushed the width beyond the max. To correct that, we
// scale the width once more, only allowing downscaling.
allowUp = false;
if (settings.mw) {
percent = (photo.width - settings.mw) / photo.width;
setResize();
}
}
}

if (settings.h) {
Expand Down