Skip to content

Instantly share code, notes, and snippets.

@topherfangio
Created January 25, 2012 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topherfangio/1678118 to your computer and use it in GitHub Desktop.
Save topherfangio/1678118 to your computer and use it in GitHub Desktop.
Simple SC.AutoResize example.
Pharos360.SelectButtonView = SC.SelectButtonView.extend(SC.AutoResize, {
supportsAutoResize: YES,
autoResizeLayer: function() { return this.get('layer') }.property('layer').cacheable(),
autoResizeText: function() { return this.get('longestChoice') }.property('longestChoice').cacheable(),
needsResize: YES,
longestChoice: "",
preferMatrix: null,//[3,0,1,2,3],
changeSelectButtonPreferMatrix: function() {
/*
* Ensure this resizes appropriately with the text.
*/
if (this.get('needsResize')) {
var choices = this.get('objects');
var longestChoice = "";
choices.forEach(function (choice) {
var rep_id = choice.get('report_identifier');
if (rep_id.length > longestChoice.length) {
longestChoice = rep_id;
}
});
this.set('longestChoice', longestChoice + "DDDD");
this.set('needsResize', NO);
}
}.observes('needsResize'),
objectsDidChange: function() {
this.set('needsResize', YES);
}.observes('objects')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment