Bug 25727: (follow-up) Some style updates, JS i18n
[koha-equinox.git] / koha-tmpl / intranet-tmpl / prog / js / select2.js
diff --git a/koha-tmpl/intranet-tmpl/prog/js/select2.js b/koha-tmpl/intranet-tmpl/prog/js/select2.js
new file mode 100644 (file)
index 0000000..5ae8085
--- /dev/null
@@ -0,0 +1,39 @@
+/* global __ */
+$.fn.select2.defaults.set("allowClear", true);
+$.fn.select2.defaults.set("placeholder", "");
+$.fn.select2.defaults.set("width", "element");
+
+// Internationalization
+$.fn.select2.defaults.set("language", {
+    errorLoading:function(){ return __("The results could not be loaded"); },
+    inputTooLong:function(e){
+        var n = e.input.length - e.max;
+        return __("Please delete %d character(s)").format(n);
+    },
+    inputTooShort:function(e){
+        var n = e.min - e.input.length;
+        return __("Please enter %n or more characters").format(n);
+    },
+    formatResult: function(item) {
+        return $('<div>', {title: item.element[0].title}).text(item.text);
+    },
+    loadingMore:function(){ return __("Loading more results…"); },
+    maximumSelected:function(e){
+        return __("You can only select %s item(s)").format(e.max);
+    },
+    noResults:function(){return __("No results found"); },
+    searching:function(){return __("Searching…"); },
+    removeAllItems:function(){return __("Remove all items"); },
+    removeItem:function(){return __("Remove item"); }
+});
+
+$(document).ready(function(){
+    $(".select2").select2();
+    $(".select2").on("select2:clear", function () {
+        $(this).on("select2:opening.cancelOpen", function (evt) {
+            evt.preventDefault();
+
+            $(this).off("select2:opening.cancelOpen");
+        });
+    });
+});