Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
added options binding
Browse files Browse the repository at this point in the history
  • Loading branch information
politician committed Jul 1, 2012
1 parent 1ceb04f commit 74c4e11
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion outback.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,5 +1134,52 @@
};

})();



/* The "options" binding
Usage:
data-bind="options: @modelAttr, optionsOptions: { }"
Purpose: The options binding is designed to support loading
options for select controls. The binding looks for the CSS
selector specified by @modelAttr, and replaces the contents
of the associated DOM element.
*/
Backbone.outback.bindingHandlers['options'] = (function () {
function optionsFor(valueAccessor, allBindingsAccessor) {
var config, options;

config = {
noContent: '<optgroup label="outback: No optgroups or options found"></optgroup>'
};

options = allBindingsAccessor('optionsOptions');

return config;
}

return {
update: function (element, valueAccessor, allBindingsAccessor, view) {
var config, value, s, $options, $el;
config = optionsFor(valueAccessor, allBindingsAccessor);

value = valueAccessor()();
$el = $(value);

// If it's a script, unpack it.
if (($options = $el.filter('script')).size() > 0) {
$el = $($options.html());
}

// Otherwise, append the options and optgroups; or nothing.
if (($options = $el.filter('optgroup, option')).size() > 0) {
$(element).empty().append($options);
} else {
$(element).html(config.noContent);
}
}
};
})();

}));

0 comments on commit 74c4e11

Please sign in to comment.