Skip to content

Instantly share code, notes, and snippets.

@ColinCampbell
Created July 7, 2011 19:50
Show Gist options
  • Select an option

  • Save ColinCampbell/1070383 to your computer and use it in GitHub Desktop.

Select an option

Save ColinCampbell/1070383 to your computer and use it in GitHub Desktop.
// ==========================================================================
// Project: HF - Select
// Copyright: ©2011 Strobe Inc.
// ==========================================================================
/*globals Hellfire HF */
/**
@class
@extends SC.TemplateCollectionView
*/
HF.Select = SC.TemplateCollectionView.extend(
/** @scope HF.Select.prototype */ {
attributeBindings: ['selected'],
tagName: 'select',
value: function(key, value) {
var elemQuery = this.$();
if (value !== undefined) {
if (this._value !== value || elemQuery.val() !== value) {
this._value = value;
elemQuery.val(value);
}
} else {
if (elemQuery.length > 0) {
value = this._value = elemQuery.val();
} else {
value = this._value;
}
}
return value;
}.property().idempotent(),
didCreateLayer: function() {
var elemQuery = this.$(),
self = this;
elemQuery.val(this._value);
elemQuery.bind('change', function() {
self.domValueDidChange();
});
},
domValueDidChange: function() {
var elemQuery = this.$();
this.set('value', elemQuery.val());
},
itemViewClass: SC.TemplateView.extend({
attributeBindings: ['label', 'value'],
tagName: 'option'
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment