Skip to content

Commit

Permalink
[#2943] Fix preview resize
Browse files Browse the repository at this point in the history
Merged manually from domoritz:fix-dataviewer-iframe
  • Loading branch information
amercader committed Oct 1, 2012
1 parent 5173eca commit 7fed400
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 267 deletions.
6 changes: 5 additions & 1 deletion ckan/public/base/datapreview/css/recline.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ body {
background-color: #fff;
}

.recline-data-explorer{
position: relative;
overflow: auto;
}

.recline-query-editor form, .recline-query-editor .text-query {
height: 28px;
}
Expand Down Expand Up @@ -56,7 +61,6 @@ body {

.loading-dialog {
width: 120px;

}

.loading-spinner {
Expand Down
51 changes: 33 additions & 18 deletions ckan/public/base/javascript/modules/data-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,61 @@
// resizes the iframe when the content is loaded
this.ckan.module('data-viewer', function (jQuery) {
return {
options: {
timeout: 200,
minHeight: 400,
padding: 42
},

initialize: function () {
jQuery.proxyAll(this, /_on/);
this.el.on('load', this._onLoad);
this._FirefoxFix();
},

_onLoad: function() {
var that = this;
var self = 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();
});
setInterval(function() {
if (!self.el.is(':animated')) {
self._recalibrate();
}
}, this.options.timeout);
} else {
this.el.animate({height: 600}, 600);
}
},

_showDebugInfo: function() {
var iframe = this.el;
console.log('=================');
console.log($(iframe.get(0), window.top.document).contents().find('body')[0].scrollHeight);
console.log($(iframe.get(0).contentWindow.document).height());
console.log($(iframe.get(0).contentWindow.document.body).height());
console.log($(iframe.contents().height()));
console.log($(iframe.contents().innerHeight()));
console.log($(iframe.contents().find('html').height()));
console.log($(iframe.contents().find('body').height()));
console.log($(iframe.contents().find('body').innerHeight()));
},

_recalibrate: function() {
// save reference to this to use in timeout
var that = this;
var MIN_HEIGHT = 400;
var PADDING = 16;

resizeTimer = setTimeout(function() {
var height = that.el.contents().height();
height = Math.max(height, MIN_HEIGHT);
var deltaHeight = height - that.el.height();
if (deltaHeight > 0 || deltaHeight < -10) {
that.el.animate({height: height+PADDING}, Math.min(700, height*2));
}
}, 100);
var self = this;
var height = self.el.contents().find('body').height();
height = Math.max(height, self.options.minHeight);
var deltaHeight = height - (self.el.height() - self.options.padding);
if (deltaHeight > 1 || deltaHeight < -10) {
self.el.animate({height: height+self.options.padding}, Math.min(700, height*2));
}
},

// firefox caches iframes so force it to get fresh content
_FirefoxFix: function() {
if(/#$/.test(this.el.src)){
if(/#$/.test(this.el.src)) {
this.el.src = this.el.src.substr(0, this.src.length - 1);
} else {
this.el.src = this.el.src + '#';
Expand Down
247 changes: 0 additions & 247 deletions ckan/public/base/vendor/resize.js

This file was deleted.

1 change: 0 additions & 1 deletion ckan/public/base/vendor/resource.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ fileupload = jquery.js
vendor =
jed.js
html5.js
resize.js
select2/select2.js
select2/select2.css
bootstrap/js/bootstrap-transition.js
Expand Down

0 comments on commit 7fed400

Please sign in to comment.