Skip to content

Commit

Permalink
feat: implement global parameter defaults with meta tags
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickfogerty committed Nov 27, 2018
1 parent 02b8c7a commit 13bb723
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ImgixTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var ImgixTag = (function() {

if (this.settings.includeLibraryParam) {
params.ixlib = 'imgixjs-' + imgix.VERSION;
}
}

return params;
};
Expand Down
3 changes: 2 additions & 1 deletion src/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
// URL assembly
host: null,
useHttps: true,
includeLibraryParam: true,
includeLibraryParam: true,
defaultParams: {},

// Output element attributes
srcAttribute: 'src',
Expand Down
5 changes: 4 additions & 1 deletion src/imgix.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ util.domReady(function() {
var metaTagValue = getMetaTagValue(key);

if (typeof metaTagValue !== 'undefined') {
const defaultConfigType = typeof defaultConfig[key]
// Only allow boolean values for boolean configs
if (typeof defaultConfig[key] === 'boolean') {
if (defaultConfigType === 'boolean') {
global.imgix.config[key] = !!metaTagValue;
} else if (defaultConfigType === 'object' && defaultConfig[key] != null) {
global.imgix.config[key] = JSON.parse(metaTagValue) || {}
} else {
global.imgix.config[key] = metaTagValue;
}
Expand Down

0 comments on commit 13bb723

Please sign in to comment.