Skip to content
This repository was archived by the owner on Apr 8, 2021. It is now read-only.

Commit ebd180d

Browse files
committed
Version 2.0.1
1 parent 7c046c8 commit ebd180d

File tree

3 files changed

+60
-51
lines changed

3 files changed

+60
-51
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloudinary-core",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"homepage": "http://cloudinary.com",
55
"authors": [
66
{

cloudinary-core.js

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Cloudinary's JavaScript library - Version 2.0.0
2+
* Cloudinary's JavaScript library - Version 2.0.1
33
* Copyright Cloudinary
44
* see https://github.com/cloudinary/cloudinary_js
55
*/
@@ -2213,9 +2213,9 @@
22132213
*/
22142214
var Cloudinary;
22152215
return Cloudinary = (function() {
2216-
var AKAMAI_SHARED_CDN, CF_SHARED_CDN, DEFAULT_POSTER_OPTIONS, DEFAULT_VIDEO_SOURCE_TYPES, OLD_AKAMAI_SHARED_CDN, SHARED_CDN, VERSION, absolutize, cdnSubdomainNumber, closestAbove, cloudinaryUrlPrefix, defaultBreakpoints, devicePixelRatioCache, finalizeResourceType, responsiveConfig, responsiveResizeInitialized;
2216+
var AKAMAI_SHARED_CDN, CF_SHARED_CDN, DEFAULT_POSTER_OPTIONS, DEFAULT_VIDEO_SOURCE_TYPES, OLD_AKAMAI_SHARED_CDN, SHARED_CDN, VERSION, absolutize, applyBreakpoints, cdnSubdomainNumber, closestAbove, cloudinaryUrlPrefix, defaultBreakpoints, finalizeResourceType, parentWidth;
22172217

2218-
VERSION = "2.0.0";
2218+
VERSION = "2.0.1";
22192219

22202220
CF_SHARED_CDN = "d3jpl91pxevbkh.cloudfront.net";
22212221

@@ -2232,12 +2232,6 @@
22322232

22332233
DEFAULT_VIDEO_SOURCE_TYPES = ['webm', 'mp4', 'ogv'];
22342234

2235-
devicePixelRatioCache = {};
2236-
2237-
responsiveConfig = {};
2238-
2239-
responsiveResizeInitialized = false;
2240-
22412235

22422236
/**
22432237
* @const {Object} Cloudinary.DEFAULT_IMAGE_PARAMS
@@ -2281,6 +2275,9 @@
22812275

22822276
function Cloudinary(options) {
22832277
var configuration;
2278+
this.devicePixelRatioCache = {};
2279+
this.responsiveConfig = {};
2280+
this.responsiveResizeInitialized = false;
22842281
configuration = new cloudinary.Configuration(options);
22852282
this.config = function(newConfig, newValue) {
22862283
return configuration.config(newConfig, newValue);
@@ -2680,24 +2677,24 @@
26802677

26812678
Cloudinary.prototype.responsive = function(options) {
26822679
var ref, ref1, responsiveResize, timeout;
2683-
responsiveConfig = Util.merge(responsiveConfig || {}, options);
2684-
this.cloudinary_update('img.cld-responsive, img.cld-hidpi', responsiveConfig);
2685-
responsiveResize = (ref = (ref1 = responsiveConfig['responsive_resize']) != null ? ref1 : this.config('responsive_resize')) != null ? ref : true;
2686-
if (responsiveResize && !responsiveResizeInitialized) {
2687-
responsiveConfig.resizing = responsiveResizeInitialized = true;
2680+
this.responsiveConfig = Util.merge(this.responsiveConfig || {}, options);
2681+
this.cloudinary_update('img.cld-responsive, img.cld-hidpi', this.responsiveConfig);
2682+
responsiveResize = (ref = (ref1 = this.responsiveConfig['responsive_resize']) != null ? ref1 : this.config('responsive_resize')) != null ? ref : true;
2683+
if (responsiveResize && !this.responsiveResizeInitialized) {
2684+
this.responsiveConfig.resizing = this.responsiveResizeInitialized = true;
26882685
timeout = null;
26892686
return window.addEventListener('resize', (function(_this) {
26902687
return function() {
26912688
var debounce, ref2, ref3, reset, run, wait;
2692-
debounce = (ref2 = (ref3 = responsiveConfig['responsive_debounce']) != null ? ref3 : _this.config('responsive_debounce')) != null ? ref2 : 100;
2689+
debounce = (ref2 = (ref3 = _this.responsiveConfig['responsive_debounce']) != null ? ref3 : _this.config('responsive_debounce')) != null ? ref2 : 100;
26932690
reset = function() {
26942691
if (timeout) {
26952692
clearTimeout(timeout);
26962693
return timeout = null;
26972694
}
26982695
};
26992696
run = function() {
2700-
return _this.cloudinary_update('img.cld-responsive', responsiveConfig);
2697+
return _this.cloudinary_update('img.cld-responsive', _this.responsiveConfig);
27012698
};
27022699
wait = function() {
27032700
reset();
@@ -2765,14 +2762,14 @@
27652762
Cloudinary.prototype.device_pixel_ratio = function() {
27662763
var dpr, dprString, dprUsed;
27672764
dpr = (typeof window !== "undefined" && window !== null ? window.devicePixelRatio : void 0) || 1;
2768-
dprString = devicePixelRatioCache[dpr];
2765+
dprString = this.devicePixelRatioCache[dpr];
27692766
if (!dprString) {
27702767
dprUsed = closestAbove(this.supported_dpr_values, dpr);
27712768
dprString = dprUsed.toString();
27722769
if (dprString.match(/^\d+$/)) {
27732770
dprString += '.0';
27742771
}
2775-
devicePixelRatioCache[dpr] = dprString;
2772+
this.devicePixelRatioCache[dpr] = dprString;
27762773
}
27772774
return dprString;
27782775
};
@@ -2877,6 +2874,25 @@
28772874
return this;
28782875
};
28792876

2877+
applyBreakpoints = function(tag, width, options) {
2878+
var ref, ref1, ref2, ref3, responsive_use_breakpoints;
2879+
responsive_use_breakpoints = (ref = (ref1 = (ref2 = (ref3 = options['responsive_use_breakpoints']) != null ? ref3 : options['responsive_use_stoppoints']) != null ? ref2 : this.config('responsive_use_breakpoints')) != null ? ref1 : this.config('responsive_use_stoppoints')) != null ? ref : 'resize';
2880+
if ((!responsive_use_breakpoints) || (responsive_use_breakpoints === 'resize' && !options.resizing)) {
2881+
return width;
2882+
} else {
2883+
return this.calc_breakpoint(tag, width);
2884+
}
2885+
};
2886+
2887+
parentWidth = function(element) {
2888+
var containerWidth;
2889+
containerWidth = 0;
2890+
while (((element = element != null ? element.parentNode : void 0) instanceof Element) && !containerWidth) {
2891+
containerWidth = Util.width(element);
2892+
}
2893+
return containerWidth;
2894+
};
2895+
28802896

28812897
/**
28822898
* Update hidpi (dpr_auto) and responsive (w_auto) fields according to the current container size and the device pixel ratio.
@@ -2894,7 +2910,7 @@
28942910
*/
28952911

28962912
Cloudinary.prototype.cloudinary_update = function(elements, options) {
2897-
var attrs, container, containerWidth, currentWidth, exact, j, len, ref, ref1, ref2, ref3, ref4, requestedWidth, responsive, responsive_use_breakpoints, src, tag;
2913+
var containerWidth, imageWidth, j, len, ref, requestedWidth, setUrl, src, tag;
28982914
if (options == null) {
28992915
options = {};
29002916
}
@@ -2910,47 +2926,40 @@
29102926
return [elements];
29112927
}
29122928
})();
2913-
responsive_use_breakpoints = (ref = (ref1 = (ref2 = (ref3 = options['responsive_use_breakpoints']) != null ? ref3 : options['responsive_use_stoppoints']) != null ? ref2 : this.config('responsive_use_breakpoints')) != null ? ref1 : this.config('responsive_use_stoppoints')) != null ? ref : 'resize';
2914-
exact = !responsive_use_breakpoints || responsive_use_breakpoints === 'resize' && !options.resizing;
29152929
for (j = 0, len = elements.length; j < len; j++) {
29162930
tag = elements[j];
2917-
if (!((ref4 = tag.tagName) != null ? ref4.match(/img/i) : void 0)) {
2931+
if (!((ref = tag.tagName) != null ? ref.match(/img/i) : void 0)) {
29182932
continue;
29192933
}
2934+
setUrl = true;
29202935
if (options.responsive) {
29212936
Util.addClass(tag, "cld-responsive");
29222937
}
2923-
attrs = {};
29242938
src = Util.getData(tag, 'src-cache') || Util.getData(tag, 'src');
2925-
if (!src) {
2926-
return;
2927-
}
2928-
responsive = Util.hasClass(tag, 'cld-responsive') && src.match(/\bw_auto\b/);
2929-
if (responsive) {
2930-
container = tag.parentNode;
2931-
containerWidth = 0;
2932-
while (container && containerWidth === 0) {
2933-
containerWidth = Util.width(container);
2934-
container = container.parentNode;
2935-
}
2936-
if (containerWidth === 0) {
2937-
return;
2938-
}
2939-
requestedWidth = exact ? containerWidth : this.calc_breakpoint(tag, containerWidth);
2940-
currentWidth = Util.getData(tag, 'width') || 0;
2941-
if (requestedWidth > currentWidth) {
2942-
Util.setData(tag, 'width', requestedWidth);
2943-
} else {
2944-
requestedWidth = currentWidth;
2939+
if (!Util.isEmpty(src)) {
2940+
src = src.replace(/\bdpr_(1\.0|auto)\b/g, 'dpr_' + this.device_pixel_ratio());
2941+
if (Util.hasClass(tag, 'cld-responsive') && /\bw_auto\b/.exec(src)) {
2942+
containerWidth = parentWidth(tag);
2943+
if (containerWidth !== 0) {
2944+
requestedWidth = applyBreakpoints.call(this, tag, containerWidth, options);
2945+
imageWidth = Util.getData(tag, 'width') || 0;
2946+
if (requestedWidth > imageWidth) {
2947+
imageWidth = requestedWidth;
2948+
}
2949+
Util.setData(tag, 'width', requestedWidth);
2950+
src = src.replace(/\bw_auto\b/g, 'w_' + imageWidth);
2951+
Util.setAttribute(tag, 'width', null);
2952+
if (!options.responsive_preserve_height) {
2953+
Util.setAttribute(tag, 'height', null);
2954+
}
2955+
} else {
2956+
setUrl = false;
2957+
}
29452958
}
2946-
src = src.replace(/\bw_auto\b/g, 'w_' + requestedWidth);
2947-
attrs.width = null;
2948-
if (!options.responsive_preserve_height) {
2949-
attrs.height = null;
2959+
if (setUrl) {
2960+
Util.setAttribute(tag, 'src', src);
29502961
}
29512962
}
2952-
attrs.src = src.replace(/\bdpr_(1\.0|auto)\b/g, 'dpr_' + this.device_pixel_ratio());
2953-
Util.setAttributes(tag, attrs);
29542963
}
29552964
return this;
29562965
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloudinary-core",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Cloudinary streamlines your web application’s image manipulation needs. Cloudinary's cloud-based servers automate image uploading, resizing, cropping, optimizing, sprite generation and more.",
55
"main": "cloudinary-core.js",
66
"repository": {

0 commit comments

Comments
 (0)