You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2019/11/29 15:46:07 UTC

[myfaces-tobago] 16/19: Tobago-1999: testing: adapter

This is an automated email from the ASF dual-hosted git repository.

weber pushed a commit to branch TOBAGO-1999_Select2
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 08693ac03a3691031cabd3d748ed28d15de6ebfc
Author: Volker Weber <v....@inexso.de>
AuthorDate: Wed Sep 4 18:52:34 2019 +0200

    Tobago-1999: testing: adapter
---
 .../src/main/webapp/script/demo.js                 | 60 ++++++++++++++++++++++
 .../standard/standard/script/tobago-select2.js     |  3 ++
 2 files changed, 63 insertions(+)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/script/demo.js b/tobago-example/tobago-example-demo/src/main/webapp/script/demo.js
index 5163424..02a8993 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/script/demo.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/script/demo.js
@@ -51,6 +51,66 @@ jQuery.fn.select2.amd.define("CustomTokenizerAdapter", [
      return function(params) {emptyFunc.tokenizer(params)};
     });
 
+jQuery.fn.select2.amd.define("HideDropdown", [
+      "select2/utils",
+      "select2/dropdown",
+      "select2/dropdown/attachBody",
+      "select2/dropdown/attachContainer",
+      "select2/dropdown/search",
+      "select2/dropdown/minimumResultsForSearch"
+    ],
+    function(Utils, Dropdown, AttachBody, AttachContainer, Search, MinimumResultsForSearch) {
+
+      // Decorate the dropdown+search with necessary containers
+      var adapter = Utils.Decorate(Dropdown, AttachBody);
+      adapter.prototype.render = function() {
+        Dropdown.prototype.render.call(this);
+        return jQuery("<span/>");
+      };
+      return adapter;
+    });
+
+
+jQuery.fn.select2.amd.define("CustomDropdownAdapter", [
+      "select2/utils",
+      "select2/dropdown",
+      "select2/dropdown/attachBody",
+      "select2/dropdown/attachContainer",
+      "select2/dropdown/search",
+      "select2/dropdown/minimumResultsForSearch"
+    ],
+    function(Utils, Dropdown, AttachBody, AttachContainer, Search, MinimumResultsForSearch) {
+
+      // Decorate Dropdown with Search functionalities
+      var dropdownWithSearch = Utils.Decorate(Dropdown, Search);
+      dropdownWithSearch.prototype.render = function() {
+        // Copy and modify default search render method
+        var $rendered = Dropdown.prototype.render.call(this);
+        // Add ability for a placeholder in the search box
+        var placeholder = this.options.get("placeholderForSearch") || "";
+        var $search = $(
+            '<span class="select2-search select2-search--dropdown">' +
+            '<input class="select2-search__field" placeholder="' + placeholder + '" type="search"' +
+            ' tabindex="-1" autocomplete="off" autocorrect="off" autocapitalize="off"' +
+            ' spellcheck="false" role="textbox" />' +
+            '</span>'
+        );
+
+        this.$searchContainer = $search;
+        this.$search = $search.find('input');
+
+        // $rendered.prepend($search);
+        return $rendered;
+      };
+
+      // Decorate the dropdown+search with necessary containers
+      var adapter = Utils.Decorate(dropdownWithSearch, AttachContainer);
+      adapter = Utils.Decorate(adapter, AttachBody);
+
+      return adapter;
+    });
+
+
 var TBG_DEMO = {
   Select2: {
     Tokenizer: function (params) {
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-select2.js b/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-select2.js
index 6fb052b..f4222af 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-select2.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-select2.js
@@ -31,6 +31,9 @@ Tobago.Select2 = {
           }
           console.info("Select2.init" + element.attr("id") + " with data: " // @DEV_ONLY
               + JSON.stringify(select2Options));                            // @DEV_ONLY
+          if (typeof select2Options.dropdownAdapter === "string") {
+            select2Options.dropdownAdapter = jQuery.fn.select2.amd.require(select2Options.dropdownAdapter);
+          }
           if (typeof select2Options.tokenizer === "string" && typeof eval(select2Options.tokenizer) === "function") {
             console.info("select2Options.tokenizer: " + typeof select2Options.tokenizer);
             console.info("select2Options.tokenizer: " + typeof eval(select2Options.tokenizer));