]> source.dussan.org Git - archiva.git/commitdiff
better to use a select2 binding: add it
authorOlivier Lamy <olamy@apache.org>
Tue, 5 Mar 2013 00:02:36 +0000 (00:02 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 5 Mar 2013 00:02:36 +0000 (00:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1452604 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/knockout.select2.js [new file with mode: 0644]

diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/knockout.select2.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/knockout.select2.js
new file mode 100644 (file)
index 0000000..886b1c4
--- /dev/null
@@ -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');
+      }
+    };
+
+
+
+})
\ No newline at end of file