()
| 1328 | * @private |
| 1329 | */ |
| 1330 | let _buildOptionBar = function () { |
| 1331 | if (!_canRenderFormattedResult()) { |
| 1332 | _clearOptionBar(); |
| 1333 | return; |
| 1334 | } |
| 1335 | |
| 1336 | let optionBar = $('#optionBar'); |
| 1337 | if (optionBar.length) { |
| 1338 | optionBar.html('').show().addClass('fh-option-bar'); |
| 1339 | } else { |
| 1340 | optionBar = $('<span id="optionBar" class="fh-option-bar" />').appendTo(jfContent.parent()); |
| 1341 | } |
| 1342 | |
| 1343 | plainJsonViewEnabled = false; |
| 1344 | prettyJsonSelectionActive = false; |
| 1345 | jfPre.hide(); |
| 1346 | jfContent.show(); |
| 1347 | |
| 1348 | $('<span class="x-split">|</span>').appendTo(optionBar); |
| 1349 | let buttonFormatted = $('<button class="xjf-btn xjf-btn-left fh-json-meta-toggle">元数据</button>').appendTo(optionBar); |
| 1350 | let buttonCollapseAll = $('<button class="xjf-btn xjf-btn-mid fh-json-collapse-toggle">折叠</button>').appendTo(optionBar); |
| 1351 | let buttonCopyPlain = $('<button class="xjf-btn xjf-btn-mid fh-json-copy-plain" title="复制格式化后的 JSON 全文">复制</button>').appendTo(optionBar); |
| 1352 | |
| 1353 | buttonFormatted.bind('click', function (e) { |
| 1354 | e.preventDefault(); |
| 1355 | e.stopPropagation(); |
| 1356 | _setPlainJsonView(!plainJsonViewEnabled); |
| 1357 | |
| 1358 | jfStatusBar && jfStatusBar.hide(); |
| 1359 | }); |
| 1360 | |
| 1361 | buttonCopyPlain.bind('click', function (e) { |
| 1362 | e.preventDefault(); |
| 1363 | e.stopPropagation(); |
| 1364 | if (!cachedJsonString) { |
| 1365 | toast('暂无可复制的格式化结果,请先执行格式化。'); |
| 1366 | return; |
| 1367 | } |
| 1368 | _copyToClipboard(cachedJsonString, '格式化后的 JSON 全文已复制到剪贴板!'); |
| 1369 | }); |
| 1370 | |
| 1371 | buttonCollapseAll.bind('click', function (e) { |
| 1372 | if (plainJsonViewEnabled) { |
| 1373 | _setPlainJsonView(false); |
| 1374 | } |
| 1375 | |
| 1376 | if (buttonCollapseAll.text() === '折叠') { |
| 1377 | _collapseAllJsonNodes(); |
| 1378 | } else { |
| 1379 | _expandAllJsonNodes(); |
| 1380 | } |
| 1381 | }); |
| 1382 | |
| 1383 | _updatePlainJsonControls(); |
| 1384 | |
| 1385 | }; |
| 1386 | |
| 1387 | // 附加操作 |
no test coverage detected