-
Notifications
You must be signed in to change notification settings - Fork 2k
/
main.js
89 lines (77 loc) · 2.46 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Global ckan namespace
this.ckan = this.ckan || {};
(function (ckan, jQuery) {
ckan.PRODUCTION = 'production';
ckan.DEVELOPMENT = 'development';
ckan.TESTING = 'testing';
/* Initialises the CKAN JavaScript setting up environment variables and
* loading localisations etc. Should be called once the page is ready.
*
* Examples
*
* jQuery(function () {
* ckan.initialize();
* });
*
* Returns nothing.
*/
ckan.initialize = function () {
var body = jQuery('body');
var locale = jQuery('html').attr('lang');
var location = window.location;
var root = location.protocol + '//' + location.host;
function getRootFromData(key) {
return (body.data(key) || root).replace(/\/$/, '');
}
ckan.SITE_ROOT = getRootFromData('siteRoot');
ckan.LOCALE_ROOT = getRootFromData('localeRoot');
ckan.API_ROOT = getRootFromData('apiRoot');
// Load the localisations before instantiating the modules.
ckan.sandbox().client.getLocaleData(locale).done(function (data) {
ckan.i18n.load(data);
ckan.module.initialize();
});
jQuery('[data-target="popover"]').popover();
};
/* 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 = null;
}
path = (path || '').replace(/^\//, '');
var root = includeLocale ? ckan.LOCALE_ROOT : ckan.SITE_ROOT;
return path ? root + '/' + path : root;
};
ckan.sandbox.extend({url: ckan.url});
if (ckan.ENV !== ckan.TESTING) {
jQuery(function () {
ckan.initialize();
});
}
})(this.ckan, this.jQuery);
// Forces this to redraw in Internet Explorer 7
// This is useful for when IE7 doesn't properly render parts of the page after
// some dom manipulation has happened
this.jQuery.fn.ie7redraw = function() {
if (jQuery('html').hasClass('ie7')) {
jQuery(this).css('zoom', 1);
}
};