Skip to content

Instantly share code, notes, and snippets.

@jtaby
Created April 14, 2010 01:22
Show Gist options
  • Save jtaby/365338 to your computer and use it in GitHub Desktop.
Save jtaby/365338 to your computer and use it in GitHub Desktop.
NPR.HTMLView = SC.View.extend({
childViews: 'article'.w(),
article: SC.View.extend(SC.StaticLayout, {
useStaticLayout: YES,
classNames: 'content-box'.w(),
htmlContent: '',
htmlContentBinding: '.owner.htmlContent',
displayProperties: 'htmlContent'.w(),
render: function(context, firstTime) {
context.begin('div')
.push(this.get('htmlContent'))
.end();
this._previousHeights = [];
this.invokeLater(this.adjustHeight,100);
},
_layer: null,
_previousHeights: [],
adjustHeight: function() {
this._layer = this.get('layer');
var layer = this._layer;
var curHeight = layer.clientHeight;
var prevHeights = this._previousHeights;
var i;
// console.log("prevHeights = "+prevHeights);
if(prevHeights.length < 5){
prevHeights.push(curHeight);
}
this._previousHeights = prevHeights;
var changed = (prevHeights.length === 1)? true : false;
for (var j = prevHeights.length - 1; j >= 0; j--){
// console.log("prevHeights = "+prevHeights);
if(prevHeights[j] !== curHeight){
changed = true;
}
}
if(prevHeights.length < 5 && changed){
console.log("curHeight = "+curHeight);
this.get('parentView').articleHeightDidChange(curHeight);
this.invokeLater(this.adjustHeight,1000);
}
}
}),
articleHeightDidChange: function(val) {
// console.log("setting height to "+val);
this.adjust('height',val);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment