Skip to content

Commit

Permalink
Fix imports; refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Tocker committed Jan 28, 2019
1 parent 48343a7 commit 7a44076
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 158 deletions.
5 changes: 4 additions & 1 deletion karma.cloudinary-core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Karma configuration
// Generated on Tue Jul 28 2015 09:31:57 GMT+0300 (IDT)
let isProd = mode === 'production';
let mode = isProd ? 'production' : 'development';
console.log(`mode is ${mode}`);
module.exports = function(config) {
return config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
Expand All @@ -11,7 +14,7 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
'node_modules/lodash/lodash.js',
'dist/cloudinary-core.min.js',
'dist/cloudinary-core' + (isProd ? '.min': '') + '.js',
'test/spec/spec-helper.js',
'test/spec/cloudinary-spec.js',
'test/spec/transformation-spec.js',
Expand Down
5 changes: 4 additions & 1 deletion karma.cloudinary-jquery-file-upload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Karma configuration
// Generated on Tue Jul 28 2015 09:31:57 GMT+0300 (IDT)
let isProd = mode === 'production';
let mode = isProd ? 'production' : 'development';
console.log(`mode is ${mode}`);
module.exports = function(config) {
return config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
Expand All @@ -15,7 +18,7 @@ module.exports = function(config) {
'node_modules/blueimp-file-upload/js/jquery.fileupload-process.js',
'node_modules/blueimp-file-upload/js/jquery.iframe-transport.js',
'node_modules/blueimp-file-upload/js/jquery.fileupload-image.js',
'dist/cloudinary-jquery-file-upload.min.js',
'dist/cloudinary-jquery-file-upload' + (isProd ? '.min': '') + '.js',
'test/spec/spec-helper.js',
'test/spec/cloudinary-spec.js',
'test/spec/cloudinary-jquery-upload-spec.js',
Expand Down
5 changes: 4 additions & 1 deletion karma.cloudinary-jquery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Karma configuration
// Generated on Tue Jul 28 2015 09:31:57 GMT+0300 (IDT)
let isProd = mode === 'production';
let mode = isProd ? 'production' : 'development';
console.log(`mode is ${mode}`);
module.exports = function(config) {
return config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
Expand All @@ -10,7 +13,7 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
'node_modules/jquery/dist/jquery.js',
'dist/cloudinary-jquery.min.js',
'dist/cloudinary-jquery' + (isProd ? '.min': '') + '.js',
'test/spec/spec-helper.js',
'test/spec/cloudinary-spec.js',
'test/spec/transformation-spec.js',
Expand Down
42 changes: 7 additions & 35 deletions src/cloudinary.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
var Cloudinary, applyBreakpoints, closestAbove, defaultBreakpoints, findContainerWidth, maxWidth, updateDpr;

import url from './url';
var applyBreakpoints, closestAbove, defaultBreakpoints, findContainerWidth, maxWidth, updateDpr;

import Configuration from './configuration';

import Transformation from './transformation';

import HtmlTag from './tags/htmltag';

import ImageTag from './tags/imagetag';

import PictureTag from './tags/picturetag';
import SourceTag from './tags/sourcetag';

import Transformation from './transformation';
import url from './url';
import VideoTag from './tags/videotag';

import {
Expand All @@ -23,7 +17,6 @@ import {
isArray,
isEmpty,
isFunction,
isPlainObject,
isString,
merge,
removeAttribute,
Expand All @@ -33,16 +26,7 @@ import {
} from './util';

import {
VERSION,
CF_SHARED_CDN,
OLD_AKAMAI_SHARED_CDN,
AKAMAI_SHARED_CDN,
SHARED_CDN,
DEFAULT_POSTER_OPTIONS,
DEFAULT_VIDEO_SOURCE_TYPES,
SEO_TYPES,
DEFAULT_IMAGE_PARAMS,
DEFAULT_VIDEO_PARAMS
DEFAULT_POSTER_OPTIONS
} from './constants';

defaultBreakpoints = function(width, steps = 100) {
Expand Down Expand Up @@ -94,7 +78,7 @@ maxWidth = function(requiredWidth, tag) {
return imageWidth;
};

Cloudinary = class Cloudinary {
var Cloudinary = class Cloudinary {
/**
* Main Cloudinary class
* @class Cloudinary
Expand Down Expand Up @@ -439,24 +423,12 @@ Cloudinary = class Cloudinary {
* @ignore
*/
calc_breakpoint(element, width, steps) {
var breakpoints, point;
breakpoints = getData(element, 'breakpoints') || getData(element, 'stoppoints') || this.config('breakpoints') || this.config('stoppoints') || defaultBreakpoints;
let breakpoints = getData(element, 'breakpoints') || getData(element, 'stoppoints') || this.config('breakpoints') || this.config('stoppoints') || defaultBreakpoints;
if (isFunction(breakpoints)) {
return breakpoints(width, steps);
} else {
if (isString(breakpoints)) {
breakpoints = ((function() {
var j, len, ref, results;
ref = breakpoints.split(',');
results = [];
for (j = 0, len = ref.length; j < len; j++) {
point = ref[j];
results.push(parseInt(point));
}
return results;
})()).sort(function(a, b) {
return a - b;
});
breakpoints = breakpoints.split(',').map(point=>parseInt(point)).sort((a, b) => a - b);
}
return closestAbove(breakpoints, width);
}
Expand Down
14 changes: 3 additions & 11 deletions src/cloudinaryjquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
var webp;

import Cloudinary from './cloudinary';

function firstNotNull(...args) {
while(args && args.length > 0) {
let next = args.shift();
if( next != null){
return next;
}
}
return null;
}
import Transformation from './transformation'
import firstNotNull from './util/firstNotNull'

const CloudinaryJQuery = class CloudinaryJQuery extends Cloudinary {
/**
Expand Down Expand Up @@ -85,7 +77,7 @@ const CloudinaryJQuery = class CloudinaryJQuery extends Cloudinary {
}
}

}
};

/**
* The following methods are provided through the jQuery class
Expand Down
2 changes: 1 addition & 1 deletion src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const Expression = class Expression {
return new this("pageY");
}

}
};

/**
* @internal
Expand Down
1 change: 1 addition & 0 deletions src/jquery-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Depends on 'jquery', 'util', 'cloudinaryjquery', 'jquery.ui.widget', 'jquery.iframe-transport','jquery.fileupload'
*/
import CloudinaryJQuery from './cloudinaryjquery';
import * as Util from './util';

/**
* Delete a resource using the upload token
Expand Down
3 changes: 2 additions & 1 deletion src/layer/fetchlayer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Layer from './layer';

import {
base64EncodeURL,
isString
} from '../util';

Expand Down Expand Up @@ -30,7 +31,7 @@ const FetchLayer = class FetchLayer extends Layer {
* @return {String}
*/
toString() {
return `fetch:${cloudinary.Util.base64EncodeURL(this.options.url)}`;
return `fetch:${base64EncodeURL(this.options.url)}`;
}

};
Expand Down
26 changes: 13 additions & 13 deletions src/layer/textlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var TextLayer = class TextLayer extends Layer {
if (options != null) {
keys.forEach((key) => {
var ref;
return this.options[key] = (ref = options[key]) != null ? ref : options[Util.snakeCase(key)];
return this.options[key] = (ref = options[key]) != null ? ref : options[snakeCase(key)];
});
}
this.options.resourceType = "text";
Expand Down Expand Up @@ -100,25 +100,25 @@ var TextLayer = class TextLayer extends Layer {
publicId = this.getFullPublicId();
}
if (this.options.text != null) {
hasPublicId = !Util.isEmpty(publicId);
hasStyle = !Util.isEmpty(style);
hasPublicId = !isEmpty(publicId);
hasStyle = !isEmpty(style);
if (hasPublicId && hasStyle || !hasPublicId && !hasStyle) {
throw "Must supply either style parameters or a public_id when providing text parameter in a text overlay/underlay, but not both!";
}
re = /\$\([a-zA-Z]\w*\)/g;
start = 0;
// textSource = text.replace(new RegExp("[,/]", 'g'), (c)-> "%#{c.charCodeAt(0).toString(16).toUpperCase()}")
textSource = Util.smartEscape(this.options.text, /[,\/]/g);
textSource = smartEscape(this.options.text, /[,\/]/g);
text = "";
while (res = re.exec(textSource)) {
text += Util.smartEscape(textSource.slice(start, res.index));
text += smartEscape(textSource.slice(start, res.index));
text += res[0];
start = res.index + res[0].length;
}
text += Util.smartEscape(textSource.slice(start));
text += smartEscape(textSource.slice(start));
}
components = [this.options.resourceType, style, publicId, text];
return Util.compact(components).join(":");
return compact(components).join(":");
}

textStyleIdentifier() {
Expand All @@ -137,22 +137,22 @@ var TextLayer = class TextLayer extends Layer {
if (this.options.stroke !== "none") {
components.push(this.options.stroke);
}
if (!(Util.isEmpty(this.options.letterSpacing) && !Util.isNumberLike(this.options.letterSpacing))) {
if (!(isEmpty(this.options.letterSpacing) && !isNumberLike(this.options.letterSpacing))) {
components.push("letter_spacing_" + this.options.letterSpacing);
}
if (!(Util.isEmpty(this.options.lineSpacing) && !Util.isNumberLike(this.options.lineSpacing))) {
if (!(isEmpty(this.options.lineSpacing) && !isNumberLike(this.options.lineSpacing))) {
components.push("line_spacing_" + this.options.lineSpacing);
}
if (!Util.isEmpty(Util.compact(components))) {
if (Util.isEmpty(this.options.fontFamily)) {
if (!isEmpty(compact(components))) {
if (isEmpty(this.options.fontFamily)) {
throw `Must supply fontFamily. ${components}`;
}
if (Util.isEmpty(this.options.fontSize) && !Util.isNumberLike(this.options.fontSize)) {
if (isEmpty(this.options.fontSize) && !isNumberLike(this.options.fontSize)) {
throw "Must supply fontSize.";
}
}
components.unshift(this.options.fontFamily, this.options.fontSize);
components = Util.compact(components).join("_");
components = compact(components).join("_");
return components;
}

Expand Down
5 changes: 3 additions & 2 deletions src/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Transformation from "./transformation";

import {
allStrings,
identity,
isArray,
isEmpty,
isFunction,
Expand Down Expand Up @@ -33,7 +34,7 @@ var Param = class Param {
* @param {function} [process=Util.identity ] - Manipulate origValue when value is called
* @ignore
*/
constructor(name, shortName, process = Util.identity) {
constructor(name, shortName, process = identity) {
/**
* The name of the parameter in snake_case
* @member {string} Param#name
Expand Down Expand Up @@ -266,7 +267,7 @@ var RangeParam = class RangeParam extends Param {
};

var RawParam = class RawParam extends Param {
constructor(name, shortName, process = Util.identity) {
constructor(name, shortName, process = identity) {
super(name, shortName, process);
}

Expand Down
2 changes: 2 additions & 0 deletions src/tags/htmltag.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
merge
} from '../util';

import Transformation from '../transformation';

var HtmlTag = class HtmlTag {
/**
* Represents an HTML (DOM) tag
Expand Down
6 changes: 3 additions & 3 deletions src/tags/imagetag.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ var ImageTag = class ImageTag extends HtmlTag {
if (isString(srcsetParam)) {
responsiveAttributes.srcset = srcsetParam
} else {
responsiveAttributes = generateImageResponsiveAttributes(this.publicId, {}, srcsetParam, options);
responsiveAttributes = generateImageResponsiveAttributes(this.publicId, attributes, srcsetParam, options);
}
if(!isEmpty(responsiveAttributes)) {
delete localOptions.width;
delete localOptions.height;
delete options.width;
delete options.height;
}

merge(attr, responsiveAttributes);
Expand Down
3 changes: 1 addition & 2 deletions src/tags/picturetag.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import HtmlTag from './htmltag';
import ImageTag from './imagetag';
import Transformation from '../transformation';
import url from '../url';
import SourceTag from './sourcetag';
import {extractUrlParams} from "../util";

Expand All @@ -22,7 +22,6 @@ const PictureTag = class PictureTag extends HtmlTag {
options.media = {min_width, max_width};
options.transformation = sourceTransformation;
return new SourceTag(this.publicId, options).toHtml();
// return `<source media="${minWidthPart}${andExpPart}${maxWidthPart}" srcset="${url(this.publicId, options)}">`;
}).join('') +
new ImageTag(this.publicId, this.getOptions()).toHtml();
}
Expand Down
15 changes: 6 additions & 9 deletions src/tags/videotag.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,25 @@ const VideoTag = class VideoTag extends HtmlTag {
}

content() {
var cld, fallback, innerTags, mimeType, sourceTransformation, sourceTypes, src, srcType, transformation, videoType;
var fallback, innerTags, type, sourceTransformation, sourceTypes, src, srcType, transformation, videoType;
sourceTypes = this.transformation().getValue('source_types');
sourceTransformation = this.transformation().getValue('source_transformation');
fallback = this.transformation().getValue('fallback_content');
if (isArray(sourceTypes)) {
cld = new Cloudinary(this.getOptions());
let options = this.getOptions();
innerTags = (function () {
var i, len, results;
results = [];
for (i = 0, len = sourceTypes.length; i < len; i++) {
srcType = sourceTypes[i];
transformation = sourceTransformation[srcType] || {};
src = cld.url(`${this.publicId}`, defaults({}, transformation, {
src = url(`${this.publicId}`, defaults({}, transformation, {
resource_type: 'video',
format: srcType
}));
}, options));
videoType = srcType === 'ogv' ? 'ogg' : srcType;
mimeType = 'video/' + videoType;
results.push(`<source ${this.htmlAttrs({
src: src,
type: mimeType
})}>`);
type = 'video/' + videoType;
results.push(`<source ${this.htmlAttrs({src, type})}>`);
}
return results;
}).call(this);
Expand Down
Loading

0 comments on commit 7a44076

Please sign in to comment.