Ghost/core/shared/ghost-url.js
Austin Burdine 8f89997deb minify ghost.url.api in production
closes #6150
- clean up ghost.url.api script
- switch to inlining config and making the ghost-url.js file an external request
- add minification in production
2015-12-10 08:46:58 -06:00

61 lines
1.5 KiB
JavaScript

(function () {
'use strict';
function generateQueryString(object) {
var queries = [],
i;
if (!object) {
return '';
}
for (i in object) {
if (object.hasOwnProperty(i) && (!!object[i] || object[i] === false)) {
queries.push(i + '=' + encodeURIComponent(object[i]));
}
}
if (queries.length) {
return '?' + queries.join('&');
}
return '';
}
var url = {
config: {},
api: function () {
var args = Array.prototype.slice.call(arguments),
url = (this.config.useOrigin) ? this.config.origin + this.config.url : this.config.url,
queryOptions;
if (args.length && typeof args[args.length - 1] === 'object') {
queryOptions = args.pop();
} else {
queryOptions = {};
}
queryOptions.client_id = this.config.clientId;
queryOptions.client_secret = this.config.clientSecret;
if (args.length) {
args.forEach(function (el) {
url += el.replace(/^\/|\/$/g, '') + '/';
});
}
return url + generateQueryString(queryOptions);
}
};
if (typeof window !== 'undefined') {
window.ghost = window.ghost || {};
url.config = window.ghost.config || {};
window.ghost.url = url;
}
if (typeof module !== 'undefined') {
module.exports = url;
}
})();