-
Notifications
You must be signed in to change notification settings - Fork 2k
/
data-viewer.js
50 lines (46 loc) · 1.5 KB
/
data-viewer.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
// data viewer module
// resizes the iframe when the content is loaded
this.ckan.module('data-viewer', function (jQuery) {
return {
initialize: function () {
jQuery.proxyAll(this, /_on/);
this.el.on('load', this._onLoad);
this._FirefoxFix();
},
_onLoad: function() {
var that = this;
var loc = $('body').data('site-root');
// see if page is in part of the same domain
if (this.el.attr('src').substring(0, loc.length) === loc) {
this._recalibrate();
this.el.contents().find('body').resize(function() {
// this might break in firefox on the graph page
that._recalibrate();
});
} else {
this.el.animate({height: 600}, 600);
}
},
_recalibrate: function() {
// save reference to this to use in timeout
var that = this;
MIN_HEIGHT = 400;
resizeTimer = setTimeout(function() {
var height = that.el.contents().find('body').get(0).scrollHeight;
height = Math.max(height, MIN_HEIGHT);
var deltaHeight = height - that.el.get(0).scrollHeight;
if (deltaHeight > 0 || deltaHeight < -10) {
that.el.animate({height: height+20}, Math.min(700, height*2));
}
}, 100);
},
// firefox caches iframes so force it to get fresh content
_FirefoxFix: function() {
if(/#$/.test(this.el.src)){
this.el.src = this.el.src.substr(0, this.src.length - 1);
} else {
this.el.src = this.el.src + '#';
}
}
};
});