better to use a select2 binding: add it

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1452604 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-03-05 00:02:36 +00:00
parent f945442570
commit 5800980416
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
(function(factory) {
if (typeof define === "function" && define.amd) {
// AMD anonymous module
define("knockout.select2",["jquery","knockout","utils","select2"], factory);
} else {
// No module loader (plain <script> tag) - put directly in global namespace
factory(window.ko, jQuery);
}
})(function ($,ko,utils,select2) {
ko.bindingHandlers.select2 = {
init: function(element, valueAccessor) {
$.log("select2 binding#init");
$(element).select2(valueAccessor());
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).select2('destroy');
});
},
update: function(element) {
$.log("select2 binding#update");
$(element).trigger('change');
}
};
})