Skip to content

Commit

Permalink
[#2648] Add url helper to ckan.url()
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Jul 16, 2012
1 parent 97bb92f commit 7b5fb0a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ckan/public/base/javascript/main.js
Expand Up @@ -14,6 +14,38 @@ this.ckan = this.ckan || {};
this.module.initialize();
};

/* Returns a full url for the current site with the provided path appended.
*
* path - A path to append to the url (default: '/')
* includeLocale - If true the current locale will be added to the page.
*
* Examples
*
* var imageUrl = sandbox.url('/my-image.png');
* // => http://example.ckan.org/my-image.png
*
* var imageUrl = sandbox.url('/my-image.png', true);
* // => http://example.ckan.org/en/my-image.png
*
* var localeUrl = sandbox.url(true);
* // => http://example.ckan.org/en
*
* Returns a url string.
*/
ckan.url = function (path, includeLocale) {
if (typeof path === 'boolean') {
includeLocale = path;
path = '';
}

path = path.replace(/^\//, '');

var root = includeLocale ? ckan.SITE_ROOT : ckan.LOCALE_ROOT;
return path ? root + '/' + path : root;
};

ckan.sandbox.extend({url: ckan.url});

jQuery(function () {
ckan.initialize();
});
Expand Down

0 comments on commit 7b5fb0a

Please sign in to comment.