Skip to content

Instantly share code, notes, and snippets.

@jtaby
Created April 17, 2010 03:03
Show Gist options
  • Save jtaby/369228 to your computer and use it in GitHub Desktop.
Save jtaby/369228 to your computer and use it in GitHub Desktop.
NPR.HTMLView = SC.View.extend({
childViews: 'article'.w(),
htmlContent: '',
article: SC.View.extend(SC.StaticLayout, {
useStaticLayout: YES,
classNames: 'content-box'.w(),
htmlContent: '',
htmlContentBinding: '*owner.htmlContent',
displayProperties: 'htmlContent'.w(),
_layer: null,
_previousHeights: null,
render: function(context, firstTime) {
console.log("rendering");
context.push(this.get('htmlContent'));
this._previousHeights = [];
this.invokeLater(this.adjustHeight,100);
},
adjustHeight: function() {
this._layer = this.get('layer');
var layer = this._layer;
var curHeight = layer.clientHeight;
var prevHeights = this._previousHeights;
var i;
// debugger;
if(prevHeights.length < 10){
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 < 10 && changed){
console.log("curHeight = "+curHeight);
this.get('parentView').articleHeightDidChange(curHeight);
this.invokeLater(this.adjustHeight,1000);
}
}
}),
// htmlContentObserver: function(){
// console.log("this.get('htmlContent') = "+this.get('htmlContent'));
// }.observes('htmlContent'),
//
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