Skip to content

Commit

Permalink
Fixes in order to prevent the flickering from happening with the data…
Browse files Browse the repository at this point in the history
…-viewer
  • Loading branch information
johnmartin committed Oct 3, 2012
1 parent a055bb1 commit c58215e
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions ckan/public/base/javascript/modules/data-viewer.js
Expand Up @@ -4,8 +4,7 @@ this.ckan.module('data-viewer', function (jQuery) {
return {
options: {
timeout: 200,
minHeight: 400,
padding: 42
minHeight: 400
},

initialize: function () {
Expand All @@ -19,39 +18,22 @@ this.ckan.module('data-viewer', function (jQuery) {
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) {
// hide the scrollbar to prevent jumping
$('<style>body{overflow:hidden}</style>').appendTo(this.el.contents().find('body'));
this._recalibrate();
setInterval(function() {
if (!self.el.is(':animated')) {
self._recalibrate();
}
self._recalibrate();
}, this.options.timeout);
} else {
this.el.animate({height: 600}, 600);
this.el.css('height', 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 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));
}
var height = this.el.contents().find('body').outerHeight();
height = Math.max(height, this.options.minHeight);
this.el.css('height', height);
},

// firefox caches iframes so force it to get fresh content
Expand Down

0 comments on commit c58215e

Please sign in to comment.