|
1 | 1 | var commonModules = deps.common; |
2 | | -var leafletModules = deps.leaflet; |
3 | | -var openlayersModules = deps.openlayers; |
| 2 | +var clientsTabs = { |
| 3 | + "OpenLayers": "openlayers", |
| 4 | + "Leaflet": "leaflet", |
| 5 | + "MapboxGL": "mapboxgl", |
| 6 | +}; |
| 7 | +//设当前客户端名称,其值为clientsTabs的key值之一 |
| 8 | +var currentClientTab = "OpenLayers"; |
4 | 9 |
|
5 | 10 | function init() { |
6 | | - document.getElementById('select-all').onclick = function () { |
7 | | - select(true); |
8 | | - }; |
9 | | - document.getElementById('deselect-all').onclick = function () { |
10 | | - select(false); |
11 | | - }; |
12 | | - function select(selectAll) { |
13 | | - var lists = $('.deplistContent.active ul'); |
14 | | - for (var i = 0; i < lists.length; i++) { |
15 | | - var checks = lists[i].getElementsByTagName('input'); |
16 | | - for (var j = 0; j < checks.length; j++) { |
17 | | - if (checks[j].id === 'common') { |
18 | | - continue; |
19 | | - } |
20 | | - checks[j].checked = selectAll; |
21 | | - } |
22 | | - var lis = lists[i].getElementsByTagName('li'); |
23 | | - for (var n = 0; n < checks.length; n++) { |
24 | | - if (checks[n].id === 'common') { |
25 | | - continue; |
26 | | - } |
27 | | - lis[n].className = (selectAll) ? 'active' : ''; |
| 11 | + initClientTabs(); |
| 12 | + addModule('common', deplist, true); |
| 13 | + |
| 14 | + $('#deplist li')[0].className = 'active'; |
| 15 | + |
| 16 | + for (var key in clientsTabs) { |
| 17 | + initModules(clientsTabs[key], deps[clientsTabs[key]]); |
| 18 | + } |
| 19 | + |
| 20 | + updateCommand(); |
| 21 | + bindEvents(); |
| 22 | +} |
| 23 | +function initClientTabs() { |
| 24 | + var $clientTabList = $("ul#client"); |
| 25 | + var $clientTabContents = $('div.tab-content'); |
| 26 | + for (var clientName in clientsTabs) { |
| 27 | + var target = clientsTabs[clientName]; |
| 28 | + var $tab = $("<li role='presentation'><a href='#" + target + "select'>" + clientName + "</a></li>").appendTo($clientTabList); |
| 29 | + var $tabContent = $("<div role='tabpanel' class='tab-pane deplistContent' id='" + target + "select'></div>").appendTo($clientTabContents); |
| 30 | + if (clientName === currentClientTab) { |
| 31 | + $tab.addClass("active"); |
| 32 | + $tabContent.addClass("active"); |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +function bindEvents() { |
| 38 | + $('.clientTabs li a').click(function (e) { |
| 39 | + e.preventDefault(); |
| 40 | + currentClientTab = this.innerHTML; |
| 41 | + for (var name in clientsTabs) { |
| 42 | + if (name === currentClientTab) { |
| 43 | + continue; |
28 | 44 | } |
| 45 | + cancelChecked(clientsTabs[name]) |
29 | 46 | } |
30 | 47 | updateCommand(); |
31 | | - return false; |
32 | | - } |
| 48 | + $(this).tab('show'); |
| 49 | + }); |
| 50 | + $('#select-all').on('click', function () { |
| 51 | + select(true); |
| 52 | + }); |
| 53 | + $('#deselect-all').on('click', function () { |
| 54 | + select(false); |
| 55 | + }); |
| 56 | +} |
33 | 57 |
|
34 | | - addModule('common', deplist, true); |
35 | | - $('#deplist li')[0].className = 'active'; |
36 | | - for (var openlayersModule in openlayersModules) { |
37 | | - var title = openlayersModules[openlayersModule].title; |
38 | | - addGroup('openlayers', openlayersModule, title, openlayersModules[openlayersModule].description, $('#openlayersselect')[0]); |
39 | | - for (var module in openlayersModules[openlayersModule]) { |
40 | | - if (module === 'title' || module === 'description') { |
| 58 | +function select(selectAll) { |
| 59 | + var lists = $('.deplistContent.active ul'); |
| 60 | + for (var i = 0; i < lists.length; i++) { |
| 61 | + var checks = lists[i].getElementsByTagName('input'); |
| 62 | + for (var j = 0; j < checks.length; j++) { |
| 63 | + if (checks[j].id === 'common') { |
41 | 64 | continue; |
42 | 65 | } |
43 | | - addModule(module, $('#openlayers_' + openlayersModule)[0], false, openlayersModules[openlayersModule][module].name); |
| 66 | + checks[j].checked = selectAll; |
44 | 67 | } |
45 | | - $('#openlayers_' + openlayersModule).append($("<div style='clear:both;'></div>")); |
46 | | - } |
47 | | - for (var leafletModule in leafletModules) { |
48 | | - var title = leafletModules[leafletModule].title; |
49 | | - addGroup('leaflet', leafletModule, title, leafletModules[leafletModule].description, $('#leafletselect')[0]); |
50 | | - for (var module in leafletModules[leafletModule]) { |
51 | | - if (module === 'title' || module === 'description') { |
| 68 | + var lis = lists[i].getElementsByTagName('li'); |
| 69 | + for (var n = 0; n < checks.length; n++) { |
| 70 | + if (checks[n].id === 'common') { |
52 | 71 | continue; |
53 | 72 | } |
54 | | - addModule(module, $('#leaflet_' + leafletModule)[0], false, leafletModules[leafletModule][module].name); |
| 73 | + lis[n].className = (selectAll) ? 'active' : ''; |
55 | 74 | } |
56 | | - $('#leaflet_' + leafletModule).append($("<div style='clear:both;'></div>")); |
57 | 75 | } |
58 | 76 | updateCommand(); |
| 77 | + return false; |
| 78 | +} |
59 | 79 |
|
60 | | - $('.clientTabs li a').click(function (e) { |
61 | | - e.preventDefault(); |
62 | | - if (this.innerHTML === 'Leaflet') { |
63 | | - cancelChecked('openlayers'); |
64 | | - } |
65 | | - if (this.innerHTML === 'OpenLayers') { |
66 | | - cancelChecked('leaflet'); |
| 80 | +function initModules(clientName, modules) { |
| 81 | + if (!clientName) { |
| 82 | + return; |
| 83 | + } |
| 84 | + clientName = clientName.toLowerCase(); |
| 85 | + |
| 86 | + for (var key in modules) { |
| 87 | + var module = modules[key]; |
| 88 | + var title = module.title; |
| 89 | + addGroup(clientName, key, title, module.description, $("#" + clientName + "select")[0]); |
| 90 | + var $container = $("#" + clientName + "_" + key); |
| 91 | + for (var itemKey in module) { |
| 92 | + if (itemKey === 'title' || itemKey === 'description') { |
| 93 | + continue; |
| 94 | + } |
| 95 | + addModule(itemKey, $container[0], false, module[itemKey].name); |
67 | 96 | } |
68 | | - updateCommand(); |
69 | | - $(this).tab('show'); |
70 | | - }) |
| 97 | + $container.append($("<div style='clear:both;'></div>")); |
| 98 | + } |
71 | 99 | } |
72 | 100 |
|
73 | 101 | function cancelChecked(clientName) { |
@@ -142,22 +170,18 @@ function updateCommand() { |
142 | 170 | } |
143 | 171 | } |
144 | 172 | modulePaths = modulePaths.substring(0, modulePaths.length - 1); |
145 | | - commandInput.value = 'npm run package - ' + getKey() + " " + modulePaths; |
| 173 | + commandInput.value = 'npm run package - ' + getPackage() + " " + modulePaths; |
146 | 174 | } |
147 | 175 |
|
148 | | -function getKey() { |
149 | | - var key = "common"; |
150 | | - for (var check in $('#openlayersselect .deplist li input')) { |
151 | | - if ($('#openlayersselect .deplist li input')[check].checked) { |
152 | | - key = "openlayers"; |
153 | | - } |
154 | | - } |
155 | | - for (var check in $('#leafletselect .deplist li input')) { |
156 | | - if ($('#leafletselect .deplist li input')[check].checked) { |
157 | | - key = "leaflet"; |
| 176 | +function getPackage() { |
| 177 | + var current = clientsTabs[currentClientTab]; |
| 178 | + var $currentTab = $("#" + current + "select .deplist li input"); |
| 179 | + for (var check in $currentTab) { |
| 180 | + if ($currentTab[check].checked) { |
| 181 | + return current; |
158 | 182 | } |
159 | 183 | } |
160 | | - return key; |
| 184 | + return "common"; |
161 | 185 | } |
162 | 186 |
|
163 | 187 | function onCheckboxChange() { |
|
0 commit comments