TOBAGO-1633: TS refactoring: split tree and tree-listbox in 2 files
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/package.json b/tobago-theme/tobago-theme-standard/src/main/npm/package.json
index 2c8f1ba..b396faf 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/package.json
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/package.json
@@ -24,7 +24,7 @@
     "css-prefix": "postcss --config postcss.config.js --replace \"css/*.css\" \"!css/*.min.css\"",
     "css-minify": "cleancss --level 1 --source-map --source-map-inline-sources --output css/tobago.min.css css/tobago.css",
     "ts-compile": "tsc",
-    "js-minify": "uglifyjs --compress typeofs=false,drop_console=true --mangle --source-map includeSources --output js/tobago.min.js js/tobago-myfaces.js js/tobago-deltaspike.js js/tobago-polyfill.js js/tobago-listener.js js/tobago-core.js js/tobago-dropdown.js js/tobago-calendar.js js/tobago-command.js js/tobago-file.js js/tobago-focus.js js/tobago-header-footer.js js/tobago-in.js js/tobago-jsf.js js/tobago-overlay.js js/tobago-panel.js js/tobago-popover.js js/tobago-popup.js js/tobago-reload.js js/tobago-select.js js/tobago-sheet.js js/tobago-split-layout.js js/tobago-stars.js js/tobago-suggest.js js/tobago-tab.js js/tobago-tree.js js/tobago-utils.js",
+    "js-minify": "uglifyjs --compress typeofs=false,drop_console=true --mangle --source-map includeSources --output js/tobago.min.js js/tobago-myfaces.js js/tobago-deltaspike.js js/tobago-polyfill.js js/tobago-listener.js js/tobago-core.js js/tobago-dropdown.js js/tobago-calendar.js js/tobago-command.js js/tobago-file.js js/tobago-focus.js js/tobago-header-footer.js js/tobago-in.js js/tobago-jsf.js js/tobago-overlay.js js/tobago-panel.js js/tobago-popover.js js/tobago-popup.js js/tobago-reload.js js/tobago-select.js js/tobago-sheet.js js/tobago-split-layout.js js/tobago-stars.js js/tobago-suggest.js js/tobago-tab.js js/tobago-tree.js js/tobago-tree-listbox.js js/tobago-utils.js",
     "test": "jest"
   },
   "devDependencies": {
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-all.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-all.ts
index f8fda21..a3f884a 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-all.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-all.ts
@@ -37,4 +37,5 @@
 import "./tobago-suggest";
 import "./tobago-tab";
 import "./tobago-tree";
+import "./tobago-tree-listbox";
 import "./tobago-utils";
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
new file mode 100644
index 0000000..94b8821
--- /dev/null
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {Listener, Phase} from "./tobago-listener";
+import {Tobago4Utils} from "./tobago-utils";
+
+class TreeListbox {
+  static init = function (elements) {
+    elements = elements.jQuery ? elements : jQuery(elements); // fixme jQuery -> ES5
+    var treeListbox = Tobago4Utils.selectWithJQuery(elements, ".tobago-treeListbox");
+    // hide select tags for level > root
+    treeListbox.children().find("select:not(:first)").hide();
+
+    var listboxSelects = treeListbox.find("select");
+
+    listboxSelects.children("option").each(TreeListbox.initNextLevel);
+    listboxSelects.each(TreeListbox.initListeners);
+  };
+
+// find all option tags and add the dedicated select tag in its data section.
+  static initNextLevel = function () {
+    var option = jQuery(this);
+    var select = option.closest(".tobago-treeListbox-level").next()
+        .find("[data-tobago-tree-parent='" + option.attr("id") + "']");
+    if (select.length == 1) {
+      option.data("tobago-select", select);
+    } else {
+      var empty = option.closest(".tobago-treeListbox-level").next().children(":first");
+      option.data("tobago-select", empty);
+    }
+  };
+
+// add on change on all select tag, all options that are not selected hide there dedicated
+// select tag, and the selected option show its dedicated select tag.
+  static initListeners = function () {
+
+    jQuery(this).change(TreeListbox.onChange);
+
+    jQuery(this).focus(function () {
+      jQuery(this).change();
+    });
+  };
+
+  static onChange = function () {
+    var listbox = jQuery(this);
+    listbox.children("option:not(:selected)").each(function () {
+      jQuery(this).data("tobago-select").hide();
+    });
+    listbox.children("option:selected").each(function () {
+      jQuery(this).data("tobago-select").show();
+    });
+    TreeListbox.setSelected(listbox);
+
+    // Deeper level (2nd and later) should only show the empty select tag.
+    // The first child is the empty selection.
+    listbox.parent().nextAll(":not(:first)").each(function () {
+      jQuery(this).children(":not(:first)").hide();
+      jQuery(this).children(":first").show();
+    });
+
+  };
+
+  static setSelected = function (listbox) {
+    var hidden = listbox.closest(".tobago-treeListbox").children("[data-tobago-selection-mode]");
+    if (hidden.length == 1) {
+      var selectedValue = ";";
+      listbox.children("option:selected").each(function () {
+        selectedValue += jQuery(this).attr("id") + ";";
+      });
+      hidden.val(selectedValue);
+    }
+  };
+}
+
+Listener.register(TreeListbox.init, Phase.DOCUMENT_READY);
+Listener.register(TreeListbox.init, Phase.AFTER_UPDATE);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts
index 04a6899..df1aebc 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts
@@ -249,74 +249,3 @@
 
 Listener.register(Tree.init, Phase.DOCUMENT_READY);
 Listener.register(Tree.init, Phase.AFTER_UPDATE);
-
-class TreeListbox {
-  static init = function (elements) {
-    elements = elements.jQuery ? elements : jQuery(elements); // fixme jQuery -> ES5
-    var treeListbox = Tobago4Utils.selectWithJQuery(elements, ".tobago-treeListbox");
-    // hide select tags for level > root
-    treeListbox.children().find("select:not(:first)").hide();
-
-    var listboxSelects = treeListbox.find("select");
-
-    listboxSelects.children("option").each(TreeListbox.initNextLevel);
-    listboxSelects.each(TreeListbox.initListeners);
-  };
-
-// find all option tags and add the dedicated select tag in its data section.
-  static initNextLevel = function () {
-    var option = jQuery(this);
-    var select = option.closest(".tobago-treeListbox-level").next()
-        .find("[data-tobago-tree-parent='" + option.attr("id") + "']");
-    if (select.length == 1) {
-      option.data("tobago-select", select);
-    } else {
-      var empty = option.closest(".tobago-treeListbox-level").next().children(":first");
-      option.data("tobago-select", empty);
-    }
-  };
-
-// add on change on all select tag, all options that are not selected hide there dedicated
-// select tag, and the selected option show its dedicated select tag.
-  static initListeners = function () {
-
-    jQuery(this).change(TreeListbox.onChange);
-
-    jQuery(this).focus(function () {
-      jQuery(this).change();
-    });
-  };
-
-  static onChange = function () {
-    var listbox = jQuery(this);
-    listbox.children("option:not(:selected)").each(function () {
-      jQuery(this).data("tobago-select").hide();
-    });
-    listbox.children("option:selected").each(function () {
-      jQuery(this).data("tobago-select").show();
-    });
-    TreeListbox.setSelected(listbox);
-
-    // Deeper level (2nd and later) should only show the empty select tag.
-    // The first child is the empty selection.
-    listbox.parent().nextAll(":not(:first)").each(function () {
-      jQuery(this).children(":not(:first)").hide();
-      jQuery(this).children(":first").show();
-    });
-
-  };
-
-  static setSelected = function (listbox) {
-    var hidden = listbox.closest(".tobago-treeListbox").children("[data-tobago-selection-mode]");
-    if (hidden.length == 1) {
-      var selectedValue = ";";
-      listbox.children("option:selected").each(function () {
-        selectedValue += jQuery(this).attr("id") + ";";
-      });
-      hidden.val(selectedValue);
-    }
-  };
-}
-
-Listener.register(TreeListbox.init, Phase.DOCUMENT_READY);
-Listener.register(TreeListbox.init, Phase.AFTER_UPDATE);
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
index 313ee3f..21b320f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
@@ -89,6 +89,7 @@
           <script name="/tobago/standard/tobago-bootstrap/${project.version}/js/tobago-suggest.js"/>
           <script name="/tobago/standard/tobago-bootstrap/${project.version}/js/tobago-tab.js"/>
           <script name="/tobago/standard/tobago-bootstrap/${project.version}/js/tobago-tree.js"/>
+          <script name="/tobago/standard/tobago-bootstrap/${project.version}/js/tobago-tree-listbox.js"/>
           <script name="/tobago/standard/tobago-bootstrap/${project.version}/js/tobago-utils.js"/>
 -->
           <script name="/tobago/pack/typeahead/0.11.1-patched-with-1212/typeahead.js"/>